You are here

class AcquiaCloudCheck in Acquia Purge 8

Acquia Purge.

Plugin annotation


@PurgeDiagnosticCheck(
  id = "acquia_purge_cloud_check",
  title = @Translation("Acquia Cloud"),
  description = @Translation("Validates the Acquia Cloud configuration."),
  dependent_queue_plugins = {},
  dependent_purger_plugins = {"acquia_purge"}
)

Hierarchy

Expanded class hierarchy of AcquiaCloudCheck

File

src/Plugin/Purge/DiagnosticCheck/AcquiaCloudCheck.php, line 22

Namespace

Drupal\acquia_purge\Plugin\Purge\DiagnosticCheck
View source
class AcquiaCloudCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {

  /**
   * The module extension list.
   *
   * @var \Drupal\Core\Extension\ModuleExtensionList
   */
  protected $moduleExtensionList;

  /**
   * Information object interfacing with the Acquia platform.
   *
   * @var \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface
   */
  protected $platformInfo;

  /**
   * Constructs a AcquiaCloudCheck object.
   *
   * @param \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface $acquia_purge_platforminfo
   *   Information object interfacing with the Acquia platform.
   * @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
   *   The module extension list.
   * @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.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaCloudCheck::$moduleExtensionList protected property The module extension list.
AcquiaCloudCheck::$platformInfo protected property Information object interfacing with the Acquia platform.
AcquiaCloudCheck::create public static function Creates an instance of the plugin. Overrides DiagnosticCheckBase::create
AcquiaCloudCheck::run public function Perform the check and determine the severity level. Overrides DiagnosticCheckInterface::run
AcquiaCloudCheck::__construct final public function Constructs a AcquiaCloudCheck object. Overrides PluginBase::__construct
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.
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.