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 70e0ad4964..3c3db18eae 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 @@ -50,6 +50,9 @@ 1 => [2, 3], 2 => [3, 0], 3 => [0], + // Insert an extra record with no corresponding term. + // See https://www.drupal.org/project/drupal/issues/2997982 + 4 => [0], ]; $query = $connection->insert('taxonomy_term_hierarchy')->fields(['tid', 'parent']); diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 2244134559..54a84d5ac2 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -32,6 +32,9 @@ function taxonomy_update_8502(&$sandbox) { $sandbox['tid'] = -1; $sandbox['delta'] = 0; $sandbox['limit'] = Settings::get('entity_update_batch_size', 50); + + // 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