trackOnEntityUpdate on paragraph with multivalue reference field

Created on 31 May 2024, 7 months ago

Hi,

Problem/Motivation

When I remove an entity from an entity reference field, where I have multiple entities referenced, the removed entity doesn't trigger
the USAGE_REGISTER event.

My goal is to add/remove media from a SolR index depending of their usage in the current revision of a published node.
So, when the node is updated, I need to use the USAGE_REGISTER event.

Steps to reproduce

Add an entity reference field to a content type.
Create a node, and add some entities to that field.
When you remove one entity, when going in trackOnEntityUpdate, it calls trackOnEntityCreation and because the removed entity is not present anymore, the USAGE_REGISTER is not triggered.

Proposed resolution

in trackOnEntityUpdate
modify that test to check if field values are different between current entity and the original one?
If they are the same, go with trackOnEntityCreation, if not, continue with trackOnEntityUpdate.

 if (($source_entity instanceof RevisionableInterface) &&
        $source_entity->getRevisionId() != $source_entity->original->getRevisionId() &&
        $source_entity->hasField($field_name) &&
        !$source_entity->{$field_name}->isEmpty()
      )

I can try to work on this, but I need to be sure I don't miss something else.
Any idea?

Thanks.
Have a good day,

Seb

🐛 Bug report
Status

Active

Component

Code

Created by

🇫🇷France seb_r

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @seb_r
  • 🇩🇪Germany stefan.korn Jossgrund

    @Seb_R: I am on the same end and can confirm that removal of only one item in a multivalued field does not trigger USAGE_REGISTER event correctly.

  • 🇩🇪Germany stefan.korn Jossgrund

    testing a bit, it seems to me that just removing this return statement solves the issue.

          if (($source_entity instanceof RevisionableInterface) &&
            $source_entity->getRevisionId() != $source_entity->original->getRevisionId() &&
            $source_entity->hasField($field_name) &&
            !$source_entity->{$field_name}->isEmpty()) {
    
            $this->trackOnEntityCreation($source_entity);
            //return;
          }
    

    It seems not to introduce problems on first quick look. But really need to understand why this return statement was introduced.

  • 🇫🇷France seb_r

    Hi,

    I just ran a few tests, and removing the "return" here will make the event trigger 2 times on the items that are in the new revision.
    I don't have much time to dig in, so I guess I'll try with this for now, as the result is what I need.

    Have a good day,

    Seb

Production build 0.71.5 2024