| 1 |
<?php |
| 2 |
/** |
| 3 |
* Give Recurring Cron |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @copyright Copyright (c) 2016, GiveWP |
| 7 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 8 |
* @since 1.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
// Exit if accessed directly |
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* The Recurring Reminders Class |
| 18 |
* |
| 19 |
* @since 2.19.0 - migrated from give-recurring |
| 20 |
*/ |
| 21 |
class Give_Recurring_Cron { |
| 22 |
|
| 23 |
protected $db; |
| 24 |
|
| 25 |
/** |
| 26 |
* Get things started |
| 27 |
* |
| 28 |
* @since 1.0 |
| 29 |
*/ |
| 30 |
public function __construct() { |
| 31 |
$this->init(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Set up our actions and properties |
| 36 |
* |
| 37 |
* @since 1.0 |
| 38 |
*/ |
| 39 |
public function init() { |
| 40 |
|
| 41 |
$this->db = new Give_Subscriptions_DB; |
| 42 |
|
| 43 |
add_action( 'give_daily_scheduled_events', array( $this, 'check_for_expired_subscriptions' ) ); |
| 44 |
add_action( 'give_weekly_scheduled_events', array( $this, 'delete_old_sync_logs' ) ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Check for expired subscriptions once per day and mark them as expired |
| 49 |
* |
| 50 |
* @since 1.0 |
| 51 |
*/ |
| 52 |
public function check_for_expired_subscriptions() { |
| 53 |
|
| 54 |
$args = array( |
| 55 |
'status' => 'active', |
| 56 |
'number' => 999999, |
| 57 |
'expiration' => array( |
| 58 |
'start' => date( 'Y-n-d 00:00:00', strtotime( '-1 day', current_time( 'timestamp' ) ) ), |
| 59 |
'end' => date( 'Y-n-d 23:59:59', strtotime( '-1 day', current_time( 'timestamp' ) ) ) |
| 60 |
) |
| 61 |
|
| 62 |
); |
| 63 |
|
| 64 |
$subs = $this->db->get_subscriptions( $args ); |
| 65 |
|
| 66 |
if ( ! empty( $subs ) ) { |
| 67 |
|
| 68 |
foreach ( $subs as $sub ) { |
| 69 |
|
| 70 |
// TODO: Run sync here. |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Deletes old Sync log data. |
| 80 |
* |
| 81 |
* @since 1.3 |
| 82 |
*/ |
| 83 |
public function delete_old_sync_logs() { |
| 84 |
|
| 85 |
} |
| 86 |
} |
| 87 |
|