Problem/Motivation

There's no code in the module related to language. I'm fairly certain that this means that, especially when using the queue, it might or might not grab the expected language version of the entity. If it grabs the wrong version there will be data loss.

Steps to reproduce

Proposed resolution

Include the language in the queue record. Load that language.

Remaining tasks

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dalin created an issue. See original summary.

rajiv.singh’s picture

StatusFileSize
new2.59 KB

Steps to produce issue before enabling the module.
1. Install devel module.
2. Translate a node (having entity/term reference field) in few available languages in the site.
- suppose node is 100.
3. Select a taxonomy term ( suppose tid is 1111)
4. Save and publish the node.
5. Do the same for its translations( Select the term, publish and save)
6. Go to pages /[Language-code]/devel/node/100 (Example - /en/devel/node/100)
7. On the devel page expand the accordion reading as VARIABLE
8. Browser search (CTRL+F) the term id 1111.
9. Now go to the term edit page /en/taxonomy/term/17341/edit and click on the delete link to delete it.
10. Repeat step 6 to 8.
11. The term id is still showing up in the variables.

Enable the module Entity Reference Purger , Check the box Remove orphaned entity references under ENTITY REFERENCE PURGER at field configuration page /en/admin/structure/types/manage/[CONTENT-TYPE]/fields/[FIELD_MACHINE_NAME]
- Repeat above steps after enabling the module , configuring field and deleting the term .
Result: The translations are still having the term reference in the database.

Solution:

Apply the patch , clear cache and verify the same with above steps.

rajiv.singh’s picture

StatusFileSize
new2.59 KB
rajiv.singh’s picture

StatusFileSize
new2.59 KB

Bug fixes in previous patch

rajiv.singh’s picture

StatusFileSize
new2.56 KB

Code cleaned up of previous patch

balagan’s picture

Status: Active » Needs review
kriboogh’s picture

The patch provided doesn't take into account that a reference field can be translated and parent entity translations can have a different set of terms:

Node A (nid=100, langcode=FR, field_tid.delta[0]=200)
Node A (nid=100, langcode=EN, field_tid.delta[0]=300, field_tid.delta[1]=200)
(A node translation, can have it's field_tid set as translatable, so it can contain a different set of terms)

I saw the latest code of the module deals with this in some way already.

kriboogh’s picture

Status: Needs review » Needs work
kriboogh’s picture

Created a MR. I implemented what #2 did, taking translations into account. Took the liberty of also refactoring the code into a service based setup where there is a EntityReferencePurger service that does the actual work, so module and queue processor don't duplicate code. Also provided a Hooks class.

kriboogh’s picture

Status: Needs work » Needs review
kriboogh’s picture

StatusFileSize
new48.24 KB

If you need to combine this with #3260777 use this patch (it combines 3348322-MR6 and 3260777-MR7)