Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ class _chunkcleanup extends \IPS\Task
$chunksCleanedUp = 0;
/* Loop over file storage configurations */
foreach( \IPS\File::getConfigurations() as $configuration )
foreach( \IPS\File::getStore() as $configuration )
{
/* If this is a filesystem config... */
if( $configuration['method'] == 'FileSystem' )
+28 -1
View File
@@ -30,6 +30,9 @@ class _cleanup extends \IPS\Task
*/
public function execute()
{
/* Delete old failed guest logins for accounts that do not exist */
unset( \IPS\Data\Store::i()->failedLogins );
/* Delete old password / security answer reset requests */
\IPS\Db::i()->delete( 'core_validating', array( '( lost_pass=1 OR forgot_security=1 ) AND email_sent < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ) );
@@ -172,6 +175,13 @@ class _cleanup extends \IPS\Task
\IPS\Db::i()->delete( 'core_api_webhook_fires', array( "status='failed' AND time < ?", \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->webhook_logs_fail . 'D' ) )->getTimestamp() ) );
}
/* ...and points log */
if( \IPS\Settings::i()->prune_points_log )
{
\IPS\Db::i()->delete( 'core_achievements_log', array( 'datetime < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_points_log . 'D' ) )->getTimestamp() ) );
\IPS\Db::i()->delete( 'core_points_log', array( 'datetime < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_points_log . 'D' ) )->getTimestamp() ) );
}
/* Delete old notifications */
if ( \IPS\Settings::i()->prune_notifications )
{
@@ -193,7 +203,10 @@ class _cleanup extends \IPS\Task
/* Delete old follows */
if ( \IPS\Settings::i()->prune_follows AND !\in_array( 'core_follow', $currentlyPruning ) )
{
\IPS\Db::i()->delete( 'core_follow', array( 'follow_member_id IN(?)', \IPS\Db::i()->select( 'member_id', 'core_members', array( 'last_activity < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_follows . 'D' ) )->getTimestamp() ) ) ) );
\IPS\Db::i()->delete( 'core_follow', array( 'follow_app!=? AND follow_area!=? AND follow_member_id IN(?)', 'core', 'member', \IPS\Db::i()->select( 'member_id', 'core_members', array( 'last_activity < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_follows . 'D' ) )->getTimestamp() ) ) ) );
/* And clear the cache so it can rebuild */
\IPS\Db::i()->delete( 'core_follow_count_cache' );
}
/* Delete old item markers */
@@ -284,9 +297,23 @@ class _cleanup extends \IPS\Task
/* Delete old core follow caches */
\IPS\Db::i()->delete( 'core_follow_count_cache', array( 'added < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P30D' ) )->getTimestamp() ) );
/* Delete old core statistic caches */
\IPS\Db::i()->delete( 'core_item_statistics_cache', array( 'cache_added < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ) );
/* Truncate the output caches table */
\IPS\Output\Cache::i()->deleteExpired( TRUE );
/* Turn on things for cloud 2 */
if ( \IPS\CIC2 AND \IPS\Cicloud\getForcedArchiving() )
{
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'archive' ) );
/* 12 years is the cutoff if archiving is forced, so if it's over 12 years, drop the value down */
if( \IPS\Settings::i()->archive_last_post_cloud > 12 )
{
\IPS\Settings::i()->changeValues( array( 'archive_last_post_cloud' => 12 ) );
}
}
return NULL;
}
+1 -1
View File
@@ -40,7 +40,7 @@ class _clearcache extends \IPS\Task
\IPS\Output\Cache::i()->deleteExpired();
/* If we are using Redis, ensure that core_store is empty. We may have switched over to Redis from MySQL and if we switch back, we do not want stale data being used */
if ( \IPS\STORE_METHOD !== 'Database' )
if ( \IPS\STORE_METHOD !== 'Database' AND \IPS\Db::i()->select( 'count(*)', 'core_store' )->first() )
{
\IPS\Db::i()->delete( 'core_store' );
}
+1 -1
View File
@@ -62,7 +62,7 @@ class _clubrebuild extends \IPS\Task
$nodeClass = $node['node_class'];
$node = $nodeClass::load( $node['node_id'] );
if ( $lastCommentTime = $node->getLastCommentTime() and $lastCommentTime->getTimestamp() > $club->last_activity )
if ( $lastCommentTime = $node->getLastCommentTime( new \IPS\Member ) and $lastCommentTime->getTimestamp() > $club->last_activity )
{
$club->last_activity = $lastCommentTime->getTimestamp();
}
+4 -1
View File
@@ -53,7 +53,10 @@ class _pruneipaddresses extends \IPS\Task
/* Personal Messages */
$time = time() - ( 86400 * \IPS\Settings::i()->ip_address_prune );
\IPS\Db::i()->update( 'core_message_posts', array( 'msg_ip_address' => '' ), array( 'msg_date <= ' . $time ) );
\IPS\Db::i()->update( 'core_message_posts', array( 'msg_ip_address' => '' ), array( "msg_ip_address != '' AND msg_date <= " . $time ) );
/* Ratings */
\IPS\Db::i()->update( 'core_ratings', array( 'ip' => '' ), array( "ip != '' AND rating_date IS NOT NULL AND rating_date <= " . $time ) );
return NULL;
}
+58
View File
@@ -0,0 +1,58 @@
<?php
/**
* @brief pwaprune Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 26 Feb 2021
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* pwaprune Task
*/
class _pwaprune extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
$expiration = \IPS\DateTime::ts( time() )->sub( new \DateInterval( 'P2D' ) )->getTimestamp();
\IPS\Db::i()->delete( 'core_notifications_pwa_queue', array( 'expiration<?', $expiration ) );
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+11 -1
View File
@@ -39,7 +39,17 @@ class _s3Delete extends \IPS\Task
{
$s3 = \IPS\Db::i()->select( '*', 'core_s3_deletions' )->first();
$keys = \IPS\File::getClass('core_Theme')->getContainerKeys( $s3['s3_container'], 101, '', $s3['s3_marker'] );
$obj = \IPS\File::getClass('core_Theme');
if ( !( $obj instanceof \IPS\File\Amazon ) )
{
/* Class is not Amazon, so just stop here and truncate the table as there's nothing we can really do now. */
\IPS\Db::i()->delete( 'core_s3_deletions' );
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 's3_delete' ) );
return NULL;
}
$keys = $obj->getContainerKeys( $s3['s3_container'], 101, '', $s3['s3_marker'] );
if ( \count( $keys ) )
{
+146 -99
View File
@@ -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 ) )
{
+3 -3
View File
@@ -154,7 +154,7 @@ class _usagereporting extends \IPS\Task
/* Settings */
foreach ( \IPS\Db::i()->select( array( 'conf_key', 'conf_value', 'conf_default', 'conf_app', 'conf_report' ), 'core_sys_conf_settings', 'conf_report IS NOT NULL' ) as $row )
{
if ( \in_array( $row['conf_app'], \IPS\Application::$ipsApps ) and \IPS\Application::appIsEnabled( $row['conf_app'] ) )
if ( \in_array( $row['conf_app'], \IPS\IPS::$ipsApps ) and \IPS\Application::appIsEnabled( $row['conf_app'] ) )
{
if ( $row['conf_report'] == 'full' )
{
@@ -168,7 +168,7 @@ class _usagereporting extends \IPS\Task
}
/* Database counts */
foreach ( \IPS\Application::$ipsApps as $app )
foreach ( \IPS\IPS::$ipsApps as $app )
{
if ( \IPS\Application::appIsEnabled( $app ) and file_exists( \IPS\ROOT_PATH . "/applications/{$app}/data/schema.json" ) )
{
@@ -276,7 +276,7 @@ class _usagereporting extends \IPS\Task
foreach( \IPS\convert\App::apps() as $app )
{
/* Some legacy converters may not have the correct sw key */
if( !\in_array( $app->sw, \IPS\Application::$ipsApps ) OR !$app->finished )
if( !\in_array( $app->sw, \IPS\IPS::$ipsApps ) OR !$app->finished )
{
continue;
}
+22 -1
View File
@@ -63,7 +63,7 @@ class _viewupdates extends \IPS\Task
catch ( \UnderflowException $e ) { }
/* Now try redis */
if ( \IPS\REDIS_ENABLED and \IPS\CACHE_METHOD == 'Redis' and \IPS\CACHE_CONFIG )
if ( \IPS\REDIS_ENABLED and \IPS\CACHE_METHOD == 'Redis' and ( \IPS\CACHE_CONFIG or \IPS\REDIS_CONFIG ) )
{
try
{
@@ -86,6 +86,27 @@ class _viewupdates extends \IPS\Task
}
catch( \Exception $e ) { }
}
/* Now try advert impressions */
try
{
$redis = \IPS\Redis::i()->zRevRangeByScore( 'advert_impressions', '+inf', '-inf', array('withscores' => TRUE, 'limit' => array( 0, 20 ) ) );
$updates = [];
foreach( $redis as $id => $count )
{
$hasCount = TRUE;
$updates[ $count ][] = $id;
\IPS\Redis::i()->zRem( 'advert_impressions', $id );
}
foreach( $updates as $incrementBy => $ids )
{
\IPS\Db::i()->update( 'core_advertisements', "ad_impressions=ad_impressions+" . $incrementBy, [ \IPS\Db::i()->in( 'ad_id', $ids ) ] );
}
}
catch( \Exception $e ) { }
/* Go for another go? */
if ( $hasCount === TRUE )