You are here

protected function ChangesListController::getChangesBetweenRemoteWorkspaces in Workspace 8

Return the array with changed entities when target is a remote workspace.

Parameters

$source_workspace_pointer \Drupal\workspace\WorkspacePointerInterface:

$target_workspace_pointer \Drupal\workspace\WorkspacePointerInterface:

Return value

array

Throws

\Doctrine\CouchDB\HTTP\HTTPException

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

1 call to ChangesListController::getChangesBetweenRemoteWorkspaces()
ChangesListController::viewChanges in src/Controller/ChangesListController.php
View a list of changes between current workspace and the target workspace.

File

src/Controller/ChangesListController.php, line 168

Class

ChangesListController

Namespace

Drupal\workspace\Controller

Code

protected function getChangesBetweenRemoteWorkspaces($source_workspace_pointer, $target_workspace_pointer) {
  $since = $this->state
    ->get('last_sequence.workspace.' . $source_workspace_pointer
    ->getWorkspaceId(), 0);

  /** @var \Drupal\relaxed\CouchdbReplicator $couch_db_replicator */
  $couch_db_replicator = \Drupal::service('relaxed.couchdb_replicator');

  /** @var \Doctrine\CouchDB\CouchDBClient $source */
  $source = $couch_db_replicator
    ->setupEndpoint($source_workspace_pointer);

  /** @var \Doctrine\CouchDB\CouchDBClient $target */
  $target = $couch_db_replicator
    ->setupEndpoint($target_workspace_pointer);
  $revs_diff = [];
  $source_workspace = $source_workspace_pointer
    ->getWorkspace();
  $task = $this
    ->getTask($source_workspace, 'push_replication_settings');
  while (1) {
    $changes = $source
      ->getChanges(array(
      'feed' => 'normal',
      'style' => 'all_docs',
      'since' => $since,
      'filter' => $task
        ->getFilter(),
      'parameters' => $task
        ->getParameters(),
      'doc_ids' => NULL,
      'limit' => 50,
    ));
    if (empty($changes['results']) || empty($changes['last_seq'])) {
      break;
    }
    $data = [];
    foreach (array_reverse($changes['results']) as $source_change) {
      $data[$source_change['id']] = [];
      foreach ($source_change['changes'] as $change) {
        $data[$source_change['id']][] = $change['rev'];
      }
    }
    $revs_diff += !empty($data) ? $target
      ->getRevisionDifference($data) : [];
    if (!in_array($changes['last_seq'], array_column($changes['results'], 'seq'))) {
      break;
    }
    $since = $changes['last_seq'];
  }
  return $this
    ->getEntitiesFromRevsDiff($source_workspace, $revs_diff);
}