diff --git a/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.php b/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.php index 70e0ad4964997d9b5eb3af0f4065aed4b5060459..6d2c41c56e192e33b5c9bc3a9511787518a0e9a0 100644 --- a/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.php +++ b/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.php @@ -60,4 +60,8 @@ } } +// Insert an extra record with no corresponding term. +// See https://www.drupal.org/project/drupal/issues/2997982 +$query->values(['tid' => max($tids) + 1, 'parent' => 0]); + $query->execute(); diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index bbcb8349ae820deb85b20d246e7be9a59c3abda5..54a84d5ac24c2e91169c92620a82dd81711882b0 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -32,7 +32,12 @@ function taxonomy_update_8502(&$sandbox) { $sandbox['tid'] = -1; $sandbox['delta'] = 0; $sandbox['limit'] = Settings::get('entity_update_batch_size', 50); - $sandbox['max'] = $database->select('taxonomy_term_hierarchy') + + // Count records using a join, as there might be orphans in the hierarchy + // table. See https://www.drupal.org/project/drupal/issues/2997982. + $select = $database->select('taxonomy_term_hierarchy', 'h'); + $select->join('taxonomy_term_data', 'd', 'h.tid = d.tid'); + $sandbox['max'] = $select ->countQuery() ->execute() ->fetchField();