AcquiaCloudCheck.php in Acquia Purge 8
File
src/Plugin/Purge/DiagnosticCheck/AcquiaCloudCheck.php
View source
<?php
namespace Drupal\acquia_purge\Plugin\Purge\DiagnosticCheck;
use Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AcquiaCloudCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $moduleExtensionList;
protected $platformInfo;
public final function __construct(PlatformInfoInterface $acquia_purge_platforminfo, ModuleExtensionList $moduleExtensionList, array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleExtensionList = $moduleExtensionList;
$this->platformInfo = $acquia_purge_platforminfo;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('acquia_purge.platforminfo'), $container
->get('extension.list.module'), $configuration, $plugin_id, $plugin_definition);
}
public function run() {
$info = get_object_vars($this->moduleExtensionList
->get('acquia_purge'));
$version = isset($info['info']['version']) ? $info['info']['version'] : 'dev';
$this->value = $version;
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;
}
$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;
}
$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;
}
}