You are here

public function AcquiaCloudPurger::invalidateEverything in Acquia Purge 8

Invalidate the entire website.

This supports invalidation objects of the type 'everything'. Because many load balancers on Acquia Cloud host multiple websites (e.g. sites in a multisite) this will only affect the current site instance. This works because all Varnish-cached resources are tagged with a unique identifier coming from platformInfo::getSiteIdentifier().

See also

\Drupal\purge\Plugin\Purge\Purger\PurgerInterface::invalidate()

\Drupal\purge\Plugin\Purge\Purger\PurgerInterface::routeTypeToMethod()

File

src/Plugin/Purge/Purger/AcquiaCloudPurger.php, line 452

Class

AcquiaCloudPurger
Acquia Cloud.

Namespace

Drupal\acquia_purge\Plugin\Purge\Purger

Code

public function invalidateEverything(array $invalidations) {
  $this
    ->debugger()
    ->callerAdd(__METHOD__);

  // Set the 'everything' object(s) into processing mode.
  foreach ($invalidations as $invalidation) {
    $invalidation
      ->setState(InvalidationInterface::PROCESSING);
  }

  // Fetch the site identifier and start with a successive outcome.
  $overall_success = TRUE;

  // Synchronously request each balancer to wipe out everything for this site.
  $opt = $this
    ->getGlobalOptions();
  $opt['headers'] = [
    'X-Acquia-Purge' => $this->platformInfo
      ->getSiteIdentifier(),
    'Accept-Encoding' => 'gzip',
    'User-Agent' => 'Acquia Purge',
  ];
  foreach ($this->platformInfo
    ->getBalancerAddresses() as $ip_address) {
    try {
      $this->httpClient
        ->request('BAN', 'http://' . $ip_address . '/site', $opt);
    } catch (\Exception $e) {
      $this
        ->debugger()
        ->logFailedRequest($e);
      $overall_success = FALSE;
    }
  }

  // Set the object states according to our overall result.
  foreach ($invalidations as $invalidation) {
    if ($overall_success) {
      $invalidation
        ->setState(InvalidationInterface::SUCCEEDED);
    }
    else {
      $invalidation
        ->setState(InvalidationInterface::FAILED);
    }
  }
  $this
    ->debugger()
    ->callerRemove(__METHOD__);
}