#923826 by catch, carlos8f, moshe weitzman: Fixed entity delete operations should use transactions.

merge-requests/26/head
Angie Byron 2010-11-14 20:42:45 +00:00
parent 8049f94756
commit 8dd7376d5a
5 changed files with 139 additions and 102 deletions

View File

@ -1583,7 +1583,8 @@ function comment_delete($cid) {
function comment_delete_multiple($cids) {
$comments = comment_load_multiple($cids);
if ($comments) {
$transaction = db_transaction();
try {
// Delete the comments.
db_delete('comment')
->condition('cid', array_keys($comments), 'IN')
@ -1599,6 +1600,12 @@ function comment_delete_multiple($cids) {
_comment_update_node_statistics($comment->nid);
}
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception('comment', $e);
throw $e;
}
}
}
/**

View File

@ -1123,7 +1123,7 @@ function node_save($node) {
db_ignore_slave();
}
catch (Exception $e) {
$transaction->rollback('node');
$transaction->rollback();
watchdog_exception('node', $e);
throw $e;
}
@ -1164,9 +1164,11 @@ function node_delete($nid) {
* An array of node IDs.
*/
function node_delete_multiple($nids) {
$transaction = db_transaction();
if (!empty($nids)) {
$nodes = node_load_multiple($nids, array());
try {
foreach ($nodes as $nid => $node) {
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
@ -1196,9 +1198,14 @@ function node_delete_multiple($nids) {
db_delete('node_access')
->condition('nid', $nids, 'IN')
->execute();
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception('node', $e);
throw $e;
}
// Clear the page and block and node_load_multiple caches.
cache_clear_all();
entity_get_controller('node')->resetCache();
}
}

View File

@ -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;
}

View File

@ -421,6 +421,8 @@ function taxonomy_vocabulary_save($vocabulary) {
function taxonomy_vocabulary_delete($vid) {
$vocabulary = taxonomy_vocabulary_load($vid);
$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) {
@ -439,6 +441,12 @@ function taxonomy_vocabulary_delete($vid) {
return SAVED_DELETED;
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception('taxonomy', $e);
throw $e;
}
}
/**
* Implements hook_taxonomy_vocabulary_update().
@ -588,6 +596,8 @@ function taxonomy_term_save($term) {
* Status constant indicating deletion.
*/
function taxonomy_term_delete($tid) {
$transaction = db_transaction();
try {
$tids = array($tid);
while ($tids) {
$children_tids = $orphans = array();
@ -620,10 +630,14 @@ function taxonomy_term_delete($tid) {
$tids = $orphans;
}
cache_clear_all();
return SAVED_DELETED;
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception('taxonomy', $e);
throw $e;
}
}
/**
* Generate an array for rendering the given term.

View File

@ -2361,6 +2361,8 @@ function user_delete_multiple(array $uids) {
if (!empty($uids)) {
$accounts = user_load_multiple($uids, array());
$transaction = db_transaction();
try {
foreach ($accounts as $uid => $account) {
module_invoke_all('user_delete', $account);
module_invoke_all('entity_delete', $account, 'user');
@ -2377,7 +2379,12 @@ function user_delete_multiple(array $uids) {
db_delete('authmap')
->condition('uid', $uids, 'IN')
->execute();
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception('user', $e);
throw $e;
}
entity_get_controller('user')->resetCache();
}
}