QueuersAvailableDiagnosticCheck.php in Purge 8.3
File
src/Plugin/Purge/DiagnosticCheck/QueuersAvailableDiagnosticCheck.php
View source
<?php
namespace Drupal\purge\Plugin\Purge\DiagnosticCheck;
use Drupal\purge\Plugin\Purge\Queuer\QueuersServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class QueuersAvailableDiagnosticCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $purgeQueuers;
public final function __construct(QueuersServiceInterface $purge_queuers, array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->purgeQueuers = $purge_queuers;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('purge.queuers'), $configuration, $plugin_id, $plugin_definition);
}
public function run() {
if (count($this->purgeQueuers) === 0) {
$this->value = '';
$this->recommendation = $this
->t("You have no queuers populating the queue!");
return self::SEVERITY_WARNING;
}
elseif (count($this->purgeQueuers) === 1) {
$plugin_id = current($this->purgeQueuers
->getPluginsEnabled());
$queuer = $this->purgeQueuers
->get($plugin_id);
$this->value = $queuer
->getLabel();
$this->recommendation = $queuer
->getDescription();
return self::SEVERITY_OK;
}
else {
$this->value = [];
foreach ($this->purgeQueuers as $queuer) {
$this->value[] = $queuer
->getLabel();
}
$this->value = implode(', ', $this->value);
$this->recommendation = $this
->t("You have multiple queuers populating the queue.");
return self::SEVERITY_OK;
}
}
}