ave no group. aioseo()->core->db->execute( "DELETE aa FROM {$prefix}actionscheduler_actions as aa WHERE `aa`.`hook` LIKE 'aioseo_%' AND `aa`.`group_id` = 0 AND `aa`.`status` IN ('complete', 'failed', 'canceled');" ); } /** * Schedules a single action at a specific time in the future. * * @since 4.0.13 * @version 4.2.7 * * @param string $actionName The action name. * @param int $time The time to add to the current time. * @param array $args Args passed down to the action. * @param bool $forceSchedule Whether we should schedule a new action regardless of whether one is already set. * @return boolean Whether the action was scheduled. */ public function scheduleSingle( $actionName, $time = 0, $args = [], $forceSchedule = false ) { try { if ( $forceSchedule || ! $this->isScheduled( $actionName, $args ) ) { as_schedule_single_action( time() + $time, $actionName, $args, $this->actionSchedulerGroup ); return true; } } catch ( \RuntimeException $e ) { // Nothing needs to happen. } return false; } /** * Checks if a given action is already scheduled. * * @since 4.0.13 * @version 4.2.7 * * @param string $actionName The action name. * @param array $args Args passed down to the action. * @return boolean Whether the action is already scheduled. */ public function isScheduled( $actionName, $args = [] ) { // We need to check for pending actions specifically since we otherwise cannot schedule another action while one is running (e.g. image and video sitemap scans). $pendingArgs = [ 'hook' => $actionName, 'status' => \ActionScheduler_Store::STATUS_PENDING, 'per_page' => 1 ]; $runningArgs = [ 'hook' => $actionName, 'status' => \ActionScheduler_Store::STATUS_RUNNING, 'per_page' => 1 ]; if ( ! empty( $args ) ) { $pendingArgs['args'] = $args; $runningArgs['args'] = $args; } $actions = array_merge( as_get_scheduled_actions( $pendingArgs ), as_get_scheduled_actions( $runningArgs ) ); return ! empty( $actions ); } /** * Unschedule an action. * * @since 4.1.4 * @version 4.2.7 * * @param string $actionName The action name to unschedule. * @param array $args Args passed down to the action. * @return void */ public function unschedule( $actionName, $args = [] ) { try { if ( as_next_scheduled_action( $actionName, $args ) ) { as_unschedule_action( $actionName, $args, $this->actionSchedulerGroup ); } } catch ( \Exception $e ) { // Do nothing. } } /** * Schedules a recurring action. * * @since 4.1.5 * @version 4.2.7 * * @param string $actionName The action name. * @param int $time The seconds to add to the current time. * @param int $interval The interval in seconds. * @param array $args Args passed down to the action. * @return boolean Whether the action was scheduled. */ public function scheduleRecurrent( $actionName, $time, $interval = 60, $args = [] ) { try { if ( ! $this->isScheduled( $actionName, $args ) ) { as_schedule_recurring_action( time() + $time, $interval, $actionName, $args, $this->actionSchedulerGroup ); return true; } } catch ( \RuntimeException $e ) { // Nothing needs to happen. } return false; } /** * Schedule a single async action. * * @since 4.1.6 * @version 4.2.7 * * @param string $actionName The name of the action. * @param array $args Any relevant arguments. * @return void */ public function scheduleAsync( $actionName, $args = [] ) { try { // Run the task immediately using an async action. as_enqueue_async_action( $actionName, $args, $this->actionSchedulerGroup ); } catch ( \Exception $e ) { // Do nothing. } } }