Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,31 +12,45 @@
namespace IPS\nexus\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\core\AdminNotification;
use IPS\Db;
use IPS\Extensions\QueueAbstract;
use IPS\Log;
use IPS\Member;
use IPS\nexus\Customer\BillingAgreement;
use IPS\nexus\Gateway;
use OutOfRangeException;
use function count;
use function defined;
use const IPS\REBUILD_SLOW;
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;
}
/**
* Cancel billing agreements before removing the payment method
*/
class _DeletePaymentMethod
class DeletePaymentMethod extends QueueAbstract
{
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_SLOW;
public int $perCycle = REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_billing_agreements', array( 'ba_method=? AND ba_canceled=?', $data['id'], 0 ) )->first();
$data['count'] = Db::i()->select( 'COUNT(*)', 'nexus_billing_agreements', array( 'ba_method=? AND ba_canceled=?', $data['id'], 0 ) )->first();
if( $data['count'] == 0 )
{
@@ -57,23 +71,23 @@ class _DeletePaymentMethod
* @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
{
$agreements = \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_method=? AND ba_id>?', $data['id'], (int) $offset ), 'ba_id ASC', $this->perCycle );
$agreements = Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_method=? AND ba_id>?', $data['id'], $offset ), 'ba_id ASC', $this->perCycle );
$lastId = 0;
foreach( $agreements as $billingAgreement )
{
try
{
\IPS\nexus\Customer\BillingAgreement::constructFromData( $billingAgreement )->cancel();
BillingAgreement::constructFromData( $billingAgreement )->cancel();
}
catch ( \Exception $e )
catch ( Exception $e )
{
/* Store the billing agreement ID so we can notify the admin once we're done */
$data['failures'][] = $billingAgreement['ba_id'];
\IPS\Log::log( $e, 'delete-nexus-ba' );
Log::log( $e, 'delete-nexus-ba' );
}
$lastId = $billingAgreement['ba_id'];
@@ -95,30 +109,31 @@ class _DeletePaymentMethod
* @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('delete_gateway_with_bas'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
return array( 'text' => Member::loggedIn()->language()->addToStack('delete_gateway_with_bas'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
}
/**
* Perform post-completion processing
*
* @param array $data
* @param array $data
* @param bool $processed
* @return void
*/
public function postComplete( $data )
public function postComplete( array $data, bool $processed = TRUE ) : void
{
$_data = json_decode( $data['data'], true );
/* Send notification about any failures */
if( \count( $_data['failures'] ) )
if( count( $_data['failures'] ) )
{
\IPS\core\AdminNotification::send( 'nexus', 'ConfigurationError', json_encode( $_data['failures'] ), FALSE );
AdminNotification::send( 'nexus', 'ConfigurationError', json_encode( $_data['failures'] ), FALSE );
}
/* And delete the gateway itself */
\IPS\nexus\Gateway::load( $_data['id'] )->delete();
Gateway::load( $_data['id'] )->delete();
}
}
@@ -12,30 +12,41 @@
namespace IPS\nexus\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\Member;
use IPS\Patterns\ActiveRecordIterator;
use OutOfRangeException;
use function count;
use function defined;
use const IPS\REBUILD_SLOW;
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 _DeleteSubscriptions
class DeleteSubscriptions extends QueueAbstract
{
/**
* 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(*)', 'nexus_member_subscriptions', [ 'sub_package_id=?', $data['id'] ] )->first();
$data['count'] = Db::i()->select( 'COUNT(*)', 'nexus_member_subscriptions', [ 'sub_package_id=?', $data['id'] ] )->first();
}
catch( \Exception $ex )
catch( Exception )
{
return NULL;
}
@@ -53,15 +64,15 @@ class _DeleteSubscriptions
* @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
{
$query = \IPS\Db::i()->select( '*', 'nexus_member_subscriptions', [ 'sub_id>? AND sub_package_id=?', $data['lastId'], $data['id'] ], 'sub_id ASC', \IPS\REBUILD_SLOW );
if ( !\count( $query ) )
$query = Db::i()->select( '*', 'nexus_member_subscriptions', [ 'sub_id>? AND sub_package_id=?', $data['lastId'], $data['id'] ], 'sub_id ASC', REBUILD_SLOW );
if ( !count( $query ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
foreach ( new \IPS\Patterns\ActiveRecordIterator( $query, 'IPS\nexus\Subscription' ) as $sub )
foreach ( new ActiveRecordIterator( $query, 'IPS\nexus\Subscription' ) as $sub )
{
$data['completed']++;
$data['lastId'] = $sub->id;
@@ -77,11 +88,11 @@ class _DeleteSubscriptions
* @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('removing_subscriptions'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack('removing_subscriptions'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
/**
@@ -91,7 +102,7 @@ class _DeleteSubscriptions
* @param bool $processed Was anything processed or not? If preQueueData returns NULL, this will be FALSE.
* @return void
*/
public function postComplete( $data, $processed = TRUE )
public function postComplete( array $data, bool $processed = TRUE ) : void
{
}
@@ -1,99 +0,0 @@
<?php
/**
* @brief Background task to fix refunded transactions following the 4.3.5 change to treat refunds and credits separately
* @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 Commerce
* @since 10 Apr 2019
*/
namespace IPS\nexus\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 to fix refunded transactions following the 4.3.5 change to treat refunds and credits separately
*/
class _FixMissingAddresses
{
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_QUICK;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', array( 'i_status=? AND i_billaddress IS NULL', \IPS\nexus\Invoice::STATUS_PAID ) )->first();
if( $data['count'] == 0 )
{
return NULL;
}
$data['done'] = 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 )
{
$invoices = \IPS\Db::i()->select( '*', 'nexus_invoices', array( array( 'i_id>?', $offset ), array( 'i_status=? AND i_billaddress IS NULL', \IPS\nexus\Invoice::STATUS_PAID ) ), 'i_id ASC', $this->perCycle );
$lastId = 0;
foreach( $invoices as $invoiceData )
{
$invoice = \IPS\nexus\Invoice::constructFromData( $invoiceData );
try
{
$invoice->billaddress = \IPS\nexus\Customer\Address::constructFromData( \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( '`member`=? AND primary_billing=1', $invoiceData['i_member'] ) )->first() )->address;
$invoice->save();
}
catch ( \UnderflowException $e ) { }
$lastId = $invoiceData['i_id'];
}
if( $lastId == 0 )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$data['done'] += $this->perCycle;
return $lastId;
}
/**
* 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('upgrade_fix_missing_addresses'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
}
}
@@ -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 );
}
}
@@ -1,155 +0,0 @@
<?php
/**
* @brief Background task to fix refunded transactions following the 4.3.5 change to treat refunds and credits separately
* @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 Commerce
* @since 20 June 2018
*/
namespace IPS\nexus\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 to fix refunded transactions following the 4.3.5 change to treat refunds and credits separately
*/
class _FixRefundTransactions
{
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_QUICK;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( \IPS\Db::i()->in( 't_status', array( \IPS\nexus\Transaction::STATUS_REFUNDED, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ) ) ) )->first();
if( $data['count'] == 0 )
{
return NULL;
}
$data['done'] = 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 )
{
$transactions = \IPS\Db::i()->select( '*', 'nexus_transactions', array( array( 't_id>?', $offset ), array( \IPS\Db::i()->in( 't_status', array( \IPS\nexus\Transaction::STATUS_REFUNDED, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ) ) ) ), 't_id ASC', $this->perCycle );
$lastId = 0;
foreach( $transactions as $transaction )
{
$extra = json_decode( $transaction['t_extra'], TRUE );
if ( $extra and isset( $extra['history'] ) )
{
$credit = new \IPS\Math\Number('0');
$totalRefunded = new \IPS\Math\Number('0');
$update = array();
$updateHistory = FALSE;
foreach ( $extra['history'] as $i => $history )
{
if ( ( $history['s'] === 'rfnd' or $history['s'] === 'prfd' ) )
{
if ( $history['to'] === 'credit' )
{
if ( $history['s'] === 'rfnd' )
{
$updateHistory = TRUE;
$extra['history'][ $i ]['s'] = 'prfd';
}
if ( isset( $history['amount'] ) )
{
$credit = $credit->add( new \IPS\Math\Number( (string) $history['amount'] ) );
}
else
{
$credit = $credit->add( new \IPS\Math\Number( (string) $transaction['t_amount'] ) );
}
}
else
{
if ( isset( $history['amount'] ) )
{
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( (string) $history['amount'] ) );
}
else
{
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( (string) $transaction['t_amount'] ) );
}
}
}
}
if ( $updateHistory )
{
$update['t_extra'] = json_encode( $extra );
}
if ( $credit->isGreaterThanZero() )
{
$update['t_credit'] = (string) $credit;
}
if ( $transaction['t_status'] === \IPS\nexus\Transaction::STATUS_PART_REFUNDED and $totalRefunded->compare( new \IPS\Math\Number( (string) $transaction['t_partial_refund'] ) ) !== 0 )
{
$update['t_partial_refund'] = (string) $totalRefunded;
}
if ( $transaction['t_status'] === \IPS\nexus\Transaction::STATUS_REFUNDED and $totalRefunded->compare( new \IPS\Math\Number( (string) $transaction['t_amount'] ) ) !== 0 )
{
$update['t_status'] = \IPS\nexus\Transaction::STATUS_PART_REFUNDED;
}
if ( $update )
{
\IPS\Db::i()->update( 'nexus_transactions', $update, array( 't_id=?', $transaction['t_id'] ) );
}
}
$lastId = $transaction['t_id'];
}
if( $lastId == 0 )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$data['done'] += $this->perCycle;
return $lastId;
}
/**
* 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('upgrade_fix_refund_transactions'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
}
}
@@ -12,26 +12,37 @@
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\Package;
use IPS\Patterns\ActiveRecordIterator;
use OutOfRangeException;
use function count;
use function defined;
use const IPS\REBUILD_SLOW;
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 _MassChangePurchases
class MassChangePurchases extends QueueAbstract
{
/**
* Parse data before queuing
*
* @param array $data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'package', $data['id'] ) )->first();
$data['count'] = Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'package', $data['id'] ) )->first();
return $data;
}
@@ -44,30 +55,30 @@ class _MassChangePurchases
* @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
{
try
{
$package = \IPS\nexus\Package::load( $data['id'] );
$package = Package::load( $data['id'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$admin = \IPS\Member::load( $data['admin'] );
$admin = Member::load( $data['admin'] );
if ( $data['cancel_type'] == 'change' )
{
$newPackage = \IPS\nexus\Package::load( $data['mass_change_purchases_to'] );
$newPackage = Package::load( $data['mass_change_purchases_to'] );
}
$query = \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'package', $data['id'] ), 'ps_id ASC', ( $data['cancel_type'] == 'change' ) ? NULL : array( $offset, \IPS\REBUILD_SLOW ) );
if ( !\count( $query ) )
$query = Db::i()->select( '*', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'package', $data['id'] ), 'ps_id ASC', ( $data['cancel_type'] == 'change' ) ? NULL : array( $offset, REBUILD_SLOW ) );
if ( !count( $query ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
foreach ( new \IPS\Patterns\ActiveRecordIterator( $query, 'IPS\nexus\Purchase' ) as $purchase )
foreach ( new ActiveRecordIterator( $query, 'IPS\nexus\Purchase' ) as $purchase )
{
if ( $data['cancel_type'] == 'change' )
{
@@ -107,7 +118,7 @@ class _MassChangePurchases
}
}
return $offset + \IPS\REBUILD_SLOW;
return $offset + REBUILD_SLOW;
}
/**
@@ -116,11 +127,11 @@ class _MassChangePurchases
* @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( 'mass_change_purchases_in_progress_text', FALSE, array( 'sprintf' => \IPS\nexus\Package::load( $data['id'] )->_title ) ), 'complete' => floor( 100 / $data['count'] * $offset ) );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'mass_change_purchases_in_progress_text', FALSE, array( 'sprintf' => Package::load( $data['id'] )->_title ) ), 'complete' => floor( 100 / $data['count'] * $offset ) );
}
/**
@@ -130,7 +141,7 @@ class _MassChangePurchases
* @param bool $processed Was anything processed or not? If preQueueData returns NULL, this will be FALSE.
* @return void
*/
public function postComplete( $data, $processed = TRUE )
public function postComplete( array $data, bool $processed = TRUE ) : void
{
}
@@ -1,122 +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 Commerce
* @since 03 Aug 2017
*/
namespace IPS\nexus\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 _MoveCustomerHistory
{
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_QUICK;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
/* Task is not needed if this table doesn't exist */
if( !\IPS\Db::i()->checkForTable( 'nexus_customer_history' ) )
{
return NULL;
}
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_history' )->first();
if( $data['count'] == 0 )
{
\IPS\Db::i()->dropTable( 'nexus_customer_history' );
return NULL;
}
$data['done'] = 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 )
{
$logs = \IPS\Db::i()->select( '*', 'nexus_customer_history', array( 'log_id>?', $offset ), 'log_id ASC', $this->perCycle );
$lastId = 0;
foreach( $logs as $log )
{
$lastId = $log['log_id'];
unset( $log['log_id'] );
/* Set log app */
$log['log_app'] = 'nexus';
/* Convert nexus info into member history format */
if( $log['log_data'] == 'info' )
{
$json = json_decode( $log['log_data'], TRUE );
if( isset( $json['email'] ) )
{
$log['log_app'] = 'core';
$log['log_data'] = json_encode( array( 'old' => $data['email'], 'new' => '' ) );
}
elseif( isset( $data['password'] ) )
{
$log['log_app'] = 'core';
$log['log_data'] = json_encode( array( 'password' => '' ) );
}
}
/* Insert into member history */
\IPS\Db::i()->insert( 'core_member_history', $log );
}
if( $lastId == 0 )
{
\IPS\Db::i()->dropTable( 'nexus_customer_history' );
throw new \IPS\Task\Queue\OutOfRangeException;
}
$data['done'] += $this->perCycle;
return $lastId;
}
/**
* 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('moving_customer_history'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
}
}
@@ -12,32 +12,42 @@
namespace IPS\nexus\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\Member;
use IPS\nexus\Customer;
use OutOfRangeException;
use function defined;
use const IPS\REBUILD_QUICK;
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 _RecountTotalSpend
class RecountTotalSpend extends QueueAbstract
{
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_QUICK;
public int $perCycle = REBUILD_QUICK;
/**
* Parse data before queuing
*
* @param array $data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
$data['count'] = (int) \IPS\Db::i()->select( 'count(*)', 'nexus_customers' )->first();
$data['count'] = (int) Db::i()->select( 'count(*)', 'nexus_customers' )->first();
if( $data['count'] == 0 )
{
@@ -57,22 +67,22 @@ class _RecountTotalSpend
* @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;
/* Loop over members to fix them */
foreach( \IPS\Db::i()->select( '*', 'nexus_customers', array( 'member_id > ?', $offset ), 'member_id ASC', array( 0, $this->perCycle ) ) as $customer )
foreach( Db::i()->select( '*', 'nexus_customers', array( 'member_id > ?', $offset ), 'member_id ASC', array( 0, $this->perCycle ) ) as $customer )
{
$last = $customer['member_id'];
$data['completed']++;
try
{
$customer = \IPS\nexus\Customer::load( $customer['member_id'] );
$customer = Customer::load( $customer['member_id'] );
$customer->recountTotalSpend();
}
catch( \Exception $ex ) { }
catch( Exception ) { }
}
if( $last === NULL )
@@ -89,10 +99,10 @@ class _RecountTotalSpend
* @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( 'recounting_total_spend' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'recounting_total_spend' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}