From f7f59e513e2a633f5a2bcf5fc581bf3c8f413680 Mon Sep 17 00:00:00 2001 From: Andrei Jechiu Date: Tue, 2 Apr 2019 14:25:42 +0300 Subject: [PATCH 1/4] Restrict creating new updates when one is queued or in progress already. --- src/Toolbar.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Toolbar.php b/src/Toolbar.php index 2f6a7a5..a2a2623 100644 --- a/src/Toolbar.php +++ b/src/Toolbar.php @@ -5,11 +5,14 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormBuilderInterface; +use Drupal\Core\Link; +use Drupal\Core\Messenger\MessengerTrait; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\multiversion\Entity\WorkspaceInterface; use Drupal\multiversion\Workspace\WorkspaceManagerInterface; +use Drupal\workspace\Entity\Replication; use Drupal\workspace\Form\WorkspaceSwitcherForm; /** @@ -17,6 +20,7 @@ */ class Toolbar { use StringTranslationTrait; + use MessengerTrait; /** * @var \Drupal\Core\Entity\EntityTypeManagerInterface @@ -143,7 +147,25 @@ public function toolbar() { $last_replication_failed = \Drupal::state()->get('workspace.last_replication_failed', FALSE); $update_access = $user->hasPermission('update any workspace from upstream'); $has_upstream = isset($active->upstream) && !$active->upstream->isEmpty(); - if ($update_access && $has_upstream && !$last_replication_failed) { + + if ($has_upstream) { + $update_in_queue = $this->entityTypeManager + ->getStorage('replication') + ->getQuery() + ->condition('source', $active->upstream->target_id) + ->condition('target', $active->id()) + ->condition('replication_status', [Replication::QUEUED, Replication::REPLICATING], 'IN') + ->execute(); + if (!empty($update_in_queue)) { + $this->messenger() + ->addWarning(t('A deployment between the active workspace and target workspace is currently queued or in progress. Creating a new deployment is not allowed until the current one ends. Check @deployments_page for the status.', [ + '@deployments_page' => Link::createFromRoute('Deployments page', 'entity.replication.collection') + ->toString() + ])); + } + } + + if ($update_access && $has_upstream && !$last_replication_failed && empty($update_in_queue)) { $items['workspace_update'] = [ '#type' => 'toolbar_item', '#weight' => 124, From eb30810a1d609cc4c0bc7a401bd9219e854122ae Mon Sep 17 00:00:00 2001 From: Andrei Jechiu Date: Wed, 3 Apr 2019 11:32:35 +0300 Subject: [PATCH 2/4] Update the messages displayed on update deployment. --- src/EventSubscriber/ReplicationInProgress.php | 66 ------------------- src/Toolbar.php | 2 +- workspace.services.yml | 5 -- 3 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 src/EventSubscriber/ReplicationInProgress.php diff --git a/src/EventSubscriber/ReplicationInProgress.php b/src/EventSubscriber/ReplicationInProgress.php deleted file mode 100644 index 5891435..0000000 --- a/src/EventSubscriber/ReplicationInProgress.php +++ /dev/null @@ -1,66 +0,0 @@ -entityTypeManager = $entity_type_manager; - $this->workspaceManager = $workspace_manager; - $this->currentUser = $current_user; - } - - /** - * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event - * - * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException - */ - public function displayMessage(GetResponseEvent $event) { - if ($this->currentUser->isAuthenticated()) { - $active_workspace_id = $this->workspaceManager->getActiveWorkspaceId(); - $replicating = $this->entityTypeManager->getStorage('replication')->getQuery()->condition('target', $active_workspace_id)->condition('replication_status', Replication::REPLICATING)->execute(); - if (!empty($replicating)) { - drupal_set_message(t('There is a deployment to the active workspace in progress. You may not see all changes yet.'), 'warning'); - } - } - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - $events[KernelEvents::REQUEST][] = ['displayMessage']; - return $events; - } - -} diff --git a/src/Toolbar.php b/src/Toolbar.php index a2a2623..1c8e6c2 100644 --- a/src/Toolbar.php +++ b/src/Toolbar.php @@ -158,7 +158,7 @@ public function toolbar() { ->execute(); if (!empty($update_in_queue)) { $this->messenger() - ->addWarning(t('A deployment between the active workspace and target workspace is currently queued or in progress. Creating a new deployment is not allowed until the current one ends. Check @deployments_page for the status.', [ + ->addWarning(t('A deployment to the active workspace is currently queued or in progress, you may not see all changes yet. Check @deployments_page for the status.', [ '@deployments_page' => Link::createFromRoute('Deployments page', 'entity.replication.collection') ->toString() ])); diff --git a/workspace.services.yml b/workspace.services.yml index 68a6cf0..5119159 100644 --- a/workspace.services.yml +++ b/workspace.services.yml @@ -33,11 +33,6 @@ services: arguments: ['@entity_type.manager', '@workspace.replicator_manager'] tags: - { name: event_subscriber } - workspace.replication_in_progress: - class: Drupal\workspace\EventSubscriber\ReplicationInProgress - arguments: ['@entity_type.manager', '@workspace.manager', '@current_user'] - tags: - - { name: event_subscriber } workspace.replication_finished: class: Drupal\workspace\EventSubscriber\ReplicationFinished arguments: ['@entity_type.manager', '@workspace.manager', '@?plugin.manager.alias_type', '@?pathauto.generator'] From 8eceefdfc0274fcab5f7d72dacc92aa75a77ee36 Mon Sep 17 00:00:00 2001 From: Andrei Jechiu Date: Mon, 15 Apr 2019 15:32:14 +0300 Subject: [PATCH 3/4] Change the message. --- src/Toolbar.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Toolbar.php b/src/Toolbar.php index 1c8e6c2..ff7b89d 100644 --- a/src/Toolbar.php +++ b/src/Toolbar.php @@ -158,7 +158,10 @@ public function toolbar() { ->execute(); if (!empty($update_in_queue)) { $this->messenger() - ->addWarning(t('A deployment to the active workspace is currently queued or in progress, you may not see all changes yet. Check @deployments_page for the status.', [ + ->addWarning(t('Users are allowed to create only one push ' . + 'and one pull (update) deployment. New deployments are allowed ' . + 'only after the current queued deployments end (after cron run). ' . + 'Check @deployments_page for the status.', [ '@deployments_page' => Link::createFromRoute('Deployments page', 'entity.replication.collection') ->toString() ])); From be3571fa31e6139b36f3bb7a097d717a991284b1 Mon Sep 17 00:00:00 2001 From: Andrei Jechiu Date: Mon, 8 Jul 2019 13:52:12 +0300 Subject: [PATCH 4/4] Fix message and pointer id. --- src/Toolbar.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Toolbar.php b/src/Toolbar.php index ff7b89d..c7f7d78 100644 --- a/src/Toolbar.php +++ b/src/Toolbar.php @@ -13,6 +13,7 @@ use Drupal\multiversion\Entity\WorkspaceInterface; use Drupal\multiversion\Workspace\WorkspaceManagerInterface; use Drupal\workspace\Entity\Replication; +use Drupal\workspace\Entity\WorkspacePointer; use Drupal\workspace\Form\WorkspaceSwitcherForm; /** @@ -153,16 +154,17 @@ public function toolbar() { ->getStorage('replication') ->getQuery() ->condition('source', $active->upstream->target_id) - ->condition('target', $active->id()) + ->condition('target', WorkspacePointer::loadFromWorkspace($active)->id()) ->condition('replication_status', [Replication::QUEUED, Replication::REPLICATING], 'IN') ->execute(); if (!empty($update_in_queue)) { $this->messenger() ->addWarning(t('Users are allowed to create only one push ' . - 'and one pull (update) deployment. New deployments are allowed ' . - 'only after the current queued deployments end (after cron run). ' . - 'Check @deployments_page for the status.', [ - '@deployments_page' => Link::createFromRoute('Deployments page', 'entity.replication.collection') + 'and one pull (update) deployment between the same source and ' . + 'target workspaces. New deployments are allowed only after the ' . + 'current queued deployments end (after cron run). ' . + 'Check @deployments_page page for the status.', [ + '@deployments_page' => Link::createFromRoute('Deployments', 'entity.replication.collection') ->toString() ])); }