Problem/Motivation

The d7_taxonomy_term_translation migration plugin skips every row where i18n_mode is 1, 0, or is empty.
If the TermTranslation migrate source plugin excluded these rows, we would get back the appropriate source record number – and that would increase DX a lot imho.

Proposed resolution

Improve source query to only get that should be migrated, where i18n_mode is not 0 or 1.
Add source plugin test source/d7/TermTranslationTest.php

Remaining tasks

Review
Commit

User interface changes

N/A

API changes

Data model changes

N/A

Release notes snippet

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Active » Needs review
StatusFileSize
new955 bytes
quietone’s picture

StatusFileSize
new1.72 KB

Then shall we remove the skip from the migration?

No interdiff because the change is small as is the whole patch.

wim leers’s picture

Status: Needs review » Needs work

This looks like a great simplification and hardening at the same time! 🥳

But as a relative outsider, both hunks (the one added by @huzooka and @quietone) are impossible to understand 🙈😅

+++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermTranslation.php
@@ -22,9 +22,16 @@ public function query() {
+    // If there is no 'i18n_mode' column, or it is equal to "0" or "1", then
+    // there is nothing to migrate.

Let's document why 0 or 1.

Refer to the constants at https://git.drupalcode.org/project/i18n/-/blob/7.x-1.x/i18n.module#L15.

@quietone's comment at #3035392-24: Migrate vocabulary translations and taxonomy term references for Drupal 7 node translations also talks about this.

wim leers’s picture

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB
new1.81 KB

Updated comment as per #5.

wim leers’s picture

Status: Needs review » Needs work

Thank you!

Wanted to RTBC this, but channeling @alexpott, I think we need to add test coverage for this in \Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d7\TermEntityTranslationTest 😅

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new8.63 KB
new10.65 KB

And you are doing a good job of channeling him!

Turns out there wasn't an existing test for this source plugin, so I added it. I don't know how that happened and I haven't researched it (and don't plan too). The test file you referenced, TermEntityTranslationTest, is for the TermEntityTranslation migration.

wim leers’s picture

Woah, thanks for the super fast turnaround! I think @huzooka is better positioned to review this than I am 🤓

quietone’s picture

Title: Improve source record count of TermTranslation migrate source plugin » Fix TermTranslation query and add missing source plugin test
Category: Feature request » Bug report
Issue summary: View changes
Priority: Minor » Normal

Changing to a bug. The query is incorrect and the test is missing.

quietone’s picture

Issue tags: +Bug Smash Initiative

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Retesting with 9.3.x.

quietone’s picture

Issue tags: +Drupal South

Tagging for Drupal South. This is for someone who has worked with migrations.

Wim Leers already thinks this can be RTBC but recommends another set of eyes on the work.

quietone’s picture

Issue tags: -Drupal South +DrupalSouth

Fixing the tag.

danflanagan8’s picture

Status: Needs review » Needs work

Now that it's classified as a bug, we need to show that the new test fails without the fix. I ran the new test locally without the other changes and got a wonderful failure: Failed asserting that actual size 7 matches expected size 4. That's exactly what the issue is about, so that's good news.

I have a question about this though.

+++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermTranslation.php
@@ -25,9 +25,16 @@ class TermTranslation extends Term {
+    else {
+      $query->condition('td.tid', '0');
+    }

I just want to confirm that I understand this condition. If the 'i18n_mode' field does not exist, then we're not translating terms. Therefore we want the query to return zero rows. To do that, we put on a condition that will never be met, since there will never be a term with a tid of zero.

Is that right? Could there maybe be a comment added to clarify that?

Or better yet, if I'm understanding the purpose of that condition, it looks like we could use ConditionInterface::alwaysFalse() instead. But I may be misunderstanding things!

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new2.11 KB
new10.99 KB
new2.11 KB
new10.99 KB

@danflanagan8, thank you for the review.

Yes, you are understanding the query correctly. I have changed to using alwaysFalse, which I think is much clearer. I have also added an sentence to the comment at the start of the if block to help explain what is happening. And I have added a test for the situation where there is not an i18n_node column in the taxonomy_vocabulary table.

danflanagan8’s picture

Status: Needs review » Reviewed & tested by the community

@quietone, I like the new test case! And thanks for making to other changes to make things clearer.

wim leers’s picture

Woah, very nice indeed, @quietone!

alexpott’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 4bc7dbb8f9 to 9.3.x and 88bb7758ba to 9.2.x. Thanks!

  • alexpott committed 4bc7dbb on 9.3.x
    Issue #3187616 by quietone, huzooka, Wim Leers, danflanagan8: Fix...

  • alexpott committed 88bb775 on 9.2.x
    Issue #3187616 by quietone, huzooka, Wim Leers, danflanagan8: Fix...

Status: Fixed » Closed (fixed)

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