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

+64 -52
View File
@@ -11,37 +11,58 @@
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\Application;
use IPS\core\AdminNotification;
use IPS\Data\Store;
use IPS\Db;
use IPS\Http\Url;
use IPS\IPS;
use IPS\Lang;
use IPS\Log;
use IPS\Settings;
use IPS\Task;
use RuntimeException;
use Throwable;
use UnderflowException;
use UnexpectedValueException;
use function count;
use function defined;
use const IPS\IPS_ALPHA_BUILD;
use const IPS\USE_DEVELOPMENT_BUILDS;
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;
}
/**
* updatecheck Task
*/
class _updatecheck extends \IPS\Task
class updatecheck extends Task
{
/**
* @brief Type to send to update server
*/
public $type = 'task';
public string $type = 'task';
/**
* Execute
*
* @return mixed Message to log or NULL
*/
public function execute()
public function execute() : mixed
{
/* Refresh stored license data */
\IPS\IPS::licenseKey( TRUE );
IPS::licenseKey( TRUE );
$fails = array();
/* Do IPS apps */
$versions = array();
foreach ( \IPS\Db::i()->select( '*', 'core_applications', \IPS\Db::i()->in( 'app_directory', \IPS\IPS::$ipsApps ) ) as $app )
foreach ( Db::i()->select( '*', 'core_applications', Db::i()->in( 'app_directory', IPS::$ipsApps ) ) as $app )
{
if ( $app['app_enabled'] )
{
@@ -49,12 +70,12 @@ class _updatecheck extends \IPS\Task
}
}
$version = min( $versions );
$url = \IPS\Http\Url::ips('updateCheck')->setQueryString( array( 'type' => $this->type, 'key' => \IPS\Settings::i()->ipb_reg_number ) );
if ( \IPS\USE_DEVELOPMENT_BUILDS )
$url = Url::ips('updateCheck5')->setQueryString( array( 'type' => $this->type, 'key' => Settings::i()->ipb_reg_number ) );
if ( USE_DEVELOPMENT_BUILDS )
{
$url = $url->setQueryString( 'development', 1 );
}
if ( \IPS\IPS_ALPHA_BUILD )
if ( IPS_ALPHA_BUILD )
{
$url = $url->setQueryString( 'alpha', 1 );
}
@@ -62,31 +83,31 @@ class _updatecheck extends \IPS\Task
{
$response = $url->setQueryString( 'version', $version )->request()->get()->decodeJson();
$coreApp = \IPS\Application::load('core');
$coreApp = Application::load('core');
$coreApp->update_version = json_encode( $response );
$coreApp->update_last_check = time();
$coreApp->save();
/* Send a notification if new version is available */
if ( $updates = $coreApp->availableUpgrade() and \count( $updates ) )
if ( $updates = $coreApp->availableUpgrade( TRUE ) and count( $updates ) )
{
\IPS\core\AdminNotification::send( 'core', 'NewVersion', NULL, FALSE );
AdminNotification::send( 'core', 'NewVersion', NULL, FALSE );
}
else
{
\IPS\core\AdminNotification::remove( 'core', 'NewVersion' );
AdminNotification::remove( 'core', 'NewVersion' );
}
}
catch ( \Exception $e ) { }
catch ( Exception $e ) { }
/* Check for bulletins while we're here */
try
{
$bulletins = \IPS\Http\Url::ips('bulletin')->request()->get()->decodeJson();
$bulletins = Url::ips('bulletin')->request()->get()->decodeJson();
foreach ( $bulletins as $id => $bulletin )
{
\IPS\Db::i()->insert( 'core_ips_bulletins', array(
Db::i()->insert( 'core_ips_bulletins', array(
'id' => $id,
'title' => $bulletin['title'],
@@ -108,36 +129,36 @@ class _updatecheck extends \IPS\Task
/* If the value is 0 for minVersion, there is no minimum version (a.k.a., display it). Same deal with maxVersion. */
( $bulletin['minVersion'] == 0 AND $bulletin['maxVersion'] == 0 )
/* If there's no minimum version, and the maximum Version is within range */
OR ( $bulletin['minVersion'] == 0 AND \IPS\Application::load('core')->long_version < $bulletin['maxVersion'] )
OR ( $bulletin['minVersion'] == 0 AND Application::load('core')->long_version < $bulletin['maxVersion'] )
/* If there's no maximum version, and the minimum version is within range */
OR ( $bulletin['maxVersion'] == 0 AND \IPS\Application::load('core')->long_version > $bulletin['minVersion'] )
OR ( $bulletin['maxVersion'] == 0 AND Application::load('core')->long_version > $bulletin['minVersion'] )
/* If both min and max versions are within range */
OR ( \IPS\Application::load('core')->long_version >= $bulletin['minVersion'] AND \IPS\Application::load('core')->long_version <= $bulletin['maxVersion'] )
OR ( Application::load('core')->long_version >= $bulletin['minVersion'] AND Application::load('core')->long_version <= $bulletin['maxVersion'] )
)
{
if ( @eval( $bulletin['conditions'] ) )
{
\IPS\core\AdminNotification::send( 'core', 'Bulletin', (string) $id, FALSE );
AdminNotification::send( 'core', 'Bulletin', (string) $id, FALSE );
}
else
{
\IPS\core\AdminNotification::remove( 'core', 'Bulletin', (string) $id );
AdminNotification::remove( 'core', 'Bulletin', (string) $id );
}
}
else
{
\IPS\core\AdminNotification::remove( 'core', 'Bulletin', (string) $id );
AdminNotification::remove( 'core', 'Bulletin', (string) $id );
}
}
catch ( \Throwable | \Exception $e )
catch ( Throwable | Exception $e )
{
\IPS\Log::log( $e, 'bulletin' );
Log::log( $e, 'bulletin' );
}
}
}
catch( \RuntimeException $e ){ }
catch( RuntimeException $e ){ }
$updateChecked = [];
$fails = [];
@@ -146,18 +167,17 @@ class _updatecheck extends \IPS\Task
$this->runUntilTimeout( function() use ( &$updateChecked, &$fails, $version, $fiveMinutesAgo ) {
try
{
$row = \IPS\Db::i()->union(
$row = 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`", 'core_applications', "app_update_last_check<{$fiveMinutesAgo} AND ( app_update_check<>'' AND app_update_check 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`", 'core_plugins', "plugin_update_check_last<{$fiveMinutesAgo} AND ( plugin_update_check<>'' AND plugin_update_check 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`", 'core_themes', "set_update_last_check<{$fiveMinutesAgo} AND ( set_update_check<>'' AND set_update_check 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`", "core_sys_lang", "lang_update_check<{$fiveMinutesAgo} AND ( lang_update_url<>'' AND lang_update_url IS NOT NULL )" )
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`", 'core_applications', "app_update_last_check<{$fiveMinutesAgo} AND ( app_update_check<>'' AND app_update_check IS NOT NULL )" ),
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`", 'core_themes', "set_update_last_check<{$fiveMinutesAgo} AND (set_update_check<>'' AND set_update_check IS NOT NULL )" ),
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`", "core_sys_lang", "lang_update_check<{$fiveMinutesAgo} AND (lang_update_url<>'' AND lang_update_url IS NOT NULL )" )
),
'last ASC',
1
)->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
return FALSE;
}
@@ -174,28 +194,20 @@ class _updatecheck extends \IPS\Task
try
{
$key = "__app_{$row['id']}";
$source = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( $key );
$source = Lang::load( Lang::defaultLanguage() )->get( $key );
}
catch ( \UnderflowException | \UnexpectedValueException $e )
catch ( UnderflowException | UnexpectedValueException $e )
{
return;
return null;
}
break;
case 'core_plugins':
$dataColumn = 'plugin_update_check_data';
$timeColumn = 'plugin_update_check_last';
$idColumn = 'plugin_id';
$source = \IPS\Plugin::load( $row['id'] )->name;
$updateChecked[] = 'plugins';
break;
case 'core_themes':
$dataColumn = 'set_update_data';
$timeColumn = 'set_update_last_check';
$idColumn = 'set_id';
$key = "core_theme_set_title_{$row['id']}";
$source = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( $key );
$source = Lang::load( Lang::defaultLanguage() )->get( $key );
$updateChecked[] = 'themes';
break;
@@ -203,14 +215,14 @@ class _updatecheck extends \IPS\Task
$dataColumn = 'lang_update_data';
$timeColumn = 'lang_update_check';
$idColumn = 'lang_id';
$source = \IPS\Lang::load( $row['id'] )->_title;
$source = Lang::load( $row['id'] )->_title;
$updateChecked[] = 'languages';
break;
}
try
{
$url = \IPS\Http\Url::external( $row['url'] )->setQueryString( array( 'version' => $row['current'], 'ips_version' => $version ) );
$url = Url::external( $row['url'] )->setQueryString( array( 'version' => $row['current'], 'ips_version' => $version ) );
$response = $url->request()->get()->decodeJson();
/* Unset the object so it isn't present for next update check. */
@@ -219,28 +231,28 @@ class _updatecheck extends \IPS\Task
/* Did we get all the information we need? */
if ( !isset( $response['version'], $response['longversion'], $response['released'], $response['updateurl'] ) )
{
throw new \RuntimeException( \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'update_check_missing' ) );
throw new RuntimeException( Lang::load( Lang::defaultLanguage() )->get( 'update_check_missing' ) );
}
/* Save the latest version data and move on to the next app */
\IPS\Db::i()->update( $row['table'], array(
Db::i()->update( $row['table'], array(
$dataColumn => json_encode( array(
'version' => $response['version'],
'longversion' => $response['longversion'],
'released' => $response['released'],
'updateurl' => $response['updateurl'],
'releasenotes' => isset( $response['releasenotes'] ) ? $response['releasenotes'] : NULL
'releasenotes' => $response['releasenotes'] ?? NULL
) ),
$timeColumn => time()
), array( "{$idColumn}=?", $row['id'] ) );
}
/* \RuntimeException catches BAD_JSON and \IPS\Http\Request\Exception both */
catch ( \RuntimeException $e )
catch ( RuntimeException $e )
{
$fails[] = $source . ": " . $e->getMessage();
/* Save the time so that the next time the task runs it can move on to other apps/plugins/themes */
\IPS\Db::i()->update( $row['table'], array(
Db::i()->update( $row['table'], array(
$timeColumn => time()
), array( "{$idColumn}=?", $row['id'] ) );
}
@@ -252,7 +264,7 @@ class _updatecheck extends \IPS\Task
foreach( $updateChecked as $type )
{
$key = 'updatecount_' . $type;
unset( \IPS\Data\Store::i()->$key, \IPS\Data\Store::i()->$type );
unset( Store::i()->$key, Store::i()->$type );
}
if ( !empty( $fails ) )