Skip to content
Snippets Groups Projects
Verified Commit 028e0937 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3323317 by amateescu, vladimir_kriukov, smustgrave, alexpott: Revision...

Issue #3323317 by amateescu, vladimir_kriukov, smustgrave, alexpott: Revision metadata is not updated when a workspace is merged into its parent

(cherry picked from commit 36006808)
parent e5ce10b4
No related branches found
No related tags found
22 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #146920 passed with warnings
Pipeline: drupal

#146926

    ......@@ -2,7 +2,6 @@
    namespace Drupal\workspaces;
    use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
    use Drupal\Core\Database\Connection;
    use Drupal\Core\Entity\EntityTypeManagerInterface;
    use Drupal\Core\Utility\Error;
    ......@@ -50,13 +49,6 @@ class WorkspaceMerger implements WorkspaceMergerInterface {
    */
    protected $workspaceAssociation;
    /**
    * The cache tag invalidator.
    *
    * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
    */
    protected $cacheTagsInvalidator;
    /**
    * Constructs a new WorkspaceMerger.
    *
    ......@@ -66,8 +58,6 @@ class WorkspaceMerger implements WorkspaceMergerInterface {
    * Database connection.
    * @param \Drupal\workspaces\WorkspaceAssociationInterface $workspace_association
    * The workspace association service.
    * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
    * The cache tags invalidator service.
    * @param \Drupal\workspaces\WorkspaceInterface $source
    * The source workspace.
    * @param \Drupal\workspaces\WorkspaceInterface $target
    ......@@ -75,11 +65,10 @@ class WorkspaceMerger implements WorkspaceMergerInterface {
    * @param \Psr\Log\LoggerInterface|null $logger
    * The logger.
    */
    public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, WorkspaceAssociationInterface $workspace_association, CacheTagsInvalidatorInterface $cache_tags_invalidator, WorkspaceInterface $source, WorkspaceInterface $target, protected ?LoggerInterface $logger = NULL) {
    public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, WorkspaceAssociationInterface $workspace_association, WorkspaceInterface $source, WorkspaceInterface $target, protected ?LoggerInterface $logger = NULL) {
    $this->entityTypeManager = $entity_type_manager;
    $this->database = $database;
    $this->workspaceAssociation = $workspace_association;
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
    $this->sourceWorkspace = $source;
    $this->targetWorkspace = $target;
    if ($this->logger === NULL) {
    ......@@ -103,21 +92,23 @@ public function merge() {
    try {
    $transaction = $this->database->startTransaction();
    foreach ($this->getDifferringRevisionIdsOnSource() as $entity_type_id => $revision_difference) {
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    $revisions_on_source = $this->entityTypeManager->getStorage($entity_type_id)
    ->loadMultipleRevisions(array_keys($revision_difference));
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
    foreach ($revisions_on_source as $revision) {
    // Track all the differing revisions from the source workspace in
    // the context of the target workspace. This will automatically
    // update all the descendants of the target workspace as well.
    $this->workspaceAssociation->trackEntity($revision, $this->targetWorkspace);
    }
    // Since we're not saving entity objects, we need to invalidate the list
    // cache tags manually.
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    $this->cacheTagsInvalidator->invalidateTags($entity_type->getListCacheTags());
    // Set the workspace in which the revision was merged.
    $field_name = $entity_type->getRevisionMetadataKey('workspace');
    $revision->{$field_name}->target_id = $this->targetWorkspace->id();
    $revision->setSyncing(TRUE);
    $revision->save();
    }
    }
    }
    catch (\Exception $e) {
    ......
    ......@@ -4,6 +4,7 @@
    use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
    use Drupal\Core\Database\Connection;
    use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
    use Drupal\Core\Entity\EntityTypeManagerInterface;
    use Psr\Log\LoggerInterface;
    use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
    ......@@ -18,6 +19,17 @@
    */
    class WorkspaceOperationFactory {
    use DeprecatedServicePropertyTrait;
    /**
    * Defines deprecated injected properties.
    *
    * @var array
    */
    protected array $deprecatedProperties = [
    'cacheTagInvalidator' => 'cache_tags.invalidator',
    ];
    /**
    * The entity type manager.
    *
    ......@@ -47,18 +59,18 @@ class WorkspaceOperationFactory {
    protected $workspaceAssociation;
    /**
    * The cache tags invalidator.
    * An event dispatcher instance to use for configuration events.
    *
    * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
    * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
    */
    protected $cacheTagsInvalidator;
    protected $eventDispatcher;
    /**
    * An event dispatcher instance to use for configuration events.
    * The logger service.
    *
    * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
    * @var \Psr\Log\LoggerInterface
    */
    protected $eventDispatcher;
    protected $logger;
    /**
    * Constructs a new WorkspaceOperationFactory.
    ......@@ -71,28 +83,33 @@ class WorkspaceOperationFactory {
    * The workspace manager service.
    * @param \Drupal\workspaces\WorkspaceAssociationInterface $workspace_association
    * The workspace association service.
    * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
    * The cache tags invalidator service.
    * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $event_dispatcher
    * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface|\Drupal\Core\Cache\CacheTagsInvalidatorInterface $event_dispatcher
    * The event dispatcher.
    * @param \Psr\Log\LoggerInterface|null $logger
    * The logger.
    */
    public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, WorkspaceManagerInterface $workspace_manager, WorkspaceAssociationInterface $workspace_association, CacheTagsInvalidatorInterface $cache_tags_invalidator, EventDispatcherInterface $event_dispatcher = NULL, protected ?LoggerInterface $logger = NULL) {
    public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, WorkspaceManagerInterface $workspace_manager, WorkspaceAssociationInterface $workspace_association, EventDispatcherInterface|CacheTagsInvalidatorInterface $event_dispatcher, LoggerInterface|EventDispatcherInterface $logger = NULL) {
    $this->entityTypeManager = $entity_type_manager;
    $this->database = $database;
    $this->workspaceManager = $workspace_manager;
    $this->workspaceAssociation = $workspace_association;
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
    if (!$event_dispatcher) {
    @trigger_error('Calling ' . __METHOD__ . '() without the $event_dispatcher argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3242573', E_USER_DEPRECATED);
    if ($event_dispatcher instanceof CacheTagsInvalidatorInterface) {
    $event_dispatcher = \Drupal::service('event_dispatcher');
    @trigger_error('Calling ' . __METHOD__ . '() with the $cache_tags_invalidator argument is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3440755', E_USER_DEPRECATED);
    }
    elseif (!$event_dispatcher instanceof EventDispatcherInterface) {
    $event_dispatcher = \Drupal::service('event_dispatcher');
    @trigger_error('Calling ' . __METHOD__ . '() without the $event_dispatcher argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3242573', E_USER_DEPRECATED);
    }
    $this->eventDispatcher = $event_dispatcher;
    if ($this->logger === NULL) {
    $logger = func_get_arg(5);
    if (!$logger instanceof LoggerInterface) {
    $logger = \Drupal::service('logger.channel.workspaces');
    @trigger_error('Calling ' . __METHOD__ . '() without the $logger argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/2932520', E_USER_DEPRECATED);
    $this->logger = \Drupal::service('logger.channel.workspaces');
    }
    $this->logger = $logger;
    }
    /**
    ......@@ -120,7 +137,7 @@ public function getPublisher(WorkspaceInterface $source) {
    * A workspace merger object.
    */
    public function getMerger(WorkspaceInterface $source, WorkspaceInterface $target) {
    return new WorkspaceMerger($this->entityTypeManager, $this->database, $this->workspaceAssociation, $this->cacheTagsInvalidator, $source, $target, $this->logger);
    return new WorkspaceMerger($this->entityTypeManager, $this->database, $this->workspaceAssociation, $source, $target, $this->logger);
    }
    }
    ......@@ -132,9 +132,30 @@ public function testWorkspaceAssociation() {
    'dev' => [3, 4, 5, 6, 7, 8, 9],
    ];
    $expected_initial_revisions += [
    'stage' => [7, 8],
    'dev' => [7, 8],
    ];
    $this->assertWorkspaceAssociations('node', $expected_latest_revisions, $expected_all_revisions, $expected_initial_revisions);
    // Merge 'dev' into 'stage' and check the workspace associations.
    /** @var \Drupal\workspaces\WorkspaceMergerInterface $workspace_merger */
    $workspace_merger = \Drupal::service('workspaces.operation_factory')->getMerger($this->workspaces['dev'], $this->workspaces['stage']);
    $workspace_merger->merge();
    // The latest revisions from 'dev' are now tracked in 'stage'.
    $expected_latest_revisions['stage'] = $expected_latest_revisions['dev'];
    // Two revisions (8 and 9) were created for 'Test article 6', but only the
    // latest one (9) is being merged into 'stage'.
    $expected_all_revisions['stage'] = [3, 4, 5, 6, 7, 9];
    // Revision 7 was both an initial and latest revision in 'dev', so it is now
    // considered an initial revision in 'stage'.
    $expected_initial_revisions['stage'] = [4, 5, 7];
    // Which leaves revision 8 as the only remaining initial revision in 'dev'.
    $expected_initial_revisions['dev'] = [8];
    $this->assertWorkspaceAssociations('node', $expected_latest_revisions, $expected_all_revisions, $expected_initial_revisions);
    }
    /**
    ......
    ......@@ -13,7 +13,7 @@ services:
    Drupal\workspaces\WorkspaceInformationInterface: '@workspaces.information'
    workspaces.operation_factory:
    class: Drupal\workspaces\WorkspaceOperationFactory
    arguments: ['@entity_type.manager', '@database', '@workspaces.manager', '@workspaces.association', '@cache_tags.invalidator', '@event_dispatcher', '@logger.channel.workspaces']
    arguments: ['@entity_type.manager', '@database', '@workspaces.manager', '@workspaces.association', '@event_dispatcher', '@logger.channel.workspaces']
    Drupal\workspaces\WorkspaceOperationFactory: '@workspaces.operation_factory'
    workspaces.association:
    class: Drupal\workspaces\WorkspaceAssociation
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment