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

@@ -11,32 +11,48 @@
namespace IPS\core\modules\admin\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Db;
use IPS\Dispatcher\Controller;
use IPS\Helpers\MultipleRedirect;
use IPS\Http\Url;
use IPS\Member;
use IPS\Output;
use IPS\Session;
use IPS\Task;
use IPS\Theme;
use UnderflowException;
use function defined;
use function intval;
use function is_array;
use const IPS\CIC;
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;
}
/**
* Background processes 'Run Now'
*/
class _background extends \IPS\Dispatcher\Controller
class background extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
if ( \IPS\CIC )
if ( CIC )
{
\IPS\Output::i()->error( 'no_writes', '2C347/1', 403, '' );
Output::i()->error( 'no_writes', '2C347/1', 403, '' );
}
parent::execute();
@@ -47,10 +63,10 @@ class _background extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('background_process_run_title');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'system' )->backgroundProcessesRunNow();
Output::i()->title = Member::loggedIn()->language()->addToStack('background_process_run_title');
Output::i()->output = Theme::i()->getTemplate( 'system' )->backgroundProcessesRunNow();
}
/**
@@ -58,35 +74,35 @@ class _background extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function process()
protected function process() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
$self = $this;
$multiRedirect = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal('app=core&module=system&controller=background&do=process')->csrf(),
$multiRedirect = new MultipleRedirect(
Url::internal('app=core&module=system&controller=background&do=process')->csrf(),
function( $data ) use ( $self )
{
/* Make sure the task is locked */
$task = \IPS\Task::load('queue', 'key');
$task = Task::load('queue', 'key');
$task->running = TRUE;
$task->next_run = time() + 900;
$task->save();
if ( ! \is_array( $data ) )
if ( ! is_array( $data ) )
{
$count = $self->getCount();
return array( array( 'count' => $count, 'done' => 0 ), \IPS\Member::loggedIn()->language()->addToStack('background_process_starting') );
return array( array( 'count' => $count, 'done' => 0 ), Member::loggedIn()->language()->addToStack('background_process_starting') );
}
else
{
try
{
/* Run the next queue task, if any */
$queueData = \IPS\Task::runQueue();
$queueData = Task::runQueue();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
/* If we're here it means there were no rows in core_queue and we are done */
return NULL;
@@ -113,7 +129,7 @@ class _background extends \IPS\Dispatcher\Controller
if ( isset( $json['count'] ) )
{
/* If the offset is larger than the count, then we should just show the count instead (to avoid situations where it will display 150 / 139, for example) */
$offset = \intval( $queueData['offset'] );
$offset = intval( $queueData['offset'] );
if ( $offset > $json['count'] )
{
$offset = $json['count'];
@@ -121,25 +137,25 @@ class _background extends \IPS\Dispatcher\Controller
$lang[] = " " . $offset . ' / ' . $json['count'];
}
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('background_processes_processing', FALSE, array( 'sprintf' => array( implode( ' - ', $lang ) ) ) ), ( $data['count'] ) ? round( ( 100 / $data['count'] * $data['done'] ), 2 ) : 100 );
return array( $data, Member::loggedIn()->language()->addToStack('background_processes_processing', FALSE, array( 'sprintf' => array( implode( ' - ', $lang ) ) ) ), ( $data['count'] ) ? round( ( 100 / $data['count'] * $data['done'] ), 2 ) : 100 );
}
},
function()
{
/* Make sure the task is unlocked */
$task = \IPS\Task::load('queue', 'key');
$task = Task::load('queue', 'key');
$task->running = FALSE;
$task->next_run = time() + 60;
$task->save();
\IPS\Session::i()->log( 'acplog__background_tasks_ran' );
Session::i()->log( 'acplog__background_tasks_ran' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=overview&controller=dashboard'), 'completed' );
Output::i()->redirect( Url::internal('app=core&module=overview&controller=dashboard'), 'completed' );
}
);
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('background_process_run_title');
\IPS\Output::i()->output = $multiRedirect;
Output::i()->title = Member::loggedIn()->language()->addToStack('background_process_run_title');
Output::i()->output = $multiRedirect;
}
/**
@@ -147,10 +163,10 @@ class _background extends \IPS\Dispatcher\Controller
*
* @return int
*/
public function getCount()
public function getCount() : int
{
$count = 0;
foreach( \IPS\Db::i()->select( '*', 'core_queue' ) as $row )
foreach( Db::i()->select( '*', 'core_queue' ) as $row )
{
if ( ! empty( $row['data'] ) )
{
@@ -158,11 +174,11 @@ class _background extends \IPS\Dispatcher\Controller
if( isset( $data['realCount'] ) )
{
$count += \intval( $data['realCount'] );
$count += intval( $data['realCount'] );
}
elseif ( isset( $data['count'] ) )
{
$count += \intval( $data['count'] );
$count += intval( $data['count'] );
}
else
{