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,43 +12,55 @@
|
||||
namespace IPS\downloads\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\File;
|
||||
use IPS\Image;
|
||||
use IPS\Member;
|
||||
use IPS\Settings;
|
||||
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 _RebuildScreenshotWatermarks
|
||||
class RebuildScreenshotWatermarks extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Number of 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
|
||||
{
|
||||
$watermark = \IPS\Settings::i()->idm_watermarkpath ? \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() : NULL;
|
||||
$watermark = Settings::i()->idm_watermarkpath ? File::get( 'core_Theme', Settings::i()->idm_watermarkpath )->contents() : NULL;
|
||||
$where = array( array( 'record_type=?', 'ssupload' ) );
|
||||
if ( !$watermark )
|
||||
{
|
||||
$where[] = array( 'record_no_watermark<>?', '' );
|
||||
}
|
||||
|
||||
$data['count'] = \IPS\Db::i()->select( 'MAX(record_id)', 'downloads_files_records', $where )->first();
|
||||
$data['realCount'] = \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files_records', $where )->first();
|
||||
$data['count'] = Db::i()->select( 'MAX(record_id)', 'downloads_files_records', $where )->first();
|
||||
$data['realCount'] = Db::i()->select( 'COUNT(*)', 'downloads_files_records', $where )->first();
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -71,10 +83,10 @@ class _RebuildScreenshotWatermarks
|
||||
* @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
|
||||
{
|
||||
$last = NULL;
|
||||
$watermark = \IPS\Settings::i()->idm_watermarkpath ? \IPS\Image::create( \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() ) : NULL;
|
||||
$watermark = Settings::i()->idm_watermarkpath ? Image::create( File::get( 'core_Theme', Settings::i()->idm_watermarkpath )->contents() ) : NULL;
|
||||
|
||||
$where = array( array( 'record_id>? AND record_type=?', $offset, 'ssupload' ) );
|
||||
if ( !$watermark )
|
||||
@@ -82,7 +94,7 @@ class _RebuildScreenshotWatermarks
|
||||
$where[] = array( 'record_no_watermark<>?', '' );
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( '*', 'downloads_files_records', $where, 'record_id', array( 0, $this->rebuild ) );
|
||||
$select = Db::i()->select( '*', 'downloads_files_records', $where, 'record_id', array( 0, $this->rebuild ) );
|
||||
|
||||
foreach ( $select as $row )
|
||||
{
|
||||
@@ -90,18 +102,18 @@ class _RebuildScreenshotWatermarks
|
||||
{
|
||||
if ( $row['record_no_watermark'] )
|
||||
{
|
||||
$original = \IPS\File::get( 'downloads_Screenshots', $row['record_no_watermark'] );
|
||||
$original = File::get( 'downloads_Screenshots', $row['record_no_watermark'] );
|
||||
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'downloads_Screenshots', $row['record_location'] )->delete();
|
||||
\IPS\File::get( 'downloads_Screenshots', $row['record_thumb'] )->delete();
|
||||
File::get( 'downloads_Screenshots', $row['record_location'] )->delete();
|
||||
File::get( 'downloads_Screenshots', $row['record_thumb'] )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
|
||||
if ( !$watermark )
|
||||
{
|
||||
\IPS\Db::i()->update( 'downloads_files_records', array(
|
||||
Db::i()->update( 'downloads_files_records', array(
|
||||
'record_location' => (string) $original,
|
||||
'record_thumb' => (string) $original->thumbnail( 'downloads_Screenshots' ),
|
||||
'record_no_watermark' => NULL
|
||||
@@ -115,21 +127,21 @@ class _RebuildScreenshotWatermarks
|
||||
}
|
||||
else
|
||||
{
|
||||
$original = \IPS\File::get( 'downloads_Screenshots', $row['record_location'] );
|
||||
$original = File::get( 'downloads_Screenshots', $row['record_location'] );
|
||||
}
|
||||
|
||||
$image = \IPS\Image::create( $original->contents() );
|
||||
$image = Image::create( $original->contents() );
|
||||
$image->watermark( $watermark );
|
||||
|
||||
$newFile = \IPS\File::create( 'downloads_Screenshots', $original->originalFilename, $image );
|
||||
$newFile = File::create( 'downloads_Screenshots', $original->originalFilename, $image );
|
||||
|
||||
\IPS\Db::i()->update( 'downloads_files_records', array(
|
||||
Db::i()->update( 'downloads_files_records', array(
|
||||
'record_location' => (string) $newFile,
|
||||
'record_thumb' => (string) $newFile->thumbnail( 'downloads_Screenshots' ),
|
||||
'record_no_watermark' => (string) $original
|
||||
), array( 'record_id=?', $row['record_id'] ) );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
|
||||
$data['indexed']++;
|
||||
$last = $row['record_id'];
|
||||
@@ -149,10 +161,10 @@ class _RebuildScreenshotWatermarks
|
||||
* @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('downloads_rebuilding_screenshots'), 'complete' => ( $data['realCount'] * $data['indexed'] ) > 0 ? round( ( $data['realCount'] * $data['indexed'] ) * 100, 2 ) : 0 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('downloads_rebuilding_screenshots'), 'complete' => ( $data['realCount'] * $data['indexed'] ) > 0 ? round( ( $data['realCount'] * $data['indexed'] ) * 100, 2 ) : 0 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user