PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.7
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.7
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Libraries / action-scheduler / classes / schedules / ActionScheduler_CronSchedule.php

ActionScheduler_CronSchedule.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.7, at app/Services/Libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php

112 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_CronSchedule
5 */
6 class ActionScheduler_CronSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule {
7
8 /**
9 * Deprecated property @see $this->__wakeup() for details.
10 *
11 * @var null
12 */
13 private $start_timestamp = null;
14
15 /**
16 * Deprecated property @see $this->__wakeup() for details.
17 *
18 * @var null
19 */
20 private $cron = null;
21
22 /**
23 * Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this
24 * objects $recurrence property.
25 *
26 * @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.
27 * @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance.
28 * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
29 */
30 public function __construct( DateTime $start, $recurrence, ?DateTime $first = null ) {
31 if ( ! is_a( $recurrence, 'CronExpression' ) ) {
32 $recurrence = CronExpression::factory( $recurrence );
33 }
34
35 // 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.
36 $date = $recurrence->getNextRunDate( $start, 0, true );
37
38 // parent::__construct() will set this to $date by default, but that may be different to $start now.
39 $first = empty( $first ) ? $start : $first;
40
41 parent::__construct( $date, $recurrence, $first );
42 }
43
44 /**
45 * Calculate when an instance of this schedule would start based on a given
46 * date & time using its the CronExpression.
47 *
48 * @param DateTime $after Timestamp.
49 * @return DateTime
50 */
51 protected function calculate_next( DateTime $after ) {
52 return $this->recurrence->getNextRunDate( $after, 0, false );
53 }
54
55 /**
56 * Get the schedule's recurrence.
57 *
58 * @return string
59 */
60 public function get_recurrence() {
61 return strval( $this->recurrence );
62 }
63
64 /**
65 * Serialize cron schedules with data required prior to AS 3.0.0
66 *
67 * Prior to Action Scheduler 3.0.0, recurring schedules used different property names to
68 * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
69 * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
70 * aligned properties and property names for better inheritance. To guard against the
71 * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to
72 * also store the data with the old property names so if it's unserialized in AS < 3.0,
73 * the schedule doesn't end up with a null recurrence.
74 *
75 * @return array
76 */
77 public function __sleep() {
78
79 $sleep_params = parent::__sleep();
80
81 $this->start_timestamp = $this->scheduled_timestamp;
82 $this->cron = $this->recurrence;
83
84 return array_merge(
85 $sleep_params,
86 array(
87 'start_timestamp',
88 'cron',
89 )
90 );
91 }
92
93 /**
94 * Unserialize cron schedules serialized/stored prior to AS 3.0.0
95 *
96 * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
97 */
98 public function __wakeup() {
99 if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
100 $this->scheduled_timestamp = $this->start_timestamp;
101 unset( $this->start_timestamp );
102 }
103
104 if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) {
105 $this->recurrence = $this->cron;
106 unset( $this->cron );
107 }
108 parent::__wakeup();
109 }
110 }
111
112