Version 4.7.0

This commit is contained in:
Neo committed 2025-12-19 16:00:35 -08:00
1 parent 517a5e1f70
commit 8ba7d43898
1933 files changed
+65613 -11332

No files matched your search

+72 -60
View File
@@ -143,93 +143,105 @@ class _Developer
/* Run queries for previous versions */
if ( static::$lastUpdates[ $this->app->directory ]['working_version'] != $latestVersion )
{
/* Get all versions past the working version */
$dirMatches = [];
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/" ) as $dir )
{
if ( $dir->isDir() and !$dir->isDot() and preg_match( '/^upg_(\d+)$/', $dir, $matches ) )
{
if ( (int) $matches[1] == static::$lastUpdates[ $this->app->directory ]['working_version'] )
if ( (int) $matches[1] >= static::$lastUpdates[ $this->app->directory ]['working_version'] )
{
if( file_exists( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$matches[1]}/queries.json" ) )
$dirMatches[] = (int) $matches[1];
}
}
}
/* Run through the *sorted* versions. Note DirectoryIterator sorts by last modified, but you want this to run in order of versions */
asort( $dirMatches );
foreach ( $dirMatches as $match )
{
if ( $match == static::$lastUpdates[ $this->app->directory ]['working_version'] )
{
if( file_exists( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$match}/queries.json" ) )
{
$queries = json_decode( file_get_contents( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$match}/queries.json" ), TRUE );
$localQueries = json_decode( static::$lastUpdates[ $this->app->directory ]['ran'], TRUE );
foreach ( $queries as $q )
{
$queries = json_decode( file_get_contents( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$matches[1]}/queries.json" ), TRUE );
$localQueries = json_decode( static::$lastUpdates[ $this->app->directory ]['ran'], TRUE );
foreach ( $queries as $q )
if ( \is_array( $localQueries ) AND !\in_array( $q, $localQueries ) )
{
if ( \is_array( $localQueries ) AND !\in_array( $q, $localQueries ) )
{
$method = $q['method'];
$params = $q['params'];
\IPS\Db::i()->$method( ...$params );
}
$method = $q['method'];
$params = $q['params'];
\IPS\Db::i()->$method( ...$params );
}
}
}
elseif ( (int) $matches[1] > static::$lastUpdates[ $this->app->directory ]['working_version'] )
}
else
{
if( file_exists( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$match}/queries.json" ) )
{
if( file_exists( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$matches[1]}/queries.json" ) )
$queries = json_decode( file_get_contents( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$match}/queries.json" ), TRUE );
foreach ( $queries as $q )
{
$queries = json_decode( file_get_contents( \IPS\ROOT_PATH . "/applications/{$this->app->directory}/setup/upg_{$matches[1]}/queries.json" ), TRUE );
foreach ( $queries as $q )
try
{
try
$method = $q['method'];
$params = $q['params'];
\IPS\Db::i()->$method( ...$params );
}
catch( \IPS\Db\Exception $e )
{
/* If the issue is with a create table other than exists, we should just throw it */
if ( $q['method'] == 'createTable' and ! \in_array( $e->getCode(), array( 1007, 1050 ) ) )
{
$method = $q['method'];
$params = $q['params'];
\IPS\Db::i()->$method( ...$params );
throw $e;
}
catch( \IPS\Db\Exception $e )
/* Can't change a column as it doesn't exist */
if ( $e->getCode() == 1054 )
{
/* If the issue is with a create table other than exists, we should just throw it */
if ( $q['method'] == 'createTable' and ! \in_array( $e->getCode(), array( 1007, 1050 ) ) )
if ( $q['method'] == 'changeColumn' )
{
throw $e;
}
/* Can't change a column as it doesn't exist */
if ( $e->getCode() == 1054 )
{
if ( $q['method'] == 'changeColumn' )
if ( \IPS\Db::i()->checkForTable( $q['params'][0] ) )
{
if ( \IPS\Db::i()->checkForTable( $q['params'][0] ) )
/* Does the column exist already? */
if ( \IPS\Db::i()->checkForColumn( $q['params'][0], $q['params'][2]['name'] ) )
{
/* Does the column exist already? */
if ( \IPS\Db::i()->checkForColumn( $q['params'][0], $q['params'][2]['name'] ) )
{
/* Just make sure it's up to date */
\IPS\Db::i()->changeColumn( $q['params'][0], $q['params'][2]['name'], $q['params'][2] );
continue;
}
else
{
/* The table exists, so lets just add the column */
\IPS\Db::i()->addColumn( $q['params'][0], $q['params'][2] );
continue;
}
/* Just make sure it's up to date */
\IPS\Db::i()->changeColumn( $q['params'][0], $q['params'][2]['name'], $q['params'][2] );
continue;
}
}
throw $e;
}
/* Can't rename a table as it doesn't exist */
else if ( $e->getCode() == 1017 )
{
if ( $q['method'] == 'renameTable' )
{
if ( \IPS\Db::i()->checkForTable( $q['params'][1] ) )
else
{
/* The table we are renaming to *does* exist */
/* The table exists, so lets just add the column */
\IPS\Db::i()->addColumn( $q['params'][0], $q['params'][2] );
continue;
}
}
throw $e;
}
/* If the error isn't important we should ignore it */
else if( !\in_array( $e->getCode(), array( 1007, 1008, 1050, 1060, 1061, 1062, 1091 ) ) )
throw $e;
}
/* Can't rename a table as it doesn't exist */
else if ( $e->getCode() == 1017 )
{
if ( $q['method'] == 'renameTable' )
{
throw $e;
if ( \IPS\Db::i()->checkForTable( $q['params'][1] ) )
{
/* The table we are renaming to *does* exist */
continue;
}
}
throw $e;
}
/* If the error isn't important we should ignore it */
else if( !\in_array( $e->getCode(), array( 1007, 1008, 1050, 1060, 1061, 1062, 1091 ) ) )
{
throw $e;
}
}
}