- Patch #749304 by catch: critical bug: programmatic term updates destroyed hierarchies.
parent
8efa768768
commit
73fbc28253
|
@ -472,50 +472,52 @@ function taxonomy_term_save($term) {
|
||||||
|
|
||||||
field_attach_presave('taxonomy_term', $term);
|
field_attach_presave('taxonomy_term', $term);
|
||||||
|
|
||||||
if (!empty($term->tid) && $term->name) {
|
if (empty($term->tid)) {
|
||||||
$status = drupal_write_record('taxonomy_term_data', $term, 'tid');
|
|
||||||
field_attach_update('taxonomy_term', $term);
|
|
||||||
module_invoke_all('taxonomy_term_update', $term);
|
|
||||||
entity_invoke('update', 'taxonomy_term', $term);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$status = drupal_write_record('taxonomy_term_data', $term);
|
$status = drupal_write_record('taxonomy_term_data', $term);
|
||||||
field_attach_insert('taxonomy_term', $term);
|
field_attach_insert('taxonomy_term', $term);
|
||||||
module_invoke_all('taxonomy_term_insert', $term);
|
module_invoke_all('taxonomy_term_insert', $term);
|
||||||
entity_invoke('insert', 'taxonomy_term', $term);
|
entity_invoke('insert', 'taxonomy_term', $term);
|
||||||
|
if (!isset($term->parent)) {
|
||||||
|
$term->parent = array(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
db_delete('taxonomy_term_hierarchy')
|
$status = drupal_write_record('taxonomy_term_data', $term, 'tid');
|
||||||
->condition('tid', $term->tid)
|
field_attach_update('taxonomy_term', $term);
|
||||||
->execute();
|
module_invoke_all('taxonomy_term_update', $term);
|
||||||
|
entity_invoke('update', 'taxonomy_term', $term);
|
||||||
if (!isset($term->parent) || empty($term->parent)) {
|
if (isset($term->parent)) {
|
||||||
$term->parent = array(0);
|
db_delete('taxonomy_term_hierarchy')
|
||||||
|
->condition('tid', $term->tid)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!is_array($term->parent)) {
|
if (isset($term->parent)) {
|
||||||
$term->parent = array($term->parent);
|
if (!is_array($term->parent)) {
|
||||||
}
|
$term->parent = array($term->parent);
|
||||||
$query = db_insert('taxonomy_term_hierarchy')
|
}
|
||||||
->fields(array('tid', 'parent'));
|
$query = db_insert('taxonomy_term_hierarchy')
|
||||||
if (is_array($term->parent)) {
|
->fields(array('tid', 'parent'));
|
||||||
foreach ($term->parent as $parent) {
|
if (is_array($term->parent)) {
|
||||||
if (is_array($parent)) {
|
foreach ($term->parent as $parent) {
|
||||||
foreach ($parent as $tid) {
|
if (is_array($parent)) {
|
||||||
|
foreach ($parent as $tid) {
|
||||||
|
$query->values(array(
|
||||||
|
'tid' => $term->tid,
|
||||||
|
'parent' => $tid
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
$query->values(array(
|
$query->values(array(
|
||||||
'tid' => $term->tid,
|
'tid' => $term->tid,
|
||||||
'parent' => $tid
|
'parent' => $parent
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$query->values(array(
|
|
||||||
'tid' => $term->tid,
|
|
||||||
'parent' => $parent
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$query->execute();
|
||||||
}
|
}
|
||||||
$query->execute();
|
|
||||||
|
|
||||||
cache_clear_all();
|
cache_clear_all();
|
||||||
taxonomy_terms_static_reset();
|
taxonomy_terms_static_reset();
|
||||||
|
|
|
@ -374,6 +374,12 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
|
||||||
$this->assertTrue(isset($children[$term2->tid]), t('Child found correctly.'));
|
$this->assertTrue(isset($children[$term2->tid]), t('Child found correctly.'));
|
||||||
$this->assertTrue(isset($parents[$term1->tid]), t('Parent found correctly.'));
|
$this->assertTrue(isset($parents[$term1->tid]), t('Parent found correctly.'));
|
||||||
|
|
||||||
|
// Load and save a term, confirming that parents are still set.
|
||||||
|
$term = taxonomy_term_load($term2->tid);
|
||||||
|
taxonomy_term_save($term);
|
||||||
|
$parents = taxonomy_get_parents($term2->tid);
|
||||||
|
$this->assertTrue(isset($parents[$term1->tid]), t('Parent found correctly.'));
|
||||||
|
|
||||||
// Create a third term and save this as a parent of term2.
|
// Create a third term and save this as a parent of term2.
|
||||||
$term3 = $this->createTerm($this->vocabulary);
|
$term3 = $this->createTerm($this->vocabulary);
|
||||||
$term2->parent = array($term1->tid, $term3->tid);
|
$term2->parent = array($term1->tid, $term3->tid);
|
||||||
|
|
Loading…
Reference in New Issue