summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreffulgentsia2018-09-14 00:44:38 (GMT)
committereffulgentsia2018-09-14 00:45:46 (GMT)
commitbc03813af19fb6ebe07bc8bbeeb89a2f55da06cf (patch)
treea568257dcec0b0e49b4883736a8be4471a908680
parent316b0bfcdf89132fc7ee2b64b0a85cf4e6d107e5 (diff)
Issue #2997982 by longwave, plach, johns996: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop
(cherry picked from commit 1bffa61218c9e1db87b0644126aa7ec9ee2b122f)
-rw-r--r--core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.php4
-rw-r--r--core/modules/taxonomy/taxonomy.install7
2 files changed, 10 insertions, 1 deletions
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 70e0ad4..6d2c41c 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 @@ foreach ($hierarchy as $tid => $parents) {
}
}
+// 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 bbcb834..54a84d5 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();