PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.0.3
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.0.3
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes / ActionScheduler_ActionFactory.php
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes Last commit date
WP_CLI 4 years ago abstracts 4 years ago actions 4 years ago data-stores 4 years ago migration 4 years ago schedules 4 years ago schema 4 years ago ActionScheduler_ActionClaim.php 4 years ago ActionScheduler_ActionFactory.php 4 years ago ActionScheduler_AdminView.php 4 years ago ActionScheduler_AsyncRequest_QueueRunner.php 4 years ago ActionScheduler_Compatibility.php 4 years ago ActionScheduler_DataController.php 4 years ago ActionScheduler_DateTime.php 4 years ago ActionScheduler_Exception.php 4 years ago ActionScheduler_FatalErrorMonitor.php 4 years ago ActionScheduler_InvalidActionException.php 4 years ago ActionScheduler_ListTable.php 4 years ago ActionScheduler_LogEntry.php 4 years ago ActionScheduler_NullLogEntry.php 4 years ago ActionScheduler_OptionLock.php 4 years ago ActionScheduler_QueueCleaner.php 4 years ago ActionScheduler_QueueRunner.php 4 years ago ActionScheduler_Versions.php 4 years ago ActionScheduler_WPCommentCleaner.php 4 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.', 'action-scheduler' ) );
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