Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,16 +11,27 @@
|
||||
namespace IPS\core\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use IPS\Task\Exception;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* deletecontent Task
|
||||
*/
|
||||
class _deletecontent extends \IPS\Task
|
||||
class deletecontent extends Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
@@ -31,16 +42,16 @@ class _deletecontent extends \IPS\Task
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : mixed
|
||||
{
|
||||
$this->runUntilTimeout( function()
|
||||
{
|
||||
$timeago = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->dellog_retention_period . 'D' ) );
|
||||
$timeago = DateTime::create()->sub( new DateInterval( 'P' . Settings::i()->dellog_retention_period . 'D' ) );
|
||||
$count = 0;
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_deletion_log', array( "dellog_deleted_date<?", $timeago->getTimestamp() ), 'dellog_deleted_date ASC', array( 0, 20 ) ), 'IPS\core\DeletionLog' ) AS $log )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_deletion_log', array( "dellog_deleted_date<?", $timeago->getTimestamp() ), 'dellog_deleted_date ASC', array( 0, 20 ) ), 'IPS\core\DeletionLog' ) AS $log )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -52,20 +63,20 @@ class _deletecontent extends \IPS\Task
|
||||
/* Make sure that the content is flagged for deletion */
|
||||
if( $content->hidden() !== -2 )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
$content->delete();
|
||||
}
|
||||
}
|
||||
/* If the content is gone already, don't let an uncaught exception bubble up...just remove the deletion log orphaned entry */
|
||||
catch( \OutOfRangeException $e ){}
|
||||
catch( OutOfRangeException $e ){}
|
||||
|
||||
$log->delete();
|
||||
$count++;
|
||||
}
|
||||
|
||||
return $count ? TRUE : FALSE;
|
||||
return (bool) $count;
|
||||
} );
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in new issue
Block a user