You are here

class AcquiaPurgeInvalidation in Acquia Purge 7

Provides an invalidation object.

Invalidations are small value objects that describe an individual path from the Acquia Purge queue, to be invalidated for the given scheme and domain name. Executors are responsible for calling ::setStatus(), so that at the end of processing, ::getStatus() evaluates whether the invalidation succeeded across all executor engines. This means that a failed CloudEdge purge, would render the entire path as failed so that it goes back into the queue.

Hierarchy

Expanded class hierarchy of AcquiaPurgeInvalidation

File

lib/invalidation/AcquiaPurgeInvalidation.php, line 13

View source
class AcquiaPurgeInvalidation implements AcquiaPurgeInvalidationInterface {
  use AcquiaPurgeQueueStatusTrait {
    setStatusContext as setStatusContextPrivate;
  }

  /**
   * Drupal's base path (or the one Acquia Purge is told to clear).
   *
   * @var string
   */
  protected $base_path;

  /**
   * String suffix to the ::setStatusContext() context to enable setting
   * multiple statuses within a single executor's ::invalidate() call for a
   * single invalidation object.
   *
   * @var string
   */
  protected $contextSuffix = '';

  /**
   * The domain name to clear the path on, e.g. "foo.com" or "bar.baz".
   *
   * @var string
   */
  protected $domain;

  /**
   * The requested scheme to be invalidated: 'http' or 'https'.
   *
   * @var string
   */
  protected $scheme;

  /**
   * The queue item to which this invalidation is associated.
   *
   * @var AcquiaPurgeQueueItemInterface
   */
  protected $queue_item;

  /**
   * {@inheritdoc}
   */
  public function __construct($scheme, $domain, $base_path, AcquiaPurgeQueueItemInterface $queue_item) {
    $this->queue_item = $queue_item;
    $this->domain = $domain;
    $this->scheme = $scheme;
    $this->base_path = $base_path;
  }

  /**
   * {@inheritdoc}
   */
  public function getScheme($fqn = FALSE) {
    if ($fqn) {
      return $this->scheme . '://';
    }
    return $this->scheme;
  }

  /**
   * {@inheritdoc}
   */
  public function getDomain() {
    return $this->domain;
  }

  /**
   * Retrieve the context value set on the queue item, adds the suffix.
   *
   * @return string|null
   */
  protected function getParentContext() {
    if (is_string($this->context) && strlen($this->contextSuffix)) {
      return $this->context . '_' . $this->contextSuffix;
    }
    return $this->context;
  }

  /**
   * {@inheritdoc}
   */
  public function getPath() {
    return $this->base_path . $this->queue_item
      ->getPath();
  }

  /**
   * {@inheritdoc}
   *
   * Route any calls to the queue item's function so that a single queue item
   * holds the overal statuses for all domain and scheme-varied copies of a
   * single HTTP path.
   */
  public function getStatus() {
    $this->queue_item
      ->setStatusContext($this
      ->getParentContext());
    return $this->queue_item
      ->getStatus();
  }

  /**
   * {@inheritdoc}
   */
  public function getUri() {
    return $this
      ->getScheme(TRUE) . $this
      ->getDomain() . $this
      ->getPath();
  }

  /**
   * {@inheritdoc}
   */
  public function hasWildcard() {
    return strpos($this
      ->getPath(), '*') !== FALSE;
  }

  /**
   * {@inheritdoc}
   *
   * Set status on the queue item, in the invalidation-specific context.
   */
  public function setStatus($status) {
    $this->queue_item
      ->setStatusContext($this
      ->getParentContext());
    $this->queue_item
      ->setStatus($status);
  }

  /**
   * {@inheritdoc}
   *
   * Since queue items hold multiple invalidations, the context is kept local.
   */
  public function setStatusContext($id) {
    if (is_null($id)) {
      $this
        ->setStatusContextPrivate(NULL);
      $this->queue_item
        ->setStatusContext(NULL);
      return;
    }
    $id = $this->scheme . '_' . $this->domain . '_' . $id;
    $this
      ->setStatusContextPrivate($id);
  }

