Problem/Motivation

#2744639: Taxonomy term hierarchy migration incomplete corrected a bug where the taxonomy_term_hierarchy was not populated on migration for terms with no parent. The fix prevented the problem from occuring on future migrations, but did not fix the missing taxonomy_term_hierarchy data for previous migration runs.

Proposed resolution

Implement an update function to fix the taxonomy_term_hierarchy table.

Remaining tasks

Review. Questions:

  1. Should the update function go in taxonomy.install instead of migrate.install?
  2. Should this fix be postponed on #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration? Without that fix, it must do direct database access.

User interface changes

None.

API changes

None.

Data model changes

None.

Original report by @Benia

If I choose either "Selection box" or "Radio buttons" for taxonomy fields, I can't choose terms. The field will just show to output -None- and that's it. Autocomplete on the other hand, works just fine.

Further information

  1. It happens both on local (Ubuntu) && prod (CentOS).
  2. It happens when no contrib or custom modules are installed (core-only work).
  3. It happens for all content types, whether created before migration to D8 or after it.
  4. Each taxonomy field is already associated with a taxonomy vocabulary (autocomplete pulling works just fine and I can save the node with the terms pulled with autocomplete --- Without any problems or errors).
  5. No related errors in drush ws-full.
  6. Not a single problem appearing in status report.
  7. No special problems with the site whatsoever (surly not in all-core mode).

JS console check

These are the 3 JS errors appearing in console when I'm inside the back-end node-edit form:

> Use of getAttributeNode() is deprecated. Use getAttribute() instead. js__79M6UrZjAw3oNGnUjsWip12JsvnUZmJGA3h9LI0kuzE__LqE6uSZqCOZhJYW910TDw_HTQzBKUPTZxunfaWkalq8__lN6fPa32KCPrfa2DFR_PrioIXIdhNdWLxQDcTXnjQaA.js:55:488
> This site appears to use a scroll-linked positioning effect. This may not work well with asynchronous panning; see https://developer.mozilla.org/docs/Mozilla/Performance/ScrollLinkedEffects for further details and to join the discussion on related tools and features! drupal
> fbcdn-profile-a.akamaihd.net : server does not support RFC 5746, see CVE-2009-3555

How to reproduce:

I can't say exactly how to reproduce it as it happened since as I can remember after my migration.

If I remember correctly I first migrated from Drupal 7.44 to Drupal 8.1.3 (I now use 8.1.8). That's all there is to it, since then the problem started.

The migrate was basically core-based with this Metatag patch to include metatag data in the upgrade. Yet, as mentioned, even when the Metatag module is removed (even with flush all caches and after cron run), the problem persist.

In comment 17 I reported a milestone that might give you more data on what went wrong.

Comments

Benia created an issue. See original summary.

Benia’s picture

Issue summary: View changes
Benia’s picture

Issue summary: View changes
Benia’s picture

Title: S.boxes or R.buttons show no tax terms (autocomplete works fine) » S.boxes or R.buttons show no taxonomy terms (autocomplete works fine)
Benia’s picture

StatusFileSize
new57.9 KB
cilefen’s picture

Title: S.boxes or R.buttons show no taxonomy terms (autocomplete works fine) » Selection boxes and radio buttons show no taxonomy terms (autocomplete works fine)
cilefen’s picture

@Benia, please add the steps to reproduce this to the issue summary.

Benia’s picture

Issue summary: View changes
Benia’s picture

Issue summary: View changes
Benia’s picture

Issue summary: View changes
Benia’s picture

Issue summary: View changes
Benia’s picture

Issue summary: View changes
swentel’s picture

It sounds that this is rather a migrate problem than a fields problem no ?

Benia’s picture

Might be. Will you suggest changing component to Migration system?

Benia’s picture

Issue summary: View changes
Benia’s picture

I've installed Devel and had an intro about it... I believe I could extract any data you might need. Please detail as much as you can so I will find it efficiently.

Benia’s picture

Milestone:

If I go to the taxonomy vocabulary page of every vocabulary whatsoever, and Just hit "Save" --- All of the terms in the vocabulary are deleted.

Conclusions:

This is not a problem in the backend form | This is not a problem in the JS | This is not a problem on the Drupal core.

The problem is migration related (as mentioned it exists since I migrated about 2 months ago).

If you need any data from any SQL table, please tell me and I will gladly try to extract it.

