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
@@ -12,16 +12,27 @@
|
||||
namespace IPS\gallery\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Lang;
|
||||
use IPS\Task;
|
||||
use function count;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear temporary uploads task
|
||||
*/
|
||||
class _clearUploads extends \IPS\Task
|
||||
class clearUploads extends Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
@@ -32,33 +43,33 @@ class _clearUploads 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 Task\Exception
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : mixed
|
||||
{
|
||||
$cutoff = \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp();
|
||||
$cutoff = DateTime::create()->sub( new DateInterval( 'P1D' ) )->getTimestamp();
|
||||
$sessions = array();
|
||||
$messages = array();
|
||||
$errorLang = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'gallery_clear_uploads_error' );
|
||||
$errorLang = Lang::load( Lang::defaultLanguage() )->get( 'gallery_clear_uploads_error' );
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'gallery_images_uploads', array( 'upload_date < ?', $cutoff ) ) as $upload )
|
||||
foreach( Db::i()->select( '*', 'gallery_images_uploads', array( 'upload_date < ?', $cutoff ) ) as $upload )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\File::get( 'gallery_Images', $upload['upload_location'] );
|
||||
$file = File::get( 'gallery_Images', $upload['upload_location'] );
|
||||
$file->delete();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
$messages[] = sprintf( $errorLang, (string) $file, $e->getMessage() );
|
||||
$messages[] = sprintf( $errorLang, $file ?? '', $e->getMessage() );
|
||||
}
|
||||
|
||||
$sessions[ $upload['upload_session'] ] = $upload['upload_session'];
|
||||
}
|
||||
|
||||
if( \count( $sessions ) )
|
||||
if( count( $sessions ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'gallery_images_uploads', array( array( "upload_session IN('" . implode( "','", $sessions ) . "')" ) ) );
|
||||
Db::i()->delete( 'gallery_images_uploads', array( array( "upload_session IN('" . implode( "','", $sessions ) . "')" ) ) );
|
||||
}
|
||||
|
||||
return !empty( $messages ) ? implode( '; ', $messages ) : NULL;
|
||||
@@ -73,7 +84,7 @@ class _clearUploads extends \IPS\Task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup()
|
||||
public function cleanup() : void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user