HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/ielts-store/wp-content/plugins/automatewoo/includes/Jobs/ToolTaskRunner.php
<?php

namespace AutomateWoo\Jobs;

use AutomateWoo\ActionScheduler\ActionSchedulerInterface;
use AutomateWoo\Exceptions\InvalidArgument;
use AutomateWoo\Tool_Background_Processed_Abstract;
use AutomateWoo\Tools\ToolsService;
use Exception;
use RuntimeException;

defined( 'ABSPATH' ) || exit;

/**
 * Class ToolTaskRunner
 *
 * Runs background tasks as required by AutomateWoo\Tools.
 *
 * @since 5.2.0.
 */
class ToolTaskRunner extends AbstractOneTimeActionSchedulerJob {

	/**
	 * Get the name of the job.
	 *
	 * @return string
	 */
	public function get_name() {
		return 'tools';
	}

	/**
	 * @var ToolsService
	 */
	protected $tools_service;

	/**
	 * ToolTaskRunner constructor.
	 *
	 * @param ActionSchedulerInterface  $action_scheduler
	 * @param ActionSchedulerJobMonitor $monitor
	 * @param ToolsService              $tools
	 */
	public function __construct( ActionSchedulerInterface $action_scheduler, ActionSchedulerJobMonitor $monitor, ToolsService $tools ) {
		$this->tools_service = $tools;
		parent::__construct( $action_scheduler, $monitor );
	}

	/**
	 * Process a single item.
	 *
	 * @param array $item A single item to process. Expects a validated item.
	 *
	 * @throws Exception If an error occurs. The exception will be logged by ActionScheduler.
	 * @throws RuntimeException If tool is not found.
	 */
	protected function process_item( array $item ) {
		$tool = $this->tools_service->get_tool( $item['tool_id'] );
		if ( ! $tool || ! $tool instanceof Tool_Background_Processed_Abstract ) {
			throw new RuntimeException( 'Valid tool not found.' );
		}

		$tool->handle_background_task( $item );
	}

	/**
	 * Validate an item to be processed by the job.
	 *
	 * @param array $item
	 *
	 * @throws InvalidArgument If the item is not valid.
	 */
	protected function validate_item( array $item ) {
		parent::validate_item( $item );

		if ( ! isset( $item['tool_id'] ) ) {
			throw InvalidArgument::missing_required( 'tool_id' );
		}
	}
}