You are here

public function PurgersAvailableDiagnosticCheck::run in Purge 8.3

Perform the check and determine the severity level.

Diagnostic checks determine whether something you are checking for is in shape, for instance CMI settings on which your plugin depends. Any check reporting self::SEVERITY_ERROR in their run() methods, will cause purge to stop working. Any other severity level will let the purgers proceed operating but you may report any warning through getRecommendation() to be shown on Drupal's status report, purge_ui or any other diagnostic listing.


public function run() {
  if (...check..) {
    return self::SEVERITY_OK;
  }
  return self::SEVERITY_WARNING;
}

@warning As diagnostic checks can be expensive, this method is called as rarely as possible. Checks derived from DiagnosticCheckBase will only see the check getting executed when any of the getter methods are called.

Return value

int Integer, matching either of the following constants:

Throws

\Drupal\purge\Plugin\Purge\DiagnosticCheck\Exception\CheckNotImplementedCorrectly Thrown when the return value is incorrect.

Overrides DiagnosticCheckInterface::run

File

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

Class

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

Namespace

Drupal\purge\Plugin\Purge\DiagnosticCheck

Code

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;
  }
}