  /**
   * {@inheritdoc}
   */
  public function setStatusContextSuffix($suffix) {
    $this->contextSuffix = $suffix;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaPurgeInvalidation::$base_path protected property Drupal's base path (or the one Acquia Purge is told to clear).
AcquiaPurgeInvalidation::$contextSuffix protected property String suffix to the ::setStatusContext() context to enable setting multiple statuses within a single executor's ::invalidate() call for a single invalidation object.
AcquiaPurgeInvalidation::$domain protected property The domain name to clear the path on, e.g. "foo.com" or "bar.baz".
AcquiaPurgeInvalidation::$queue_item protected property The queue item to which this invalidation is associated.
AcquiaPurgeInvalidation::$scheme protected property The requested scheme to be invalidated: 'http' or 'https'.
AcquiaPurgeInvalidation::getDomain public function Get the HTTP domain name. Overrides AcquiaPurgeInvalidationInterface::getDomain
AcquiaPurgeInvalidation::getParentContext protected function Retrieve the context value set on the queue item, adds the suffix.
AcquiaPurgeInvalidation::getPath public function Get the HTTP path. Overrides AcquiaPurgeInvalidationInterface::getPath
AcquiaPurgeInvalidation::getScheme public function Get the HTTP scheme. Overrides AcquiaPurgeInvalidationInterface::getScheme
AcquiaPurgeInvalidation::getStatus public function Route any calls to the queue item's function so that a single queue item holds the overal statuses for all domain and scheme-varied copies of a single HTTP path. Overrides AcquiaPurgeQueueStatusTrait::getStatus
AcquiaPurgeInvalidation::getUri public function Get the fully qualified URI. Overrides AcquiaPurgeInvalidationInterface::getUri
AcquiaPurgeInvalidation::hasWildcard public function Detect if the invalidation has a '*' character in it. Overrides AcquiaPurgeInvalidationInterface::hasWildcard
AcquiaPurgeInvalidation::setStatus public function Set status on the queue item, in the invalidation-specific context. Overrides AcquiaPurgeQueueStatusTrait::setStatus
AcquiaPurgeInvalidation::setStatusContext public function Since queue items hold multiple invalidations, the context is kept local. Overrides AcquiaPurgeQueueStatusInterface::setStatusContext
AcquiaPurgeInvalidation::setStatusContextSuffix public function Set a string suffix to the ::setStatusContext() context to enable setting multiple statuses within a single executor's ::invalidate() call for a single invalidation object. Overrides AcquiaPurgeInvalidationInterface::setStatusContextSuffix
AcquiaPurgeInvalidation::__construct public function Constructs an invalidation queue item object. Overrides AcquiaPurgeInvalidationInterface::__construct
AcquiaPurgeQueueStatusInterface::FAILED constant The actor failed processing the item.
AcquiaPurgeQueueStatusInterface::FRESH constant Item is new and no processing has been attempted on it yet.
AcquiaPurgeQueueStatusInterface::SUCCEEDED constant The actor succeeded processing the item.
AcquiaPurgeQueueStatusTrait::$context protected property The instance ID of the executor that is about to process this object, or NULL when no longer any executors are processing it. NULL is the default.
AcquiaPurgeQueueStatusTrait::$statuses protected property Associative list in which each key is the context id and the value can be:
AcquiaPurgeQueueStatusTrait::$statuses_after_processing protected property Statuses in which queue objects can leave processing. Notice that AcquiaPurgeQueueStatusInterface::FRESH is missing, this protects us against badly written executors.
AcquiaPurgeQueueStatusTrait::getStatusBoolean public function
AcquiaPurgeQueueStatusTrait::getStatusString public function
AcquiaPurgeQueueStatusTrait::setStatusContext public function Aliased as: setStatusContextPrivate
AcquiaPurgeQueueStatusTrait::setStatusFailed public function
AcquiaPurgeQueueStatusTrait::setStatusSucceeded public function