From 9cc96a8835b12f8374f4931a58bd1d00eb3caa6c Mon Sep 17 00:00:00 2001 From: florenttorregrosa Date: Tue, 7 Feb 2017 16:49:18 +0100 Subject: [PATCH] Issue #2849487 by Grimreaper: Check if workspaces are available --- src/InternalReplicator.php | 9 +++++++++ src/ReplicatorInterface.php | 13 +++++++++++++ src/ReplicatorManager.php | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/InternalReplicator.php b/src/InternalReplicator.php index ba33a3c..4d5d4c2 100644 --- a/src/InternalReplicator.php +++ b/src/InternalReplicator.php @@ -191,4 +191,13 @@ class InternalReplicator implements ReplicatorInterface { return $replication_log; } + /** + * {@inheritdoc} + */ + public function targetWorkspaceAvailable(WorkspacePointerInterface $source, WorkspacePointerInterface $target) { + // For internal workspaces, there is no reason that the workspace is not + // available. + return TRUE; + } + } diff --git a/src/ReplicatorInterface.php b/src/ReplicatorInterface.php index 5891aeb..9dc6a7c 100644 --- a/src/ReplicatorInterface.php +++ b/src/ReplicatorInterface.php @@ -35,4 +35,17 @@ interface ReplicatorInterface { */ public function replicate(WorkspacePointerInterface $source, WorkspacePointerInterface $target, $task = NULL); + /** + * Check that the target workspace is available. + * + * @param \Drupal\workspace\WorkspacePointerInterface $source + * The workspace to replicate from. + * @param \Drupal\workspace\WorkspacePointerInterface $target + * The workspace to replicate to. + * + * @return bool + * TRUE if the workspace is available. FALSE otherwise. + */ + public function targetWorkspaceAvailable(WorkspacePointerInterface $source, WorkspacePointerInterface $target); + } diff --git a/src/ReplicatorManager.php b/src/ReplicatorManager.php index 170f7da..afba13c 100644 --- a/src/ReplicatorManager.php +++ b/src/ReplicatorManager.php @@ -167,6 +167,17 @@ class ReplicatorManager implements ReplicatorInterface { } /** + * {@inheritdoc} + */ + public function targetWorkspaceAvailable(WorkspacePointerInterface $source, WorkspacePointerInterface $target) { + foreach ($this->replicators as $replicator) { + if ($replicator->applies($source, $target)) { + return $replicator->targetWorkspaceAvailable($source, $target); + } + } + } + + /** * Internal method to contain replication logic. * * @param \Drupal\workspace\WorkspacePointerInterface $source -- 1.9.1