Problem/Motivation

CCK field options are translated using i18n_cck submodule of the suite i18n, we need to migrate those respecting the language.

Use the d6 version as a guide #2961114: Migrate D6 i18n CCK field option translations

Proposed resolution

Additionally we should add an orderBy to the query in the source plugin because the test asserts the results in a specific order, and test it on PostgreSQL.

Patch
Review
Commit

Remaining tasks

- Write a test
- Write a patch to migrate field labels and options.
- Write a patch that combines #21 and #25

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quietone created an issue. See original summary.

quietone’s picture

Status: Postponed » Active

No longer postponed!

quietone’s picture

Issue tags: +Migrate critical

Seems to me this should be migrate critical like the other i18n issues.

quietone’s picture

Title: Migrate D7 i18n CCK field option translations » Migrate D7 i18n field option translations

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

Assigned: Unassigned » quietone

Should be able to make a patch by the end of the week.

quietone’s picture

Issue summary: View changes
Status: Active » Postponed
quietone’s picture

Assigned: quietone » Unassigned
quietone’s picture

Issue summary: View changes
Status: Postponed » Active
quietone’s picture

Status: Active » Needs review
FileSize
31.83 KB

And finally a patch.

Status: Needs review » Needs work

The last submitted patch, 10: 3008029-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Status: Needs work » Needs review
FileSize
1.53 KB
31.37 KB

Remove code for an earlier version of the test fixture and fix a coding standard error.

quietone’s picture

Status: Needs review » Needs work

The next thing I want to do is review the migration yml files, which were a quick copy/paste. I reckon they can be trimmed down.

quietone’s picture

Status: Needs work » Needs review
FileSize
6.94 KB
30.67 KB

Reworked the source plugin query and also trimmed out unnecessary items from the process pipeline.

Status: Needs review » Needs work

The last submitted patch, 14: 3008029-14.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
4.13 KB
30.57 KB

Fix tests and remove debug coe.

Gábor Hojtsy’s picture

Thanks for working on this. Only found a few things:

  1. +++ b/core/modules/config_translation/migrations/d7_field_instance_option_translation.yml
    @@ -0,0 +1,59 @@
    +#class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
    +#field_plugin_method: alterFieldInstanceMigration
    

    Why did you keep these here?

  2. +++ b/core/modules/config_translation/migrations/d7_field_instance_option_translation.yml
    @@ -0,0 +1,59 @@
    +      index: [1]
    ...
    +      index: [0]
    
    +++ b/core/modules/config_translation/migrations/d7_field_option_translation.yml
    @@ -0,0 +1,47 @@
    +      index: [1]
    ...
    +      index: [0]
    

    Is number indexing results the best approach? Are there precedents elsewhere? Should we name them instead?

  3. +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstanceOptionTranslation.php
    @@ -0,0 +1,25 @@
    +  public function fields() {
    +    $fields = [
    +      'type_name' => $this->t('Type (article, page, ....)'),
    +    ];
    +    return parent::fields() + $fields;
    +  }
    

    Where does the type_name value actually come from? I am not seeing it in the query.

quietone’s picture

1. Because I didn't review my work.
2. The precedence is d6_field_instance_option_translation. If we were going to change that I would want to search for other instances of the same pattern and change them all at once. It would increase readability but I think only marginally.
3. Good point. Reason is the same as 1. That source plugin is not needed.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me now. Thanks for the quick update!

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldOptionTranslation.php
@@ -0,0 +1,79 @@
+    $query->addField('i18n', 'lid', 'i18n_lid');
+    $query->addField('i18n', 'textgroup');
+    $query->addField('i18n', 'context');
+    $query->addField('i18n', 'objectid');
+    $query->addField('i18n', 'type', 'i18n_type');
+    $query->addField('i18n', 'property');
+    $query->addField('i18n', 'objectindex');
+    $query->addField('i18n', 'format');

