You are here

class AcquiaPurgeQueueItem in Acquia Purge 7

Provides a queue item object.

On the outside, these queue objects are identical in behavior to Drupal's standard DrupalReliableQueueInterface::claimItem() objects and allow read access to its 'item_id', 'created' and 'data' properties.

On top of that however, these objects are capable of letting executor plugins set statuses on them through the ::setStatus() method on the invalidation objects created by ::getInvalidation(). With this, we can easily evaluate the overall outcome at the end and claim or delete it from the queue.

Hierarchy

Expanded class hierarchy of AcquiaPurgeQueueItem

File

lib/queue/AcquiaPurgeQueueItem.php, line 15

View source
class AcquiaPurgeQueueItem implements AcquiaPurgeQueueItemInterface {
  use AcquiaPurgeQueueStatusTrait;

  /**
   * The invalidation class to instantiate invalidation objects from.
   *
   * @var string
   */
  protected $class_invalidation;

  /**
   * Timestamp when the item was put into the queue.
   *
   * @var int
   * @see AcquiaPurgeQueueInterface::createItem
   * @see AcquiaPurgeQueueInterface::claimItem
   */
  protected $created;

  /**
   * Purge specific data to be associated with the new task in the queue.
   *
   * @var mixed
   * @see AcquiaPurgeQueueInterface::createItem
   * @see AcquiaPurgeQueueInterface::claimItem
   */
  protected $data;

  /**
   * Timestamp when the item expires from the queue.
   *
   * @var int
   * @see AcquiaPurgeQueueInterface::createItem
   * @see AcquiaPurgeQueueInterface::claimItem
   */
  protected $expire;

  /**
   * The unique ID from AcquiaPurgeQueueInterface::createItem().
   *
   * @var string|int
   * @see AcquiaPurgeQueueInterface::createItem
   * @see AcquiaPurgeQueueInterface::claimItem
   */
  protected $item_id;

  /**
   * Describes the accessible properties and if they're RO (FALSE) or RW (TRUE).
   *
   * @var bool[string]
   */
  protected $properties = [
    'item_id' => TRUE,
    'created' => TRUE,
    'data' => FALSE,
  ];

  /**
   * {@inheritdoc}
   */
  public function __construct($created, $data, $expire, $item_id) {
    $this->created = $created;
    $this->item_id = $item_id;
    $this->expire = $expire;
    $this->data = $data;
    $this->class_invalidation = _acquia_purge_load(array(
      '_acquia_purge_invalidation_interface',
      '_acquia_purge_invalidation',
    ));
  }

  /**
   * {@inheritdoc}
   */
  public function __get($name) {
    if (!isset($this->properties[$name])) {
      throw new RuntimeException("The property '{$name}' does not exist.");
    }
    return $this->{$name};
  }

  /**
   * {@inheritdoc}
   */
  public function __set($name, $value) {
    if (!isset($this->properties[$name])) {
      throw new RuntimeException("The property '{$name}' does not exist.");
    }
    if (!$this->properties[$name]) {
      throw new RuntimeException("The property '{$name}' is read-only.");
    }
    $this->{$name} = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function getInvalidation($scheme, $domain, $base_path) {
    return new $this->class_invalidation($scheme, $domain, $base_path, $this);
  }

  /**
   * {@inheritdoc}
   */
  public function getPath() {
    return $this->data[0];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaPurgeQueueItem::$class_invalidation protected property The invalidation class to instantiate invalidation objects from.
AcquiaPurgeQueueItem::$created protected property Timestamp when the item was put into the queue.
AcquiaPurgeQueueItem::$data protected property Purge specific data to be associated with the new task in the queue.
AcquiaPurgeQueueItem::$expire protected property Timestamp when the item expires from the queue.
AcquiaPurgeQueueItem::$item_id protected property The unique ID from AcquiaPurgeQueueInterface::createItem().
AcquiaPurgeQueueItem::$properties protected property Describes the accessible properties and if they're RO (FALSE) or RW (TRUE).
AcquiaPurgeQueueItem::getInvalidation public function Create a invalidation object for the given scheme, domain and base path. Overrides AcquiaPurgeQueueItemInterface::getInvalidation
AcquiaPurgeQueueItem::getPath public function Get the HTTP path. Overrides AcquiaPurgeQueueItemInterface::getPath
AcquiaPurgeQueueItem::__construct public function Constructs an queue item object. Overrides AcquiaPurgeQueueItemInterface::__construct
AcquiaPurgeQueueItem::__get public function Retrieve a property. Overrides AcquiaPurgeQueueItemInterface::__get
AcquiaPurgeQueueItem::__set public function Set a writable property. Overrides AcquiaPurgeQueueItemInterface::__set
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::getStatus public function 1
AcquiaPurgeQueueStatusTrait::getStatusBoolean public function
AcquiaPurgeQueueStatusTrait::getStatusString public function
AcquiaPurgeQueueStatusTrait::setStatus public function 1
AcquiaPurgeQueueStatusTrait::setStatusContext public function
AcquiaPurgeQueueStatusTrait::setStatusFailed public function
AcquiaPurgeQueueStatusTrait::setStatusSucceeded public function