I create a separate issue based on reported feedback from JordanMagnuson here: https://www.drupal.org/node/2628854#comment-10796874

Here's the feedback itself:
I had a bunch of duplicate terms with the same exact names, that were present at aliases like term/my-term, term/my-term-0, term/my-term-1, etc. When I tried merging these terms (present in a very large vocabulary) using the "autocomplete" to find the term to merge into, I had a couple of issues:

1) When I seached for "my-term", only one of the "my-term" terms came up in the auto-complete.

2) when I tried to go ahead and merge, I got an error message saying that you can't merge into a term that has been selected, or is in the same trunk term... even though I checked the TID to make sure I had NOT selected this "my-term" term when selecting the terms to merge.

3) When I went to the "select from dropdown" option, I was able to complete the merge successfully... but still had the issue that only one of the "my-term" terms showed up in the dropdown. I wanted to merge all these terms into the original "my-term" term (the one with the lowest tid, the one that existed at term/my-term, rather than term/my-term-0, etc.) but the one that showed up was, randomly, something like term/my-term-8.

I'm guessing these issues come from the fact that I had these terms with identical names? (I'm not even sure how this happened, as I'm using a free-tagging taxonomy, which shouldn't allow duplicate terms like this, and haven't seen it happen before... some kind of glitch somewhere, evidently).

Comments

bucefal91 created an issue. See original summary.

bucefal91’s picture

The first 2 items are related to how autocomplete works right now. Basically when you work with an autocomplete widget all it has on hands is the term name and not its TID. So if a vocabulary have terms with identical names, then any term will be considered among those with the same name (the first one it comes across). So autocomplete behavior is unreliable for the case of terms with the same name.

Probably I should improve it, however, so it can handle this case of identical names. After all, this module is an useful tool for website admins to bring their vocabularies in order and we shouldn't fail the mission just because a vocabulary has terms with the same name.

As for the 3rd position: what you described is not expected. I checked the code and right now on my dummy Drupal installation tried it with the same outcome - you should have seen all terms. The only condition why the branch terms could have been incomplete is if they were children of the selected trunk term. For a matter of simple logic one cannot merge a term into its child because it would create inconsistency in the hierarchy. Could you double check this issue with select widget? If you still see problem, would you tell me your vocabulary terms and the hierarchy relationship between them? So I can debug it better.

rade’s picture

Status: Active » Needs review
StatusFileSize
new3.42 KB

We ran into the same issue where we needed to merge multiple terms with the exact same name and they didn't show up in the autocomplete.

Here is a patch to fix that.

rade’s picture

StatusFileSize
new3.42 KB

Ah, the patch had a small typo. Here is a fixed one.

The last submitted patch, 3: autocomplete_term_trunk-2660790-3.patch, failed testing.

The last submitted patch, 3: autocomplete_term_trunk-2660790-3.patch, failed testing.

The last submitted patch, 3: autocomplete_term_trunk-2660790-3.patch, failed testing.

The last submitted patch, 3: autocomplete_term_trunk-2660790-3.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: autocomplete_term_trunk-2660790-4.patch, failed testing.

The last submitted patch, 4: autocomplete_term_trunk-2660790-4.patch, failed testing.

The last submitted patch, 4: autocomplete_term_trunk-2660790-4.patch, failed testing.

The last submitted patch, 4: autocomplete_term_trunk-2660790-4.patch, failed testing.

rade’s picture

Adding also patch against release 7.x-1.3.

rade’s picture

Status: Needs work » Needs review
StatusFileSize
new3.96 KB
new452 bytes

New patch against dev, let's see if test pass this time.

Status: Needs review » Needs work

The last submitted patch, 14: autocomplete_term_trunk-2660790-14.patch, failed testing.

The last submitted patch, 14: autocomplete_term_trunk-2660790-14.patch, failed testing.

The last submitted patch, 14: autocomplete_term_trunk-2660790-14.patch, failed testing.

The last submitted patch, 14: autocomplete_term_trunk-2660790-14.patch, failed testing.

rade’s picture

Status: Needs work » Needs review
StatusFileSize
new4.87 KB
new956 bytes

Updated tests again.

Status: Needs review » Needs work

The last submitted patch, 19: autocomplete_term_trunk-2660790-19.patch, failed testing.

The last submitted patch, 19: autocomplete_term_trunk-2660790-19.patch, failed testing.

The last submitted patch, 19: autocomplete_term_trunk-2660790-19.patch, failed testing.

The last submitted patch, 19: autocomplete_term_trunk-2660790-19.patch, failed testing.

rade’s picture

Status: Needs work » Needs review
StatusFileSize
new5.41 KB
new563 bytes

Ooonce again

Status: Needs review » Needs work

The last submitted patch, 24: autocomplete_term_trunk-2660790-24.patch, failed testing.

The last submitted patch, 24: autocomplete_term_trunk-2660790-24.patch, failed testing.

The last submitted patch, 24: autocomplete_term_trunk-2660790-24.patch, failed testing.

The last submitted patch, 24: autocomplete_term_trunk-2660790-24.patch, failed testing.

rade’s picture

Status: Needs work » Needs review

The latest patch fails due to "Fatal error: Call to undefined function synonyms_behavior_settings_save() in /var/www/html/sites/all/modules/term_merge/term_merge.test on line 1282", which is unrelated to my changes. The cause of the error is that the Synonyms module has been updated and the synonyms_behavior_settings_save() function has been removed.

Changing back to "Needs review".

bucefal91’s picture

Hello, Rade!
Alright, let's get it done :) Seems like you were able to serve your own need, so there is no direct urgency. I would first settle down the integration with Synonyms and then review your patch (this way we can leverage existing SimpleTests when testing your patch). I am the maintainer of Synonyms module, so it will be quick.

I got the issue for Synonyms integration here #2728743: Synonyms 7.x-1.5 integration. In a matter of few hours it will have a patch.

bucefal91’s picture

StatusFileSize
new4.75 KB
new6.5 KB

I've committed the synonyms integration, so we can resolve this one now. Your patch looks really good, I wish all the patches were like this one :) I only have a handful of questions/proposals:

  • Why did you include HTML stripping and space manipulation into the autocomplete callback? I am rather geared towards minimal filtering (just enough to close XSS holes).
  • I would make your regex a bit stricter: I would match \((\d+\)$ (with the $ at the end to make sure we do not catch things like "My first (1) term", for example).
  • Your patch assumes if regex failed, then the autocomplete text field contains tid. This is incorrect assumption. The textfield will contain term name (the user is much likelier to enter term name than its tid).
  • I also found some debugging code from my synonyms issue (cleaning that up)
  • Lastly, in the simpletests I would test both cases: term names and $term->name ($term->tid).

All of the items above are included in the patch I enclose to this comment. What would you say?

  • bucefal91 committed b6f44d5 on 7.x-1.x
    Issue #2660790 by Rade, bucefal91: autocomplete term trunk widget.
    
bucefal91’s picture

Status: Needs review » Fixed

I've committed my patch (#31) since there was no feedback in the last few days.

Status: Fixed » Closed (fixed)

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