accessibility_scanner-8.x-1.0-alpha8/src/Plugin/QueueWorker/AxeCoreCliAggregateRunDataQueueWorker.php

src/Plugin/QueueWorker/AxeCoreCliAggregateRunDataQueueWorker.php
<?php

namespace Drupal\accessibility_scanner\Plugin\QueueWorker;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\State\StateInterface;
use Drupal\accessibility_scanner\Controller\AxeCoreCliHistoryController;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides functionality for processing the aggregator run data queue.
 *
 * @QueueWorker(
 *   id = "axecore_cli_aggregate_runs_queue_worker",
 *   title = @Translation("Accessibility Scanner aggregator run data queue"),
 * )
 */
class AxeCoreCliAggregateRunDataQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The lock service.
   *
   * @var \Drupal\Core\Lock\LockBackendInterface
   */
  protected $lock;

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * Constructs a new AggregateRunDataQueueWorker.
   *
   * @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\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   * @param \Drupal\Core\Lock\LockBackendInterface $lock
   *   The lock service.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LockBackendInterface $lock, StateInterface $state) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
    $this->lock = $lock;
    $this->state = $state;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('entity_type.manager'),
      $container->get('lock'),
      $container->get('state')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    if ($this->lock->acquire($data['queue_name'])) {
      $run_storage = $this->entityTypeManager->getStorage('web_page_archive_run');
      $state_array = $this->state->get($data['queue_name']);
      $run = $run_storage->loadRevision($data['vid']);
      foreach ($run->getCapturedArray() as $capture) {
        $unserialized = unserialize($capture->getString());
        if (get_class($unserialized['capture_response']) !== '__PHP_Incomplete_Class') {
          $report_data = AxeCoreCliHistoryController::generateAggregateReportData($run);
          $state_array[$run->getRevisionCreationTime()] = $report_data;
        }
      }
      $this->state->set($data['queue_name'], $state_array);
      $this->lock->release($data['queue_name']);
    }
    return TRUE;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc