query_actions( $query->get_query() ); if ( 'ids' === $query->get_return_type() ) { return $action_ids ?? []; } foreach ( $action_ids as $action_id ) { try { $action = $store->fetch_action( $action_id ); } catch ( Throwable $t ) { Logger::log( Logger::LEVEL_ERROR, "Unable to fetch an action `$action_id`. Reason: " . $t->getMessage() ); continue; } if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { Logger::log( Logger::LEVEL_WARN, 'ActionScheduler_NullAction found' ); continue; } $item = new Async_Operation_Item(); $actions[] = $item->set_id( $action_id ) ->set_hook( $action->get_hook() ) ->set_status( $store->get_status( $action_id ) ) ->set_args( $action->get_args() ) ->set_queue( $action->get_group() ) ->set_date( $store->get_date( $action_id ) ) ->set_logs( $logger->get_logs( $action_id ) ); } return $actions; } /** * @throws Async_Operation_Exception */ public static function cancel( int $operation_id ): void { self::check_library_is_registered(); $store = ActionScheduler::store(); $store->cancel_action( $operation_id ); } /** * @throws Async_Operation_Exception */ public static function remove( array $operation_ids ): void { self::check_library_is_registered(); $store = ActionScheduler::store(); foreach ( $operation_ids as $operation_id ) { $store->delete_action( $operation_id ); } } /** * @throws Async_Operation_Exception */ private static function check_library_is_registered(): void { if ( ! ActionScheduler::is_initialized() ) { Logger::log( Logger::LEVEL_ERROR, 'ActionScheduler is not initialised though its method was called' ); throw new Async_Operation_Exception(); } } }