jetformbuilder
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
abstracts
/
ActionScheduler_Abstract_Schedule.php
ActionScheduler.php
1 month ago
ActionScheduler_Abstract_ListTable.php
1 year ago
ActionScheduler_Abstract_QueueRunner.php
1 month ago
ActionScheduler_Abstract_RecurringSchedule.php
1 year ago
ActionScheduler_Abstract_Schedule.php
1 year ago
ActionScheduler_Abstract_Schema.php
1 year ago
ActionScheduler_Lock.php
1 year ago
ActionScheduler_Logger.php
1 year ago
ActionScheduler_Store.php
1 year ago
ActionScheduler_TimezoneHelper.php
1 year ago
ActionScheduler_WPCLI_Command.php
1 year ago
ActionScheduler_Abstract_Schedule.php
90 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class ActionScheduler_Abstract_Schedule |
| 5 | */ |
| 6 | abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedule_Deprecated { |
| 7 | |
| 8 | /** |
| 9 | * The date & time the schedule is set to run. |
| 10 | * |
| 11 | * @var DateTime |
| 12 | */ |
| 13 | private $scheduled_date = null; |
| 14 | |
| 15 | /** |
| 16 | * Timestamp equivalent of @see $this->scheduled_date |
| 17 | * |
| 18 | * @var int |
| 19 | */ |
| 20 | protected $scheduled_timestamp = null; |
| 21 | |
| 22 | /** |
| 23 | * Construct. |
| 24 | * |
| 25 | * @param DateTime $date The date & time to run the action. |
| 26 | */ |
| 27 | public function __construct( DateTime $date ) { |
| 28 | $this->scheduled_date = $date; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Check if a schedule should recur. |
| 33 | * |
| 34 | * @return bool |
| 35 | */ |
| 36 | abstract public function is_recurring(); |
| 37 | |
| 38 | /** |
| 39 | * Calculate when the next instance of this schedule would run based on a given date & time. |
| 40 | * |
| 41 | * @param DateTime $after Start timestamp. |
| 42 | * @return DateTime |
| 43 | */ |
| 44 | abstract protected function calculate_next( DateTime $after ); |
| 45 | |
| 46 | /** |
| 47 | * Get the next date & time when this schedule should run after a given date & time. |
| 48 | * |
| 49 | * @param DateTime $after Start timestamp. |
| 50 | * @return DateTime|null |
| 51 | */ |
| 52 | public function get_next( DateTime $after ) { |
| 53 | $after = clone $after; |
| 54 | if ( $after > $this->scheduled_date ) { |
| 55 | $after = $this->calculate_next( $after ); |
| 56 | return $after; |
| 57 | } |
| 58 | return clone $this->scheduled_date; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get the date & time the schedule is set to run. |
| 63 | * |
| 64 | * @return DateTime|null |
| 65 | */ |
| 66 | public function get_date() { |
| 67 | return $this->scheduled_date; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * For PHP 5.2 compat, because DateTime objects can't be serialized |
| 72 | * |
| 73 | * @return array |
| 74 | */ |
| 75 | public function __sleep() { |
| 76 | $this->scheduled_timestamp = $this->scheduled_date->getTimestamp(); |
| 77 | return array( |
| 78 | 'scheduled_timestamp', |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Wakeup. |
| 84 | */ |
| 85 | public function __wakeup() { |
| 86 | $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp ); |
| 87 | unset( $this->scheduled_timestamp ); |
| 88 | } |
| 89 | } |
| 90 |