Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
My configs:
PHP 5.6
Soure:
- Drupal 7.58
- Category with hierarchy (max depth =3)
Destination:
- Drupal 8.52
- Migrate_plus
- Migrate_tools
When i migrate Taxonomy Term (has parent), parent and parent_id always return array(0=>null). I looked at core/modules/taxonomy/migrations/d7_taxonomy_term.yml and found plugin: migration_lookup and migration: d7_taxonomy_term alway return NULL although plugin Get return valid value.
parent_id:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration_lookup
migration: d7_taxonomy_term
parent:
plugin: default_value
default_value: 0
source: '@parent_id'
Please try to change the code:
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- a/core/modules/migrate/src/MigrateExecutable.php
+++ b/core/modules/migrate/src/MigrateExecutable.php
@@ -363,8 +363,18 @@
$break = FALSE;
foreach ($value as $scalar_value) {
try {
- $new_value[] = $plugin->transform($scalar_value, $this, $row, $destination);
+// $new_value[] = $plugin->transform($scalar_value, $this, $row, $destination);
+ // reserve salar value
+ $result = $plugin->transform($scalar_value, $this, $row, $destination);
+ // fix parent_id always return null on MigrationLookup::transform
+ if (is_null($result)) {
+ if ($scalar_value) {
+ $new_value[] = $scalar_value;
}
+ } else {
+ $new_value[] = $result;
+ }
+ }
catch (MigrateSkipProcessException $e) {
$new_value[] = NULL;
$break = TRUE;
Comment | File | Size | Author |
---|---|---|---|
#10 | 2965938-10.patch | 12.9 KB | maxocub |
Comments
Comment #2
trong.nguyen.tcec CreditAttribution: trong.nguyen.tcec commentedComment #3
trong.nguyen.tcec CreditAttribution: trong.nguyen.tcec commentedComment #4
AlanHDev CreditAttribution: AlanHDev at Investis Digital commentedWe are migrating nested taxonomies with a max depth of 3 levels from a 7.59 source to an 8.5.3 destination and have just experienced this issue too.
I have re-rolled the patch to observe coding standards and this does appear to address the issue. I'll mark this as needs further work as I am unsure whether the solution may have a detrimental effect on other migrations.
Comment #5
AlanHDev CreditAttribution: AlanHDev at Investis Digital commentedComment #6
heddnThis seems like a duplicate of other already open issues. Can we review https://www.drupal.org/project/issues/drupal?text=migration_lookup&statu... and see if that is true?
Comment #8
heddnTest needs to create a child term before the parent is created. Terms require parent, vid, name as inputs. Will need to be at least a Kernel test.
Comment #9
maxocub CreditAttribution: maxocub commentedWorking on the test.
Comment #10
maxocub CreditAttribution: maxocub commentedFirst of all, we should not modify MigrateExecutable to fix this.
I think I found the source of the problem and it's a mix of migration_lookup process plugin and migrate_plus.
Since d7_taxonomy_term is a derived migration, migrate_plus generate one migration per vocabulary, for example:
But when you look at those generated migrations, the migration in the migration_lookup process plugin is not the derived one, so it doesn't exists:
If you change it to
upgrade_d7_taxonomy_term_tags
, then it works.Also to be noted, upgrading from th UI works, it's only when using migrate_plus that the hierarchy is lost.
I'll try to see if the fix should be in migrate_plus or in migration_lookup.
In the meanwhile, here's a test that shows that the parent IDs are migrated, even if the childs are created first (that is with a lower tid than their parent).
Comment #11
maxocub CreditAttribution: maxocub commentedThanks to @mikelutz help on Slack, we discovered that this problem is already fixed by this issue: #2976379: Expand all derived migrations in migration_lookup from the migrate_upgrade module.
I did test it manually with the patch from that issue and it fixes this term hierarchy lost. (I was also able to reproduce the bug before applying the patch)
I'm closing this issue as outdated and I'll ask you to try again with either the patch from that issue or the latest dev branch from migrate_upgrade. You'll have to re-run --configure-only or manually update your migrations to expand the derivatives.