wp-mail-smtp
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
schedules
/
ActionScheduler_IntervalSchedule.php
ActionScheduler_CanceledSchedule.php
6 years ago
ActionScheduler_CronSchedule.php
6 years ago
ActionScheduler_IntervalSchedule.php
6 years ago
ActionScheduler_NullSchedule.php
6 years ago
ActionScheduler_Schedule.php
6 years ago
ActionScheduler_SimpleSchedule.php
6 years ago
ActionScheduler_IntervalSchedule.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class ActionScheduler_IntervalSchedule |
| 5 | */ |
| 6 | class ActionScheduler_IntervalSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule { |
| 7 | |
| 8 | /** |
| 9 | * Deprecated property @see $this->__wakeup() for details. |
| 10 | **/ |
| 11 | private $start_timestamp = NULL; |
| 12 | |
| 13 | /** |
| 14 | * Deprecated property @see $this->__wakeup() for details. |
| 15 | **/ |
| 16 | private $interval_in_seconds = NULL; |
| 17 | |
| 18 | /** |
| 19 | * Calculate when this schedule should start after a given date & time using |
| 20 | * the number of seconds between recurrences. |
| 21 | * |
| 22 | * @param DateTime $after |
| 23 | * @return DateTime |
| 24 | */ |
| 25 | protected function calculate_next( DateTime $after ) { |
| 26 | $after->modify( '+' . (int) $this->get_recurrence() . ' seconds' ); |
| 27 | return $after; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return int |
| 32 | */ |
| 33 | public function interval_in_seconds() { |
| 34 | _deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' ); |
| 35 | return (int) $this->get_recurrence(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Serialize interval schedules with data required prior to AS 3.0.0 |
| 40 | * |
| 41 | * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to |
| 42 | * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
| 43 | * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
| 44 | * aligned properties and property names for better inheritance. To guard against the |
| 45 | * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to |
| 46 | * also store the data with the old property names so if it's unserialized in AS < 3.0, |
| 47 | * the schedule doesn't end up with a null/false/0 recurrence. |
| 48 | * |
| 49 | * @return array |
| 50 | */ |
| 51 | public function __sleep() { |
| 52 | |
| 53 | $sleep_params = parent::__sleep(); |
| 54 | |
| 55 | $this->start_timestamp = $this->scheduled_timestamp; |
| 56 | $this->interval_in_seconds = $this->recurrence; |
| 57 | |
| 58 | return array_merge( $sleep_params, array( |
| 59 | 'start_timestamp', |
| 60 | 'interval_in_seconds' |
| 61 | ) ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Unserialize interval schedules serialized/stored prior to AS 3.0.0 |
| 66 | * |
| 67 | * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). |
| 68 | */ |
| 69 | public function __wakeup() { |
| 70 | if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { |
| 71 | $this->scheduled_timestamp = $this->start_timestamp; |
| 72 | unset( $this->start_timestamp ); |
| 73 | } |
| 74 | |
| 75 | if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) { |
| 76 | $this->recurrence = $this->interval_in_seconds; |
| 77 | unset( $this->interval_in_seconds ); |
| 78 | } |
| 79 | parent::__wakeup(); |
| 80 | } |
| 81 | } |
| 82 |