As Entity reference is highly popular module and is moving to core in D8, it would make sense supporting it. It is currently possible to add this compatibility in custom module, but it is not efficient, because custom module would contain basically copy of original module code (around 60 lines) and would need update if api changes.

Goal would be to add Entity reference support without changes in current implementation, just by making Term Merge little bit more module agnostic.

Comments

henrijs.seso’s picture

Title: Entity reference support for Term Merge module » Entity reference support
StatusFileSize
new3.26 KB

And here is patch.

  1. Does not brake current installations.
  2. Does not include Entity reference specific code.

Since I wished this patch to be clean and universal, Entity reference module needs patching.

  1. Apply patch to Entity reference found here (http://drupal.org/node/1340748#comment-5806046)
  2. Resave all entityreference fields (click on edit, then on save without changing stuff)

There is core bug #1416506: Field schema foreign keys support is broken that will be ported to D7. Entity reference will then be able to fix it's foreign keys issue. Meanwhile follow this issue #1969018: Field schema foreign keys is always hard-coded to 'node' despite target type not set to node entity type for further development.

henrijs.seso’s picture

Title: Entity reference support » Entity reference support for Term Merge module
Status: Active » Needs review

Changing title to more descriptive for linking in other queues.

bucefal91’s picture

Title: Entity reference support » Entity reference support for Term Merge module

Hello!

It is not difficult to notice you did a deep research on how to integrate Entity reference in the best way. I see the core issue is fixed. Do we still need to wait for the issue #1969018: Field schema foreign keys is always hard-coded to 'node' despite target type not set to node entity type to be fixed? Or your patch now can be applied to Term Merge module and it will be working without any extra patches?

Thank you very much for contributing back into the module. It is really touching when a module administrator sees that people are willing to make a module better.

n3uronick’s picture

Issue summary: View changes
StatusFileSize
new629 bytes

This patch works for me but it generates a lot of notices in watchdog for the fields which do not have foreign keys. Here is a small interdiff to fix this.

n3uronick’s picture

StatusFileSize
new3.35 KB
mrdalesmith’s picture

I'm not getting any joy from this patch - does it need re-upping for the current dev version? Because after applying the other patches required here and following the instructions, line 313 on term_merge has $fields = field_info_field_map();, which never returns the $v['foreign keys'] required by the code, and the results variable seems to be using a $k variable that doesn't exist.

bucefal91’s picture

Hello

Those patches are over a year ago, apparently the code has moved forward since then. There hasn't been much demand for this feature, so I didn't concentrate my effort on coding this functionality.

But if folks speak up and ask for this feature, I'll be happy to implement it (be it just adjusting those patches or writing it up from scratch).

mrdalesmith’s picture

Entity reference is a core module in D8, so I think more and more D7 sites are going to be utilising it to keep their upgrade path clean. I think it'd make ter merge much more useful if it updated taxonomy terms wherever they were used, so my vote is for updating and including.

MathieuMa’s picture

Version: 7.x-1.x-dev » 7.x-1.2
StatusFileSize
new3.25 KB

Here is an updated patch for the latest stable version.

mrdalesmith’s picture

Have applied the updated patch without problems, and seen the expected results.

vildoc’s picture

some errors in watchdog key() expects parameter 1 to be array, null given in term_merge_action()
And node doesn't get new term.

Leeteq’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
dasginganinja’s picture

Does this patch still require each node with the entity references to be saved? If so, we have something along the order of 1000 nodes that use these term references and need to have their terms merged. Touching each node and saving would take a large amount of time and resources. Is there any way to automate the saving with VBO / Drush or a similar fashion?

Are the instructions at this point?

  1. Patch Entity Reference 7.x-1.1 per comment #1)
  2. Patch Term Merge 7.x-1.2 per #9's patch

Thanks in advance!

andriuzss’s picture

StatusFileSize
new3.5 KB

I still getting empty 'foreign keys'
This will do a trick.

Leeteq’s picture

mrdalesmith’s picture

Have noticed intermittent failure to merge terms. Patch in #14 seems to have fixed: I may have been premature in saying the previous one worked.

jennypanighetti’s picture

I applied patch #14 and it broke my Term Merging. Now when I try to merge a term, it stops at "Initializing" and times out.

I increased the max_execution_time to 3 minutes, and now it just stays at "Initializing" and does nothing.

henrijs.seso’s picture

@MrDaleSmith, @jenstechs Did you patch Entityreference? See #1.

mrdalesmith’s picture

@mansspams The core bug is now fixed: there's no need for the patch: re-saving the entity reference fields updates the information to be correct.

jennypanighetti’s picture

But we shouldn't be expected to re-save 8,000+ nodes for this module to work.

I ended up writing my own script - search for nodes, update reference field taxonomy ID, save node - and ran it via drush scr. No problems there.

bucefal91’s picture

StatusFileSize
new4.65 KB

Hello!

Thanks for putting up the patches above in the issue. I have slightly taken it further from the last patch. In this patch it should not only work for entityreference fields, but pretty much for any field that correctly defines its "foreign keys" property. I've also fixed comments here and there.

Please, try it out. I was able to successfully merge both taxonomy_term_reference and entityreference fields with this patch. If everybody likes it, then I'll add simpletests to cover entityreference integration and and then I'll commit it into the module.

devad’s picture

Status: Needs review » Reviewed & tested by the community

I have tested it.

I have tryed to trick it various ways to cause misfunction - with no success.

I have also tested this patch with Synonyms module enabled since Term Merge and Synonyms work closely together.

The conclusion is: It works!

I think it's ok to declare this patch "tested by community".

bucefal91’s picture

Status: Reviewed & tested by the community » Needs work

Awesome news! And devad, I am in debt for your support. Thank you for being willing to test all of these issues. I know it takes time and I am sure you have many other things to do in your free time.

The issue will require to code simpletests (automated unit tests) that cover this new feature, before we can merge it; so I mark it as 'needs work'.

  • bucefal91 committed 56316a9 on 7.x-1.x
    Issue #1981262 by n3uronick, mansspams, MathieuMa, andriuzss, bucefal91...
  • bucefal91 committed eed925e on 7.x-1.x
    Issue #1981262 by bucefal91: Adding simpletests to cover the support of...
bucefal91’s picture

Status: Needs work » Fixed

I've added the simpletests for the existing patch and then committed into the repository. Hooray! We finally got the entityreference support :)

Thank you to everybody for collaboration and making it happen :)

Status: Fixed » Closed (fixed)

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