Version 5.0.0 beta 4

This commit is contained in:
Neo committed 2025-12-19 16:57:00 -08:00
1 parent e86153356a
commit 2f24f9de48
276 files changed
+8614 -6044

No files matched your search

+41 -50
View File
@@ -15,6 +15,7 @@ namespace IPS\convert;
use ErrorException;
use Exception;
use IPS\convert\Software\Exception as SoftwareException;
use IPS\Db;
use IPS\Db\Select;
use IPS\forums\Topic\ArchivedPost;
@@ -43,37 +44,37 @@ abstract class Library
/**
* @brief Flag to indicate that we are using a specific key, and should do WHERE static::$currentKeyName > static::$currentKeyValue rather than LIMIT 0,1000
*/
public static $usingKeys = FALSE;
public static bool $usingKeys = FALSE;
/**
* @brief The name of the current key in the database for this step
*/
public static $currentKeyName = NULL;
public static ?string $currentKeyName = NULL;
/**
* @brief The current value of the key
*/
public static $currentKeyValue = 0;
public static ?int $currentKeyValue = 0;
/**
* @brief Amount of data being processed per cycle.
*/
public static $perCycle = 2000;
public static int $perCycle = 2000;
/**
* @brief If not using keys, the current start value for LIMIT clause.
*/
public static $startValue = 0;
public static int $startValue = 0;
/**
* @brief The current conversion step
*/
public static $action = NULL;
public static ?string $action = NULL;
/**
* @brief \IPS\convert\Software instance for the software we are converting from
*/
public $software = NULL;
public ?Software $software = NULL;
/**
* @brief Obscure filenames?
@@ -81,12 +82,12 @@ abstract class Library
* This is only referenced in certain content types that may be referenced in already parsed data such as attachments and emoticons
* - Designed for use with the Invision Community converter.
*/
public static $obscureFilenames = TRUE;
public static bool $obscureFilenames = TRUE;
/**
* @brief Array of field types
*/
protected static $fieldTypes = array( 'Address', 'Checkbox', 'CheckboxSet', 'Codemirror', 'Color', 'Date', 'Editor', 'Email', 'Item', 'Member', 'Number', 'Password', 'Poll', 'Radio', 'Rating', 'Select', 'Tel', 'Text', 'TextArea', 'Upload', 'Url', 'YesNo' );
protected static array $fieldTypes = array( 'Address', 'Checkbox', 'CheckboxSet', 'Codemirror', 'Color', 'Date', 'Editor', 'Email', 'Item', 'Member', 'Number', 'Password', 'Poll', 'Radio', 'Rating', 'Select', 'Tel', 'Text', 'TextArea', 'Upload', 'Url', 'YesNo' );
/**
* Constructor
@@ -104,7 +105,7 @@ abstract class Library
*
* @return array
*/
public static function libraries()
public static function libraries() : array
{
return array(
'core' => 'IPS\convert\Library\Core',
@@ -124,7 +125,7 @@ abstract class Library
* @param string $key The key to use
* @return void
*/
public static function setKey( $key )
public static function setKey( string $key ) : void
{
static::$usingKeys = TRUE;
static::$currentKeyName = $key;
@@ -136,7 +137,7 @@ abstract class Library
* @param mixed $value The current value
* @return void
*/
public function setLastKeyValue( $value )
public function setLastKeyValue( mixed $value ) : void
{
$_SESSION['currentKeyValue'] = $value;
static::$currentKeyValue = $value;
@@ -150,7 +151,7 @@ abstract class Library
* @param int|NULL $perCycle The number of results to process per cycle
* @return array|NULL Data for the MultipleRedirect
*/
public function process( $data, $method, $perCycle=NULL )
public function process( int $data, string $method, ?int $perCycle=NULL ) : ?array
{
if ( !is_null( $perCycle ) )
{
@@ -250,7 +251,7 @@ abstract class Library
}
catch( UnderflowException $e )
{
// Nothing has been ran yet
// Nothing has been run yet
$lastId = 0;
}
@@ -276,7 +277,7 @@ abstract class Library
if( $this->software->app->getRunningFlag( $method ) )
{
/* Count how many times we've seen this */
$_SESSION['convertSkipped'] = ( isset( $_SESSION['convertSkipped'] ) ? $_SESSION['convertSkipped'] : 0 ) + 1;
$_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 ))
@@ -301,7 +302,7 @@ abstract class Library
{
$this->software->$method();
}
catch( \IPS\convert\Software\Exception $e )
catch( SoftwareException $e )
{
/* A Software Exception indicates we are done */
$completed = $this->software->app->_session['completed'];
@@ -332,16 +333,6 @@ abstract class Library
$this->software->app->log( $e->getMessage(), __METHOD__, App::LOG_WARNING );
throw new Exception;
}
catch( ErrorException $e )
{
Log::log( $e, 'converters' );
/* Clear the running flag */
$this->software->app->setRunningFlag( $method, FALSE );
$this->software->app->log( $e->getMessage(), __METHOD__, App::LOG_WARNING );
throw new Exception;
}
/* Manually set running flag to save write queries */
$running = $this->software->app->_session['running'];
@@ -360,7 +351,7 @@ abstract class Library
* @param int $add Amount to add to completed count
* @return int
*/
protected function _getConvertedCount( $add = 0 )
protected function _getConvertedCount( int $add = 0 ) : int
{
if( $this->software->app->parent )
{
@@ -403,11 +394,11 @@ abstract class Library
/**
* Empty Conversion Data
*
* @param integer $data Data from the previous step.
* @param App $method The conversion method to empty results for
* @param int $data Data from the previous step.
* @param string $method The conversion method to empty results for
* @return array|NULL Data for the MultipleRedirect
*/
public function emptyData( $data, $method )
public function emptyData( int $data, string $method ) : ?array
{
$perCycle = 500;
@@ -491,17 +482,10 @@ abstract class Library
if ( isset( $def['indexes']['PRIMARY']['columns'] ) )
{
$id = array_pop( $def['indexes']['PRIMARY']['columns'] );
Db::i()->delete( $type, array( Db::i()->in( $id, array_values( $rows ) ) ) );
}
Db::i()->delete( $type, array( Db::i()->in( $id, array_values( $rows ) ) ) );
Db::i()->delete( $table, array( Db::i()->in( 'link_id', array_keys( $rows ) ) ) );
}
catch( Exception $e )
{
Log::log( $e, 'converters' );
$this->software->app->log( $e->getMessage(), __METHOD__, App::LOG_WARNING );
throw new Exception;
Db::i()->delete( $table, array( Db::i()->in( 'link_id', array_keys( $rows ) ) ) );
}
catch( ErrorException $e )
{
@@ -510,6 +494,13 @@ abstract class Library
$this->software->app->log( $e->getMessage(), __METHOD__, App::LOG_ERROR );
throw new Exception;
}
catch( Exception $e )
{
Log::log( $e, 'converters' );
$this->software->app->log( $e->getMessage(), __METHOD__, App::LOG_WARNING );
throw new Exception;
}
return array( $data + $perCycle, sprintf( Member::loggedIn()->language()->get( 'removed_x_of_x' ), ( $data + $perCycle > $total ) ? $_SESSION['emptyConvertedDataCount'] : $data + $perCycle, Member::loggedIn()->language()->addToStack( $method ), $_SESSION['emptyConvertedDataCount'] ), 100 / $_SESSION['emptyConvertedDataCount'] * ( $data + $perCycle ) );
}
@@ -521,7 +512,7 @@ abstract class Library
* @param string $method Convert method to run truncate call for
* @return void
*/
public function emptyLocalData( $method )
public function emptyLocalData( string $method ) : void
{
$truncate = $this->truncate( $method );
@@ -613,14 +604,14 @@ abstract class Library
/**
* @brief Cached convertable items
*/
protected $convertable = NULL;
protected ?array $convertable = NULL;
/**
* Return the items we can convert. Removes things that are empty.
*
* @return array
*/
public function getConvertableItems()
public function getConvertableItems() : array
{
if( $this->convertable !== NULL )
{
@@ -653,7 +644,7 @@ abstract class Library
* @param mixed $arguments Arguments to pass to the method
* @return mixed
*/
public function __call( $name, $arguments )
public function __call( string $name, mixed $arguments )
{
if ( method_exists( $this, 'convert' . $name ) )
{
@@ -676,7 +667,7 @@ abstract class Library
*
* @return string
*/
public function getPostConversionInformation()
public function getPostConversionInformation() : string
{
return '';
}
@@ -705,7 +696,7 @@ abstract class Library
* @param bool $rowCounts enable row counts
* @return array
*/
abstract public function menuRows( $rowCounts=FALSE );
abstract public function menuRows( bool $rowCounts=FALSE ) : array;
/**
* Utility method to run queries for menuRows() data
@@ -717,7 +708,7 @@ abstract class Library
* @throws UnderflowException
* @throws Exception
*/
public function getDatabaseRowCounts( array $return, $ips=TRUE, $source=TRUE )
public function getDatabaseRowCounts( array $return, bool $ips=TRUE, bool $source=TRUE ) : array
{
foreach( $return as $key => $value )
{
@@ -738,7 +729,7 @@ abstract class Library
/**
* @brief Cache menu row data
*/
protected $_menuRowCache = array( 'rows' => array(), 'noRows' => array() );
protected array $_menuRowCache = array( 'rows' => array(), 'noRows' => array() );
/**
* Get method from menu rows - abstracted to allow 'fake' entries not in menuRows()
@@ -747,7 +738,7 @@ abstract class Library
* @param bool $rowCount Count local rows
* @return array
*/
public function getMethodFromMenuRows( $method, $rowCount=FALSE )
public function getMethodFromMenuRows( string $method, bool $rowCount=FALSE ) : array
{
$key = $rowCount ? 'rows' : 'noRows';
if( isset( $this->_menuRowCache[ $key ][ $method ] ) )
@@ -755,7 +746,7 @@ abstract class Library
return $this->_menuRowCache[ $key ][ $method ];
}
/* Set to to the cache */
/* Set to the cache */
$this->_menuRowCache[ $key ] = $this->menuRows( $rowCount );
/* Cache an empty array for the response */
@@ -773,5 +764,5 @@ abstract class Library
* @param string $method The method to truncate
* @return array
*/
abstract protected function truncate( $method );
abstract protected function truncate( string $method ) : array;
}