summaryrefslogtreecommitdiff
path: root/modules/taxonomy
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-14 20:42:45 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-14 20:42:45 +0000
commit8dd7376d5a15f2485fdd83c8db402a244314e30b (patch)
tree1b6241df8c5eeb5692e2345144fad8ee435de941 /modules/taxonomy
parent8049f94756021402a34ad3f2eb54fee5b19ae39b (diff)
downloadbrdo-8dd7376d5a15f2485fdd83c8db402a244314e30b.tar.gz
brdo-8dd7376d5a15f2485fdd83c8db402a244314e30b.tar.bz2
#923826 by catch, carlos8f, moshe weitzman: Fixed entity delete operations should use transactions.
Diffstat (limited to 'modules/taxonomy')
-rw-r--r--modules/taxonomy/taxonomy.admin.inc2
-rw-r--r--modules/taxonomy/taxonomy.module104
2 files changed, 61 insertions, 45 deletions
diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc
index 84ac05bb3..52cecb298 100644
--- a/modules/taxonomy/taxonomy.admin.inc
+++ b/modules/taxonomy/taxonomy.admin.inc
@@ -902,6 +902,7 @@ function taxonomy_term_confirm_delete_submit($form, &$form_state) {
drupal_set_message(t('Deleted term %name.', array('%name' => $form_state['values']['name'])));
watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/taxonomy';
+ cache_clear_all();
return;
}
@@ -941,6 +942,7 @@ function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) {
drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_state['values']['name'])));
watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/taxonomy';
+ cache_clear_all();
return;
}
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 10393eea9..5097da288 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -421,23 +421,31 @@ function taxonomy_vocabulary_save($vocabulary) {
function taxonomy_vocabulary_delete($vid) {
$vocabulary = taxonomy_vocabulary_load($vid);
- // Only load terms without a parent, child terms will get deleted too.
- $result = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid = :vid AND th.parent = 0', array(':vid' => $vid))->fetchCol();
- foreach ($result as $tid) {
- taxonomy_term_delete($tid);
+ $transaction = db_transaction();
+ try {
+ // Only load terms without a parent, child terms will get deleted too.
+ $result = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid = :vid AND th.parent = 0', array(':vid' => $vid))->fetchCol();
+ foreach ($result as $tid) {
+ taxonomy_term_delete($tid);
+ }
+ db_delete('taxonomy_vocabulary')
+ ->condition('vid', $vid)
+ ->execute();
+
+ field_attach_delete_bundle('taxonomy_term', $vocabulary->machine_name);
+ module_invoke_all('taxonomy_vocabulary_delete', $vocabulary);
+ module_invoke_all('entity_delete', $vocabulary, 'taxonomy_vocabulary');
+
+ cache_clear_all();
+ entity_get_controller('taxonomy_vocabulary')->resetCache();
+
+ return SAVED_DELETED;
+ }
+ catch (Exception $e) {
+ $transaction->rollback();
+ watchdog_exception('taxonomy', $e);
+ throw $e;
}
- db_delete('taxonomy_vocabulary')
- ->condition('vid', $vid)
- ->execute();
-
- field_attach_delete_bundle('taxonomy_term', $vocabulary->machine_name);
- module_invoke_all('taxonomy_vocabulary_delete', $vocabulary);
- module_invoke_all('entity_delete', $vocabulary, 'taxonomy_vocabulary');
-
- cache_clear_all();
- entity_get_controller('taxonomy_vocabulary')->resetCache();
-
- return SAVED_DELETED;
}
/**
@@ -588,41 +596,47 @@ function taxonomy_term_save($term) {
* Status constant indicating deletion.
*/
function taxonomy_term_delete($tid) {
- $tids = array($tid);
- while ($tids) {
- $children_tids = $orphans = array();
- foreach ($tids as $tid) {
- // See if any of the term's children are about to be become orphans:
- if ($children = taxonomy_get_children($tid)) {
- foreach ($children as $child) {
- // If the term has multiple parents, we don't delete it.
- $parents = taxonomy_get_parents($child->tid);
- if (count($parents) == 1) {
- $orphans[] = $child->tid;
+ $transaction = db_transaction();
+ try {
+ $tids = array($tid);
+ while ($tids) {
+ $children_tids = $orphans = array();
+ foreach ($tids as $tid) {
+ // See if any of the term's children are about to be become orphans:
+ if ($children = taxonomy_get_children($tid)) {
+ foreach ($children as $child) {
+ // If the term has multiple parents, we don't delete it.
+ $parents = taxonomy_get_parents($child->tid);
+ if (count($parents) == 1) {
+ $orphans[] = $child->tid;
+ }
}
}
- }
- if ($term = taxonomy_term_load($tid)) {
- db_delete('taxonomy_term_data')
- ->condition('tid', $tid)
- ->execute();
- db_delete('taxonomy_term_hierarchy')
- ->condition('tid', $tid)
- ->execute();
-
- field_attach_delete('taxonomy_term', $term);
- module_invoke_all('taxonomy_term_delete', $term);
- module_invoke_all('entity_delete', $term, 'taxonomy_term');
- taxonomy_terms_static_reset();
+ if ($term = taxonomy_term_load($tid)) {
+ db_delete('taxonomy_term_data')
+ ->condition('tid', $tid)
+ ->execute();
+ db_delete('taxonomy_term_hierarchy')
+ ->condition('tid', $tid)
+ ->execute();
+
+ field_attach_delete('taxonomy_term', $term);
+ module_invoke_all('taxonomy_term_delete', $term);
+ module_invoke_all('entity_delete', $term, 'taxonomy_term');
+ taxonomy_terms_static_reset();
+ }
}
- }
- $tids = $orphans;
+ $tids = $orphans;
+ }
+ return SAVED_DELETED;
+ }
+ catch (Exception $e) {
+ $transaction->rollback();
+ watchdog_exception('taxonomy', $e);
+ throw $e;
}
-
- cache_clear_all();
- return SAVED_DELETED;
}
/**