Problem/Motivation
Steps to reproduce on Drupal 6.
1. Install and enable i18n on your Drupal 6 source site so that you have 2 languages. This example has English as primary and Finnish as secondary language.
2. Enable 'Multilingual support, with translation' to a node content type. This example uses the 'Story' content type.
3. Create an English node and add a comment to it. Let these be nid 1 and cid 1 in Drupal 6.
4. Translate the node from step 3 to Finnish and add a comment to the Finnish translation. Let these be nid 2 and cid 2 in Drupal 6.
5. Run the upgrade to Drupal 8.
In Drupal 8, things boil down...
7. Navigate to node/1 (English) and see that the English content (nid 1 in Drupal 6) and English comment (cid 1 in Drupal 6) are shown as expected.
8. Navigate to fi/node/1 and see that the Finnish node content (nid 2 in Drupal 6) is shown as expceted. However, the English comment (cid 1 in Drupal 6) is shown instead of the Finnish comment (cid 2 in Drupal 6).
9. Navigate to the English comment 1 directly at /comment/1 and see that the English comment (cid 1 in Drupal 6) is shown as expected.
10. Navigate to the Finnish comment 2 directly at /comment/2 or at /fi/comment/2 and notice how you will get an internal server error.
11. Navigate to the comment list at /admin/content/comment and notice how you will get an internal server error.
Root cause analysis and investigation on the database level.
12. The Drupal 6 database table 'comments' does not store the language of the comments. Each comment has a relation to the nid. The nodes have a language in the 'node' database table. D8 'comment' table has a language. All comments are having the site default (English) language after migration. The D8 comment language should be taken from the D6 node language during the migration.
13. D8 comment_entity_statistics has an entry for node/2 (Finnish node in Drupal 6) which does not exist in D8 because the Finnish D6 node was migrated as field level translation to node/1 in Drupal 8. This is not causing the internal server errors, though.
14. The internal server error is caused by an invalid reference in the comment_field_data database table. The Finnish node (nid 2) was migrated as field level translation to the English node (nid 1) in Drupal 8. The comment_field_data for the Finnish comment is pointing to nid 2 which does not exist in D8. If you manually fix this relation to point to nid 1 and clear caches, the internal server error is gone.
Proposed resolution
A. When migrating comments, set the language of the D8 comment based on the Drupal 6 node's language.
B. Ensure that comment_entity_statistics does not get a ghost entry for translated node/2 because it was 'merged' to node/1 as field level translation.
C. Ensure that the records in comment_field_data have correct references when there are comments to translated D6 nodes which are 'merged' to the original language node in D8.
D. Default language and language selector for the new comments posted on D8.
Migrations generate one comment type for each Drupal 6 content type (except Forum which uses the hard coded comment_forum). The D8 comment type has a default language for new comments. It also has an option for showing the language selector. These settings are not currently migrated sensibly for multilingual sites. However, this is an issue of it's own and will be handled in #2981393: Migrate D6 comment type language settings.
Steps to reproduce on Drupal 7
As for Drupal 6 but use the D7 core Content Translation. On D6 we used the contributed i18n family.
Remaining tasks
1. Review proposed resolution.
2. Patch
3. Test coverage
4. Review
5. Commit
6. Evaluate if the same thing happens in D7-D8 migration. Most probably yes.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | interdiff-2981392-30-33.txt | 4.2 KB | masipila |
| #33 | 2981392-33.patch | 23.83 KB | masipila |
| #30 | interdiff-2981392-28-30.txt | 2.01 KB | masipila |
| #30 | 2981392-30.patch | 23.01 KB | masipila |
| #28 | 2981392-28.patch | 22.4 KB | masipila |
Comments
Comment #2
masipila commentedComment #3
masipila commentedComment #4
masipila commentedComment #5
masipila commentedComment #6
masipila commentedDiscussed with @maxocub in Slack.
At first glance, we first need to migrate a langcode for the comments, and the d6_comment source plugin already join the node table so we can get it there.
Then for the step 14, if we look at d6_comment.yml migration, instead of entity_id: nid, we will need to get the new nid with a migration_lookup. I haven't tried to reproduce the problem yet, so I'm not 100% sure about this.
Comment #8
masipila commentedHere's a start. The patch does not have tests yet, I'm setting this to NR just to trigger the testbot in order to see if this breaks any existing tests.
Changes:
D7-D8 migration most probably has the same bug, I'll check that next.
Comment #9
masipila commentedI've heard rumors that the system works a bit better if I actually attach the patch to the post. Doh.
Comment #11
masipila commentedSeems that there are quite a few failing tests. Let's break some more by adding D7-D8 to the picture. The same bug is there, the only difference is that the D7 comments have language directly in the comments table so we can use that instead of taking the language of the node.
Setting to NR to trigger the testbot for the D7-D8 tests.
Comment #13
masipila commentedI analyzed the test failures a bit for the D6 comment migration. Currently we don't map the destination 'langcode' property at all in d6_comment. As a result, the migrated comments get the site default language ('en' if the D8 site was installed in English).
The patch #11 leaves the destination langcode property empty / null if the source node did not have a language specified. This will boil down in D8 and is not OK.
Option A: Should we map the destination 'langcode' property only if the source 'language' property has been set? This would be close to what the migration is currently doing i.e. the missing langcode mapping will the lead to site's default language code to be assumed.
Option B: Or should we set the destingation 'langcode' as 'und' if the source 'language' property has not been set?
Cheers,
Markus
Comment #14
masipila commentedActually I think the most elegant approach is to indicate the source site language as a fallback in the source plugin if the comment / node language is not set. I'll write a patch with this approach hopefully still today.
Comment #15
masipila commentedStill work in progress but submitting the next patch version.
This now has fixtures for both D6 and D7.
This also has the first attempt on the D6 tests. There is no test-only patch at this point of time as this is still work in progress.
The language determination logic was discussed today in the weekly meeting. This patch has the D6 language fallback logic in the source plugin. However, it was concluded that it might be more elegant to either try to use migration_lookup + default_language or to write a process plugin that reads the default language of the destination Drupal site. I'll continue on this + test failures (I'm sure there will still be) + D7 part tomorrow.
Comment #17
maxocub commentedI confirm that the
migration_lookupidea won't work. I looked at the mapping table of thedefault_languagemigration and the value you would get back would besystem.site(the destination config ID) which is not very useful in our case.Comment #18
masipila commentedHere's a new patch. It needed a re-roll due to the fact that the D7 fixture had changed. This changed quite much so there's no interdiff. There will most likely still be some real test failures but let's see what the testbot says.
There's only a test-only patch that should fail and show the bug that we are fixing here. As mentioned above, there's most probably some other test failures as well but core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php and core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php have been updated so they should definitely fail with the new test data in the fixtures.
I'm still trying to figure out a least painful workflow with the fixture changes so please bare with me...
Cheers,
Markus
p.s. Big thanks to @maxocub on coaching me with the fixtures!
edit: p.p.s This patch still has the language fallback logic in the source plugin. I want to see all tests green before I add more complexity by writing a new process plugin.
Comment #20
masipila commentedD6 fixture had changed so this needed a re-roll.
Comment #22
masipila commentedDoh. I somehow managed to have an extra whitespace in the patch #20 causing it not to apply. Here's a working re-roll.
Comment #24
masipila commentedHere's the next version which should hopefully fix most of the remaining test failures. I could use some help with the MigrateUpgrade7NoMultilingualTest test failure, time to go to bed now...
About the changes here:
This fixes the d6\MigrateForumTest failure where things are done to all comments regardless if they are forum comments or any other comments. Thanks @maxocub for your help with this one!
Cheers,
Markus
Comment #26
masipila commentedFixing entity counts for the UI tests.
Comment #28
masipila commentedPatch #26 did not apply anymore, let's start with a re-roll. Expecting to see the same test failures as previously so no need to do a review yet, I'm just triggering the testbot by setting this to NR.
Comment #30
masipila commentedAnother round with testbot. Unfortunately I'm not able to run the full migration tests on my dev environment so need to test them here :( Please bare with me...
Comment #32
maxocub commentedJust a quick review for the recent changes.
We should add a skip_on empty here too.
Maybe we could also test the language of the commented nodes, to make sure the comments are on the right language.
Same here.
Indentation of 'vid'.
This test is supposed to check what happen if we try to run multilingual migrations without Migrate Drupal Multilingual enabled. So, we should not enable it. I think the fact that we have failure here is because the migration shown on the UI change depending on the discovery order. This is something we should try to fix in another issue. For now, we should find which migration is displayed in the warning and change it. I'm currently running the test and I'll report back with the correct migration in a few minutes.
EDIT: Change
d7_node_entity_translation:articletod7_node_translation:article.Comment #33
masipila commented1. Fixed.
2. I don't think we can.
3. Same as above.
4. Fixed.
5. Fixed.
Let's see if I got any luck with the entity counts in the UI tests this time...
Markus
EDIT: typos
Comment #35
maxocub commentedUnrelated failure, back to Needs review.
Comment #36
maxocub commentedI tested the patch manually with both D6 & D7.
The problems mentioned in the IS no longer occur and the resolutions from the IS have been implemented.
Patch looks good, let's move this into RTBC land.
Comment #39
catchCommitted/pushed to 8.7.x and cherry-picked to 8.6.x. Thanks!