Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+114 -90
View File
@@ -12,32 +12,56 @@
namespace IPS\convert;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use ArrayIterator;
use BadMethodCallException;
use Exception;
use InvalidArgumentException;
use IPS\Data\Store;
use IPS\Db;
use IPS\Patterns\ActiveRecord;
use IPS\Patterns\ActiveRecordIterator;
use OutOfRangeException;
use UnderflowException;
use function array_column;
use function array_diff;
use function array_keys;
use function array_map;
use function array_merge;
use function array_unique;
use function count;
use function defined;
use function get_class;
use function in_array;
use function is_array;
use function is_null;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Converter Application Class
*/
class _App extends \IPS\Patterns\ActiveRecord
class App extends ActiveRecord
{
/**
* @brief [ActiveRecord] Caches
* @note Defined cache keys will be cleared automatically as needed
*/
protected $caches = array( 'convert_apps' );
protected array $caches = array( 'convert_apps' );
/**
* @brief [ActiveRecord] ID Database Column
*/
public static $databaseColumnId = 'app_id';
public static string $databaseColumnId = 'app_id';
/**
* @brief [ActiveRecord] Database table
*/
public static $databaseTable = 'convert_apps';
public static ?string $databaseTable = 'convert_apps';
/**
* @brief Array Storage of loaded ID links.
@@ -62,11 +86,11 @@ class _App extends \IPS\Patterns\ActiveRecord
/**
* Get converted apps
*
* @return \IPS\Patterns\ActiveRecordIterator
* @return ActiveRecordIterator
*/
public static function apps()
{
return new \IPS\Patterns\ActiveRecordIterator( new \ArrayIterator( static::getStore() ), 'IPS\convert\App' );
return new ActiveRecordIterator( new ArrayIterator( static::getStore() ), 'IPS\convert\App' );
}
/**
@@ -74,19 +98,19 @@ class _App extends \IPS\Patterns\ActiveRecord
*
* @return array
*/
public static function getStore()
public static function getStore(): array
{
if ( !isset( \IPS\Data\Store::i()->convert_apps ) )
if ( !isset( Store::i()->convert_apps ) )
{
try
{
$rows = iterator_to_array( \IPS\Db::i()->select( '*', 'convert_apps', array(), 'app_id ASC' ) );
$rows = iterator_to_array( Db::i()->select( '*', 'convert_apps', array(), 'app_id ASC' ) );
}
catch ( \IPS\Db\Exception $e )
{
if ( $e->getCode() === 1146 )
{
$rows = iterator_to_array( \IPS\Db::i()->select( '*', 'conv_apps', array(), 'app_id ASC' ) );
$rows = iterator_to_array( Db::i()->select( '*', 'conv_apps', array(), 'app_id ASC' ) );
}
else
{
@@ -94,33 +118,33 @@ class _App extends \IPS\Patterns\ActiveRecord
}
}
\IPS\Data\Store::i()->convert_apps = $rows;
Store::i()->convert_apps = $rows;
}
return \IPS\Data\Store::i()->convert_apps;
return Store::i()->convert_apps;
}
/**
* [ActiveRecord] Save Record
*
* @return void
* @return void
*/
public function save()
public function save(): void
{
if ( !$this->app_id )
{
$this->start_date = time();
parent::save();
\IPS\convert\Application::checkConvParent( $this->getSource()->getLibrary()->app );
Application::checkConvParent( $this->getSource()->getLibrary()->app );
\IPS\Db::i()->insert( 'convert_app_sessions', array(
Db::i()->insert( 'convert_app_sessions', array(
'session_app_id' => $this->app_id,
'session_app_data' => json_encode( array( 'completed' => array(), 'working' => array(), 'more_info' => array() ) ),
) );
}
$classname = \get_class( $this->getSource( TRUE, FALSE ) );
$classname = get_class( $this->getSource( TRUE, FALSE ) );
$this->login = ( $classname::loginEnabled() === TRUE ) ? 1 : 0;
$this->db_driver = 'mysql'; /* I was going to drop this, but it has the potential for expansion in the future, as all we do is select from the source */
$this->app_merge = 1;
@@ -130,17 +154,17 @@ class _App extends \IPS\Patterns\ActiveRecord
/**
* [ActiveRecord] Delete Record
*
* @return void
* @return void
*/
public function delete()
public function delete(): void
{
foreach( array( 'convert_link', 'convert_link_pms', 'convert_link_topics', 'convert_link_posts' ) AS $table )
{
\IPS\Db::i()->delete( $table, array( 'app=?', $this->app_id ) );
Db::i()->delete( $table, array( 'app=?', $this->app_id ) );
}
\IPS\Db::i()->delete( 'convert_app_sessions', array( 'session_app_id=?', $this->app_id ) );
\IPS\Db::i()->delete( 'convert_logs', array( 'log_app=?', $this->app_id ) );
Db::i()->delete( 'convert_app_sessions', array( 'session_app_id=?', $this->app_id ) );
Db::i()->delete( 'convert_logs', array( 'log_app=?', $this->app_id ) );
parent::delete();
}
@@ -158,7 +182,7 @@ class _App extends \IPS\Patterns\ActiveRecord
*/
public function set__session( $value )
{
\IPS\Db::i()->update( 'convert_app_sessions', array( 'session_app_data' => json_encode( $value ) ), array( 'session_app_id=?', $this->app_id ) );
Db::i()->update( 'convert_app_sessions', array( 'session_app_data' => json_encode( $value ) ), array( 'session_app_id=?', $this->app_id ) );
$this->_sessionData = $value;
}
@@ -178,13 +202,13 @@ class _App extends \IPS\Patterns\ActiveRecord
try
{
$this->_sessionData = json_decode( \IPS\Db::i()->select( 'session_app_data', 'convert_app_sessions', array( 'session_app_id=?', $this->app_id ) )->first(), TRUE );
$this->_sessionData = json_decode( Db::i()->select( 'session_app_data', 'convert_app_sessions', array( 'session_app_id=?', $this->app_id ) )->first(), TRUE );
return $this->_sessionData;
}
catch( \Exception $e )
catch( Exception $e )
{
/* If it doesn't exist, create it in the database and return an empty array. */
\IPS\Db::i()->insert( 'convert_app_sessions', array(
Db::i()->insert( 'convert_app_sessions', array(
'session_app_id' => $this->app_id,
'session_app_data' => json_encode( array( 'completed' => array(), 'working' => array(), 'more_info' => array() ) )
) );
@@ -247,29 +271,29 @@ class _App extends \IPS\Patterns\ActiveRecord
/**
* Get parent application
*
* @return \IPS\convert\App
* @throws \BadMethodCallException
* @return App
* @throws BadMethodCallException
*/
public function get__parent()
{
if ( \is_null( $this->parentStore ) )
if ( is_null( $this->parentStore ) )
{
if ( ! $this->parent )
{
throw new \BadMethodCallException;
throw new BadMethodCallException;
}
try
{
$this->parentStore = static::constructFromData( \IPS\Db::i()->select( '*', 'convert_apps', array( "app_id=?", $this->parent ) )->first() );
$this->parentStore = static::constructFromData( Db::i()->select( '*', 'convert_apps', array( "app_id=?", $this->parent ) )->first() );
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
throw new \BadMethodCallException;
throw new BadMethodCallException;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
throw new \BadMethodCallException;
throw new BadMethodCallException;
}
}
@@ -279,7 +303,7 @@ class _App extends \IPS\Patterns\ActiveRecord
/**
* Return this application's children applications
*
* @return array|\IPS\Patterns\ActiveRecordIterator
* @return array|ActiveRecordIterator
*/
public function children()
{
@@ -289,7 +313,7 @@ class _App extends \IPS\Patterns\ActiveRecord
return array();
}
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'convert_apps', array( 'parent=?', $this->app_id ) ), 'IPS\convert\App' );
return new ActiveRecordIterator( Db::i()->select( '*', 'convert_apps', array( 'parent=?', $this->app_id ) ), 'IPS\convert\App' );
}
/**
@@ -301,22 +325,22 @@ class _App extends \IPS\Patterns\ActiveRecord
* @param boolean $mainTable If set to TRUE, and the type is of either 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map', 'forums_topics', or 'forums_posts', then the ID is retrieved from convert_link, rather than the other link tables.
*
* @return integer The Invision Community ID.
* @throws \OutOfRangeException
* @throws OutOfRangeException
*/
public function getLink( $foreign_id, $type, $parent=FALSE, $mainTable=FALSE )
{
if ( !\is_array( $type ) )
if ( !is_array( $type ) )
{
$type = array( $type );
}
$key = \count( $type ) > 1 ? md5( implode('', $type ) ) : $type[0];
$key = count( $type ) > 1 ? md5( implode('', $type ) ) : $type[0];
if ( isset( $this->linkCache[ $key ][ $foreign_id ] ) )
{
if( $this->linkCache[ $key ][ $foreign_id ] === FALSE )
{
throw new \OutOfRangeException( 'link_invalid' );
throw new OutOfRangeException( 'link_invalid' );
}
return $this->linkCache[ $key ][ $foreign_id ];
@@ -329,23 +353,23 @@ class _App extends \IPS\Patterns\ActiveRecord
try
{
$link = \IPS\Db::i()->select( 'ipb_id', $table, array( \IPS\Db::i()->in( 'type', $type ) . ' AND foreign_id=? AND app=?', (string) $foreign_id, ( $parent === TRUE and $this->parent ) ? $this->parent : $this->app_id ), 'link_id DESC' )->first();
$link = Db::i()->select( 'ipb_id', $table, array( Db::i()->in( 'type', $type ) . ' AND foreign_id=? AND app=?', (string) $foreign_id, ( $parent === TRUE and $this->parent ) ? $this->parent : $this->app_id ), 'link_id DESC' )->first();
$this->linkCache[ $key ][ $foreign_id ] = $link;
return $this->linkCache[ $key ][ $foreign_id ];
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
/* If lookup failed, and we have a parent, try it anyway */
try
{
$link = \IPS\Db::i()->select( 'ipb_id', $table, array( \IPS\Db::i()->in( 'type', $type ) . ' AND foreign_id=? AND app=?', (string) $foreign_id, $this->parent ), 'link_id DESC' )->first();
$link = Db::i()->select( 'ipb_id', $table, array( Db::i()->in( 'type', $type ) . ' AND foreign_id=? AND app=?', (string) $foreign_id, $this->parent ), 'link_id DESC' )->first();
$this->linkCache[ $key ][ $foreign_id ] = $link;
return $this->linkCache[ $key ][ $foreign_id ];
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
/* Still here? Throw the exception */
throw new \OutOfRangeException( 'link_invalid' );
throw new OutOfRangeException( 'link_invalid' );
}
}
@@ -360,7 +384,7 @@ class _App extends \IPS\Patterns\ActiveRecord
{
return $this->_parent->app_id;
}
catch( \BadMethodCallException $e )
catch( BadMethodCallException $e )
{
return $this->app_id;
}
@@ -380,7 +404,7 @@ class _App extends \IPS\Patterns\ActiveRecord
* @param boolean $mainTable If set to TRUE, and the type is of either 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map', 'forums_topics', or 'forums_posts', then the ID is retrieved from convert_link, rather than the other link tables.
*
* @return inteer The Invision Community ID.
* @throws \OutOfRangeException
* @throws OutOfRangeException
*/
public function getSiblingLink( $foreign_id, $type, $sibling, $mainTable=FALSE )
{
@@ -391,11 +415,11 @@ class _App extends \IPS\Patterns\ActiveRecord
try
{
$sibling = static::constructFromData( \IPS\Db::i()->select( '*', 'convert_apps', array( "sw=? AND parent=?", $sibling, $this->parent ) )->first() );
$sibling = static::constructFromData( Db::i()->select( '*', 'convert_apps', array( "sw=? AND parent=?", $sibling, $this->parent ) )->first() );
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
throw new \OutOfRangeException( 'sibling_invalid' );
throw new OutOfRangeException( 'sibling_invalid' );
}
return $sibling->getLink( $foreign_id, $type, FALSE, $mainTable );
@@ -415,9 +439,9 @@ class _App extends \IPS\Patterns\ActiveRecord
{
$table = 'convert_link';
if ( \in_array( $type, [ 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map', 'forums_topics', 'forums_posts', 'forums_topics_old', 'forums_posts_old' ] ) AND $mainTable === FALSE )
if ( in_array( $type, [ 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map', 'forums_topics', 'forums_posts', 'forums_topics_old', 'forums_posts_old' ] ) AND $mainTable === FALSE )
{
if ( \in_array( $type, array( 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map' ) ) )
if ( in_array( $type, array( 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map' ) ) )
{
$table = 'convert_link_pms';
}
@@ -428,7 +452,7 @@ class _App extends \IPS\Patterns\ActiveRecord
}
}
\IPS\Db::i()->insert( $table, array(
Db::i()->insert( $table, array(
'ipb_id' => $ips_id,
'foreign_id' => $foreign_id,
'type' => $type,
@@ -451,7 +475,7 @@ class _App extends \IPS\Patterns\ActiveRecord
$tables = [];
/* Check for data */
if( !\count( $data ) )
if( !count( $data ) )
{
return;
}
@@ -459,24 +483,24 @@ class _App extends \IPS\Patterns\ActiveRecord
foreach( $map as $type => $columns )
{
$cachesToLookup[ $type ] = array();
if ( \is_array( $columns ) )
if ( is_array( $columns ) )
{
foreach ( $columns as $column )
{
$cachesToLookup[ $type ] = \array_merge( $cachesToLookup[ $type ], \array_column( $data, $column ) );
$cachesToLookup[ $type ] = array_merge( $cachesToLookup[ $type ], array_column( $data, $column ) );
}
$cachesToLookup[ $type ] = \array_map( 'strval', \array_unique( $cachesToLookup[ $type ] ) );
$cachesToLookup[ $type ] = array_map( 'strval', array_unique( $cachesToLookup[ $type ] ) );
}
else
{
$cachesToLookup[ $type ] = \array_map( 'strval', \array_unique( \array_column( $data, $columns ) ) );
$cachesToLookup[ $type ] = array_map( 'strval', array_unique( array_column( $data, $columns ) ) );
}
/* Check whether there are values we don't have cached */
if( isset( $this->linkCache[ $type ] ) )
{
$cachesToLookup[ $type ] = \array_diff( $cachesToLookup[ $type ], \array_keys( $this->linkCache[ $type ] ) );
if ( !\count( $cachesToLookup[ $type ] ) )
$cachesToLookup[ $type ] = array_diff( $cachesToLookup[ $type ], array_keys( $this->linkCache[ $type ] ) );
if ( !count( $cachesToLookup[ $type ] ) )
{
/* nope, so skip the query */
continue;
@@ -493,8 +517,8 @@ class _App extends \IPS\Patterns\ActiveRecord
$this->linkCache[ $link ] = array();
}
$where = [ '`type`=? AND ' . \IPS\Db::i()->in('foreign_id', $cachesToLookup[ $link ] ) . ' AND (app=? OR app=?)', $link, $this->parent, $this->app_id ];
foreach( \IPS\Db::i()->select( 'ipb_id, foreign_id', $table, $where ) as $result )
$where = [ '`type`=? AND ' . Db::i()->in('foreign_id', $cachesToLookup[ $link ] ) . ' AND (app=? OR app=?)', $link, $this->parent, $this->app_id ];
foreach( Db::i()->select( 'ipb_id, foreign_id', $table, $where ) as $result )
{
$this->linkCache[ $link ][ (string) $result['foreign_id'] ] = $result['ipb_id'];
}
@@ -516,7 +540,7 @@ class _App extends \IPS\Patterns\ActiveRecord
* @param string $type The type of item
* @param bool $mainTable If TRUE, then link will be check against the main convert_link table even if $type is 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map', 'forums_topics', or 'forums_posts'
* @return void
* @throws \OutOfRangeException
* @throws OutOfRangeException
*/
public function checkLink( $ips_id, $type, $mainTable=FALSE )
{
@@ -524,11 +548,11 @@ class _App extends \IPS\Patterns\ActiveRecord
try
{
$link = \IPS\Db::i()->select( '*', $table, array( "app=? AND ipb_id=? AND type=?", $this->app_id, $ips_id, $type ) )->first();
$link = Db::i()->select( '*', $table, array( "app=? AND ipb_id=? AND type=?", $this->app_id, $ips_id, $type ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
@@ -537,17 +561,17 @@ class _App extends \IPS\Patterns\ActiveRecord
*
* @param string $software The application key to look for
* @return void
* @throws \OutOfRangeException
* @throws OutOfRangeException
*/
public function checkForSibling( $software )
{
try
{
\IPS\Db::i()->select( '*', 'convert_apps', array( "sw=? AND parent=?", $software, $this->parent ) )->first();
Db::i()->select( '*', 'convert_apps', array( "sw=? AND parent=?", $software, $this->parent ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
@@ -562,7 +586,7 @@ class _App extends \IPS\Patterns\ActiveRecord
{
$table = $this->_getLinkTableName( $type );
\IPS\Db::i()->delete( $table, array( 'foreign_id=? AND type=? AND app=?', $foreignId, $type, $this->app_id ) );
Db::i()->delete( $table, array( 'foreign_id=? AND type=? AND app=?', $foreignId, $type, $this->app_id ) );
/* Remove this from the link cache */
if( isset( $this->linkCache[ $type ][ $foreignId ] ) )
@@ -580,8 +604,8 @@ class _App extends \IPS\Patterns\ActiveRecord
* Construct an \IPS\convert\App object for a sibling application.
*
* @param string $software The application key to look for
* @return \IPS\convert\App
* @throws \OutOfRangeException
* @return App
* @throws OutOfRangeException
*/
public function getSibling( $software )
{
@@ -589,11 +613,11 @@ class _App extends \IPS\Patterns\ActiveRecord
{
try
{
$this->siblingCache[$software] = static::constructFromData( \IPS\Db::i()->select( '*', 'convert_apps', array( "sw=? AND parent=?", $software, $this->parent ) )->first() );
$this->siblingCache[$software] = static::constructFromData( Db::i()->select( '*', 'convert_apps', array( "sw=? AND parent=?", $software, $this->parent ) )->first() );
}
catch( \Exception $e )
catch( Exception $e )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
@@ -605,8 +629,8 @@ class _App extends \IPS\Patterns\ActiveRecord
*
* @param bool $construct Construct the object
* @param bool $needDB Establish a database connection ($construct must be TRUE)
* @return \IPS\convert\Software|string
* @throws \InvalidArgumentException
* @return Software|string
* @throws InvalidArgumentException
*/
public function getSource( $construct=TRUE, $needDB=TRUE )
{
@@ -671,11 +695,11 @@ class _App extends \IPS\Patterns\ActiveRecord
break;
}
$classname = \IPS\convert\Software::software()[ $this->_data['sw'] ][ $this->_data['app_key'] ];
$classname = Software::software()[ $this->_data['sw'] ][ $this->_data['app_key'] ];
if ( ! class_exists( $classname ) )
{
throw new \InvalidArgumentException( 'invalid_source' );
throw new InvalidArgumentException( 'invalid_source' );
}
if ( $construct )
@@ -696,16 +720,16 @@ class _App extends \IPS\Patterns\ActiveRecord
* @param integer $severity The severity level of the log. Default to LOG_NOTICE
* @param int|NULL $id The item ID
* @return void
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function log( $message, $method, $severity=1, $id=NULL )
{
if ( ! \in_array( $severity, array( static::LOG_NOTICE, static::LOG_WARNING, static::LOG_ERROR ) ) )
if ( ! in_array( $severity, array( static::LOG_NOTICE, static::LOG_WARNING, static::LOG_ERROR ) ) )
{
throw new \InvalidArgumentException( 'invalid_severity' );
throw new InvalidArgumentException( 'invalid_severity' );
}
\IPS\Db::i()->insert( 'convert_logs', array(
Db::i()->insert( 'convert_logs', array(
'log_message' => $message,
'log_app' => $this->app_id,
'log_severity' => $severity,
@@ -723,7 +747,7 @@ class _App extends \IPS\Patterns\ActiveRecord
*/
public function dependencies( $value )
{
if ( !\in_array( $value, $this->_session['completed'] ) )
if ( !in_array( $value, $this->_session['completed'] ) )
{
return TRUE;
}
@@ -819,9 +843,9 @@ class _App extends \IPS\Patterns\ActiveRecord
if ( $mainTable === FALSE )
{
if ( \in_array( $type, array( 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map', 'forums_topics', 'forums_posts', 'forums_topics_old', 'forums_posts_old' ) ) )
if ( in_array( $type, array( 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map', 'forums_topics', 'forums_posts', 'forums_topics_old', 'forums_posts_old' ) ) )
{
if ( \in_array( $type, array( 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map' ) ) )
if ( in_array( $type, array( 'core_message_topics', 'core_message_posts', 'core_message_topic_user_map' ) ) )
{
$table = 'convert_link_pms';
}