Benia’s picture

StatusFileSize
new71 KB

I mean to this page.

cilefen’s picture

@Benia: Regarding this:

If I go to the taxonomy vocabulary page of every vocabulary whatsoever, and Just hit "Save" --- All of the terms in the vocabulary are deleted.

Is this yet another issue? This would be critical priority.

Benia’s picture

Priority: Major » Critical

I would say it's not another issue as I'm sure from all my checks and tests it's related to the problem reported above if not the root cause of it.

cilefen’s picture

@Benia: This issue needs a new title and a summary update, with a focus on the most serious aspect, because it will be difficult for people to understand. Have you seen the template and "How to create a good issue"? They help.

The component should be "taxonomy.module".

catch’s picture

Title: Selection boxes and radio buttons show no taxonomy terms (autocomplete works fine) » Selection boxes and radio buttons show no taxonomy terms (autocomplete works fine) after migration
Component: field system » taxonomy.module
Issue tags: +Migrate critical

@Benia with an issue like this, it's most likely to be diagnosed if you're able to provide a copy of the Drupal 6 database and/or the migrated Drupal 8 database. Obviously would need to remove any sensitive information.

Moving to taxonomy module and tagging for migrate for now.

cilefen’s picture

Title: Selection boxes and radio buttons show no taxonomy terms (autocomplete works fine) after migration » All terms in a vocabulary are deleted on save
Issue summary: View changes
cilefen’s picture

Component: taxonomy.module » field system
Issue summary: View changes
cilefen’s picture

Component: field system » taxonomy.module
Issue tags: +Needs steps to reproduce
Benia’s picture

Sadly I can't supply reproducing steps as this is a bug from migration...

What I would most need is instruction --- Where to go in the SQL and what to check there so to paste here.

If someone wants to help this way, I will most appreciate.

Benia’s picture

Dear programmers, please make sure to read comment #17 where I reported a milestone.

Benia’s picture

Component: taxonomy.module » migration system
catch’s picture

@benia see #22 - a copy of the pre- and/or post-migration databases would be most useful here. mysqldump would be best.

Benia’s picture

Can I share a partial mysqldump, if so, can you please tell me exact tables are needed from the post-migration site?

BTW, Is it possible its the PDO ?

Benia’s picture

Issue summary: View changes
quietone’s picture

If I go to the taxonomy vocabulary page of every vocabulary whatsoever, and Just hit "Save" --- All of the terms in the vocabulary are deleted.

It isn't clear to me if the D8 taxonomy tables have been checked to see if the data is there. Or, what is missing.

Benia’s picture

Of course, there is data in these tables but it is being saved in a "corrupted" way (corrupted? That's the right word in programming isn't it?).

quietone’s picture

Of course, there is data in these tables

The issue summary says the data is deleted. I want to be sure I understand that point. So, to summarize, if you look in say, taxonomy_term_field_data you see the vocabulary and terms that no longer display since pressing save on a taxonomy vocabulary page. That it, the data is there but not displaying.

The MetaTag patch touches the taxonomy. Perhaps it incorrectly migrated something? Is it possible to rerun the migration with out the MetaTag patch? And then see if the problem persists? Just a thought.

Benia’s picture

Milestone:

I have now noticed that when I click "Save" for a single vocabluary, not only that all its terms seemingly deleted but actually all terms ---> In all other vocabularies, are also seemingly deleted.

I am not making this up. If I go to structure > Taxonomy, and there chose any given vocabualry and click "Save" it will suddenly appear as all other terms, of all vocabularies, have been deleted.

Table check:

if you look in say, taxonomy_term_field_data you see the vocabulary and terms that no longer display since pressing save on a taxonomy vocabulary page. That it, the data is there but not displaying.

I see all terms 30 terms/entries in that table (I have about three hundred and fifty nodes in the site and say 99% of these include at least one of these 30 terms). So, if they appear there, why Drupal no longer recognizes them after hitting save and present all term lists as empty ?

The problem here seems more and more about the SQL syntax in which they are stored after hitting"Save" ---> Drupal seem not to recognize it... Can you please give me an SQL query to try to run to "reset" the why in wihch these terms are saved there so Drupal might be able to recognize them?

About Metatag, its possible but I think I don't have any copy of the pre upgrade site and in any case I've already made many content changes inside nodes.

