diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 5e2a546eb3..ea50bf2aac 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -29,6 +29,8 @@ function taxonomy_update_8502(&$sandbox) { if (!isset($sandbox['current'])) { // Set batch ops sandbox. $sandbox['current'] = 0; + $sandbox['tid'] = -1; + $sandbox['delta'] = 0; $sandbox['limit'] = Settings::get('entity_update_batch_size', 50); $sandbox['max'] = $database->select('taxonomy_term_hierarchy') ->countQuery() @@ -49,12 +51,11 @@ function taxonomy_update_8502(&$sandbox) { // Restore data. $insert = $database->insert('taxonomy_term__parent') ->fields(['bundle', 'entity_id', 'revision_id', 'langcode', 'delta', 'parent_target_id']); - $tid = -1; foreach ($hierarchy as $row) { - if ($row->tid !== $tid) { - $delta = 0; - $tid = $row->tid; + if ($row->tid !== $sandbox['tid']) { + $sandbox['delta'] = 0; + $sandbox['tid'] = $row->tid; } $insert->values([ @@ -62,11 +63,11 @@ function taxonomy_update_8502(&$sandbox) { 'entity_id' => $row->tid, 'revision_id' => $row->tid, 'langcode' => $row->langcode, - 'delta' => $delta, + 'delta' => $sandbox['delta'], 'parent_target_id' => $row->parent, ]); - $delta++; + $sandbox['delta']++; $sandbox['current']++; }