I think you can use $query->fields('i18n') here as a shortcut for 'add all the fields form this table'

Same for the 'lt' alias

Other than that, this is over my head 🤔

quietone’s picture

@larowlan, thanks. Yes, that is messy.

Here is a tidier version. I changed the isNotNull('translation') to isNotNull('language') to be consistent with the intention of #3030937: Ensure language is not Null in translation source queries even though the decision over there (comments 16, 17) is to use an inner join. I didn't use the inner join because, frankly, I don't see how to make that work and there is precedence for using the isNotNull approach.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. #3030937: Ensure language is not Null in translation source queries could either be solved by not null checks or inner join, where inner joins could be made to work. I am fine with either. The rest of the patch I already reviewed before, still looks complete and good.

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed b4192ba and pushed to 8.8.x. Thanks!

  • larowlan committed b4192ba on 8.8.x
    Issue #3008029 by quietone, Gábor Hojtsy: Migrate D7 i18n field option...
mradcliffe’s picture

This broke core branch tests in PostgreSQL: https://www.drupal.org/pift-ci-job/1373837

This is usually because of an assertion on the order of items when the order of items wasn't guaranteed in a query. If the order is not guaranteed, then there is no way to assert that the results will be selected in a certain order.

I think this is in an issue in the source plugin, but I can't tell for sure. I'll upload a patch here to see if my hypothesis is correct about the source plugin.

mradcliffe’s picture

Status: Fixed » Needs review

Okay, that looks pretty good. I'm going to re-open as Needs review to confirm the order by column is the correct lid to use.

mikelutz’s picture

Status: Needs review » Reviewed & tested by the community

The fix looks correct, indeterminate sort orders are a common source of issues with postgres (and differences between php versions too.) I'll RTBC the follow up patch for now, and leave it to the committers whether they want to just commit the follow up or revert. If they want to revert we can roll a combined patch to commit later.

  • xjm committed 807afc1 on 8.8.x
    Revert "Issue #3008029 by quietone, Gábor Hojtsy: Migrate D7 i18n field...
xjm’s picture

Status: Reviewed & tested by the community » Needs work

Oops! Thanks for catching the postgres regression. I'm going to go ahead and revert this since HEAD is broken (and has been for days, oops -- I missed adding my email notifications for the branch).

After the revert we can combine #25 with the original fix to ensure this works with postgres.

We also should always run any Migrate patch against all three databases prior to commit. :)

Thanks!

xjm’s picture

Also crediting @mikelutz for the review of the fix.

wilsonsp’s picture

Hi, I will try to combine the origin patch #21 with patch #25

mradcliffe’s picture

Issue summary: View changes
Issue tags: +mwds2019

What we will do is to download both the patches, apply them, and create a new patch. Then we should create an interdiff between the patch in #21 and this new patch, which should confirm that we are only introducing the changes in comment #25.

Edit: this was already outlined by @xjm above in #29 and I missed it. I'm sorry.

I adjusted the issue summary to describe the remaining work and new resolution.

wilsonsp’s picture

Combined patch #21 and #25, created a new patch and interdiff.

wilsonsp’s picture

Issue summary: View changes
Issue tags: +PostgreSQL

Add PostgreSQL to the issue tag

mikelutz’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -PostgreSQL

Fix looks good, RTBC contingent on the last postgres test coming back green.

No need to tag postgreSQL on the issue, it's not really a postgreSQL related issue at all, we just happened to have to make a small adjustment to make sure the tests pass on postgre

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed ae23684 and pushed to 8.8.x. Thanks!

  • larowlan committed ae23684 on 8.8.x
    Issue #3008029 by quietone, wilsonsp, mradcliffe, Gábor Hojtsy, xjm,...

Status: Fixed » Closed (fixed)

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

xjm’s picture

Issue tags: +8.8.0 highlights

I don't actually know what field option translations are, but presumably it's a multilingual migrate improvement we might want to list along with the rest. Tagging accordingly. :)