You are here

public function ReplicatorManager::doReplication in Workspace 8

Internal method to contain replication logic.

Parameters

\Drupal\workspace\Entity\Replication $replication: The replication.

mixed $task: Optional information that defines the replication task to perform.

Return value

\Drupal\replication\Entity\ReplicationLogInterface The log entry for this replication.

Throws

\Drupal\Core\Entity\EntityStorageException

File

src/ReplicatorManager.php, line 233

Class

ReplicatorManager
Provides the Replicator manager.

Namespace

Drupal\workspace

Code

public function doReplication(Replication $replication, $task = NULL) {
  $source = $replication
    ->get('source')->entity;
  $target = $replication
    ->get('target')->entity;
  foreach ($this->replicators as $replicator) {
    if ($replicator
      ->applies($source, $target)) {

      // Do the mysterious dance of replication...
      $log = $replicator
        ->replicate($source, $target, $task);
      $doc_ids_exist = FALSE;

      // If there are doc IDs specified in the task, we don't set a new
      // "last_sequence.workspace.WORKSPACE_ID" state. That because we'll need
      // to get changes from the previous value of that state when replicating
      // selective content.
      if (!empty($task) && !empty($task
        ->getDocIds())) {
        $doc_ids_exist = TRUE;
      }
      if ($log instanceof ReplicationLogInterface && $log
        ->get('ok')->value == TRUE && isset($log->workspace->target_id) && !$doc_ids_exist) {
        \Drupal::state()
          ->set('last_sequence.workspace.' . $log->workspace->target_id, $log->source_last_seq->value);
      }
      return $log;
    }
  }
  return $this
    ->replicationLog($source, $target, $task);
}