Benia’s picture

Next minor update should include reset to all related PDO syntax, I think.

heddn’s picture

Status: Active » Postponed (maintainer needs more info)

Reviewed in weekly Migrate standup. See https://www.drupal.org/node/2735059 for a schedule of these meetings. Marking postponed for now.

catch’s picture

@Benia, it's not possible to 'reset' the storage. Also we can't provide a fix for this without being able to see the data or having clear steps to reproduce the bug.

Can you provide a dump of your database? drush sql-dump --sanitize will remove e-mail addresses etc. Potentially just the term tables might be enough (but note the storage uses multiple tables, not just one).

Also could you check dblog and look for PHP errors on the site, that might also help.

Benia’s picture

Catch, will all 4 taxonomy tables be enough? If so, I will export them from PMA and put here.

If anything further is needed in the dump, please tell me...

steinmb’s picture

@Benia If you only can share the term tables, make sure you include them all, but, yes.

Benia’s picture

StatusFileSize
new9.22 KB

Here are all four taxonomy tables.

Benia’s picture

Status: Postponed (maintainer needs more info) » Active
catch’s picture

@Benia a configuration export from your site would probably help too.

Benia’s picture

StatusFileSize
new21.93 KB

Attached a taxonomy configuration export.

Benia’s picture

Title: All terms in a vocabulary are deleted on save » All terms in all taxonomy vocabularies deleted when saving a vocabulary
Benia’s picture

Issue summary: View changes
mikeryan’s picture

Title: All terms in all taxonomy vocabularies deleted when saving a vocabulary » Taxonomy terms not displayed after migration
Status: Active » Postponed (maintainer needs more info)

Retitling - the terms are not actually deleted (they are present in the database), but they are not displayed in places where the hierarchy table is joined.

Your taxonomy_term_hierarchy table is empty - this strongly suggests this is an instance of #2744639: Taxonomy term hierarchy migration incomplete, which was fixed in 8.1.8. You say:

If I remember correctly I first migrated from Drupal 7.44 to Drupal 8.1.3 (I now use 8.1.8). That's all there is to it, since then the problem started.

Just to be clear - you have not rerun your migration under 8.1.8, your migration was actually last run under 8.1.3? Then that's it, what you have is the remnants of a bug which has been fixed since your migration.

I believe you should be able to fix your database with the following query (be sure to backup your database before trying this!):

Edit: Actually, don't try this query, try the patch in the following comment.

insert into taxonomy_term_hierarchy (tid, parent)
select tid, 0 from taxonomy_term_data
where tid not in (select tid from taxonomy_term_hierarchy)

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.19 KB

Actually, forget about the manual query, please apply the attached patch and run db updates on your D8 site - see if that fixes it for you.

Patch reviewers - should the update go into the taxonomy module instead?

cosmicdreams’s picture

Which appears to be the focus on this more current issue #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration. Looks like solve that issue may solve the one you've linked.

mikeryan’s picture

Bumping down to Major - migrate is experimental and not required to do database updates, and we do have the "Migrate critical" tag on this.

Updating the issue summary to reflect the details of what's going on here.

mikeryan’s picture

Issue summary: View changes
Benia’s picture

I tried to run the patch this way, and then flushed cache but don't see change.

patch -p1 < taxonomy_terms_not-2783423
patching file core/modules/migrate/migrate.install
Reversed (or previously applied) patch detected!  Assume -R? [n] n
Apply anyway? [n] y
drush cr

If needed, I will rollback and try run it again differently.

mikeryan’s picture

You need to run database updates - what was added was an update function.

drush -y dbupdate
Benia’s picture

I tried to do "drush updb" but was told no database updates are available...

Could you please refer me to documentation about these db updates you mentioned? I am quite new to this...

mikeryan’s picture

Having trouble finding the D8 administrator docs, with the major doc re-org going on...

Can you verify that the patch actually took? Look at core/modules/migrate/migrate.install and make sure that "function migrate_update_8002()" is in there. If it is... I don't understand why it wouldn't be recognized.

Benia’s picture

Indeed, it is, last in the file:

