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,24 +12,37 @@
|
||||
namespace IPS\downloads\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\Content;
|
||||
use IPS\Db;
|
||||
use IPS\downloads\File;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\Notification;
|
||||
use IPS\Task\Queue\OutOfRangeException;
|
||||
use IPS\Theme;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _Notify
|
||||
class Notify extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
@@ -40,33 +53,33 @@ class _Notify
|
||||
* @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
|
||||
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
public function run( array &$data, int $offset ): int
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\downloads\File::load( $data['file'] );
|
||||
$file = File::load( $data['file'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
$notifyIds = array();
|
||||
|
||||
$recipients = iterator_to_array( \IPS\Db::i()->select( 'downloads_files_notify.*', 'downloads_files_notify', array( 'notify_file_id=?', $data['file'] ), 'notify_id ASC', array( $offset, \IPS\Downloads\File::NOTIFICATIONS_PER_BATCH ) ) );
|
||||
$recipients = iterator_to_array( Db::i()->select( 'downloads_files_notify.*', 'downloads_files_notify', array( 'notify_file_id=?', $data['file'] ), 'notify_id ASC', array( $offset, Content::NOTIFICATIONS_PER_BATCH ) ) );
|
||||
|
||||
if( !\count( $recipients ) )
|
||||
if( !count( $recipients ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
$notification = new \IPS\Notification( \IPS\Application::load( 'downloads' ), 'new_file_version', $file, array( $file ) );
|
||||
$notification = new Notification( Application::load( 'downloads' ), 'new_file_version', $file, array( $file ) );
|
||||
|
||||
foreach( $recipients AS $recipient )
|
||||
{
|
||||
$recipientMember = \IPS\Member::load( $recipient['notify_member_id'] );
|
||||
$recipientMember = Member::load( $recipient['notify_member_id'] );
|
||||
if ( $file->container()->can( 'view', $recipientMember ) )
|
||||
{
|
||||
$notifyIds[] = $recipient['notify_id'];
|
||||
@@ -74,10 +87,10 @@ class _Notify
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'downloads_files_notify', array( 'notify_sent' => time() ), \IPS\Db::i()->in( 'notify_id', $notifyIds ) );
|
||||
Db::i()->update( 'downloads_files_notify', array( 'notify_sent' => time() ), Db::i()->in( 'notify_id', $notifyIds ) );
|
||||
$notification->send();
|
||||
|
||||
return $offset + \IPS\downloads\File::NOTIFICATIONS_PER_BATCH;
|
||||
return $offset + Content::NOTIFICATIONS_PER_BATCH;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,19 +101,19 @@ class _Notify
|
||||
* @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 )
|
||||
public function getProgress( mixed $data, int $offset ): array
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\downloads\File::load( $data['file'] );
|
||||
$file = File::load( $data['file'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
$complete = $data['notifyCount'] ? round( 100 / $data['notifyCount'] * $offset, 2 ) : 100;
|
||||
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('backgroundQueue_new_version', FALSE, array( 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $file->url(), TRUE, $file->name, FALSE ) ) ) ), 'complete' => $complete );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('backgroundQueue_new_version', FALSE, array( 'htmlsprintf' => array( Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $file->url(), TRUE, $file->name, FALSE ) ) ) ), 'complete' => $complete );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user