diff -u b/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php --- b/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -65,9 +65,10 @@ public static function postDelete(EntityStorageInterface $storage, array $entities) { parent::postDelete($storage, $entities); + $tids = array_keys($entities); // See if any of the term's children are about to be become orphans. $orphans = array(); - foreach (array_keys($entities) as $tid) { + foreach ($tids as $tid) { if ($children = taxonomy_term_load_children($tid)) { foreach ($children as $child) { // If the term has multiple parents, we don't delete it. @@ -81,8 +82,7 @@ // Delete term hierarchy information after looking up orphans but before // deleting them so that their children/parent information is consistent. - $storage->deleteTermHierarchy(array_keys($entities)); - $storage->deleteTermHierarchyByParent(array_keys($entities)); + $storage->deleteTermHierarchy($tids); if (!empty($orphans)) { entity_delete_multiple('taxonomy_term', $orphans); @@ -98,7 +98,6 @@ // Only change the parents if a value is set, keep the existing values if // not. if (isset($this->parent->target_id)) { - $storage->deleteTermHierarchy(array($this->id())); $storage->updateTermHierarchy($this); } } diff -u b/core/modules/taxonomy/src/TermStorage.php b/core/modules/taxonomy/src/TermStorage.php --- b/core/modules/taxonomy/src/TermStorage.php +++ b/core/modules/taxonomy/src/TermStorage.php @@ -101,16 +101,10 @@ */ public function deleteTermHierarchy($tids) { $this->database->delete('taxonomy_term_hierarchy') - ->condition('tid', $tids, 'IN') - ->execute(); - } - - /** - *{@inheritdoc} - */ - public function deleteTermHierarchyByParent($pids) { - $this->database->delete('taxonomy_term_hierarchy') - ->condition('parent', $pids, 'IN') + ->condition(db_or() + ->condition('tid', $tids, 'IN') + ->condition('parent', $tids, 'IN') + ) ->execute(); } @@ -118,6 +112,10 @@ * {@inheritdoc} */ public function updateTermHierarchy(EntityInterface $term) { + // Remove the term from taxonomy_term_hierarchy before repopulating. + $this->database->delete('taxonomy_term_hierarchy') + ->condition('tid', $term->id()) + ->execute(); $query = $this->database->insert('taxonomy_term_hierarchy') ->fields(array('tid', 'parent')); diff -u b/core/modules/taxonomy/src/TermStorageInterface.php b/core/modules/taxonomy/src/TermStorageInterface.php --- b/core/modules/taxonomy/src/TermStorageInterface.php +++ b/core/modules/taxonomy/src/TermStorageInterface.php @@ -24,14 +24,6 @@ public function deleteTermHierarchy($tids); /** - * Removes reference to terms from term_hierarchy parent. - * - * @param array $pids - * Array of parent terms that need to be removed from hierarchy. - */ - public function deleteTermHierarchyByParent($pids); - - /** * Updates terms hierarchy information with the hierarchy trail of it. * * @param \Drupal\Core\Entity\EntityInterface $term