function migrate_update_8002() {
  if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
    // We need to use a database query due to
    // https://www.drupal.org/node/2599450.
    $query = Database::getConnection()
      ->select('taxonomy_term_data', 'td')
      ->fields('td', ['tid']);
    $query->leftJoin('taxonomy_term_hierarchy', 'th', 'td.tid = th.tid');
    $query->isNull('th.parent');
    $terms = Term::loadMultiple($query->execute()->fetchCol());
    /** @var Drupal\taxonomy\Entity\Term $term */
    foreach ($terms as $term) {
      $term->set('parent', 0);
      $term->save();
    }
  }
}

/**
 * @} End of "addtogroup updates-8.0.0-beta".
 */
mikeryan’s picture

Hmm, I don't understand why drush -y updatedb didn't pick it up - perhaps if you tried through the UI (http://example.com/update.php, where "example.com" is your web address)?

Benia’s picture

I tried it from Putty after navigating to my specific site's folder.

Benia’s picture

I would gladly upload any publicly-exposable data needed, in here.

Benia’s picture

And any data you need in private.

catch’s picture

@Benia do you actually have migrate module installed on the site or did you uninstall after the migration?

mikeryan’s picture

@catch: Good point - that's an excellent reason to put the update function into the taxonomy module...

Benia’s picture

I already uninstalled the module, as to keep minimal with enabled modules that aren't being used... Didn't imagine it's problematic in that case...

mikeryan’s picture

StatusFileSize
new1.07 KB

@Benia: Please give this patch a try - it puts the update function in the taxonomy module. Be sure to run db updates (drush -y updatedb, or go to /update.php on your server).

mikeryan’s picture

StatusFileSize
new1.05 KB

Cleaner version of the patch, please skip the previous one.

heddn’s picture

Component: migration system » taxonomy.module
Status: Needs review » Needs work

Shall we move this over to taxonomy's queue then?

Also, this should really use the batch API. Entity save's are expensive and if there are a lot of terms to re-save, this is going to timeout.

The last submitted patch, 66: taxonomy_terms_not-2783423-66.patch, failed testing.

mikeryan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.53 KB

Shamelessly stealing from system_update_8200()...

mikeryan’s picture

StatusFileSize
new1.53 KB

*Sigh* - had temporarily set the limit to 10 because my test db had only 33 terms, restoring the 50...

@Benia - please use the last patch here. Don't forget to run the db updates after applying the patch.

Benia’s picture

zantech0@siteground341 [~/www/benia.biz]# patch p1 taxonomy_terms_not-2783423-70.patch
patching file p1
zantech0@siteground341 [~/www/benia.biz]# drush updb
No database updates required                                         [success]
Cache rebuild complete.                                              [ok]
Finished performing updates.                                         [ok]

It seems there are still no dbupdates. I don't know what to say...

berdir’s picture

patch -p1 < filename

On a single line. That is the correct command. what you are doing doesn't actually do anything.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Benia’s picture

Status: Needs review » Closed (fixed)

For some reason I missed the dashboard notification regarding your comment Berdir. Today I got in saying to myself someone must have replied and I might have missed it.

I have good news, I ran the patch including the DB update (only 1 appeared for me to run) and now it's back to normal !

I tried to edit existing nodes, adding taxonomy data from both select-list && radio buttons, as well as creating new noes that way and it all went without a problem.

Thank you for creating that patch, dear Mike Ryan and for anyone else who helped !

mikeryan’s picture

Status: Closed (fixed) » Needs review

Thanks for testing it Benia!

We leave this in "Needs review" now for technical review of the code, so we can get this patch into Drupal core and fix this situation for anyone else who runs into it...

mikeryan’s picture

StatusFileSize
new1.53 KB
new753 bytes

Updated target version of the update function, obviously it's not going into 8.1.x.

@catch: Does this need a test? Note we'd have to munge the db (taxonomy_term_hierarchy table) to create the situation it's fixing.

matt b’s picture

Thanks @catch for pointing me here. I have previously run migrations prior to #2744639: Taxonomy term hierarchy migration incomplete being implemented so was missing taxonomy_term_hierarchy data and could still not see the terms in the ui. I have applied the patch from #76, run the DB update and confirm it worked successfully. I can now see all my imported terms in the ui under /admin/structure/taxonomy - thank you!

I now just need to figure out how to get the nodes to be associated with taxonomy terms as per the source site - however that is a separate issue.

matt b’s picture

)-: I've just rolled back all the migrations and done a migrate-import --all and the taxonomy_term_hierarchy has reverted back. I no cannot see the taxonomy terms again.

phenaproxima’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +function taxonomy_update_8200(&$sandbox) {
    

    $sandbox should be type hinted.

  2. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +  if (!array_key_exists('tids', $sandbox)) {
    

    Should be !isset() && is_array()<code>, because <code>array_key_exists() will return TRUE if the key exists and the value is NULL or some other invalid cruft.

  3. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +  $tids_to_process = array_slice($sandbox['tids'], 0, 50);
    +  $terms = Term::loadMultiple($tids_to_process);
    +  /** @var Drupal\taxonomy\Entity\Term $term */
    +  foreach ($terms as $term) {
    +    $term->set('parent', 0);
    +    $term->save();
    +  }
    

    If any of the terms throw an exception or otherwise fail when $term->save() is called, $sandbox['tids'] might end up in an uncertain state. A while loop that continually pops term IDs out of the array would make me more comfortable.

  4. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +  $sandbox['#finished'] = empty($sandbox['tids']) ? 1 : ($sandbox['max'] - count($sandbox['tids'])) / $sandbox['max'];
    

    How is $sandbox['#finished'] used?

eli-t’s picture

StatusFileSize
new1.52 KB

Should address 1, 2, 3 in #79.

I'm sure the calculation of #finished can be clarified better though.

eli-t’s picture

StatusFileSize
new1.24 KB

Adding interdiff

eli-t’s picture

Status: Needs work » Needs review

I've tested this with 1000 taxonomy terms nested three deep by

1) creating them in D7.44
2) running migrate_drupal through the ui to Drupal 8.1.3 and observing the initial problem where terms aren't displayed
3) updating to the code to 8.2.x HEAD plus the latest patch here and running update.php.

The terms are again visible and correctly nested.

Hence putting back to needs review.

phenaproxima’s picture

Status: Needs review » Needs work
+++ b/core/modules/taxonomy/taxonomy.install
@@ -0,0 +1,45 @@
+    array_shift($sandbox['tids']);
+    $term->set('parent', 0);
+    $term->save();

The array_shift() call should be the last thing in the loop, so that it will only be called if the term saves without blowing up.

Other than that, I'm OK with this.

eli-t’s picture

StatusFileSize
new1.52 KB
new693 bytes

New patch reflecting comments made in #83 and interdiff.

eli-t’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Preemptively RTBC assuming Drupal CI passes everything.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Nice fix and sleuthing to find out the problem. Unfortunately this is exactly the type of upgrade path that needs testing. I think the best way will be to use the bare update and use database methods to insert terms without hierarchy and then run the updates.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new4.08 KB
new2.56 KB

Add test for update hook.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

phenaproxima’s picture

Assigned: Unassigned » phenaproxima

Self-assigning for re-review.

phenaproxima’s picture

