Version 4.3.6

This commit is contained in:
Neo committed 2025-12-19 05:49:12 -08:00
1 parent fe1acf984a
commit 1a0c7fd3c2
609 files changed
+14707 -5726

No files matched your search

+154 -23
View File
@@ -149,7 +149,12 @@ abstract class _Library
{
$completed[] = $method;
}
$this->software->app->_session = array( 'working' => array(), 'more_info' => $more_info, 'completed' => $completed );
/* Manually set running flag to save write queries */
$running = $this->software->app->_session['running'];
$running[ $method ] = FALSE;
$this->software->app->_session = array( 'working' => array(), 'more_info' => $more_info, 'completed' => $completed, 'running' => $running );
unset( $_SESSION['currentKeyValue'] );
unset( $_SESSION['convertCountRows'][ $method ] );
unset( $_SESSION['convertContinue'] );
@@ -194,10 +199,41 @@ abstract class _Library
/* Set as last key value */
$this->setLastKeyValue( $lastId );
/* Clear the running flag but only after we've given previous runs a chance to clear */
if( $this->software->app->getRunningFlag( $method ) AND $this->software->app->getRunningFlag( $method ) < ( time() - 45 ) )
{
unset( $_SESSION['convertSkipped'] );
$this->software->app->setRunningFlag( $method, FALSE );
}
/* Unset this so we don't do this again. */
unset( $_SESSION['convertContinue'] );
}
/* Conversion process is still running, process may have broken out of the multiredirector */
if( $this->software->app->getRunningFlag( $method ) )
{
/* Count how many times we've seen this */
$_SESSION['convertSkipped'] = ( isset( $_SESSION['convertSkipped'] ) ? $_SESSION['convertSkipped'] : 0 ) + 1;
/* If we've shown this 5 times, and the flag was set more than 60 seconds ago, there's a good chance something is wrong */
if( $_SESSION['convertSkipped'] > 5 AND $this->software->app->getRunningFlag( $method ) < ( time() - 60 ))
{
unset( $_SESSION['convertSkipped'] );
\IPS\Output::i()->error( 'converter_could_not_continue', '2V387/1', 403, '' );
}
/* Generate dots for UI to show that processing is still occuring */
$dots = str_repeat( '.', $_SESSION['convertSkipped'] );
/* Sleep to allow the other process to complete without hammering the server */
sleep(5);
return array( $data, \IPS\Member::loggedIn()->language()->get( 'waiting_previous_process' ) . $dots, 100 / $total * ( $data ) );
}
/* Set conversion as running */
$this->software->app->setRunningFlag( $method, TRUE );
/* Fetch data from the software */
try
{
@@ -212,7 +248,12 @@ abstract class _Library
{
$completed[] = $method;
}
$this->software->app->_session = array( 'working' => array(), 'more_info' => $more_info, 'completed' => $completed );
/* Manually set running flag to save write queries */
$running = $this->software->app->_session['running'];
$running[ $method ] = FALSE;
$this->software->app->_session = array( 'working' => array(), 'more_info' => $more_info, 'completed' => $completed, 'running' => $running );
unset( $_SESSION['currentKeyValue'] );
unset( $_SESSION['convertContinue'] );
return NULL;
@@ -221,6 +262,9 @@ abstract class _Library
{
\IPS\Log::log( $e, 'converters' );
/* Clear the running flag */
$this->software->app->setRunningFlag( $method, FALSE );
$this->software->app->log( $e->getMessage(), __METHOD__, \IPS\convert\App::LOG_WARNING );
throw new \IPS\convert\Exception;
}
@@ -228,11 +272,18 @@ abstract class _Library
{
\IPS\Log::log( $e, 'converters' );
/* Clear the running flag */
$this->software->app->setRunningFlag( $method, FALSE );
$this->software->app->log( $e->getMessage(), __METHOD__, \IPS\convert\App::LOG_WARNING );
throw new \IPS\convert\Exception;
}
$this->software->app->_session = array_merge( $this->software->app->_session, array( 'working' => array( $method => $data + static::$perCycle ) ) );
/* Manually set running flag to save write queries */
$running = $this->software->app->_session['running'];
$running[ $method ] = FALSE;
$this->software->app->_session = array_merge( $this->software->app->_session, array( 'working' => array( $method => $data + static::$perCycle ), 'running' => $running ) );
return array( $data + static::$perCycle, sprintf( \IPS\Member::loggedIn()->language()->get( 'converted_x_of_x' ), ( $data + static::$perCycle > $total ) ? $total : $data + static::$perCycle, \IPS\Member::loggedIn()->language()->addToStack( $this->getMethodFromMenuRows( $method )['step_title'] ), $total ), 100 / $total * ( $data + static::$perCycle ) );
}
}
@@ -365,6 +416,9 @@ abstract class _Library
/* Get the link type */
$menuRows = $this->menuRows();
/* Delete these */
$toDelete = array( 'convert_link' => array(), 'convert_link_pms' => array(), 'convert_link_posts' => array(), 'convert_link_topics' => array() );
foreach( $truncate as $table => $where )
{
/* Kind of a hacky way to make sure we truncate the right forums archive table */
@@ -383,20 +437,55 @@ abstract class _Library
{
$linkType = $menuRows[ $method ]['link_type'];
}
/* Remove links... we don't really care about which table they are in right now */
foreach( array( 'convert_link', 'convert_link_pms', 'convert_link_posts', 'convert_link_topics' ) as $linkTable )
{
if( $linkType !== NULL )
{
\IPS\Db::i()->delete( $linkTable, array( "type=? AND app=?", $linkType, $this->software->app->app_id ) );
continue;
}
\IPS\Db::i()->delete( $linkTable, array( "type=? AND app=?", $table, $this->software->app->app_id ) );
switch( $linkType )
{
default:
$key = $linkType ?: $table;
$toDelete['convert_link'][ $key ] = $key;
break;
case 'core_message_topics':
case 'core_message_posts':
$toDelete['convert_link_pms'][ $linkType ] = $linkType;
break;
case 'forums_topics':
$toDelete['convert_link_topics'][ $linkType ] = $linkType;
break;
case 'forums_posts':
$toDelete['convert_link_posts'][ $linkType ] = $linkType;
break;
}
}
unset( $_SESSION['currentKeyValue'] );
foreach( $toDelete AS $table => $links )
{
if( !\count( $links ) )
{
continue;
}
/* If posts or topics we may be able to truncate */
if( \in_array( $table, array( 'convert_link_topics', 'convert_link_posts' ) ) )
{
try
{
/* Check for other app data in this table */
\IPS\Db::i()->select( 'link_id', $table, array('app<>?', $this->software->app->app_id ), NULL, 1 )->first();
}
catch ( \UnderflowException $e )
{
/* There isn't any other app data in this table, truncate */
\IPS\Db::i()->delete( $table );
continue;
}
}
\IPS\Db::i()->delete( $table, array( \IPS\Db::i()->in( 'type', $links ) . " AND app=?", $this->software->app->app_id ) );
}
/* Clear the running flag */
$this->software->app->setRunningFlag( $method, FALSE );
}
/**
@@ -472,29 +561,71 @@ abstract class _Library
(string) \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=finish&id={$appId}" )
) ) );
}
/**
* Returns an array of items that we can convert, including the amount of rows stored in the Community Suite as well as the recommend value of rows to convert per cycle
*
* @param bool $rowCounts enable row counts
* @return array
*/
abstract public function menuRows();
abstract public function menuRows( $rowCounts=FALSE );
/**
* Utility method to run queries for menuRows() data
*
* @param array $return menuRow() data
* @return array
* @throws \UnderflowException
* @throws \IPS\convert\Exception
*/
public function getDatabaseRowCounts( array $return )
{
foreach( $return as $key => $value )
{
if( isset( $value['ips_rows'] ) AND $value['ips_rows'] instanceof \IPS\Db\Select )
{
$return[ $key ]['ips_rows'] = (int) $value['ips_rows']->first();
}
if( isset( $return[ $key ]['source_rows']['table'] ) )
{
$return[ $key ]['source_rows'] = $this->software->countRows( $value['source_rows']['table'], $value['source_rows']['where'] );
}
}
return $return;
}
/**
* @brief Cache menu row data
*/
protected $_menuRowCache = array( 'rows' => array(), 'noRows' => array() );
/**
* Get method from menu rows - abstracted to allow 'fake' entries not in menuRows()
*
* @param string $method Method requested
* @param string $method Method requested
* @param bool $rowCount Count local rows
* @return array
*/
public function getMethodFromMenuRows( $method )
public function getMethodFromMenuRows( $method, $rowCount=FALSE )
{
$menuRows = $this->menuRows();
if( isset( $menuRows[ $method ] ) )
$key = $rowCount ? 'rows' : 'noRows';
if( isset( $this->_menuRowCache[ $key ][ $method ] ) )
{
return $menuRows[ $method ];
return $this->_menuRowCache[ $key ][ $method ];
}
return array();
/* Set to to the cache */
$this->_menuRowCache[ $key ] = $this->menuRows( $rowCount );
/* Cache an empty array for the response */
if( !isset( $this->_menuRowCache[ $key ][ $method ] ) )
{
$this->_menuRowCache[ $key ][ $method ] = array();
}
return $this->_menuRowCache[ $key ][ $method ];
}
/**