You are here

class DeployIterator in Deploy - Content Staging 7.2

Same name and namespace in other branches
  1. 7.3 includes/DeployIterator.inc \DeployIterator

Iterator class which does the heavy lifting for detecting dependencies.

Hierarchy

Expanded class hierarchy of DeployIterator

1 string reference to 'DeployIterator'
deploy_entity_dependency_iterator in ./deploy.module
Implements hook_entity_dependency_iterator().

File

includes/DeployIterator.inc, line 10
Deploy interator implementation.

View source
class DeployIterator extends EntityDependencyIterator {

  /**
   * Cache entity information.
   */
  protected static $entity_info = array();

  /**
   * We override this method since we need to return our own iterator.
   *
   * @return DeployIterator
   */
  public function getChildren() {
    return new DeployIterator($this
      ->getChildrenEntities(), $this);
  }

  /**
   * We override this method since we need to return UUID entities, with some
   * extra hooks.
   *
   * @see http://www.odata.org/developers/protocols
   */
  public function current() {
    $current = current($this->entities);

    // Load and cache the entity info.
    if (!isset(self::$entity_info[$current['type']])) {
      self::$entity_info[$current['type']] = entity_get_info($current['type']);
    }
    $uuids = entity_get_uuid_by_id($current['type'], array(
      $current['id'],
    ));
    $uuid = reset($uuids);
    $conditions = array();
    $unique_id = $current['id'];
    if (!empty($current['revision_id']) && !empty(self::$entity_info[$current['type']]['entity keys']['revision uuid'])) {
      $revision_key = self::$entity_info[$current['type']]['entity keys']['revision uuid'];
      $revisions = entity_get_uuid_by_id($current['type'], array(
        $current['revision_id'],
      ), TRUE);
      $conditions[$revision_key] = reset($revisions);
      $unique_id .= "-{$current['revision_id']}";
    }

    // Load the current entity with UUID.
    $entities = entity_uuid_load($current['type'], array(
      $uuid,
    ), $conditions);
    $entity = reset($entities);

    // Add necessary metadata to the entity.
    $cause = FALSE;
    if (!empty($this->causes[$current['type']][$current['id']])) {
      $cause_type = $this->causes[$current['type']][$current['id']]['type'];
      $cause_id = $this->causes[$current['type']][$current['id']]['id'];
      $cause_uuids = entity_get_uuid_by_id($cause_type, array(
        $cause_id,
      ));
      $cause_uuid = reset($cause_uuids);
      $cause = $cause_type . '/' . $cause_uuid;
    }
    $entity->__metadata = array(
      'type' => $current['type'],
      'uri' => $current['type'] . '/' . $uuid,
      'cause' => $cause,
    );

    // Now mark this as traversed.
    $this->traversed[$current['type']][$unique_id] = TRUE;

    // Let other modules have their say.
    drupal_alter('deploy_entity', $entity, $current['type']);
    return $entity;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeployIterator::$entity_info protected static property Cache entity information.
DeployIterator::current public function We override this method since we need to return UUID entities, with some extra hooks. Overrides EntityDependencyIterator::current
DeployIterator::getChildren public function We override this method since we need to return our own iterator. Overrides EntityDependencyIterator::getChildren 1
EntityDependencyIterator::$belongings public property An array of belongings to the entity being parsed.
EntityDependencyIterator::$causes public property An array with information on the cause/reason why an entity exists in the tree. Basically, the cause for term A's existance in the tree, might be becasue node B depends on it.
EntityDependencyIterator::$checked public property Keeps track of entities that have already been checked for dependencies.
EntityDependencyIterator::$dependencies public property An array of dependencies to the entity being parsed.
EntityDependencyIterator::$entities public property The entities to be iterated over.
EntityDependencyIterator::$entityId public property The entity ID of the entity currently being iterated over.
EntityDependencyIterator::$entityType public property The entity type of the entity currently being iterated over.
EntityDependencyIterator::$traversed public property Keeps track of entities that have already been traversed (output).
EntityDependencyIterator::getChildrenEntities public function Helper method to get entity dependencies.
EntityDependencyIterator::hasChildren public function Returns TRUE if an iterator can be created for the current item in the entities array.
EntityDependencyIterator::key public function Returns the key of the current element.
EntityDependencyIterator::next public function Moves the current position to the next element.
EntityDependencyIterator::rewind public function Rewinds the Iterator to the first element.
EntityDependencyIterator::valid public function Checks if current position is valid.
EntityDependencyIterator::__construct public function Constructor.