Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -46,7 +46,7 @@ class _updatecheck extends \IPS\Task
|
||||
|
||||
/* Do IPS apps */
|
||||
$versions = array();
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_applications', \IPS\Db::i()->in( 'app_directory', \IPS\Application::$ipsApps ) ) as $app )
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_applications', \IPS\Db::i()->in( 'app_directory', \IPS\IPS::$ipsApps ) ) as $app )
|
||||
{
|
||||
if ( $app['app_enabled'] )
|
||||
{
|
||||
@@ -84,20 +84,81 @@ class _updatecheck extends \IPS\Task
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
$updateChecked = [];
|
||||
|
||||
/* Do everything else */
|
||||
foreach ( \IPS\Db::i()->union(
|
||||
array(
|
||||
\IPS\Db::i()->select( "'core_applications' AS `table`, app_directory AS `id`, app_update_check AS `url`, app_update_last_check AS `last`, app_long_version AS `current`, app_marketplace_id as `marketplace_id`", 'core_applications', "( app_update_check<>'' AND app_update_check IS NOT NULL ) OR app_marketplace_id IS NOT NULL" ),
|
||||
\IPS\Db::i()->select( "'core_plugins' AS `table`, plugin_id AS id, plugin_update_check as url, plugin_update_check_last AS last, plugin_version_long AS `current`, plugin_marketplace_id as `marketplace_id`", 'core_plugins', "(plugin_update_check<>'' AND plugin_update_check IS NOT NULL ) OR plugin_marketplace_id IS NOT NULL" ),
|
||||
\IPS\Db::i()->select( "'core_themes' AS `table`, set_id AS `id`, set_update_check AS `url`, set_update_last_check AS `last`, set_long_version AS `current`, set_marketplace_id as `marketplace_id`", 'core_themes', "(set_update_check<>'' AND set_update_check IS NOT NULL ) OR set_marketplace_id IS NOT NULL" ),
|
||||
\IPS\Db::i()->select( "'core_sys_lang' AS `table`, lang_id AS `id`, `lang_update_url` AS `url`, `lang_update_check` AS `last`, `lang_version_long` AS `current`, `lang_marketplace_id` as `marketplace_id`", "core_sys_lang", "(lang_update_url<>'' AND lang_update_url IS NOT NULL ) OR lang_marketplace_id IS NOT NULL" )
|
||||
),
|
||||
'last ASC',
|
||||
3
|
||||
) as $row )
|
||||
/* Check for bulletins while we're here */
|
||||
try
|
||||
{
|
||||
$bulletins = \IPS\Http\Url::ips('bulletin')->request()->get()->decodeJson();
|
||||
$knownBulletins = iterator_to_array( \IPS\Db::i()->select( 'id', 'core_ips_bulletins' ) );
|
||||
|
||||
foreach ( $bulletins as $id => $bulletin )
|
||||
{
|
||||
if ( \in_array( $id, $knownBulletins ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'core_ips_bulletins', array(
|
||||
'id' => $id,
|
||||
'title' => $bulletin['title'],
|
||||
'body' => $bulletin['body'],
|
||||
'severity' => $bulletin['severity'],
|
||||
'style' => $bulletin['style'],
|
||||
'dismissible' => $bulletin['dismissible'],
|
||||
'link' => $bulletin['link'],
|
||||
'conditions' => $bulletin['conditions'],
|
||||
'cached' => time(),
|
||||
'minVersion' => $bulletin['minVersion'],
|
||||
'maxVersion' => $bulletin['maxVersion']
|
||||
) );
|
||||
|
||||
/* Don't send the notification until after we insert the bulletin data */
|
||||
try
|
||||
{
|
||||
if ( @eval( $bulletin['conditions'] ) )
|
||||
{
|
||||
\IPS\core\AdminNotification::send( 'core', 'Bulletin', $id, FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\core\AdminNotification::remove( 'core', 'Bulletin', $id );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'bulletin' );
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'bulletin' );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \RuntimeException $e ) { }
|
||||
|
||||
$updateChecked = [];
|
||||
$marketplaceUpdates = [];
|
||||
$fails = [];
|
||||
$fiveMinutesAgo = time() - 300;
|
||||
|
||||
$this->runUntilTimeout( function() use ( &$updateChecked, &$marketplaceUpdates, &$fails, $version, $fiveMinutesAgo ) {
|
||||
try
|
||||
{
|
||||
$row = \IPS\Db::i()->union(
|
||||
array(
|
||||
\IPS\Db::i()->select( "'core_applications' AS `table`, app_directory AS `id`, app_update_check AS `url`, app_update_last_check AS `last`, app_long_version AS `current`, app_marketplace_id as `marketplace_id`", 'core_applications', "app_update_last_check<{$fiveMinutesAgo} AND ( ( app_update_check<>'' AND app_update_check IS NOT NULL ) OR app_marketplace_id IS NOT NULL )" ),
|
||||
\IPS\Db::i()->select( "'core_plugins' AS `table`, plugin_id AS id, plugin_update_check as url, plugin_update_check_last AS last, plugin_version_long AS `current`, plugin_marketplace_id as `marketplace_id`", 'core_plugins', "plugin_update_check_last<{$fiveMinutesAgo} AND ( (plugin_update_check<>'' AND plugin_update_check IS NOT NULL ) OR plugin_marketplace_id IS NOT NULL )" ),
|
||||
\IPS\Db::i()->select( "'core_themes' AS `table`, set_id AS `id`, set_update_check AS `url`, set_update_last_check AS `last`, set_long_version AS `current`, set_marketplace_id as `marketplace_id`", 'core_themes', "set_update_last_check<{$fiveMinutesAgo} AND ( (set_update_check<>'' AND set_update_check IS NOT NULL ) OR set_marketplace_id IS NOT NULL )" ),
|
||||
\IPS\Db::i()->select( "'core_sys_lang' AS `table`, lang_id AS `id`, `lang_update_url` AS `url`, `lang_update_check` AS `last`, `lang_version_long` AS `current`, `lang_marketplace_id` as `marketplace_id`", "core_sys_lang", "lang_update_check<{$fiveMinutesAgo} AND ( (lang_update_url<>'' AND lang_update_url IS NOT NULL ) OR lang_marketplace_id IS NOT NULL )" )
|
||||
),
|
||||
'last ASC',
|
||||
1
|
||||
)->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch ( $row['table'] )
|
||||
{
|
||||
case 'core_applications':
|
||||
@@ -105,30 +166,24 @@ class _updatecheck extends \IPS\Task
|
||||
$timeColumn = 'app_update_last_check';
|
||||
$idColumn = 'app_directory';
|
||||
$updateChecked[] = 'applications';
|
||||
$object = \IPS\Application::load( $row['id'] );
|
||||
|
||||
/* Account for legacy applications */
|
||||
try
|
||||
{
|
||||
/* Account for legacy applications */
|
||||
try
|
||||
{
|
||||
$key = "__app_{$row['id']}";
|
||||
$source = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( $key );
|
||||
}
|
||||
catch( \UnexpectedValueException $e )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
$source = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( $key );
|
||||
}
|
||||
catch ( \UnderflowException | \UnexpectedValueException $e )
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'core_plugins':
|
||||
$dataColumn = 'plugin_update_check_data';
|
||||
$timeColumn = 'plugin_update_check_last';
|
||||
$idColumn = 'plugin_id';
|
||||
$object = \IPS\Plugin::load( $row['id'] );
|
||||
$source = $object->name;
|
||||
$source = \IPS\Plugin::load( $row['id'] )->name;
|
||||
$updateChecked[] = 'plugins';
|
||||
break;
|
||||
|
||||
@@ -145,7 +200,7 @@ class _updatecheck extends \IPS\Task
|
||||
$dataColumn = 'lang_update_data';
|
||||
$timeColumn = 'lang_update_check';
|
||||
$idColumn = 'lang_id';
|
||||
$source = \IPS\Lang::load( $row['id'] )->name;
|
||||
$source = \IPS\Lang::load( $row['id'] )->_title;
|
||||
$updateChecked[] = 'languages';
|
||||
break;
|
||||
}
|
||||
@@ -155,28 +210,22 @@ class _updatecheck extends \IPS\Task
|
||||
/* Query the marketplace */
|
||||
if( $row['marketplace_id'] )
|
||||
{
|
||||
if( $this->_marketplaceController === null )
|
||||
{
|
||||
$this->_marketplaceController = new \IPS\core\modules\admin\marketplace\marketplace;
|
||||
}
|
||||
$marketplaceUpdates[ $row['marketplace_id'] ] = [
|
||||
'table' => $row['table'],
|
||||
'current' => $row['current'],
|
||||
'dataColumn' => $dataColumn,
|
||||
'timeColumn' => $timeColumn,
|
||||
'idColumn' => $idColumn,
|
||||
'id' => $row['id'],
|
||||
'marketplace_id'=> $row['marketplace_id']
|
||||
];
|
||||
|
||||
/* Get update information */
|
||||
try
|
||||
{
|
||||
$response = $this->_marketplaceController->_updateCheck( $row['marketplace_id'], $row['current'] );
|
||||
}
|
||||
catch( \Throwable $e )
|
||||
{
|
||||
throw new \RuntimeException( $e->getMessage(), $e->getCode() );
|
||||
}
|
||||
/* Update the timestamp so we can deal with other resources */
|
||||
\IPS\Db::i()->update( $row['table'], array(
|
||||
$timeColumn => time()
|
||||
), array( "{$idColumn}=?", $row['id'] ) );
|
||||
|
||||
/* Use a local update URL */
|
||||
$response['updateurl'] = (string) \IPS\Http\Url::internal("app=core&module=marketplace&controller=marketplace&do=viewFile&id={$row['marketplace_id']}");
|
||||
if( isset( $object ) AND isset( $response['disableresource'] ) AND $response['disableresource'] === TRUE )
|
||||
{
|
||||
$object->_enabled = FALSE;
|
||||
$object->save();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
/* Query the applications update URL */
|
||||
else
|
||||
@@ -216,6 +265,52 @@ class _updatecheck extends \IPS\Task
|
||||
$timeColumn => time()
|
||||
), array( "{$idColumn}=?", $row['id'] ) );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
});
|
||||
|
||||
/* Check Marketplace updates in bulk */
|
||||
if( \count( $marketplaceUpdates ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$marketplaceController = new \IPS\core\modules\admin\marketplace\marketplace;
|
||||
$response = $marketplaceController->_updateCheck( array_column( $marketplaceUpdates, 'current', 'marketplace_id' ) );
|
||||
|
||||
foreach( $marketplaceUpdates as $resourceId => $resourceData )
|
||||
{
|
||||
$releaseData = $response[ $resourceId ] ?? NULL;
|
||||
|
||||
if( $releaseData !== NULL )
|
||||
{
|
||||
if( $resourceData['table'] == 'core_applications' )
|
||||
{
|
||||
$object = \IPS\Application::load( $resourceData['id'] );
|
||||
}
|
||||
elseif( $resourceData['table'] == 'core_plugins' )
|
||||
{
|
||||
$object = \IPS\Plugin::load( $resourceData['id'] );
|
||||
}
|
||||
|
||||
/* Use a local update URL */
|
||||
$releaseData['updateurl'] = (string) \IPS\Http\Url::internal("app=core&module=marketplace&controller=marketplace&do=viewFile&id={$resourceId}", 'admin' );
|
||||
if( isset( $object ) AND isset( $releaseData['disableresource'] ) AND $releaseData['disableresource'] === TRUE )
|
||||
{
|
||||
$object->_enabled = FALSE;
|
||||
$object->save();
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( $resourceData['table'], array(
|
||||
$resourceData['dataColumn'] => json_encode( $releaseData ),
|
||||
$resourceData['timeColumn'] => time()
|
||||
), array( "{$resourceData['idColumn']}=?", $resourceData['id'] ) );
|
||||
}
|
||||
}
|
||||
catch( \RuntimeException | \UnexpectedValueException $e )
|
||||
{
|
||||
$fails[] = '';
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset Menu Cache */
|
||||
@@ -224,54 +319,6 @@ class _updatecheck extends \IPS\Task
|
||||
$key = 'updatecount_' . $type;
|
||||
unset( \IPS\Data\Store::i()->$key, \IPS\Data\Store::i()->$type );
|
||||
}
|
||||
|
||||
/* Check for bulletins while we're here */
|
||||
try
|
||||
{
|
||||
$bulletins = \IPS\Http\Url::ips('bulletin')->request()->get()->decodeJson();
|
||||
$knownBulletins = iterator_to_array( \IPS\Db::i()->select( 'id', 'core_ips_bulletins' ) );
|
||||
|
||||
foreach ( $bulletins as $id => $bulletin )
|
||||
{
|
||||
if ( \in_array( $id, $knownBulletins ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( @eval( $bulletin['conditions'] ) )
|
||||
{
|
||||
\IPS\core\AdminNotification::send( 'core', 'Bulletin', $id, FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\core\AdminNotification::remove( 'core', 'Bulletin', $id );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'bulletin' );
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'bulletin' );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'core_ips_bulletins', array(
|
||||
'id' => $id,
|
||||
'title' => $bulletin['title'],
|
||||
'body' => $bulletin['body'],
|
||||
'severity' => $bulletin['severity'],
|
||||
'style' => $bulletin['style'],
|
||||
'dismissible' => $bulletin['dismissible'],
|
||||
'link' => $bulletin['link'],
|
||||
'conditions' => $bulletin['conditions'],
|
||||
'cached' => time()
|
||||
) );
|
||||
}
|
||||
}
|
||||
catch( \RuntimeException $e ) { }
|
||||
|
||||
if ( !empty( $fails ) )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user