Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+59 -35
View File
@@ -11,7 +11,7 @@
namespace IPS\core\Setup;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -30,6 +30,12 @@ class _Install
public static function systemRequirements()
{
$return = array();
/* We don't need to check the CIC platform */
if( \IPS\CIC )
{
return array( 'recommendations' => array(), 'requirements' => array() );
}
/* PHP Version */
$phpVersion = PHP_VERSION;
@@ -53,16 +59,25 @@ class _Install
$return['requirements']['PHP']['version']['message'] = \IPS\Member::loggedIn()->language()->addToStack( 'requirements_php_version_success', FALSE, array( 'sprintf' => array( $phpVersion ) ) );
$return['advice']['php'] = \IPS\Member::loggedIn()->language()->addToStack( 'requirements_php_version_advice', FALSE, array( 'sprintf' => array( $phpVersion, $requirements['php']['recommended'] ) ) );
}
/* We require file_uploads otherwise lots of stuff won't work */
if( !ini_get('file_uploads') OR mb_strtolower( ini_get('file_uploads') ) == 'off' )
{
$return['requirements']['PHP'][] = array(
'success' => FALSE,
'message' => \IPS\Member::loggedIn()->language()->addToStack( 'requirements_file_uploads' ),
);
}
/* cURL or allow_url_fopen */
if ( extension_loaded('curl') and $version = curl_version() and version_compare( $version['version'], '7.36', '>=' ) )
if ( \extension_loaded('curl') and $version = curl_version() and version_compare( $version['version'], '7.36', '>=' ) )
{
$return['requirements']['PHP'][] = array(
'success' => TRUE,
'message' => \IPS\Member::loggedIn()->language()->addToStack( 'requirements_curl_success' ),
);
}
elseif ( function_exists('fsockopen') )
elseif ( \function_exists('fsockopen') )
{
$return['requirements']['PHP'][] = array(
'success' => TRUE,
@@ -80,9 +95,9 @@ class _Install
}
/* mbstring can be configured with --disable-mbregex */
if ( extension_loaded( 'mbstring' ) )
if ( \extension_loaded( 'mbstring' ) )
{
if ( function_exists( 'mb_eregi' ) )
if ( \function_exists( 'mb_eregi' ) )
{
$return['requirements']['PHP'][] = array(
'success' => TRUE,
@@ -121,7 +136,7 @@ class _Install
{
foreach ( $extensions as $extension )
{
if ( extension_loaded( $extension ) )
if ( \extension_loaded( $extension ) )
{
$return['requirements']['PHP'][] = array(
'success' => TRUE,
@@ -149,12 +164,6 @@ class _Install
}
}
/* Recommend GD freetype */
if( extension_loaded('gd') AND !function_exists( 'imagettfbbox' ) )
{
$return['advice'][] = \IPS\Member::loggedIn()->language()->addToStack( 'requirements_missing_imagettfbbox' );
}
/* Memory Limit */
$_memoryLimit = @ini_get('memory_limit');
$memoryLimit = $_memoryLimit;
@@ -163,19 +172,19 @@ class _Install
preg_match( "#^(\d+)(\w+)$#", mb_strtolower($memoryLimit), $match );
if( $match[2] == 'g' )
{
$memoryLimit = intval( $memoryLimit ) * 1024 * 1024 * 1024;
$memoryLimit = \intval( $memoryLimit ) * 1024 * 1024 * 1024;
}
else if ( $match[2] == 'm' )
{
$memoryLimit = intval( $memoryLimit ) * 1024 * 1024;
$memoryLimit = \intval( $memoryLimit ) * 1024 * 1024;
}
else if ( $match[2] == 'k' )
{
$memoryLimit = intval( $memoryLimit ) * 1024;
$memoryLimit = \intval( $memoryLimit ) * 1024;
}
else
{
$memoryLimit = intval( $memoryLimit );
$memoryLimit = \intval( $memoryLimit );
}
}
if ( $memoryLimit >= ( 128 * 1024 * 1024 ) OR $memoryLimit == -1 )
@@ -194,7 +203,7 @@ class _Install
}
/* Suhosin */
if ( extension_loaded( 'suhosin' ) )
if ( \extension_loaded( 'suhosin' ) )
{
foreach ( array(
'suhosin.post.max_vars' => 4096,
@@ -301,7 +310,7 @@ class _Install
public function __construct( $apps, $defaultApp, $baseUrl, $path, $db, $adminName, $adminPass, $adminEmail, $diagnostics=TRUE )
{
/* Have core app? */
if ( !in_array( 'core', $apps ) )
if ( !\in_array( 'core', $apps ) )
{
throw new \InvalidArgumentException( 'NO_CORE_APP' );
}
@@ -347,7 +356,7 @@ class _Install
/**
* Process
*
* @param array Multiple-Redirector Data
* @param array $data Multi-redirector data
* @return array|null Multiple-Redirector Data or NULL indicates done
*/
public function process( $data )
@@ -359,7 +368,7 @@ class _Install
}
/* Run the step */
$step = intval( $data[0] );
$step = \intval( $data[0] );
if ( $step == 13 )
{
@@ -369,7 +378,8 @@ class _Install
{
throw new \BadMethodCallException( 'NO_STEP' );
}
$response = call_user_func( array( $this, "step{$step}" ), $data );
$stepFunction = "step{$step}";
$response = $this->$stepFunction( $data );
return array( $response, ( $this->customTitle ) ? $this->customTitle : \IPS\Member::loggedIn()->language()->addToStack( 'install_step_' . $step ), ( ( ( 100/12 ) * $data[0] + ( ( 100/12 ) / 100 * $this->stepProgress ) ) ) ?: 1 );
}
@@ -377,7 +387,7 @@ class _Install
/**
* App Looper
*
* @param array data Multiple-Redirector Data
* @param array $data Multiple-Redirector Data
* @param callback $code Code to execute for each app
* @return array Data to Multiple-Redirector Data
*/
@@ -388,7 +398,7 @@ class _Install
$returnNext = FALSE;
foreach ( $this->apps as $app )
{
$this->stepProgress += ( 100 / count( $this->apps ) );
$this->stepProgress += ( 100 / \count( $this->apps ) );
if ( !isset( $data[1] ) )
{
@@ -396,9 +406,9 @@ class _Install
}
elseif ( $data[1] == $app )
{
$val = call_user_func( $code, $app );
$val = $code( $app );
if ( is_array( $val ) )
if ( \is_array( $val ) )
{
return $val;
}
@@ -420,12 +430,13 @@ class _Install
* Step 1
* Create database
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step1( $data )
{
$this->stepProgress = 0;
$perAppProgress = floor( 100 / count( $this->apps ) );
$perAppProgress = floor( 100 / \count( $this->apps ) );
$returnNext = FALSE;
foreach ( $this->apps as $app )
@@ -448,9 +459,9 @@ class _Install
if ( file_exists( \IPS\ROOT_PATH . "/applications/{$app}/data/schema.json" ) )
{
$schema = json_decode( file_get_contents( \IPS\ROOT_PATH . "/applications/{$app}/data/schema.json" ), TRUE );
if ( count( $schema ) )
if ( \count( $schema ) )
{
$perTableProgress = ( $perAppProgress / count( $schema ) );
$perTableProgress = ( $perAppProgress / \count( $schema ) );
$i = 0;
foreach( $schema as $dbTable )
{
@@ -470,7 +481,7 @@ class _Install
{
$adminName = $this->adminName;
\IPS\Db::i()->insert( $dbTable['name'], array_map( function( $column ) use( $adminName ) {
if( !is_string( $column ) )
if( !\is_string( $column ) )
{
return $column;
}
@@ -513,7 +524,7 @@ class _Install
}
}
if( isset( $instruction['params'][1] ) and is_array( $instruction['params'][1] ) )
if( isset( $instruction['params'][1] ) and \is_array( $instruction['params'][1] ) )
{
$groups = array_filter( iterator_to_array( \IPS\Db::i()->select( 'g_id', 'core_groups' ) ), function( $groupId ) {
if( $groupId == 2 )
@@ -532,8 +543,10 @@ class _Install
}
}
}
call_user_func_array( array( \IPS\Db::i(), $instruction['method'] ), $instruction['params'] );
$method = $instruction['method'];
$params = $instruction['params'];
\IPS\Db::i()->$method( ...$params );
}
}
@@ -552,6 +565,7 @@ class _Install
* Step 2
* Insert application and module data
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step2( $data )
@@ -616,6 +630,7 @@ class _Install
* Step 3
* Insert Settings
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step3( $data )
@@ -647,6 +662,7 @@ class _Install
* Step 4
* Create admin account
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step4( $data )
@@ -679,6 +695,7 @@ class _Install
* Step 5
* Create Tasks
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step5( $data )
@@ -695,12 +712,13 @@ class _Install
* Step 6
* Install default Language
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step6( $data )
{
/* Install the default language */
$locales = array( 'en_US', 'en_US.utf8', 'en_US.UTF8', 'english' );
$locales = array( 'en_US', 'en_US.UTF-8', 'en_US.UTF8', 'en_US.utf8', 'english' );
foreach ( $locales as $k => $localeCode )
{
try
@@ -738,6 +756,7 @@ class _Install
* Step 7
* Create Languages
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step7( $data )
@@ -767,6 +786,7 @@ class _Install
* Step 8
* Create Email Templates
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step8( $data )
@@ -782,6 +802,7 @@ class _Install
* Step 9
* Create Themes
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step9( $data )
@@ -818,6 +839,7 @@ class _Install
* Step 10
* Create Javascript
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step10( $data )
@@ -848,6 +870,7 @@ class _Install
* Step 11
* Create Search Keywords
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step11( $data )
@@ -863,6 +886,7 @@ class _Install
* Step 12
* Install any widgets/extensions that need adding on install
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step12( $data )
@@ -919,7 +943,7 @@ class _Install
);
}
if( count( $inserts ) )
if( \count( $inserts ) )
{
\IPS\Db::i()->insert( 'core_emoticons', $inserts );
}
@@ -929,7 +953,7 @@ class _Install
{
$fileObj = \IPS\File::create( 'core_Reaction', "react_{$reaction}.png", file_get_contents( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . "/install/reaction/react_{$reaction}.png" ), 'reactions', FALSE, NULL, FALSE );
$id = \IPS\Db::i()->insert( 'core_reactions', array(
'reaction_value' => ( in_array( $reaction, array( 'confused', 'sad' ) ) ) ? 0 : 1,
'reaction_value' => ( \in_array( $reaction, array( 'confused', 'sad' ) ) ) ? 0 : 1,
'reaction_icon' => (string) $fileObj,
'reaction_position' => ++$position,
'reaction_enabled' => 1,
+131 -52
View File
@@ -12,7 +12,7 @@
namespace IPS\core\Setup;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -30,6 +30,12 @@ class _Upgrade
*/
public static function systemRequirements()
{
/* We don't need to check the CIC platform */
if( \IPS\CIC )
{
return array( 'recommendations' => array(), 'requirements' => array() );
}
$return = Install::systemRequirements();
/* MySQL Requirements */
@@ -41,6 +47,13 @@ class _Upgrade
if( \IPS\Db::i()->checkForTable('core_file_storage') )
{
$fileSystemItems = array();
$successfulStorage = FALSE;
$maxChunkSize = \IPS\Helpers\Form\Upload::maxChunkSize();
if ( $maxChunkSize = \IPS\Helpers\Form\Upload::maxChunkSize() )
{
$maxChunkSize = $maxChunkSize / 1048576;
}
foreach ( \IPS\Application::allExtensions( 'core', 'FileStorage', FALSE ) as $k => $v )
{
@@ -66,6 +79,23 @@ class _Upgrade
'success' => TRUE,
'message' => ( $class instanceof \IPS\File\FileSystem ) ? \IPS\Member::loggedIn()->language()->addToStack( 'requirements_file_writable', FALSE, array( 'sprintf' => array( str_replace( '{root}', \IPS\ROOT_PATH, $class->configuration['dir'] ) ) ) ) : $class->displayName( $class->configuration )
);
if ( $maxChunkSize and $class::$supportsChunking and isset( $class::$minChunkSize ) and $class::$minChunkSize > $maxChunkSize )
{
$maxChunkSizeValues = [];
foreach ( \IPS\Helpers\Form\Upload::maxChunkSizeValues() as $k => $v )
{
if ( ( $v / 1048576 ) < $class::$minChunkSize )
{
$maxChunkSizeValues[] = \IPS\Member::loggedIn()->language()->addToStack( 'file_storage_test_chunk_mismatch_value', FALSE, array( 'sprintf' => array( $k, \IPS\Output\Plugin\Filesize::humanReadableFilesize( $v ) ) ) );
}
}
$maxChunkSizeValues = \IPS\Member::loggedIn()->language()->formatList( $maxChunkSizeValues );
$return['advice']["filesystem{$class->configurationId}"] = \IPS\Member::loggedIn()->language()->addToStack( 'file_storage_test_chunk_mismatch', FALSE, array( 'sprintf' => array( $class->displayName( $class->configuration ), \IPS\Output\Plugin\Filesize::humanReadableFilesize( $maxChunkSize * 1048576 ), \IPS\Output\Plugin\Filesize::humanReadableFilesize( $class::$minChunkSize * 1048576 ), $maxChunkSizeValues ) ) );
}
$successfulStorage = TRUE;
}
}
catch ( \Exception $e )
@@ -80,7 +110,15 @@ class _Upgrade
}
}
}
/* Flag a storage issue in upgrader/system check since zero storage methods are working */
if( !$successfulStorage )
{
array_walk( $fileSystemItems, function( &$item ) {
$item['success'] = FALSE;
} );
}
array_splice( $return['requirements'][ $writeablesKey ], array_search( 'uploads', array_keys( $return['requirements'][ $writeablesKey ] ) ), 1, $fileSystemItems );
}
@@ -96,7 +134,6 @@ class _Upgrade
{
unset( $return['requirements'][ $writeablesKey ]['datastore'] );
}
return $return;
}
@@ -109,8 +146,15 @@ class _Upgrade
*/
public static function mysqlRequirements( $db=NULL )
{
/* We don't need to check the CIC platform */
if( \IPS\CIC )
{
return array( 'recommendations' => array(), 'requirements' => array() );
}
/* MySQL Version */
$return = array();
$db ? $db->checkConnection() : \IPS\Db::i()->checkConnection();
$mysqlVersion = $db ? $db->server_info : \IPS\Db::i()->server_info;
$requirements = json_decode( file_get_contents( \IPS\ROOT_PATH . '/applications/core/data/requirements.json' ), TRUE );
if ( version_compare( $mysqlVersion, $requirements['mysql']['required'] ) >= 0 )
@@ -182,7 +226,7 @@ class _Upgrade
/**
* Process
*
* @param array Multiple-Redirector Data
* @param array $data Multiple-Redirector Data
* @return array|null Multiple-Redirector Data or NULL indicates done
*/
public function process( $data )
@@ -200,26 +244,26 @@ class _Upgrade
}
/* Run the step */
$step = intval( $data[0] );
$step = \intval( $data[0] );
if ( $step === 1 )
{
/* Set the we're setting up flag */
static::setUpgradingFlag( TRUE );
if ( function_exists('opcache_reset') )
if ( \function_exists('opcache_reset') )
{
@opcache_reset();
}
}
/* Write the log */
@file_put_contents( \IPS\ROOT_PATH . '/uploads/logs/upgrader_data.cgi', json_encode( array(
/* Write the upgrade data */
$upgraderData = json_encode( array(
'session' => $_SESSION,
'step' => $step,
'data' => $data
) ) );
@chmod( \IPS\ROOT_PATH . '/uploads/logs/upgrader_data.cgi', \IPS\IPS_FILE_PERMISSION );
) );
\IPS\Db::i()->replace( 'upgrade_temp', array( 'id' => 1, 'upgrade_data' => $upgraderData, 'lastaccess' => time() ) );
if ( $step == 11 )
{
@@ -232,10 +276,6 @@ class _Upgrade
/* Clear widget caches */
\IPS\Widget::deleteCaches();
/* Clear store */
\IPS\Data\Cache::i()->clearAll();
\IPS\Data\Store::i()->clearAll();
/* Clear theme cache for default theme */
try
{
@@ -252,6 +292,10 @@ class _Upgrade
/* Make all disk template caches stale */
\IPS\Theme::resetAllCacheKeys();
/* Clear store */
\IPS\Data\Cache::i()->clearAll();
\IPS\Data\Store::i()->clearAll();
/* Remove the flag */
static::setUpgradingFlag( FALSE );
@@ -263,7 +307,8 @@ class _Upgrade
throw new \BadMethodCallException( 'NO_STEP' );
}
$response = call_user_func( array( $this, "step{$step}" ), $data );
$stepFunc = array( $this, "step{$step}" );
$response = $stepFunc( $data );
return array( $response, \IPS\Member::loggedIn()->language()->addToStack( ( $this->customTitle ) ? $this->customTitle : 'upgrade_step_' . $step ), ( ( ( 100/10 ) * $data[0] + ( ( 100/10 ) / 100 * $this->stepProgress ) ) ) ?: 1 );
}
@@ -281,13 +326,13 @@ class _Upgrade
$upgradeSteps = \IPS\Application::load( $app )->getUpgradeSteps( $current ? $current : $currentVersion );
/* Grab next upgrade step to run */
if ( ! count( $upgradeSteps ) )
if ( ! \count( $upgradeSteps ) )
{
return NULL;
}
$next = array_shift( $upgradeSteps );
$next = intval( $next );
$next = \intval( $next );
if( !isset( $_SESSION['upgrade_steps'] ) )
{
@@ -308,7 +353,7 @@ class _Upgrade
/**
* App Looper
*
* @param array data Multiple-Redirector Data
* @param array $data Multiple-Redirector Data
* @param callback $code Code to execute for each app
* @return array Data to Multiple-Redirector Data
*/
@@ -319,7 +364,7 @@ class _Upgrade
$returnNext = FALSE;
foreach ( $this->apps as $app )
{
$this->stepProgress += ( 100 / count( $this->apps ) );
$this->stepProgress += ( 100 / \count( $this->apps ) );
if ( !isset( $data[1] ) )
{
@@ -327,9 +372,9 @@ class _Upgrade
}
elseif ( $data[1] == $app )
{
$val = call_user_func( $code, $app );
$val = $code( $app );
if ( is_array( $val ) OR is_string( $val ) )
if ( \is_array( $val ) OR \is_string( $val ) )
{
return $val;
}
@@ -351,12 +396,13 @@ class _Upgrade
* Step 1
* Upgrade database
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step1( $data )
{
$this->stepProgress = 0;
$perAppProgress = floor( 100 / count( $this->apps ) );
$perAppProgress = floor( 100 / \count( $this->apps ) );
$returnNext = FALSE;
$extra = array();
@@ -419,7 +465,7 @@ class _Upgrade
}
/* What step in the upgrader file are we on? */
$upgradeStep = ( isset($data['extra']['_upgradeStep']) ) ? intval($data['extra']['_upgradeStep']) : 1;
$upgradeStep = ( isset($data['extra']['_upgradeStep']) ) ? \intval($data['extra']['_upgradeStep']) : 1;
/* We're on the first step of the current version's upgrade.php, so run the raw queries yet, do so */
if( $upgradeStep == 1 AND ! isset( $data['extra']['_upgradeData'] ) and ( ! ( isset( $_SESSION['sqlFinished'][ $app ][ $extra['_current'] ] ) AND $_SESSION['sqlFinished'][ $app ][ $extra['_current'] ] ) ) )
@@ -434,6 +480,19 @@ class _Upgrade
try
{
if( file_exists( \IPS\ROOT_PATH . "/applications/{$app}/setup/upg_{$extra['_current']}/lang.json" ) )
{
$langChanges = json_decode( \file_get_contents( \IPS\ROOT_PATH . "/applications/{$app}/setup/upg_{$extra['_current']}/lang.json" ), TRUE );
if ( isset( $langChanges['normal']['removed'] ) and $langChanges['normal']['removed'] )
{
\IPS\Db::i()->delete( 'core_sys_lang_words', array( array( 'word_app=?', $app ), array( 'word_js=0' ), array( \IPS\Db::i()->in( 'word_key', $langChanges['normal']['removed'] ) ) ) );
}
if ( isset( $langChanges['js']['removed'] ) and $langChanges['js']['removed'] )
{
\IPS\Db::i()->delete( 'core_sys_lang_words', array( array( 'word_app=?', $app ), array( 'word_js=1' ), array( \IPS\Db::i()->in( 'word_key', $langChanges['js']['removed'] ) ) ) );
}
}
$fetched = \IPS\Application::load( $app )->installDatabaseUpdates( $extra['_current'], ( \IPS\Request::i()->run_anyway ) ? $lastSqlId - 0.1 : $lastSqlId, 10, !\IPS\Request::i()->run_anyway );
if( isset( \IPS\Request::i()->mr_continue ) AND \IPS\Request::i()->mr_continue )
@@ -465,7 +524,7 @@ class _Upgrade
}
/* Queries to run manually */
if( is_array( $fetched['queriesToRun'] ) and count( $fetched['queriesToRun'] ) )
if( \is_array( $fetched['queriesToRun'] ) and \count( $fetched['queriesToRun'] ) )
{
\IPS\core\Setup\Upgrade::adjustMultipleRedirect( array( 1 => $app, 'extra' => array( 'lastSqlId' => $_SESSION['lastJsonIndex'], '_current' => $extra['_current'] ) ) );
@@ -583,7 +642,7 @@ class _Upgrade
}
}
/* If the result is an array with 'html' key, we show that */
else if( is_array( $result ) AND isset( $result['html'] ) )
else if( \is_array( $result ) AND isset( $result['html'] ) )
{
return $result['html'];
}
@@ -636,7 +695,7 @@ class _Upgrade
} # Foreach
/* We're done, look for finish methods for this upgrade ID */
if ( $lastAppToRun === $app AND isset( $_SESSION['upgrade_steps'] ) AND count( $_SESSION['upgrade_steps'] ) )
if ( $lastAppToRun === $app AND isset( $_SESSION['upgrade_steps'] ) AND \count( $_SESSION['upgrade_steps'] ) )
{
$this->customTitle = "Running finish step (" . ucfirst( $app ) . ': Upgrade ID ' . $extra['_current'] . ')';
@@ -644,6 +703,7 @@ class _Upgrade
{
foreach( $_versionApps as $_versionApp )
{
\IPS\Application::installNewFeatures( $_versionApp, $_versionId );
\IPS\Log::debug( "Running finish step for: {$_versionApp} version {$_versionId}", 'upgrade' );
/* Get the object */
@@ -679,6 +739,7 @@ class _Upgrade
* Step 2
* Run a database check
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step2( $data )
@@ -687,10 +748,10 @@ class _Upgrade
{
$this->customTitle = sprintf( \IPS\Member::loggedIn()->language()->get('upgrade_step_2_app'), $app );
$changesToMake = \IPS\Application::load( $app )->databaseCheck();
if ( count( $changesToMake ) )
if ( \count( $changesToMake ) )
{
$toRun = \IPS\core\Setup\Upgrade::runManualQueries( $changesToMake );
if ( count( $toRun ) )
if ( \count( $toRun ) )
{
\IPS\core\Setup\Upgrade::adjustMultipleRedirect( array( 1 => $app, 'extra' => array( '_upgradeStep' => 2 ) ) );
return \IPS\Theme::i()->getTemplate( 'forms' )->queries( $toRun, \IPS\Http\Url::internal( 'controller=upgrade' )->setQueryString( array( 'key' => $_SESSION['uniqueKey'], 'mr_continue' => 1, 'mr' => \IPS\Request::i()->mr ) ) );
@@ -704,19 +765,34 @@ class _Upgrade
* Step 3
* Insert app data
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step3( $data )
{
/* Set administrator new features flags - if none were added, then it'll automatically reset back */
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( \IPS\Db::i()->in('member_id', \array_keys( \IPS\Member::administrators()['m'] ) ) . " OR " . \IPS\Db::i()->in( 'member_group_id', \array_keys( \IPS\Member::administrators()['g'] ) ) . " OR " . \IPS\Db::i()->findInSet( 'mgroup_others', \array_keys( \IPS\Member::administrators()['g'] ) ) ) ), 'IPS\Member' ) AS $admin )
{
$admin->members_bitoptions['has_new_acp_features'] = TRUE;
$admin->save();
}
return $this->appLoop( $data, function( $app )
{
if( !file_exists( \IPS\ROOT_PATH . '/plugins/hooks.php' ) )
if ( !file_exists( \IPS\SITE_FILES_PATH . '/plugins/hooks.php' ) )
{
@touch( \IPS\ROOT_PATH . '/plugins/hooks.php' );
@chmod( \IPS\ROOT_PATH . '/plugins/hooks.php', 0777 );
if ( \IPS\CIC2 )
{
\IPS\Cicloud\file( 'hooks.php', '', 'plugins' );
}
else
{
@touch( \IPS\SITE_FILES_PATH . '/plugins/hooks.php' );
@chmod( \IPS\SITE_FILES_PATH . '/plugins/hooks.php', 0777 );
}
}
if( !is_writable( \IPS\ROOT_PATH . '/plugins/hooks.php' ) )
if( !\IPS\CIC2 AND !is_writable( \IPS\SITE_FILES_PATH . '/plugins/hooks.php' ) )
{
throw new \RuntimeException( sprintf( \IPS\Member::loggedIn()->language()->get("hook_file_not_writable"), \IPS\ROOT_PATH . '/plugins/hooks.php' ) );
}
@@ -732,7 +808,7 @@ class _Upgrade
$longVersions = array_keys( $versions );
$humanVersions = array_values( $versions );
if( count($versions) )
if( \count($versions) )
{
$latestLVersion = array_pop( $longVersions );
$latestHVersion = array_pop( $humanVersions );
@@ -780,6 +856,7 @@ class _Upgrade
* Step 4
* Update settings, tasks, etc.
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step4( $data )
@@ -798,6 +875,7 @@ class _Upgrade
* Step 5
* Update Languages
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step5( $data )
@@ -839,6 +917,7 @@ class _Upgrade
* Step 6
* Update Email Templates
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step6( $data )
@@ -854,6 +933,7 @@ class _Upgrade
* Step 7
* Update theme settings
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step7( $data )
@@ -882,6 +962,7 @@ class _Upgrade
* Step 8
* Clear existing templates
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step8( $data )
@@ -889,6 +970,13 @@ class _Upgrade
/* Clear old caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Data\Store::i()->clearAll();
if ( \IPS\CIC )
{
/* If this is CiC, make sure the core_store and core_cache tables are empty in case the primary caching engines fail, so we're not serving old data when it falls back to database storage */
\IPS\Db::i()->delete( 'core_store' );
\IPS\Db::i()->delete( 'core_cache' );
}
\IPS\Theme::clearFiles( \IPS\Theme::IMAGES );
@@ -911,6 +999,7 @@ class _Upgrade
* Step 9
* Update templates
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step9( $data )
@@ -959,6 +1048,7 @@ class _Upgrade
* Step 10
* Update Javascript
*
* @param array $data Multi-redirector data
* @return array Multiple-Redirector Data
*/
protected function step10( $data )
@@ -1031,7 +1121,7 @@ class _Upgrade
\IPS\Db::i()->insert( 'core_sys_conf_settings', $insert );
}
\IPS\Settings::i()->changeValues( array( 'setup_in_progress' => intval( $value ) ) );
\IPS\Settings::i()->changeValues( array( 'setup_in_progress' => \intval( $value ) ) );
}
/**
@@ -1058,7 +1148,7 @@ class _Upgrade
{
require( $queryFile );
if ( is_array( $SQL ) )
if ( \is_array( $SQL ) )
{
foreach( $SQL as $k => $query )
{
@@ -1075,7 +1165,7 @@ class _Upgrade
}
catch( \IPS\Db\Exception $e )
{
if ( ! in_array( $e->getCode(), array( 1007, 1008, 1050, 1060, 1061, 1062, 1091, 1051 ) ) )
if ( ! \in_array( $e->getCode(), array( 1007, 1008, 1050, 1060, 1061, 1062, 1091, 1051 ) ) )
{
throw $e;
}
@@ -1088,7 +1178,7 @@ class _Upgrade
/**
* Add SQL Prefix to Query
*
* @param string SQL Query
* @param string $query SQL Query
* @return string
*/
public static function addPrefixToQuery( $query )
@@ -1137,23 +1227,12 @@ class _Upgrade
}
$toReturn = array();
$tableCounts = array();
foreach( $queries as $id => $data )
{
$database = ( isset( $data['db'] ) ) ? $data['db'] : \IPS\Db::i();
if ( ! isset( $tableCounts[ $data['table'] ] ) and $database->checkForTable( $data['table'] ) )
{
$tableCounts[ $data['table'] ] = $database->select( 'count(*)', $data['table'] )->first();
}
}
foreach( $queries as $id => $data )
{
$database = ( isset( $data['db'] ) ) ? $data['db'] : \IPS\Db::i();
if( !\IPS\Request::i()->run_anyway and isset( $tableCounts[ $data['table'] ] ) AND $tableCounts[ $data['table'] ] > \IPS\UPGRADE_MANUAL_THRESHOLD )
if( !\IPS\Request::i()->run_anyway and $database->recommendManualQuery( $data['table'] ) )
{
\IPS\Log::debug( "Big table " . $data['table'] . ", storing query to run manually", 'upgrade' );
@@ -1170,7 +1249,7 @@ class _Upgrade
catch( \IPS\Db\Exception $e )
{
/* If the error isn't important we should ignore it and is consistent with \Application::installDatabaseUpdates() */
if( !in_array( $e->getCode(), array( 1007, 1008, 1050, 1060, 1061, 1062, 1069, 1091 ) ) )
if( !\in_array( $e->getCode(), array( 1007, 1008, 1050, 1060, 1061, 1062, 1069, 1091 ) ) )
{
throw $e;
}
@@ -1255,7 +1334,7 @@ class _Upgrade
foreach( $changes as $k => $v )
{
if( is_array( $v ) )
if( \is_array( $v ) )
{
foreach( $v as $_k => $_v )
{