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 2f6a7a5..c7f7d78 100644 --- a/src/Toolbar.php +++ b/src/Toolbar.php @@ -5,11 +5,15 @@ 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\Entity\WorkspacePointer; use Drupal\workspace\Form\WorkspaceSwitcherForm; /** @@ -17,6 +21,7 @@ */ class Toolbar { use StringTranslationTrait; + use MessengerTrait; /** * @var \Drupal\Core\Entity\EntityTypeManagerInterface @@ -143,7 +148,29 @@ 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', 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 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() + ])); + } + } + + if ($update_access && $has_upstream && !$last_replication_failed && empty($update_in_queue)) { $items['workspace_update'] = [ '#type' => 'toolbar_item', '#weight' => 124, 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']