Commit 49334ae5 authored by Dries's avatar Dries

- Patch #735726 by catch: optimize taxonomy_term_save().

parent 2a79bce9
......@@ -93,6 +93,8 @@ function forum_form_submit($form, &$form_state) {
break;
case SAVED_UPDATED:
drupal_set_message(t('The @type %term has been updated.', array('%term' => $form_state['values']['name'], '@type' => $type)));
// Clear the page and block caches to avoid stale data.
cache_clear_all();
break;
}
$form_state['redirect'] = 'admin/structure/forum';
......
......@@ -791,6 +791,8 @@ function taxonomy_form_term_submit($form, &$form_state) {
case SAVED_UPDATED:
drupal_set_message(t('Updated term %term.', array('%term' => $term->name)));
watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->name), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
// Clear the page and block caches to avoid stale data.
cache_clear_all();
break;
}
......
......@@ -461,10 +461,8 @@ function taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term) {
* Status constant indicating if term was inserted or updated.
*/
function taxonomy_term_save($term) {
if ($term->name) {
// Prevent leading and trailing spaces in term names.
$term->name = trim($term->name);
}
// Prevent leading and trailing spaces in term names.
$term->name = trim($term->name);
if (!isset($term->vocabulary_machine_name)) {
$vocabulary = taxonomy_vocabulary_load($term->vid);
$term->vocabulary_machine_name = $vocabulary->machine_name;
......@@ -498,28 +496,24 @@ function taxonomy_term_save($term) {
}
$query = db_insert('taxonomy_term_hierarchy')
->fields(array('tid', 'parent'));
if (is_array($term->parent)) {
foreach ($term->parent as $parent) {
if (is_array($parent)) {
foreach ($parent as $tid) {
$query->values(array(
'tid' => $term->tid,
'parent' => $tid
));
}
}
else {
foreach ($term->parent as $parent) {
if (is_array($parent)) {
foreach ($parent as $tid) {
$query->values(array(
'tid' => $term->tid,
'parent' => $parent
'parent' => $tid
));
}
}
else {
$query->values(array(
'tid' => $term->tid,
'parent' => $parent
));
}
}
$query->execute();
}
cache_clear_all();
taxonomy_terms_static_reset();
return $status;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment