wp-mail-smtp
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
abstracts
/
ActionScheduler_Abstract_Schedule.php
ActionScheduler.php
2 years ago
ActionScheduler_Abstract_ListTable.php
2 years ago
ActionScheduler_Abstract_QueueRunner.php
2 years ago
ActionScheduler_Abstract_RecurringSchedule.php
2 years ago
ActionScheduler_Abstract_Schedule.php
2 years ago
ActionScheduler_Abstract_Schema.php
2 years ago
ActionScheduler_Lock.php
2 years ago
ActionScheduler_Logger.php
2 years ago
ActionScheduler_Store.php
2 years ago
ActionScheduler_TimezoneHelper.php
2 years ago
ActionScheduler_Abstract_Schedule.php
84 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 | * @param DateTime $date The date & time to run the action. |
| 24 | */ |
| 25 | public function __construct( DateTime $date ) { |
| 26 | $this->scheduled_date = $date; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Check if a schedule should recur. |
| 31 | * |
| 32 | * @return bool |
| 33 | */ |
| 34 | abstract public function is_recurring(); |
| 35 | |
| 36 | /** |
| 37 | * Calculate when the next instance of this schedule would run based on a given date & time. |
| 38 | * |
| 39 | * @param DateTime $after |
| 40 | * @return DateTime |
| 41 | */ |
| 42 | abstract protected function calculate_next( DateTime $after ); |
| 43 | |
| 44 | /** |
| 45 | * Get the next date & time when this schedule should run after a given date & time. |
| 46 | * |
| 47 | * @param DateTime $after |
| 48 | * @return DateTime|null |
| 49 | */ |
| 50 | public function get_next( DateTime $after ) { |
| 51 | $after = clone $after; |
| 52 | if ( $after > $this->scheduled_date ) { |
| 53 | $after = $this->calculate_next( $after ); |
| 54 | return $after; |
| 55 | } |
| 56 | return clone $this->scheduled_date; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get the date & time the schedule is set to run. |
| 61 | * |
| 62 | * @return DateTime|null |
| 63 | */ |
| 64 | public function get_date() { |
| 65 | return $this->scheduled_date; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * For PHP 5.2 compat, since DateTime objects can't be serialized |
| 70 | * @return array |
| 71 | */ |
| 72 | public function __sleep() { |
| 73 | $this->scheduled_timestamp = $this->scheduled_date->getTimestamp(); |
| 74 | return array( |
| 75 | 'scheduled_timestamp', |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | public function __wakeup() { |
| 80 | $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp ); |
| 81 | unset( $this->scheduled_timestamp ); |
| 82 | } |
| 83 | } |
| 84 |