class TomeStaticQueueWorker in Tome 8
Process a queue of static paths.
@QueueWorker( id = "tome_static_cron", title = @Translation("Tome Static path processor"), cron = {"time" = 60} )
@internal
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\tome_static_cron\Plugin\QueueWorker\TomeStaticQueueWorker implements ContainerFactoryPluginInterface
 
 
 - class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
 
Expanded class hierarchy of TomeStaticQueueWorker
1 file declares its use of TomeStaticQueueWorker
- tome_static_cron.module in modules/
tome_static/ modules/ tome_static_cron/ tome_static_cron.module  - Contains hook implementations for the tome_static_cron module.
 
File
- modules/
tome_static/ modules/ tome_static_cron/ src/ Plugin/ QueueWorker/ TomeStaticQueueWorker.php, line 26  
Namespace
Drupal\tome_static_cron\Plugin\QueueWorkerView source
class TomeStaticQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
  /**
   * An array of paths to invoke.
   */
  const STATE_KEY_INVOKE_PATHS = 'tome_static_cron.invoke_paths';
  /**
   * An array of paths already processed this run.
   */
  const STATE_KEY_OLD_PATHS = 'tome_static_cron.old_paths';
  /**
   * The static generator.
   *
   * @var \Drupal\tome_static\StaticGeneratorInterface
   */
  protected $static;
  /**
   * The request preparer.
   *
   * @var \Drupal\tome_static\RequestPreparer
   */
  protected $requestPreparer;
  /**
   * The current request, or NULL if there is no request.
   *
   * @var null|\Symfony\Component\HttpFoundation\Request
   */
  protected $currentRequest;
  /**
   * The state system.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;
  /**
   * The logger.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $logger;
  /**
   * Constructs a new class instance.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\tome_static\StaticGeneratorInterface $static
   *   The static generator.
   * @param \Drupal\tome_static\RequestPreparer $request_preparer
   *   The request preparer.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state system.
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
   *   The logger.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, StaticGeneratorInterface $static, RequestPreparer $request_preparer, RequestStack $request_stack, StateInterface $state, LoggerChannelFactoryInterface $logger_factory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->static = $static;
    $this->requestPreparer = $request_preparer;
    $this->currentRequest = $request_stack
      ->getCurrentRequest();
    $this->state = $state;
    $this->logger = $logger_factory
      ->get('tome_static_cron');
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('tome_static.generator'), $container
      ->get('tome_static.request_preparer'), $container
      ->get('request_stack'), $container
      ->get('state'), $container
      ->get('logger.factory'));
  }
  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $base_url = $data['base_url'];
    $state_invoke_paths = $this->state
      ->get(self::STATE_KEY_INVOKE_PATHS, []);
    if (isset($data['action']) && $data['action'] === 'process_invoke_paths') {
      $state_invoke_paths = $this->static
        ->exportPaths($state_invoke_paths);
      _tome_static_cron_queue_paths($state_invoke_paths, $base_url);
      $this->state
        ->set(TomeStaticQueueWorker::STATE_KEY_INVOKE_PATHS, []);
      return;
    }
    $path = $data['path'];
    if ($this->currentRequest) {
      $this->static
        ->prepareStaticDirectory();
      $original_params = TomeStaticHelper::setBaseUrl($this->currentRequest, $base_url);
    }
    $this->requestPreparer
      ->prepareForRequest();
    try {
      $invoke_paths = $this->static
        ->requestPath($path);
    } catch (\Exception $e) {
      $this->logger
        ->error('Error when requesting path "' . $path . '"": ' . $e
        ->getMessage() . ' ' . $e
        ->getTraceAsString(), []);
      $invoke_paths = [];
    }
    $this->state
      ->set(self::STATE_KEY_INVOKE_PATHS, array_merge($state_invoke_paths, $invoke_paths));
    if ($this->currentRequest) {
      TomeStaticHelper::restoreBaseUrl($this->currentRequest, $original_params);
    }
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            PluginBase:: | 
                  protected | property | Configuration information passed into the plugin. | 1 | 
| 
            PluginBase:: | 
                  protected | property | The plugin implementation definition. | 1 | 
| 
            PluginBase:: | 
                  protected | property | The plugin_id. | |
| 
            PluginBase:: | 
                  constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
| 
            PluginBase:: | 
                  public | function | 
            Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: | 
                  |
| 
            PluginBase:: | 
                  public | function | 
            Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: | 
                  |
| 
            PluginBase:: | 
                  public | function | 
            Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: | 
                  3 | 
| 
            PluginBase:: | 
                  public | function | 
            Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: | 
                  |
| 
            PluginBase:: | 
                  public | function | Determines if the plugin is configurable. | |
| 
            TomeStaticQueueWorker:: | 
                  protected | property | The current request, or NULL if there is no request. | |
| 
            TomeStaticQueueWorker:: | 
                  protected | property | The logger. | |
| 
            TomeStaticQueueWorker:: | 
                  protected | property | The request preparer. | |
| 
            TomeStaticQueueWorker:: | 
                  protected | property | The state system. | |
| 
            TomeStaticQueueWorker:: | 
                  protected | property | The static generator. | |
| 
            TomeStaticQueueWorker:: | 
                  public static | function | 
            Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: | 
                  |
| 
            TomeStaticQueueWorker:: | 
                  public | function | 
            Works on a single queue item. Overrides QueueWorkerInterface:: | 
                  |
| 
            TomeStaticQueueWorker:: | 
                  constant | An array of paths to invoke. | ||
| 
            TomeStaticQueueWorker:: | 
                  constant | An array of paths already processed this run. | ||
| 
            TomeStaticQueueWorker:: | 
                  public | function | 
            Constructs a new class instance. Overrides PluginBase:: |