Problem/motivation

Upon completion of replication, entities have differences in url alias from source url aliases.

Current behaviour

If url aliases patterns depend on several entities, during replication they can be created earlier than the replication of dependent entities is completed, which leads to differences in the summary alias of the source and target workspace entities.

Expected behaviour

Source and targets entities must have the same url aliases.

Remaining tasks

  1. Add test_dependencies in a separate patch #3019632: Add `pathauto` to `test_dependencies`.
  2. Handle Event dispatching in #2971926: Better dispatch events. Add all events already proposed there but store $replication object in Event.
  3. In current issue we should only add EventSubscriber and test.

Comments

axicdv created an issue. See original summary.

axicdv’s picture

StatusFileSize
new8.54 KB
l0ke’s picture

Status: Active » Needs work
  1. +++ b/src/EventSubscriber/ReplicationFinished.php
    @@ -0,0 +1,102 @@
    +      $definitions = $this->aliasTypeManager->getVisibleDefinitions();
    +      foreach ($definitions as $id => $definition) {
    +        $entity_type = array_keys($definition['context'])[0];
    +        $this->updateEntitiesAlias($entity_type);
    +      }
    

    Usage of array_keys and accessing element in array by index is very sensitive to any change and can be broken easily
    Suggestion:

        $definitions = $this->aliasTypeManager->getVisibleDefinitions();
        foreach ($definitions as ['context' => $context]) {
          foreach ($context as $entity_type => $context_definition) {
            $this->updateEntitiesAlias($entity_type);
          }
        }
    
  2. +++ b/src/EventSubscriber/ReplicationFinished.php
    @@ -0,0 +1,102 @@
    +    $ids = \Drupal::entityQuery($entity_type)->execute();
    +
    +    $storage = $this->entityTypeManager->getStorage($entity_type);
    

    Don't use \Drupal:: in OOP
    Suggestion:

        $ids = $this->entityTypeManager->getStorage($entity_type)->getQuery('AND')->execute();
        $storage = $this->entityTypeManager->getStorage($entity_type);
    
axicdv’s picture

Status: Needs work » Active
StatusFileSize
new8.56 KB
axicdv’s picture

Status: Active » Needs review

The last submitted patch, 2: 3015058-2.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 4: 3015058-4.patch, failed testing. View results

l0ke’s picture

Status: Needs work » Reviewed & tested by the community
jeqq’s picture

Status: Reviewed & tested by the community » Needs work

The failing tests points to the issue.

l0ke’s picture

+++ b/src/EventSubscriber/ReplicationFinished.php
@@ -0,0 +1,103 @@
+  public function __construct(EntityTypeManagerInterface $entity_type_manager, ?AliasTypeManager $alias_type_manager, ?PathautoGeneratorInterface $path_auto_generator) {

I don't think there is an issue, it's just that coding standards does not support nullable types.

jeqq’s picture

@l0ke I tend to not accept new PHP features until they will be fully supported by core and tests on d.o pass.

axicdv’s picture

StatusFileSize
new8.57 KB
new849 bytes
axicdv’s picture

Status: Needs work » Needs review
l0ke’s picture

Status: Needs review » Reviewed & tested by the community
jeqq’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -path alias replication +Needs tests

This needs tests.

axicdv’s picture

Status: Needs work » Needs review
StatusFileSize
new16.31 KB
new11.87 KB

The last submitted patch, 12: 3015058-12.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 16: 3015058-16.patch, failed testing. View results

axicdv’s picture

Status: Needs work » Needs review
StatusFileSize
new16.31 KB
new694 bytes

Status: Needs review » Needs work

The last submitted patch, 19: 3015058-17.patch, failed testing. View results

axicdv’s picture

Status: Needs work » Needs review
StatusFileSize
new16.24 KB
new505 bytes

Status: Needs review » Needs work

The last submitted patch, 21: 3015058-21.patch, failed testing. View results

l0ke’s picture

https://www.drupal.org/docs/8/creating-custom-modules/let-drupal-8-know-...

Note that you need to have the test_dependencies change committed to your Git repository before you try to run a test that depends on it -- you cannot just put the info.yml change into the same patch as the new test.

test_dependencies:
  - pathauto:pathauto

We need to add test_dependencies to run our test properly but as the quote above says it cannot be done in a single patch.
I'd like to ask for your opinion what is the best scenario here?

And I also noticed that there is another issue with dispatching events #2971926: Better dispatch events we need to align with.

+++ b/src/Event/WorkspaceReplicationFinishedEvent.php
@@ -0,0 +1,45 @@
+class WorkspaceReplicationFinishedEvent extends Event {
...
+  protected $replication;

In my opinion it is better to store full $replication entity in event not just $source and $target to give as much context as we can.

jeqq’s picture

Regarding the test dependencies, I faced this before and the fix is simple, as the documentation says, we need to add the test dependence in a separate patch and commit that one first.

I agree that using the replication object in the event is better.

l0ke’s picture

I've updated the issue summary. Patches will follow-up soon.

l0ke’s picture

Issue summary: View changes
axicdv’s picture

Status: Needs work » Needs review
StatusFileSize
new15.97 KB

This patch is not a continuation of patch 3015058-21 and is intended only for local testing.

axicdv’s picture

Related issues: +#3020496: Relaxed. Better dispatch events
StatusFileSize
new13.98 KB
new8.95 KB

Status: Needs review » Needs work

The last submitted patch, 28: 3015058-28.patch, failed testing. View results

axicdv’s picture

Status: Needs work » Needs review
StatusFileSize
new13.69 KB
new212 bytes
new299 bytes

The last submitted patch, 30: 3015058-29.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 30: 3015058-29-dependencies.patch, failed testing. View results

jeqq’s picture

@axicdv Relaxed and Workspaces are two modules that implement totally different concepts, Relaxed provides an extension for the core REST API and Workspace makes possible to group content together (on workspaces). While Relaxed depends on Workspace, the second one should work independently of the first one (as it is now). Making Relaxed a dependence for Workspaces is not correct, it shouldn't be there neither as a test dependence.

jeqq’s picture

As I see from the patch, if you need to use the Relaxed events then your patch should go into Relaxed, not into Workspace. If you still need to fix aliases for internal replication too, then there should be implemented a fix in Workspaces without using Relaxed.

axicdv’s picture

StatusFileSize
new12.68 KB
new4.28 KB
axicdv’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 35: 3015058-35.patch, failed testing. View results

l0ke’s picture

Status: Needs work » Postponed
Issue tags: -Needs tests

#2971926: Better dispatch events needs to be commited first.

l0ke’s picture

Status: Postponed » Needs review
l0ke’s picture

Status: Needs review » Reviewed & tested by the community

I think all points were sorted out, the current case is covered with a new test and all tests are passing.

l0ke’s picture

  • jeqq committed 29754e8 on 8.x-1.x authored by axicdv
    Issue #3015058 by axicdv, l0ke: Entity aliases are created before...
jeqq’s picture

Status: Reviewed & tested by the community » Fixed

Thank you!

jeqq’s picture

  • jeqq committed 4ccfe61 on 8.x-1.x
    Revert "Issue #3015058 by axicdv, l0ke: Entity aliases are created...

  • jeqq committed f480781 on 8.x-1.x
    Revert "Revert "Issue #3015058 by axicdv, l0ke: Entity aliases are...
spheresh’s picture

StatusFileSize
new646 bytes
new12.68 KB
jeqq’s picture

@spheresh Why do you upload a patch that has been already committed and the issue fixed? First it won't apply and second the issue has been fixed, open a new issue if needed.

spheresh’s picture

@jeqq I just should apply this path to @beta18 version of the module. I know that life is much better when you are a maintainer, but I have to live in a world where you need to solve the composer.json requirements. Thank you for remarks, I'll create a new issue.

jeqq’s picture

@spheresh The purpose of my remark is for respecting the best practices and your perception about us living in different worlds is wrong.

I respect your work and at the same time I have to be responsible for what people post here. In your case, the change you added to that patch is totally non relevant to this issue and it should live in another patch, in another d.o issue. Even if it would be relevant - in that case is created a follow-up issue if the current one is already fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.