You are here

class LinkCheck in Link checker 8

Checks the link.

Plugin annotation


@QueueWorker(
  id = "linkchecker_check",
  title = @Translation("LinkChecker check"),
  cron = {"time" = 240}
)

Hierarchy

Expanded class hierarchy of LinkCheck

File

src/Plugin/QueueWorker/LinkCheck.php, line 21

Namespace

Drupal\linkchecker\Plugin\QueueWorker
View source
class LinkCheck extends QueueWorkerBase implements ContainerFactoryPluginInterface {

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

  /**
   * The link checker service.
   *
   * @var \Drupal\linkchecker\LinkCheckerService
   */
  protected $linkChecker;

  /**
   * LinkExtract constructor.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, LinkCheckerService $linkChecker) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entityTypeManager;
    $this->linkChecker = $linkChecker;
  }

  /**
   * {@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('linkchecker.checker'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $promises = [];

    // Collect all request promises.
    foreach ($data as $id) {

      /** @var \Drupal\linkchecker\LinkCheckerLinkInterface $link */
      $link = $this->entityTypeManager
        ->getStorage('linkcheckerlink')
        ->load($id);
      if ($link) {
        $promises[] = $this->linkChecker
          ->check($link);
      }
    }

    // Force wait to complete of all requests
    // to prevent next items of queue to be run.
    Promise\settle($promises)
      ->wait();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkCheck::$entityTypeManager protected property The entity type manager.
LinkCheck::$linkChecker protected property The link checker service.
LinkCheck::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
LinkCheck::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
LinkCheck::__construct public function LinkExtract constructor. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.