return ActionScheduler_DataController::is_migration_complete(); } /** * Whether task has been scheduled and is pending or in-progress. * * @since 1.6.0 * * @param string $hook Hook to check for. * * @return bool|null * @noinspection PhpUndefinedFunctionInspection */ public function is_scheduled( $hook ) { if ( ! function_exists( 'as_has_scheduled_action' ) ) { return null; } if ( in_array( $hook, $this->active_actions, true ) ) { return true; } // Action is not in the array, so it is not scheduled or belongs to another group. return as_has_scheduled_action( $hook ); } /** * Get all WPForms pending or in-progress actions. * * @since 1.7.3 */ private function get_active_actions() { global $wpdb; $group = self::GROUP; $sql = "SELECT a.hook FROM {$wpdb->prefix}actionscheduler_actions a JOIN {$wpdb->prefix}actionscheduler_groups g ON g.group_id = a.group_id WHERE g.slug = '$group' AND a.status IN ( 'in-progress', 'pending' )"; // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared $results = $wpdb->get_results( $sql, 'ARRAY_N' ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared return $results ? array_merge( ...$results ) : []; } /** * Delete a task by its ID. * * @since 1.9.6.1 * * @param int $action_id Action ID. */ public function delete_action( $action_id ): void { global $wpdb; $sql = "DELETE FROM {$wpdb->prefix}actionscheduler_actions WHERE action_id = %d"; // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $wpdb->prepare( $sql, (int) $action_id ) ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared } /** * Fetch action by ID. * * @since 1.9.6.1 * * @param int $action_id Action ID. * * @return null|ActionScheduler_Action */ public function fetch_action( $action_id ): ?ActionScheduler_Action { if ( ! class_exists( 'ActionScheduler' ) ) { return null; } return ActionScheduler::store()->fetch_action( $action_id ); } /** * Clear the meta after action complete. * Fired before an action is marked as completed. * * @since 1.7.5 * * @param integer $action_id Action ID. * @param ActionScheduler_Action $action Action name. */ public function clear_action_meta( $action_id, $action ) { $action_schedule = $action->get_schedule(); if ( $action_schedule === null || $action_schedule->is_recurring() ) { return; } $hook_name = $action->get_hook(); if ( ! $this->is_scheduled( $hook_name ) ) { return; } $hook_args = $action->get_args(); if ( ! isset( $hook_args['tasks_meta_id'] ) ) { return; } $meta = new Meta(); $meta->delete( $hook_args['tasks_meta_id'] ); } }