You are here

class PurgersAvailableDiagnosticCheck in Purge 8.3

Checks if there is a purger plugin that invalidates an external cache.

Plugin annotation


@PurgeDiagnosticCheck(
  id = "purgersavailable",
  title = @Translation("Purgers"),
  description = @Translation("Checks if there is a purger plugin available."),
  dependent_queue_plugins = {},
  dependent_purger_plugins = {}
)

Hierarchy

Expanded class hierarchy of PurgersAvailableDiagnosticCheck

File

src/Plugin/Purge/DiagnosticCheck/PurgersAvailableDiagnosticCheck.php, line 20

Namespace

Drupal\purge\Plugin\Purge\DiagnosticCheck
View source
class PurgersAvailableDiagnosticCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {

  /**
   * The factory for configuration objects.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The purge executive service, which wipes content from external caches.
   *
   * @var \Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface
   */
  protected $purgePurgers;

  /**
   * Construct a PurgersAvailableDiagnosticCheck object.
   *
   * @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\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   * @param \Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface $purge_purgers
   *   The purge executive service, which wipes content from external caches.
   */
  public final function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, PurgersServiceInterface $purge_purgers) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->configFactory = $config_factory;
    $this->purgePurgers = $purge_purgers;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('config.factory'), $container
      ->get('purge.purgers'));
  }

  /**
   * {@inheritdoc}
   */
  public function run() {
    $purgerlabels = $this->purgePurgers
      ->getLabels();

    // Put all enabled in a comma separated value.
    $this->value = '';
    if (!empty($purgerlabels)) {
      $this->value = [];
      foreach ($purgerlabels as $label) {
        $this->value[] = (string) $label;
      }
      $this->value = implode(', ', $this->value);
    }

    // Test for an empty set of labels, indicating no purgers are configured.
    if (empty($purgerlabels)) {
      $this->recommendation = $this
        ->t("There is no purger loaded which means that you need a module enabled to provide a purger plugin to clear your external cache or CDN.");
      return self::SEVERITY_ERROR;
    }
    elseif (count($purgerlabels) == 1) {
      $this->recommendation = $this
        ->t("Purger configured.");
      return self::SEVERITY_OK;
    }
    elseif (count($purgerlabels) > 3) {
      $this->recommendation = $this
        ->t("You have more than 3 purgers active on one system. This introduces the risk of congesting Drupal as multiple purgers are clearing external caches. It is highly recommended is to simplify your caching architecture if possible.");
      return self::SEVERITY_WARNING;
    }
    else {
      $this->recommendation = $this
        ->t("Purgers configured.");
      return self::SEVERITY_OK;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DiagnosticCheckBase::$description private property The description of the check as described in the plugin's metadata.
DiagnosticCheckBase::$recommendation protected property A recommendation matching the severity level, may contain NULL.
DiagnosticCheckBase::$severity private property The severity of the outcome of this check.
DiagnosticCheckBase::$title private property The title of the check as described in the plugin's metadata.
DiagnosticCheckBase::$value protected property Optional check outcome / value (e.g. version numbers), may contain NULL.
DiagnosticCheckBase::getDescription public function Gets the description of the check. Overrides DiagnosticCheckInterface::getDescription
DiagnosticCheckBase::getRecommendation public function Get a recommendation matching the severity level, may return NULL. Overrides DiagnosticCheckInterface::getRecommendation
DiagnosticCheckBase::getRequirementsArray public function Generates a individual Drupal-like requirements array. Overrides DiagnosticCheckInterface::getRequirementsArray
DiagnosticCheckBase::getRequirementsSeverity public function Get the severity level, expressed as a status_report severity. Overrides DiagnosticCheckInterface::getRequirementsSeverity
DiagnosticCheckBase::getSeverity public function Get the severity level. Overrides DiagnosticCheckInterface::getSeverity
DiagnosticCheckBase::getSeverityString public function Get the severity level as unprefixed string. Overrides DiagnosticCheckInterface::getSeverityString
DiagnosticCheckBase::getTitle public function Gets the title of the check. Overrides DiagnosticCheckInterface::getTitle
DiagnosticCheckBase::getValue public function Get an optional value for the check output, may return NULL. Overrides DiagnosticCheckInterface::getValue
DiagnosticCheckBase::runCheck protected function Late runtime helper to assure that ::run() got called (and only once).
DiagnosticCheckInterface::SEVERITY_ERROR constant BLOCKING severity -- Error condition; purge.purgers service cannot operate.
DiagnosticCheckInterface::SEVERITY_INFO constant Non-blocking severity -- Informational message only.
DiagnosticCheckInterface::SEVERITY_OK constant Non-blocking severity -- check successfully passed.
DiagnosticCheckInterface::SEVERITY_WARNING constant Non-blocking severity -- Warning condition; proceed but flag warning.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
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.
PurgersAvailableDiagnosticCheck::$configFactory protected property The factory for configuration objects.
PurgersAvailableDiagnosticCheck::$purgePurgers protected property The purge executive service, which wipes content from external caches.
PurgersAvailableDiagnosticCheck::create public static function Creates an instance of the plugin. Overrides DiagnosticCheckBase::create
PurgersAvailableDiagnosticCheck::run public function Perform the check and determine the severity level. Overrides DiagnosticCheckInterface::run
PurgersAvailableDiagnosticCheck::__construct final public function Construct a PurgersAvailableDiagnosticCheck object. Overrides PluginBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.