You are here

public function RecommendationsCheck::run in Acquia Purge 8

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/RecommendationsCheck.php, line 205

Class

RecommendationsCheck
Acquia Purge Recommendations.

Namespace

Drupal\acquia_purge\Plugin\Purge\DiagnosticCheck

Code

public function run() {

  // Check for the use of basic HTTP authentication.
  if ($this
    ->basicHttpAuthenticationFound()) {
    $this->recommendation = $this
      ->t('Acquia Purge detected that you are protecting your website with basic HTTP authentication. However, on Acquia Cloud all HTTP responses with access authentication deliberately MISS cache to prevent sensitive content from getting served to prying eyes. Acquia Purge cannot detect if specific parts of the site are protected or all pages, but does recommend you to temporarily disable invalidating caches if indeed your full site is protected. Please wipe Drupal\'s "default" cache bin when this warning persists after you updated your .htaccess file or uninstalled the Shield module!');
    return self::SEVERITY_WARNING;
  }

  // Issue a warning when the user forgot to add the AcquiaCloudPurger.
  if (!in_array('acquia_purge', $this->purgePurgers
    ->getPluginsEnabled())) {
    $this->recommendation = $this
      ->t("The 'Acquia Cloud' purger is not installed!");
    return self::SEVERITY_WARNING;
  }

  // The purge_queuer_url can quickly cause issues.
  if ($this->moduleHandler
    ->moduleExists('purge_queuer_url')) {
    $this->recommendation = $this
      ->t("For an optimal experience, you're recommended to not use the URLs queuer (and module) as this module creates a very high load. If you keep using it, make sure your website has only a small number of content so that the risks of using it, are contained.");
    return self::SEVERITY_WARNING;
  }

  // Test for the existence of the lateruntime and cron processors.
  if (!$this->purgeProcessors
    ->get('lateruntime') || !$this->purgeProcessors
    ->get('cron')) {
    $this->recommendation = $this
      ->t("For an optimal experience, you're recommended to enable the cron processor and the late runtime processors simultaneously. These two processors will complement each other and assure that the queue is processed as fast as possible.");
    return self::SEVERITY_WARNING;
  }

  // Test for the existence of the tags queuer, to ensure we're queuing tags!
  if (!$this->purgeQueuers
    ->get('coretags')) {
    $this->recommendation = $this
      ->t("For an optimal experience, you're recommended to enable the coretags queuer as this queues cache tags for Acquia Purge to process.");
    return self::SEVERITY_WARNING;
  }

  // All okay!
  $this->value = $this
    ->t("Nothing to recommend!");
  return self::SEVERITY_OK;
}