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,37 +12,49 @@
|
||||
namespace IPS\gallery\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\File;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use const IPS\REBUILD_INTENSE;
|
||||
|
||||
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 Task
|
||||
*/
|
||||
class _RebuildGalleryImages
|
||||
class RebuildGalleryImages extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = \IPS\REBUILD_INTENSE;
|
||||
public int $rebuild = REBUILD_INTENSE;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images', array( 'image_media=?', 0 ) )->first();
|
||||
$data['count'] = Db::i()->select( 'COUNT(*)', 'gallery_images', array( 'image_media=?', 0 ) )->first();
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
@@ -63,14 +75,14 @@ class _RebuildGalleryImages
|
||||
* @return int New offset
|
||||
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
public function run( mixed &$data, int $offset ): int
|
||||
{
|
||||
if ( !\IPS\Application::appIsEnabled( 'gallery' ) )
|
||||
if ( !Application::appIsEnabled( 'gallery' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$iterator = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_images', array( array( 'image_media=? AND image_id>?', 0, $offset ) ), 'image_id ASC', array( 0, $this->rebuild ) ), 'IPS\\gallery\\Image' );
|
||||
$iterator = new ActiveRecordIterator( Db::i()->select( '*', 'gallery_images', array( array( 'image_media=? AND image_id>?', 0, $offset ) ), 'image_id ASC', array( 0, $this->rebuild ) ), 'IPS\\gallery\\Image' );
|
||||
$last = NULL;
|
||||
|
||||
foreach( $iterator as $image )
|
||||
@@ -78,13 +90,16 @@ class _RebuildGalleryImages
|
||||
try
|
||||
{
|
||||
/* Make sure the original image exists and has content */
|
||||
$file = \IPS\File::get( 'gallery_Images', $image->original_file_name );
|
||||
$file->contents();
|
||||
if ( $image->original_file_name )
|
||||
{
|
||||
$file = File::get( 'gallery_Images', $image->original_file_name );
|
||||
$file->contents();
|
||||
|
||||
$image->buildThumbnails( $file );
|
||||
$image->save();
|
||||
$image->buildThumbnails( $file );
|
||||
$image->save();
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
catch ( Exception ) {}
|
||||
|
||||
$last = $image->id;
|
||||
$data['indexed']++;
|
||||
@@ -104,10 +119,10 @@ class _RebuildGalleryImages
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
|
||||
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
public function getProgress( mixed $data, int $offset ): array
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_gallery_images' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['indexed'], 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('rebuilding_gallery_images' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['indexed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user