public function ReplicatorManager::replicate in Workspace 8
Perform the replication from the source to target workspace.
Parameters
\Drupal\workspace\WorkspacePointerInterface $source: The workspace to replicate from.
\Drupal\workspace\WorkspacePointerInterface $target: The workspace to replicate to.
mixed $task: Optional information that defines the replication task to perform.
Return value
\Drupal\replication\Entity\ReplicationLog The replication log entry.
Overrides ReplicatorInterface::replicate
File
- src/
ReplicatorManager.php, line 88
Class
- ReplicatorManager
- Provides the Replicator manager.
Namespace
Drupal\workspaceCode
public function replicate(WorkspacePointerInterface $source, WorkspacePointerInterface $target, $task = NULL, Replication $replication = NULL) {
if ($replication === NULL) {
// Create replication entity to Deploy changes from $source to $target.
$replication = Replication::create([
'name' => t('Deploy from @source to @target', [
'@source' => $source
->label(),
'@target' => $target
->label(),
]),
'source' => $source,
'target' => $target,
]);
}
// @todo Use here $replication->setDocIds() to set selected UUIDs when we'll
// have implemented the way users can select changes for next deployment.
// It is assumed a caller of replicate will set this static variable to
// FALSE if they wish to proceed with replicating content upstream even in
// the presence of conflicts. If the caller wants to make sure no conflicts
// are replicated to the upstream, set this value to TRUE.
// By default, the value is FALSE so as not to break the previous
// behavior.
// @todo Use a sequence index instead of boolean? This will allow the
// caller to know there haven't been additional conflicts.
$is_aborted_on_conflict = drupal_static('workspace_is_aborted_on_conflict', FALSE);
// Abort updating the Workspace if there are conflicts.
$initial_conflicts = $this->conflictTracker
->useWorkspace($source
->getWorkspace())
->getAll();
if ($is_aborted_on_conflict && $initial_conflicts) {
return $this
->replicationLog($source, $target, $task);
}
// Derive a pull replication task from the Workspace we are acting on.
$pull_task = $this
->getTask($source
->getWorkspace(), 'pull_replication_settings');
// Set selected for deployment UUIDs.
$doc_ids = $replication
->getDocIds();
if (is_array($doc_ids) && !empty($doc_ids)) {
$pull_task
->setFilter('_doc_ids');
$pull_task
->setDocIds($doc_ids);
}
// Pull in changes from $target to $source to ensure a merge will complete.
$this
->update($target, $source, $pull_task);
// Automatically derive settings from the workspace if no task sent.
// @todo Refactor to eliminate obscurity of having an optional parameter
// and automatically setting the parameter's value.
if ($task === NULL) {
// Derive a push replication task from the Workspace we are acting on.
$task = $this
->getTask($source
->getWorkspace(), 'push_replication_settings');
}
// Set selected for deployment UUIDs.
if (is_array($doc_ids) && !empty($doc_ids)) {
$task
->setFilter('_doc_ids');
$task
->setDocIds($doc_ids);
}
// Push changes from $source to $target.
$this
->queueReplication($replication, $task);
return $this
->replicationLog($source, $target, $task, TRUE);
}