Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -0,0 +1,124 @@
<?php
/**
* @brief Cancel billing agreements before removing the payment method
* @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 14 Jan 2020
*/
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;
}
/**
* Cancel billing agreements before removing the payment method
*/
class _DeletePaymentMethod
{
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_billing_agreements', array( 'ba_method=? AND ba_canceled=?', $data['id'], 0 ) )->first();
if( $data['count'] == 0 )
{
return NULL;
}
$data['done'] = 0;
$data['failures'] = array();
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 )
{
$agreements = \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_method=? AND ba_id>?', $data['id'], (int) $offset ), 'ba_id ASC', $this->perCycle );
$lastId = 0;
foreach( $agreements as $billingAgreement )
{
try
{
\IPS\nexus\Customer\BillingAgreement::constructFromData( $billingAgreement )->cancel();
}
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' );
}
$lastId = $billingAgreement['ba_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('delete_gateway_with_bas'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
}
/**
* Perform post-completion processing
*
* @param array $data
* @return void
*/
public function postComplete( $data )
{
$_data = json_decode( $data['data'], true );
/* Send notification about any failures */
if( \count( $_data['failures'] ) )
{
\IPS\core\AdminNotification::send( 'nexus', 'ConfigurationError', json_encode( $_data['failures'] ), FALSE );
}
/* And delete the gateway itself */
\IPS\nexus\Gateway::load( $_data['id'] )->delete();
}
}
@@ -0,0 +1,99 @@
<?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,7 +12,7 @@
namespace IPS\nexus\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,8 +23,10 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _FixRefundTransactions
{
public $perCycle = 500;
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_QUICK;
/**
* Parse data before queuing
@@ -82,22 +84,22 @@ class _FixRefundTransactions
if ( isset( $history['amount'] ) )
{
$credit = $credit->add( new \IPS\Math\Number( $history['amount'] ) );
$credit = $credit->add( new \IPS\Math\Number( (string) $history['amount'] ) );
}
else
{
$credit = $credit->add( new \IPS\Math\Number( $transaction['t_amount'] ) );
$credit = $credit->add( new \IPS\Math\Number( (string) $transaction['t_amount'] ) );
}
}
else
{
if ( isset( $history['amount'] ) )
{
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( $history['amount'] ) );
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( (string) $history['amount'] ) );
}
else
{
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( $transaction['t_amount'] ) );
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( (string) $transaction['t_amount'] ) );
}
}
}
@@ -111,11 +113,11 @@ class _FixRefundTransactions
{
$update['t_credit'] = (string) $credit;
}
if ( $transaction['t_status'] === \IPS\nexus\Transaction::STATUS_PART_REFUNDED and $totalRefunded->compare( new \IPS\Math\Number( $transaction['t_partial_refund'] ) ) !== 0 )
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( $transaction['t_amount'] ) ) !== 0 )
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;
}
@@ -0,0 +1,129 @@
<?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 20 Dec 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
*/
class _MassChangePurchases
{
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'package', $data['id'] ) )->first();
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 )
{
$package = \IPS\nexus\Package::load( $data['id'] );
$admin = \IPS\Member::load( $data['admin'] );
if ( $data['cancel_type'] == 'change' )
{
$newPackage = \IPS\nexus\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 ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
foreach ( new \IPS\Patterns\ActiveRecordIterator( $query, 'IPS\nexus\Purchase' ) as $purchase )
{
if ( $data['cancel_type'] == 'change' )
{
$package->upgradeDowngrade( $purchase, $newPackage, isset( $data[ 'renew_option_' . $newPackage->_id ] ) ? $data[ 'renew_option_' . $newPackage->_id ] : NULL, (bool) $data['mass_change_purchases_override'] );
$purchase->member->log( 'purchase', array( 'type' => 'change', 'id' => $purchase->id, 'old' => $purchase->name, 'name' => $newPackage->titleForLog(), 'system' => FALSE ), $admin );
}
else
{
/* If grouped, ungroup */
$grouped = $purchase->grouped_renewals;
if ( $grouped )
{
$purchase->ungroupFromParent();
$purchase->save();
}
/* Update purchase and log */
if ( $data['cancel_type'] == 'expire' )
{
$purchase->renewals = NULL;
$purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $purchase->id, 'name' => $purchase->name, 'info' => 'remove_renewals' ), $admin );
}
else
{
$purchase->cancelled = TRUE;
$purchase->member->log( 'purchase', array( 'type' => 'cancel', 'id' => $purchase->id, 'name' => $purchase->name ), $admin );
}
$purchase->can_reactivate = $data['ps_can_reactivate'];
$purchase->save();
/* If grouped, regroup */
if ( $grouped )
{
$purchase->groupWithParent();
$purchase->save();
}
}
}
return $offset + \IPS\REBUILD_SLOW;
}
/**
* 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( 'mass_change_purchases_in_progress_text', FALSE, array( 'sprintf' => \IPS\nexus\Package::load( $data['id'] )->_title ) ), 'complete' => floor( 100 / $data['count'] * $offset ) );
}
/**
* 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 )
{
}
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,8 +23,10 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _MoveCustomerHistory
{
public $perCycle = 500;
/**
* @brief Number of records to process per cycle
*/
public $perCycle = \IPS\REBUILD_QUICK;
/**
* Parse data before queuing
@@ -0,0 +1,98 @@
<?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 08 Aug 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
*/
class _RecountTotalSpend
{
/**
* @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'] = (int) \IPS\Db::i()->select( 'count(*)', 'nexus_customers' )->first();
if( $data['count'] == 0 )
{
return null;
}
$data['completed'] = 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 )
{
$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 )
{
$last = $customer['member_id'];
$data['completed']++;
try
{
$customer = \IPS\nexus\Customer::load( $customer['member_id'] );
$customer->recountTotalSpend();
}
catch( \Exception $ex ) { }
}
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( 'recounting_total_spend' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
Whitespace-only changes.