Assigned: phenaproxima » Unassigned
Status: Needs review » Needs work
  1. +++ b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php
    @@ -0,0 +1,76 @@
    +  protected function setUp() {
    

    Missing @inheritdoc comment.

  2. +++ b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php
    @@ -0,0 +1,76 @@
    +    $connection->insert('taxonomy_term_data')
    +      ->fields(['tid', 'vid', 'uuid', 'langcode'])
    +      ->values([1, 'test_vocabulary', 'uuid-abc', 'en'])
    +      ->values([2, 'test_vocabulary', 'uuid-xyz', 'en'])
    +      ->execute();
    +    $connection->insert('taxonomy_term_field_data')
    +      ->fields(['tid', 'vid', 'langcode', 'name', 'weight', 'default_langcode'])
    +      ->values([1, 'test_vocabulary', 'en', 'Term1', 0, 1])
    +      ->values([2, 'test_vocabulary', 'en', 'Term2', 0, 1])
    +      ->execute();
    +    $connection->insert('taxonomy_term_hierarchy')
    +      ->fields(['tid', 'parent'])
    +      ->values([1, 0])
    +      ->execute();
    

    I'd like to see a few comments explaining what is being set up here.

  3. +++ b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php
    @@ -0,0 +1,76 @@
    +      ->execute()->fetchCol();
    

    Nit: The fetchCol() calls should be on their own line.

  4. +++ b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php
    @@ -0,0 +1,76 @@
    +    $this->assertIdentical($term_tids, $term_parent_tids);
    

    Use assertSame(), not assertIdentical().

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new4.29 KB
new1.27 KB
  1. Added @inheritdoc comment.
  2. Added comments to explain test set up.
  3. Moved fetchCol() onto its own line.
  4. No change - it seems there is no assertSame() in Drupal\simpletest\TestBase
phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

No change - it seems there is no assertSame() in Drupal\simpletest\TestBase

Good catch. My bad.

Otherwise, I think this looks fine and dandy. Let us proceed with it. Thanks, @Jo Fitzgerald!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +/**
    + * @addtogroup updates-8.2.x
    + * @{
    + */
    +
    +/**
    + * Fix taxonomy terms previously migrated with no hierarchy.
    + */
    +function taxonomy_update_8200(array &$sandbox) {
    

    This at best will make it into 8.3.x

  2. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +  // We need to use a database query due to https://www.drupal.org/node/2599450.
    

    This should point to https://www.drupal.org/node/2543726

  3. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +    $query = Database::getConnection()
    +      ->select('taxonomy_term_data', 'td')
    +      ->fields('td', ['tid']);
    +    $query->leftJoin('taxonomy_term_hierarchy', 'th', 'td.tid = th.tid');
    +    $query->isNull('th.parent');
    +    $sandbox['tids'] = $query->execute()->fetchCol();
    +    $sandbox['max'] = count($sandbox['tids']);
    

    It's a shame we have to use a database query and not an entity query.

    Also should we be concerned about the number of tids here potentially? I guess it could be very very long. Maybe we should get a new 50 every time until there is none?

  4. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -0,0 +1,45 @@
    +  $tids_to_process = array_slice($sandbox['tids'], 0, 50);
    

    We're debating adding a setting for 50 in ...[issue]

  5. Did we consider just running a single query on the taxonomy_term_hierarchy table to update NULL to 0? An advantage of this is that I'm not sure about the Term::loadMultiple() in a hook_update_N()
mikeryan’s picture

Assigned: Unassigned » mikeryan
mikeryan’s picture

Priority: Major » Normal
Issue tags: -Migrate critical

Doesn't really seem critical at this point - it's been a long time since the bug causing the situation was fixed.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

docans’s picture

looks like i am having the same issue

Greetings
I am migrating taxonomy from a tab file, The script and everything runs well and all the 279 taxonomies show in the migration status as beeing completed.
But when i go to view my taxonomies in drupal, only 180 of the taxonomies show up in the taxonomy vocabulary. I even tried creating a view to see all the taxonomies but it only shows 180 and i cant find the rest.
Here is a my migration script

id: migrate_taxonomy
label: 'Migrate the Main Taxonomy terms from the csv file'
migration_group: migrate_group
source:
  plugin: csv
  # Full path to the file.
  path: modules/custom/migration_content/source/REF_Taxonomy.TAB
  delimiter: "\t"
  header_row_count: 0
  ids:
    - Taxonomy_ID
process:
  tid: tid
  vid:
    plugin: default_value
    default_value: vocab_taxonomy # vacabulary to populate
  name: FullName # field in cvs to get the actual term names to become the term name
  parent_id:
    - plugin: skip_on_empty
      method: process
      source: ParentID
    - plugin: migration_lookup
      migration: migrate_taxonomy
  parent:
    plugin: default_value
    default_value: 0
    source: '@parent_id'
destination:
  plugin: entity:taxonomy_term
And here is the Tab file sample
Taxonomy_ID		FullName			ParentID
1				Fruit				0
2				mango			1
3				apple			1
digitalfrontiersmedia’s picture

I know this is a really old thread, but came across it while looking at some old patches during an update. And it reminded me of another issue that sounds related that I documented here: #2985762: Terms created when override_selector = TRUE don't appear on Terms List/Overview page

People experiencing missing terms after a migration may want to check that out. It has some thoughts on a workaround and a patch, although it's pretty old and not sure if it still applies.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Component: taxonomy.module » migration system
Issue tags: +migrate-d6-d8, +migrate-d7-d8

The bug causing this was fixed in July 2016 but this update function was never committed and it would fix long standing migrations.

Moving to migration system since this fix is a fix for a problem caused by migration and the migrate maintainers will see it.

quietone’s picture

Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

This issue was discussed as a migrate maintainer meeting, #3199420: [meeting] Migrate Meeting 2021-02-25 Item #10. The conclusion was that this can be closed as outdated. Read the minutes for the full discussion.