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,16 +12,30 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Email;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Invoice;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use IPS\Task\Exception;
|
||||
use OutOfRangeException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expire Invoices Task
|
||||
*/
|
||||
class _expireInvoices extends \IPS\Task
|
||||
class expireInvoices extends Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
@@ -31,15 +45,15 @@ class _expireInvoices extends \IPS\Task
|
||||
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
* @return string|null Message to log or NULL
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : string|null
|
||||
{
|
||||
$expireDate = \IPS\DateTime::create();
|
||||
if( \IPS\Settings::i()->cm_invoice_expireafter )
|
||||
$expireDate = DateTime::create();
|
||||
if( Settings::i()->cm_invoice_expireafter )
|
||||
{
|
||||
$expireDate->sub( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_expireafter . 'D' ) );
|
||||
$expireDate->sub( new DateInterval( 'P' . Settings::i()->cm_invoice_expireafter . 'D' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -47,16 +61,16 @@ class _expireInvoices extends \IPS\Task
|
||||
return NULL;
|
||||
}
|
||||
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_invoices', array( 'i_status=? AND i_date<?', \IPS\nexus\Invoice::STATUS_PENDING, $expireDate->getTimestamp() ), 'i_date ASC', 100 ), 'IPS\nexus\Invoice' ) as $invoice )
|
||||
foreach ( new ActiveRecordIterator( Db::i()->select( '*', 'nexus_invoices', array( 'i_status=? AND i_date<?', Invoice::STATUS_PENDING, $expireDate->getTimestamp() ), 'i_date ASC', 100 ), 'IPS\nexus\Invoice' ) as $invoice )
|
||||
{
|
||||
$invoice->status = $invoice::STATUS_EXPIRED;
|
||||
$invoice->save();
|
||||
|
||||
/* Send tracked notifications */
|
||||
foreach ( \IPS\Db::i()->select( 'member_id', 'nexus_invoice_tracker', array( 'invoice_id=?', $invoice->id ) ) as $trackingMember )
|
||||
foreach ( Db::i()->select( 'member_id', 'nexus_invoice_tracker', array( 'invoice_id=?', $invoice->id ) ) as $trackingMember )
|
||||
{
|
||||
$trackingMember = \IPS\Member::load( $trackingMember );
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceTrackExpired', array( $invoice, $invoice->summary( $trackingMember->language() ) ), \IPS\Email::TYPE_LIST )
|
||||
$trackingMember = Member::load( $trackingMember );
|
||||
Email::buildFromTemplate( 'nexus', 'invoiceTrackExpired', array( $invoice, $invoice->summary() ), Email::TYPE_LIST )
|
||||
->send( $trackingMember );
|
||||
}
|
||||
|
||||
@@ -68,8 +82,10 @@ class _expireInvoices extends \IPS\Task
|
||||
'title' => $invoice->title,
|
||||
), FALSE );
|
||||
}
|
||||
catch ( \OutOfRangeException $exception ) {}
|
||||
catch ( OutOfRangeException ) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +97,7 @@ class _expireInvoices extends \IPS\Task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup()
|
||||
public function cleanup() : void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user