ProcessorsAvailableDiagnosticCheck.php in Purge 8.3
File
src/Plugin/Purge/DiagnosticCheck/ProcessorsAvailableDiagnosticCheck.php
View source
<?php
namespace Drupal\purge\Plugin\Purge\DiagnosticCheck;
use Drupal\purge\Plugin\Purge\Processor\ProcessorsServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ProcessorsAvailableDiagnosticCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $purgeProcessors;
public final function __construct(ProcessorsServiceInterface $purge_processors, array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->purgeProcessors = $purge_processors;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('purge.processors'), $configuration, $plugin_id, $plugin_definition);
}
public function run() {
if (count($this->purgeProcessors) === 0) {
$this->value = '';
$this->recommendation = $this
->t("You have no processors, the queue can now build up because of this.");
return self::SEVERITY_WARNING;
}
elseif (count($this->purgeProcessors) === 1) {
$plugin_id = current($this->purgeProcessors
->getPluginsEnabled());
$processor = $this->purgeProcessors
->get($plugin_id);
$this->value = $processor
->getLabel();
$this->recommendation = $processor
->getDescription();
return self::SEVERITY_OK;
}
else {
$this->value = [];
foreach ($this->purgeProcessors as $processor) {
$this->value[] = $processor
->getLabel();
}
$this->value = implode(', ', $this->value);
$this->recommendation = $this
->t("You have multiple processors working the queue.");
return self::SEVERITY_OK;
}
}
}