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1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / packages / action-scheduler / classes / ActionScheduler_ActionFactory.php
woocommerce / packages / action-scheduler / classes Last commit date
WP_CLI 6 years ago abstracts 4 years ago actions 4 years ago data-stores 4 years ago migration 4 years ago schedules 6 years ago schema 4 years ago ActionScheduler_ActionClaim.php 6 years ago ActionScheduler_ActionFactory.php 6 years ago ActionScheduler_AdminView.php 6 years ago ActionScheduler_AsyncRequest_QueueRunner.php 6 years ago ActionScheduler_Compatibility.php 6 years ago ActionScheduler_DataController.php 6 years ago ActionScheduler_DateTime.php 6 years ago ActionScheduler_Exception.php 6 years ago ActionScheduler_FatalErrorMonitor.php 6 years ago ActionScheduler_InvalidActionException.php 6 years ago ActionScheduler_ListTable.php 6 years ago ActionScheduler_LogEntry.php 6 years ago ActionScheduler_NullLogEntry.php 6 years ago ActionScheduler_OptionLock.php 6 years ago ActionScheduler_QueueCleaner.php 4 years ago ActionScheduler_QueueRunner.php 6 years ago ActionScheduler_Versions.php 6 years ago ActionScheduler_WPCommentCleaner.php 6 years ago ActionScheduler_wcSystemStatus.php 4 years ago
ActionScheduler_ActionFactory.php
180 lines
1 <?php
2
3 /**
4 * Class ActionScheduler_ActionFactory
5 */
6 class ActionScheduler_ActionFactory {
7
8 /**
9 * @param string $status The action's status in the data store
10 * @param string $hook The hook to trigger when this action runs
11 * @param array $args Args to pass to callbacks when the hook is triggered
12 * @param ActionScheduler_Schedule $schedule The action's schedule
13 * @param string $group A group to put the action in
14 *
15 * @return ActionScheduler_Action An instance of the stored action
16 */
17 public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
18
19 switch ( $status ) {
20 case ActionScheduler_Store::STATUS_PENDING :
21 $action_class = 'ActionScheduler_Action';
22 break;
23 case ActionScheduler_Store::STATUS_CANCELED :
24 $action_class = 'ActionScheduler_CanceledAction';
25 if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) && ! is_a( $schedule, 'ActionScheduler_NullSchedule' ) ) {
26 $schedule = new ActionScheduler_CanceledSchedule( $schedule->get_date() );
27 }
28 break;
29 default :
30 $action_class = 'ActionScheduler_FinishedAction';
31 break;
32 }
33
34 $action_class = apply_filters( 'action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group );
35
36 $action = new $action_class( $hook, $args, $schedule, $group );
37
38 /**
39 * Allow 3rd party code to change the instantiated action for a given hook, args, schedule and group.
40 *
41 * @param ActionScheduler_Action $action The instantiated action.
42 * @param string $hook The instantiated action's hook.
43 * @param array $args The instantiated action's args.
44 * @param ActionScheduler_Schedule $schedule The instantiated action's schedule.
45 * @param string $group The instantiated action's group.
46 */
47 return apply_filters( 'action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group );
48 }
49
50 /**
51 * Enqueue an action to run one time, as soon as possible (rather a specific scheduled time).
52 *
53 * This method creates a new action with the NULLSchedule. This schedule maps to a MySQL datetime string of
54 * 0000-00-00 00:00:00. This is done to create a psuedo "async action" type that is fully backward compatible.
55 * Existing queries to claim actions claim by date, meaning actions scheduled for 0000-00-00 00:00:00 will
56 * always be claimed prior to actions scheduled for a specific date. This makes sure that any async action is
57 * given priority in queue processing. This has the added advantage of making sure async actions can be
58 * claimed by both the existing WP Cron and WP CLI runners, as well as a new async request runner.
59 *
60 * @param string $hook The hook to trigger when this action runs
61 * @param array $args Args to pass when the hook is triggered
62 * @param string $group A group to put the action in
63 *
64 * @return int The ID of the stored action
65 */
66 public function async( $hook, $args = array(), $group = '' ) {
67 $schedule = new ActionScheduler_NullSchedule();
68 $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
69 return $this->store( $action );
70 }
71
72 /**
73 * @param string $hook The hook to trigger when this action runs
74 * @param array $args Args to pass when the hook is triggered
75 * @param int $when Unix timestamp when the action will run
76 * @param string $group A group to put the action in
77 *
78 * @return int The ID of the stored action
79 */
80 public function single( $hook, $args = array(), $when = null, $group = '' ) {
81 $date = as_get_datetime_object( $when );
82 $schedule = new ActionScheduler_SimpleSchedule( $date );
83 $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
84 return $this->store( $action );
85 }
86
87 /**
88 * Create the first instance of an action recurring on a given interval.
89 *
90 * @param string $hook The hook to trigger when this action runs
91 * @param array $args Args to pass when the hook is triggered
92 * @param int $first Unix timestamp for the first run
93 * @param int $interval Seconds between runs
94 * @param string $group A group to put the action in
95 *
96 * @return int The ID of the stored action
97 */
98 public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) {
99 if ( empty($interval) ) {
100 return $this->single( $hook, $args, $first, $group );
101 }
102 $date = as_get_datetime_object( $first );
103 $schedule = new ActionScheduler_IntervalSchedule( $date, $interval );
104 $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
105 return $this->store( $action );
106 }
107
108 /**
109 * Create the first instance of an action recurring on a Cron schedule.
110 *
111 * @param string $hook The hook to trigger when this action runs
112 * @param array $args Args to pass when the hook is triggered
113 * @param int $base_timestamp The first instance of the action will be scheduled
114 * to run at a time calculated after this timestamp matching the cron
115 * expression. This can be used to delay the first instance of the action.
116 * @param int $schedule A cron definition string
117 * @param string $group A group to put the action in
118 *
119 * @return int The ID of the stored action
120 */
121 public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) {
122 if ( empty($schedule) ) {
123 return $this->single( $hook, $args, $base_timestamp, $group );
124 }
125 $date = as_get_datetime_object( $base_timestamp );
126 $cron = CronExpression::factory( $schedule );
127 $schedule = new ActionScheduler_CronSchedule( $date, $cron );
128 $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
129 return $this->store( $action );
130 }
131
132 /**
133 * Create a successive instance of a recurring or cron action.
134 *
135 * Importantly, the action will be rescheduled to run based on the current date/time.
136 * That means when the action is scheduled to run in the past, the next scheduled date
137 * will be pushed forward. For example, if a recurring action set to run every hour
138 * was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the
139 * future, which is 1 hour and 5 seconds from when it was last scheduled to run.
140 *
141 * Alternatively, if the action is scheduled to run in the future, and is run early,
142 * likely via manual intervention, then its schedule will change based on the time now.
143 * For example, if a recurring action set to run every day, and is run 12 hours early,
144 * it will run again in 24 hours, not 36 hours.
145 *
146 * This slippage is less of an issue with Cron actions, as the specific run time can
147 * be set for them to run, e.g. 1am each day. In those cases, and entire period would
148 * need to be missed before there was any change is scheduled, e.g. in the case of an
149 * action scheduled for 1am each day, the action would need to run an entire day late.
150 *
151 * @param ActionScheduler_Action $action The existing action.
152 *
153 * @return string The ID of the stored action
154 * @throws InvalidArgumentException If $action is not a recurring action.
155 */
156 public function repeat( $action ) {
157 $schedule = $action->get_schedule();
158 $next = $schedule->get_next( as_get_datetime_object() );
159
160 if ( is_null( $next ) || ! $schedule->is_recurring() ) {
161 throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'woocommerce' ) );
162 }
163
164 $schedule_class = get_class( $schedule );
165 $new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() );
166 $new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() );
167 return $this->store( $new_action );
168 }
169
170 /**
171 * @param ActionScheduler_Action $action
172 *
173 * @return int The ID of the stored action
174 */
175 protected function store( ActionScheduler_Action $action ) {
176 $store = ActionScheduler_Store::instance();
177 return $store->save_action( $action );
178 }
179 }
180