public function AcquiaCloudCheck::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:
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_INFO
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_OK
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_WARNING
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_ERROR
Throws
\Drupal\purge\Plugin\Purge\DiagnosticCheck\Exception\CheckNotImplementedCorrectly Thrown when the return value is incorrect.
Overrides DiagnosticCheckInterface::run
File
- src/
Plugin/ Purge/ DiagnosticCheck/ AcquiaCloudCheck.php, line 74
Class
- AcquiaCloudCheck
- Acquia Purge.
Namespace
Drupal\acquia_purge\Plugin\Purge\DiagnosticCheckCode
public function run() {
// Use get_object_vars() to avoid the following Phpstan error:
// Access to an undefined property Drupal\Core\Extension\Extension::$info.
$info = get_object_vars($this->moduleExtensionList
->get('acquia_purge'));
$version = isset($info['info']['version']) ? $info['info']['version'] : 'dev';
$this->value = $version;
// Block the entire system when this is a third-party platform.
if (!$this->platformInfo
->isThisAcquiaCloud()) {
$this->recommendation = $this
->t("Acquia Purge only works on your Acquia Cloud environment and doesn't work outside of it.");
return self::SEVERITY_ERROR;
}
// Check the balancer composition for crazy setups.
$balancers = $this->platformInfo
->getBalancerAddresses();
$balancerscount = count($balancers);
$this->value = $balancerscount ? implode(', ', $balancers) : '';
if (!$balancerscount) {
$this->value = '';
$this->recommendation = $this
->t("No balancers found, therefore cache invalidation has been disabled. Please contact Acquia Support!");
return self::SEVERITY_ERROR;
}
elseif ($balancerscount < 2) {
$this->recommendation = $this
->t("You have only one load balancer, this means your site cannot be failed over in case of emergency. Please contact Acquia Support!");
return self::SEVERITY_WARNING;
}
elseif ($balancerscount >= 5) {
$this->recommendation = $this
->t("Your site has @n load balancers, which will put severe stress on your system. Please pay attention to your queue, contact Acquia Support and request less but bigger load balancers!", [
'@n' => $balancerscount,
]);
return self::SEVERITY_WARNING;
}
// Under normal operating conditions, we'll report site info and version.
$this->value = $this
->t("@site_group.@site_env (@version)", [
'@site_group' => $this->platformInfo
->getSiteGroup(),
'@site_env' => $this->platformInfo
->getSiteEnvironment(),
'@version' => $version,
]);
$this->recommendation = " ";
return self::SEVERITY_OK;
}