ActionScheduler_ActionFactory::repeat()
Create a successive instance of a recurring or cron action.
Importantly, the action will be rescheduled to run based on the current date/time. That means when the action is scheduled to run in the past, the next scheduled date will be pushed forward. For example, if a recurring action set to run every hour was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the future, which is 1 hour and 5 seconds from when it was last scheduled to run.
Alternatively, if the action is scheduled to run in the future, and is run early, likely via manual intervention, then its schedule will change based on the time now. For example, if a recurring action set to run every day, and is run 12 hours early, it will run again in 24 hours, not 36 hours.
This slippage is less of an issue with Cron actions, as the specific run time can be set for them to run, e.g. 1am each day. In those cases, and entire period would need to be missed before there was any change is scheduled, e.g. in the case of an action scheduled for 1am each day, the action would need to run an entire day late.
Method of the class: ActionScheduler_ActionFactory{}
No Hooks.
Return
String
. The ID of the stored action
Usage
$ActionScheduler_ActionFactory = new ActionScheduler_ActionFactory(); $ActionScheduler_ActionFactory->repeat( $action );
- $action(ActionScheduler_Action) (required)
- The existing action.
ActionScheduler_ActionFactory::repeat() ActionScheduler ActionFactory::repeat code WC 9.3.3
public function repeat( $action ) { $schedule = $action->get_schedule(); $next = $schedule->get_next( as_get_datetime_object() ); if ( is_null( $next ) || ! $schedule->is_recurring() ) { throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'woocommerce' ) ); } $schedule_class = get_class( $schedule ); $new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() ); $new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() ); $new_action->set_priority( $action->get_priority() ); return $this->store( $new_action ); }