Initial Commit
This commit is contained in:
57
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php
vendored
Normal file
57
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_SimpleSchedule
|
||||
*/
|
||||
class ActionScheduler_CanceledSchedule extends ActionScheduler_SimpleSchedule {
|
||||
|
||||
/**
|
||||
* Deprecated property @see $this->__wakeup() for details.
|
||||
**/
|
||||
private $timestamp = NULL;
|
||||
|
||||
/**
|
||||
* @param DateTime $after
|
||||
*
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function calculate_next( DateTime $after ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancelled actions should never have a next schedule, even if get_next()
|
||||
* is called with $after < $this->scheduled_date.
|
||||
*
|
||||
* @param DateTime $after
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function get_next( DateTime $after ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_recurring() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize recurring schedules serialized/stored prior to AS 3.0.0
|
||||
*
|
||||
* Prior to Action Scheduler 3.0.0, schedules used different property names to refer
|
||||
* to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
|
||||
* was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
|
||||
* aligned properties and property names for better inheritance. To maintain backward
|
||||
* compatibility with schedules serialized and stored prior to 3.0, we need to correctly
|
||||
* map the old property names with matching visibility.
|
||||
*/
|
||||
public function __wakeup() {
|
||||
if ( ! is_null( $this->timestamp ) ) {
|
||||
$this->scheduled_timestamp = $this->timestamp;
|
||||
unset( $this->timestamp );
|
||||
}
|
||||
parent::__wakeup();
|
||||
}
|
||||
}
|
102
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php
vendored
Normal file
102
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_CronSchedule
|
||||
*/
|
||||
class ActionScheduler_CronSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule {
|
||||
|
||||
/**
|
||||
* Deprecated property @see $this->__wakeup() for details.
|
||||
**/
|
||||
private $start_timestamp = NULL;
|
||||
|
||||
/**
|
||||
* Deprecated property @see $this->__wakeup() for details.
|
||||
**/
|
||||
private $cron = NULL;
|
||||
|
||||
/**
|
||||
* Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this
|
||||
* objects $recurrence property.
|
||||
*
|
||||
* @param DateTime $start The date & time to run the action at or after. If $start aligns with the CronSchedule passed via $recurrence, it will be used. If it does not align, the first matching date after it will be used.
|
||||
* @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance.
|
||||
* @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
|
||||
*/
|
||||
public function __construct( DateTime $start, $recurrence, DateTime $first = null ) {
|
||||
if ( ! is_a( $recurrence, 'CronExpression' ) ) {
|
||||
$recurrence = CronExpression::factory( $recurrence );
|
||||
}
|
||||
|
||||
// For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method.
|
||||
$date = $recurrence->getNextRunDate( $start, 0, true );
|
||||
|
||||
// parent::__construct() will set this to $date by default, but that may be different to $start now.
|
||||
$first = empty( $first ) ? $start : $first;
|
||||
|
||||
parent::__construct( $date, $recurrence, $first );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate when an instance of this schedule would start based on a given
|
||||
* date & time using its the CronExpression.
|
||||
*
|
||||
* @param DateTime $after
|
||||
* @return DateTime
|
||||
*/
|
||||
protected function calculate_next( DateTime $after ) {
|
||||
return $this->recurrence->getNextRunDate( $after, 0, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_recurrence() {
|
||||
return strval( $this->recurrence );
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize cron schedules with data required prior to AS 3.0.0
|
||||
*
|
||||
* Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to
|
||||
* refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
|
||||
* was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
|
||||
* aligned properties and property names for better inheritance. To guard against the
|
||||
* possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to
|
||||
* also store the data with the old property names so if it's unserialized in AS < 3.0,
|
||||
* the schedule doesn't end up with a null recurrence.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep() {
|
||||
|
||||
$sleep_params = parent::__sleep();
|
||||
|
||||
$this->start_timestamp = $this->scheduled_timestamp;
|
||||
$this->cron = $this->recurrence;
|
||||
|
||||
return array_merge( $sleep_params, array(
|
||||
'start_timestamp',
|
||||
'cron'
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize cron schedules serialized/stored prior to AS 3.0.0
|
||||
*
|
||||
* For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
|
||||
*/
|
||||
public function __wakeup() {
|
||||
if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
|
||||
$this->scheduled_timestamp = $this->start_timestamp;
|
||||
unset( $this->start_timestamp );
|
||||
}
|
||||
|
||||
if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) {
|
||||
$this->recurrence = $this->cron;
|
||||
unset( $this->cron );
|
||||
}
|
||||
parent::__wakeup();
|
||||
}
|
||||
}
|
||||
|
81
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php
vendored
Normal file
81
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_IntervalSchedule
|
||||
*/
|
||||
class ActionScheduler_IntervalSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule {
|
||||
|
||||
/**
|
||||
* Deprecated property @see $this->__wakeup() for details.
|
||||
**/
|
||||
private $start_timestamp = NULL;
|
||||
|
||||
/**
|
||||
* Deprecated property @see $this->__wakeup() for details.
|
||||
**/
|
||||
private $interval_in_seconds = NULL;
|
||||
|
||||
/**
|
||||
* Calculate when this schedule should start after a given date & time using
|
||||
* the number of seconds between recurrences.
|
||||
*
|
||||
* @param DateTime $after
|
||||
* @return DateTime
|
||||
*/
|
||||
protected function calculate_next( DateTime $after ) {
|
||||
$after->modify( '+' . (int) $this->get_recurrence() . ' seconds' );
|
||||
return $after;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function interval_in_seconds() {
|
||||
_deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' );
|
||||
return (int) $this->get_recurrence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize interval schedules with data required prior to AS 3.0.0
|
||||
*
|
||||
* Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to
|
||||
* refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
|
||||
* was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
|
||||
* aligned properties and property names for better inheritance. To guard against the
|
||||
* possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to
|
||||
* also store the data with the old property names so if it's unserialized in AS < 3.0,
|
||||
* the schedule doesn't end up with a null/false/0 recurrence.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep() {
|
||||
|
||||
$sleep_params = parent::__sleep();
|
||||
|
||||
$this->start_timestamp = $this->scheduled_timestamp;
|
||||
$this->interval_in_seconds = $this->recurrence;
|
||||
|
||||
return array_merge( $sleep_params, array(
|
||||
'start_timestamp',
|
||||
'interval_in_seconds'
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize interval schedules serialized/stored prior to AS 3.0.0
|
||||
*
|
||||
* For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
|
||||
*/
|
||||
public function __wakeup() {
|
||||
if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
|
||||
$this->scheduled_timestamp = $this->start_timestamp;
|
||||
unset( $this->start_timestamp );
|
||||
}
|
||||
|
||||
if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) {
|
||||
$this->recurrence = $this->interval_in_seconds;
|
||||
unset( $this->interval_in_seconds );
|
||||
}
|
||||
parent::__wakeup();
|
||||
}
|
||||
}
|
31
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php
vendored
Normal file
31
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_NullSchedule
|
||||
*/
|
||||
class ActionScheduler_NullSchedule extends ActionScheduler_SimpleSchedule {
|
||||
|
||||
/** @var DateTime|null */
|
||||
protected $scheduled_date;
|
||||
|
||||
/**
|
||||
* Make the $date param optional and default to null.
|
||||
*
|
||||
* @param null $date The date & time to run the action.
|
||||
*/
|
||||
public function __construct( DateTime $date = null ) {
|
||||
$this->scheduled_date = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This schedule has no scheduled DateTime, so we need to override the parent __sleep()
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep() {
|
||||
return array();
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
$this->scheduled_date = null;
|
||||
}
|
||||
}
|
18
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_Schedule.php
vendored
Normal file
18
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_Schedule.php
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_Schedule
|
||||
*/
|
||||
interface ActionScheduler_Schedule {
|
||||
/**
|
||||
* @param DateTime $after
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function next( DateTime $after = NULL );
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_recurring();
|
||||
}
|
||||
|
71
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_SimpleSchedule.php
vendored
Normal file
71
dependencies/woocommerce/action-scheduler/classes/schedules/ActionScheduler_SimpleSchedule.php
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_SimpleSchedule
|
||||
*/
|
||||
class ActionScheduler_SimpleSchedule extends ActionScheduler_Abstract_Schedule {
|
||||
|
||||
/**
|
||||
* Deprecated property @see $this->__wakeup() for details.
|
||||
**/
|
||||
private $timestamp = NULL;
|
||||
|
||||
/**
|
||||
* @param DateTime $after
|
||||
*
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function calculate_next( DateTime $after ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_recurring() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize schedule with data required prior to AS 3.0.0
|
||||
*
|
||||
* Prior to Action Scheduler 3.0.0, schedules used different property names to refer
|
||||
* to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
|
||||
* was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
|
||||
* aligned properties and property names for better inheritance. To guard against the
|
||||
* scheduled date for single actions always being seen as "now" if downgrading to
|
||||
* Action Scheduler < 3.0.0, we need to also store the data with the old property names
|
||||
* so if it's unserialized in AS < 3.0, the schedule doesn't end up with a null recurrence.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep() {
|
||||
|
||||
$sleep_params = parent::__sleep();
|
||||
|
||||
$this->timestamp = $this->scheduled_timestamp;
|
||||
|
||||
return array_merge( $sleep_params, array(
|
||||
'timestamp',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize recurring schedules serialized/stored prior to AS 3.0.0
|
||||
*
|
||||
* Prior to Action Scheduler 3.0.0, schedules used different property names to refer
|
||||
* to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
|
||||
* was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
|
||||
* aligned properties and property names for better inheritance. To maintain backward
|
||||
* compatibility with schedules serialized and stored prior to 3.0, we need to correctly
|
||||
* map the old property names with matching visibility.
|
||||
*/
|
||||
public function __wakeup() {
|
||||
|
||||
if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) {
|
||||
$this->scheduled_timestamp = $this->timestamp;
|
||||
unset( $this->timestamp );
|
||||
}
|
||||
parent::__wakeup();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user