Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions src/EventSubscriber/ReplicationInProgress.php

This file was deleted.

29 changes: 28 additions & 1 deletion src/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@

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;

/**
* Service for hooks and utilities related to Toolbar integration.
*/
class Toolbar {
use StringTranslationTrait;
use MessengerTrait;

/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions workspace.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down