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\nexus\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\nexus\Purchase;
|
||||
use IPS\nexus\Subscription\Package;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use const IPS\REBUILD_NORMAL;
|
||||
|
||||
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 _FixMissingSubscriptionPurchases
|
||||
class FixMissingSubscriptionPurchases extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Number of subscriptions to check per cycle
|
||||
*/
|
||||
public $batch = \IPS\REBUILD_NORMAL;
|
||||
public int $batch = REBUILD_NORMAL;
|
||||
|
||||
/**
|
||||
* 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(sub_id)', 'nexus_member_subscriptions' )->first();
|
||||
$data['count'] = Db::i()->select( 'count(sub_id)', 'nexus_member_subscriptions' )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
@@ -63,39 +75,39 @@ class _FixMissingSubscriptionPurchases
|
||||
* @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;
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'nexus_member_subscriptions', [ 'sub_id>?', $offset ], NULL, $this->batch ) as $subscription )
|
||||
foreach( Db::i()->select( '*', 'nexus_member_subscriptions', [ 'sub_id>?', $offset ], NULL, $this->batch ) as $subscription )
|
||||
{
|
||||
if( $subscription['sub_purchase_id'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\nexus\Purchase::load( $subscription['sub_purchase_id' ] );
|
||||
Purchase::load( $subscription['sub_purchase_id' ] );
|
||||
|
||||
/* Nothing to do here */
|
||||
$data['completed']++;
|
||||
$last = $subscription['sub_id'];
|
||||
continue;
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
catch( OutOfRangeException ) { }
|
||||
}
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Subscription\Package::load( $subscription['sub_package_id'] );
|
||||
$package = Package::load( $subscription['sub_package_id'] );
|
||||
|
||||
if( !$subscription['sub_added_manually'] AND $subscription['sub_renews'] )
|
||||
{
|
||||
$term = $package->renewalTerm( \IPS\nexus\Customer::load( $subscription['sub_member_id'] )->defaultCurrency() );
|
||||
$term = $package->renewalTerm( Customer::load( $subscription['sub_member_id'] )->defaultCurrency() );
|
||||
$termData = $term->getTerm();
|
||||
}
|
||||
|
||||
/* Create purchase manually - we don't want to trigger any on* methods */
|
||||
$purchaseId = \IPS\Db::i()->insert( 'nexus_purchases', [
|
||||
$purchaseId = Db::i()->insert( 'nexus_purchases', [
|
||||
'ps_member' => $subscription['sub_member_id'],
|
||||
'ps_name' => \IPS\nexus\Customer::load( $subscription['sub_member_id'] )->language()->get( $package::$titleLangPrefix . $subscription['sub_package_id'] ),
|
||||
'ps_name' => Customer::load( $subscription['sub_member_id'] )->language()->get( $package::$titleLangPrefix . $subscription['sub_package_id'] ),
|
||||
'ps_active' => $subscription['sub_active'],
|
||||
'ps_cancelled' => $subscription['sub_cancelled'],
|
||||
'ps_start' => $subscription['sub_start'],
|
||||
@@ -112,9 +124,9 @@ class _FixMissingSubscriptionPurchases
|
||||
]);
|
||||
|
||||
/* update sub with purchase id */
|
||||
\IPS\Db::i()->update( 'nexus_member_subscriptions', [ 'sub_purchase_id' => $purchaseId ], [ 'sub_id=?', $subscription['sub_id'] ] );
|
||||
Db::i()->update( 'nexus_member_subscriptions', [ 'sub_purchase_id' => $purchaseId ], [ 'sub_id=?', $subscription['sub_id'] ] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{}
|
||||
|
||||
|
||||
@@ -136,10 +148,10 @@ class _FixMissingSubscriptionPurchases
|
||||
* @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( 'nexus_queue_missing_sub_purchases' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack( 'nexus_queue_missing_sub_purchases' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user