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
@@ -1,170 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Gallery
|
||||
* @since 06 Mar 2018
|
||||
*/
|
||||
|
||||
namespace IPS\gallery\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _CleanUpGalleryImages
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images', array( 'image_media=?', 0 ) )->first();
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['did'] = 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return int New offset
|
||||
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
if ( !\IPS\Application::appIsEnabled( 'gallery' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$last = NULL;
|
||||
foreach( \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_media=? AND image_id > ?', 0, (int) $offset ), 'image_id ASC', \IPS\REBUILD_SLOW ) as $image )
|
||||
{
|
||||
$data['did']++;
|
||||
|
||||
/* Update the sizes array to remove the images we no longer support */
|
||||
$sizes = json_decode( $image['image_data'], true );
|
||||
|
||||
if( isset( $sizes['thumb'] ) )
|
||||
{
|
||||
unset( $sizes['thumb'] );
|
||||
}
|
||||
|
||||
if( isset( $sizes['medium'] ) )
|
||||
{
|
||||
unset( $sizes['medium'] );
|
||||
}
|
||||
|
||||
$update = array( 'image_data' => json_encode( $sizes ) );
|
||||
|
||||
/* If we have a medium but no large image, or a thumb but no small image, adapt as appropriate. Also if one image is mapped for
|
||||
multiple columns be sure we don't remove it if we still need it. */
|
||||
$keepMedium = FALSE;
|
||||
if( $image['image_medium_file_name'] == $image['image_masked_file_name'] )
|
||||
{
|
||||
$keepMedium = TRUE;
|
||||
}
|
||||
$keepThumb = FALSE;
|
||||
if( $image['image_thumb_file_name'] == $image['image_masked_file_name'] )
|
||||
{
|
||||
$keepThumb = TRUE;
|
||||
}
|
||||
|
||||
if( !$image['image_masked_file_name'] AND $image['image_medium_file_name'] )
|
||||
{
|
||||
$image['image_masked_file_name'] = $image['image_medium_file_name'];
|
||||
$update['image_masked_file_name'] = $image['image_masked_file_name'];
|
||||
$keepMedium = TRUE;
|
||||
}
|
||||
|
||||
if( !$image['image_small_file_name'] AND $image['image_thumb_file_name'] )
|
||||
{
|
||||
$image['image_small_file_name'] = $image['image_thumb_file_name'];
|
||||
$update['image_small_file_name'] = $image['image_small_file_name'];
|
||||
$keepThumb = TRUE;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'gallery_images', $update, array( 'image_id=?', $image['image_id'] ) );
|
||||
|
||||
/* Delete the images we don't need now */
|
||||
if( !$keepMedium AND $image['image_medium_file_name'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'gallery_Images', $image['image_medium_file_name'] )->delete();
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
}
|
||||
|
||||
if( !$keepThumb AND $image['image_thumb_file_name'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'gallery_Images', $image['image_thumb_file_name'] )->delete();
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
}
|
||||
$last = $image['image_id'];
|
||||
}
|
||||
|
||||
if ( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Progress
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('cleaning_up_gallery_images'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['did'], 2 ) ) : 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform post-completion processing
|
||||
*
|
||||
* @param array $data Data returned from preQueueData
|
||||
* @param bool $processed Was anything processed or not? If preQueueData returns NULL, this will be FALSE.
|
||||
* @return void
|
||||
*/
|
||||
public function postComplete( $data, $processed = TRUE )
|
||||
{
|
||||
\IPS\Db::i()->query( "ALTER TABLE `" . \IPS\Db::i()->prefix . "gallery_images` DROP COLUMN image_thumb_file_name, DROP COLUMN image_medium_file_name" );
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,27 @@
|
||||
namespace IPS\gallery\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\gallery\Album;
|
||||
use IPS\gallery\Category;
|
||||
use IPS\gallery\Image;
|
||||
use IPS\Member;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function is_null;
|
||||
|
||||
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 _Follow
|
||||
class Follow extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* Run Background Task
|
||||
@@ -31,12 +42,13 @@ class _Follow
|
||||
* @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( array &$data, int $offset ): int
|
||||
{
|
||||
$category = \IPS\gallery\Category::load( $data['category_id'] );
|
||||
$album = ( !\is_null( $data['album_id'] ) ) ? \IPS\gallery\Album::load( $data['album_id'] ) : NULL;
|
||||
$member = \IPS\Member::load( $data['member_id'] );
|
||||
$newOffset = \IPS\gallery\Image::_sendNotificationsBatch( $category, $album, $member, $offset );
|
||||
$category = Category::load( $data['category_id'] );
|
||||
$album = ( !is_null( $data['album_id'] ) ) ? Album::load( $data['album_id'] ) : NULL;
|
||||
$member = Member::load( $data['member_id'] );
|
||||
$tags = $data['tags'] ?? null;
|
||||
$newOffset = Image::_sendNotificationsBatch( $category, $album, $member, $tags, $offset );
|
||||
|
||||
if( $newOffset === NULL )
|
||||
{
|
||||
@@ -52,13 +64,24 @@ class _Follow
|
||||
* @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
|
||||
{
|
||||
$complete = $data['followerCount'] ? round( 100 / $data['followerCount'] * $offset, 2 ) : 100;
|
||||
$directContainer = ( !\is_null( $data['album_id'] ) ) ? \IPS\gallery\Album::load( $data['album_id'] ) : \IPS\gallery\Category::load( $data['category_id'] );
|
||||
$directContainer = ( !is_null( $data['album_id'] ) ) ? Album::load( $data['album_id'] ) : Category::load( $data['category_id'] );
|
||||
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('backgroundQueue_follow', FALSE, array( 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $directContainer->url(), TRUE, $directContainer->_title, FALSE ) ) ) ), 'complete' => $complete );
|
||||
}
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('backgroundQueue_follow', FALSE, array( 'htmlsprintf' => array( Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $directContainer->url(), TRUE, $directContainer->_title, FALSE ) ) ) ), 'complete' => $complete );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -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