View source
<?php
namespace Drupal\acquia_purge\Plugin\Purge\DiagnosticCheck;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Site\Settings;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\purge\Plugin\Purge\Processor\ProcessorsServiceInterface;
use Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface;
use Drupal\purge\Plugin\Purge\Queuer\QueuersServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RecommendationsCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $cache;
protected $configFactory;
protected $htaccess;
protected $moduleHandler;
protected $purgeProcessors;
protected $purgeQueuers;
protected $purgePurgers;
protected $settings;
public final function __construct($root, CacheBackendInterface $cache_backend, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ProcessorsServiceInterface $purge_processors, QueuersServiceInterface $purge_queuers, PurgersServiceInterface $purge_purgers, Settings $settings, array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->cache = $cache_backend;
$this->configFactory = $config_factory;
$this->htaccess = $root . '/.htaccess';
$this->moduleHandler = $module_handler;
$this->purgeProcessors = $purge_processors;
$this->purgeQueuers = $purge_queuers;
$this->purgePurgers = $purge_purgers;
$this->settings = $settings;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('app.root'), $container
->get('cache.default'), $container
->get('config.factory'), $container
->get('module_handler'), $container
->get('purge.processors'), $container
->get('purge.queuers'), $container
->get('purge.purgers'), $container
->get('settings'), $configuration, $plugin_id, $plugin_definition);
}
protected function basicHttpAuthenticationFound() {
$cid = 'acquia_purge_recommendations_basicauth';
if ($cache = $this->cache
->get($cid)) {
$found = $cache->data;
}
else {
$found = FALSE;
if ($this->moduleHandler
->moduleExists('shield')) {
if ($this->configFactory
->get('shield.settings')
->get('credentials.shield.user')) {
$found = TRUE;
}
}
if (!$found && file_exists($this->htaccess) && is_readable($this->htaccess)) {
$handle = fopen($this->htaccess, "r");
if ($handle) {
while ($found == FALSE && ($line = fgets($handle)) !== FALSE) {
$line = trim($line);
$not_a_comment = strpos($line, '#') === FALSE;
if ($not_a_comment && strpos($line, 'AuthType') !== FALSE) {
$found = TRUE;
}
elseif ($not_a_comment && strpos($line, 'AuthName') !== FALSE) {
$found = TRUE;
}
elseif ($not_a_comment && strpos($line, 'AuthUserFile') !== FALSE) {
$found = TRUE;
}
elseif ($not_a_comment && strpos($line, 'Require valid-user') !== FALSE) {
$found = TRUE;
}
}
fclose($handle);
}
}
$this->cache
->set($cid, $found, time() + 7200);
}
return $found;
}
public function run() {
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;
}
if (!in_array('acquia_purge', $this->purgePurgers
->getPluginsEnabled())) {
$this->recommendation = $this
->t("The 'Acquia Cloud' purger is not installed!");
return self::SEVERITY_WARNING;
}
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;
}
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;
}
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;
}
$this->value = $this
->t("Nothing to recommend!");
return self::SEVERITY_OK;
}
}