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,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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user