You are here

class AllDocs in Replication 8

Same name and namespace in other branches
  1. 8.2 src/AllDocs/AllDocs.php \Drupal\replication\AllDocs\AllDocs

Hierarchy

Expanded class hierarchy of AllDocs

1 file declares its use of AllDocs
AllDocsFactory.php in src/AllDocsFactory.php

File

src/AllDocs/AllDocs.php, line 12

Namespace

Drupal\replication\AllDocs
View source
class AllDocs implements AllDocsInterface {
  use DependencySerializationTrait;

  /**
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * @var \Drupal\multiversion\MultiversionManagerInterface
   */
  protected $multiversionManager;

  /**
   * @var \Drupal\multiversion\Entity\WorkspaceInterface
   */
  protected $workspace;

  /**
   * @var \Drupal\multiversion\Entity\Index\EntityIndexInterface
   */
  protected $entityIndex;

  /**
   * @var \Symfony\Component\Serializer\SerializerInterface
   */
  protected $serializer;

  /**
   * @var boolean
   */
  protected $includeDocs = FALSE;

  /**
   * @var int
   */
  protected $limit = NULL;

  /**
   * @var int
   */
  protected $skip = 0;

  /**
   * @var boolean
   */
  protected $descending = FALSE;

  /**
   * @var string
   */
  protected $startKey;

  /**
   * @var string
   */
  protected $endKey;

  /**
   * @var boolean
   */
  protected $inclusiveEnd = TRUE;

  /**
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   * @param \Drupal\multiversion\MultiversionManagerInterface $multiversion_manager
   * @param \Drupal\multiversion\Entity\WorkspaceInterface $workspace
   * @param \Drupal\multiversion\Entity\Index\EntityIndexInterface
   * @param \Symfony\Component\Serializer\SerializerInterface
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, MultiversionManagerInterface $multiversion_manager, WorkspaceInterface $workspace, EntityIndexInterface $entity_index, SerializerInterface $serializer) {
    $this->entityTypeManager = $entity_type_manager;
    $this->multiversionManager = $multiversion_manager;
    $this->workspace = $workspace;
    $this->entityIndex = $entity_index;
    $this->serializer = $serializer;
  }

  /**
   * {@inheritdoc}
   */
  public function includeDocs($include_docs) {
    $this->includeDocs = (bool) $include_docs;
  }

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

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

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

  /**
   * {@inheritdoc}
   */
  public function startKey($key) {
    $this->startKey = $key;
  }

  /**
   * {@inheritdoc}
   */
  public function endKey($key) {
    $this->endKey = $key;
  }

  /**
   * {@inheritdoc}
   */
  public function inclusiveEnd($inclusive_end) {
    $this->inclusiveEnd = $inclusive_end;
  }

  /**
   * {@inheritdoc}
   *
   * @todo {@link https://www.drupal.org/node/2599900 Move any logic around 'includeDocs' and the serialization format
   *   into the serializer to better separate concerns.}
   */
  public function execute() {
    $rows = [];
    $entity_types = $this->entityTypeManager
      ->getDefinitions();
    foreach ($entity_types as $entity_type_id => $entity_type) {
      if ($this->multiversionManager
        ->isEnabledEntityType($entity_type) && !$entity_type
        ->get('local')) {
        try {
          $query = $this->entityTypeManager
            ->getStorage($entity_type_id)
            ->getQuery();
          if ($entity_type
            ->get('workspace') !== FALSE) {
            $query
              ->condition('workspace', $this->workspace
              ->id());
          }
          $ids = $query
            ->execute();
        } catch (\Exception $e) {
          watchdog_exception('replication', $e);
          continue;
        }
        $keys = [];
        foreach ($ids as $id) {
          $keys[] = $entity_type_id . ':' . $id;
        }
        $items = $this->entityIndex
          ->getMultiple($keys);
        foreach ($items as $item) {
          if ($item['is_stub'] == TRUE) {
            continue;
          }
          $rows[$item['uuid']] = [
            'rev' => $item['rev'],
          ];
        }
        if ($this->includeDocs) {
          $entities = $this->entityTypeManager
            ->getStorage($entity_type_id)
            ->loadMultiple($ids);
          foreach ($entities as $entity) {
            if ($entity->_rev->is_stub) {
              continue;
            }
            $rows[$entity
              ->uuid()]['doc'] = $this->serializer
              ->normalize($entity, 'json');
          }
        }
      }
    }
    return $rows;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AllDocs::$descending protected property
AllDocs::$endKey protected property
AllDocs::$entityIndex protected property
AllDocs::$entityTypeManager protected property
AllDocs::$includeDocs protected property
AllDocs::$inclusiveEnd protected property
AllDocs::$limit protected property
AllDocs::$multiversionManager protected property
AllDocs::$serializer protected property
AllDocs::$skip protected property
AllDocs::$startKey protected property
AllDocs::$workspace protected property
AllDocs::descending public function Overrides AllDocsInterface::descending
AllDocs::endKey public function Overrides AllDocsInterface::endKey
AllDocs::execute public function @todo {@link https://www.drupal.org/node/2599900 Move any logic around 'includeDocs' and the serialization format into the serializer to better separate concerns.} Overrides AllDocsInterface::execute
AllDocs::includeDocs public function Overrides AllDocsInterface::includeDocs
AllDocs::inclusiveEnd public function Overrides AllDocsInterface::inclusiveEnd
AllDocs::limit public function Overrides AllDocsInterface::limit
AllDocs::skip public function Overrides AllDocsInterface::skip
AllDocs::startKey public function Overrides AllDocsInterface::startKey
AllDocs::__construct public function
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2