diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-07-01 17:41:16 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-07-01 17:41:16 +0000 |
commit | e59852d336467e7269853724a28d80bc070bcbf6 (patch) | |
tree | 5be53c3b52d923476e8be517f15251f1487efa9c | |
parent | c11cb4ec24479e801076c094f043f2084b344d0c (diff) | |
download | brdo-e59852d336467e7269853724a28d80bc070bcbf6.tar.gz brdo-e59852d336467e7269853724a28d80bc070bcbf6.tar.bz2 |
- Rollback of patch #147723: delete API. Talked to Steven and Gabor and we
unanimously agreed to rollback the deletion API. We all support the
features this patch added, yet not its actual design and implementation.
After some talk, we decided that it would be better for Drupal -- in the
long term -- not to go with a solution that isn't 100%. We also recognize
that in the short term, this patch would have been useful addition. So
let's figure out how we can implement this properly in D7.
-rw-r--r-- | includes/common.inc | 162 | ||||
-rw-r--r-- | includes/form.inc | 12 | ||||
-rw-r--r-- | includes/locale.inc | 4 | ||||
-rw-r--r-- | modules/block/block.module | 2 | ||||
-rw-r--r-- | modules/book/book.module | 4 | ||||
-rw-r--r-- | modules/comment/comment.module | 70 | ||||
-rw-r--r-- | modules/contact/contact.module | 2 | ||||
-rw-r--r-- | modules/filter/filter.module | 4 | ||||
-rw-r--r-- | modules/forum/forum.module | 8 | ||||
-rw-r--r-- | modules/menu/menu.module | 7 | ||||
-rw-r--r-- | modules/node/content_types.inc | 4 | ||||
-rw-r--r-- | modules/node/node.module | 62 | ||||
-rw-r--r-- | modules/path/path.module | 9 | ||||
-rw-r--r-- | modules/poll/poll.module | 6 | ||||
-rw-r--r-- | modules/profile/profile.module | 6 | ||||
-rw-r--r-- | modules/search/search.module | 7 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 2 | ||||
-rw-r--r-- | modules/system/system.module | 90 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 18 | ||||
-rw-r--r-- | modules/upload/upload.module | 31 | ||||
-rw-r--r-- | modules/user/user.module | 19 |
21 files changed, 167 insertions, 362 deletions
diff --git a/includes/common.inc b/includes/common.inc index e4db9acc7..b20da7e74 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2805,154 +2805,6 @@ function drupal_common_themes() { } /** - * @ingroup deletionapi - * @{ - */ - -/** - * Used to begin a new deletion package. A package is set of deletion - * queries associated with a particular kind of deletion -- for example, - * all the queries associated with a node deletion. Most often it will - * not be necessary to start a new package, as most non-core deletions will - * already be part of a package initiated by core. Once a package has - * been started, all metadata, callbacks, and queries are added to the package. - * A package is complete when either a new package is started, or when a - * confirm or execute command is given. - * - * @param $type - * The deletion type for the package, ex. 'node', 'user', 'comment'. - * @param $id - * A unique identifier for the package. By convention this is the primary - * key of the 'root' deletion, ex. the nid for node type deletions, the uid - * for user type deletions, etc. - */ -function drupal_delete_initiate($type, $id) { - _drupal_delete('new package', array('type' => $type, 'id' => $id)); -} - -/** - * Pass a deletion query into a deletion package. - * - * @param $query - * The query to be passed, followed by any additional arguments for escaped values. - * ex. drupal_delete_add_query('DELETE FROM {comments} WHERE nid = %d', $node->nid); - * The additional arguments can be passed in any fashion that db_query() accepts. - */ -function drupal_delete_add_query($query) { - $all_args = func_get_args(); - array_unshift($all_args, 'query', ''); - call_user_func_array('_drupal_delete', $all_args); -} - -/** - * Initiates the confirmation cycle. This command fully builds all packages - * for deletion, and returns a confirm form array containing any injected messages - * which can be used to print a confirmation screen. - * - * @code - * drupal_delete_confirm( - * array( - * 'form' => $form, - * 'question' => t('Are you sure you want to delete these items?'), - * 'destination' => 'admin/content/node', - * 'yes' => t('Delete all'), - * ) - * ); - * @endcode - * - * @param $confirm - * An associative array with the following key/value pairs: - * 'form' => Optional. An array representing the form elements to pass to the confirm form. - * 'question' => Optional. The question for the confirm form. - * 'destination' => Optional. The destination path for form submissions and form cancellations. - * - * Also, any valid options from the $options argument of confirm_form() may - * be passed, and they will be passed through to the confirm form. - */ -function drupal_delete_confirm($confirm) { - return _drupal_delete('confirm', '', $confirm); -} - -/** - * Initiates the deletion of all constructed packages. Confirmation messages - * are bypassed, but abort messages are respected. - * - * @param $destination - * Optional. A destination to go to after all packages are executed. - * Can be either a Drupal path, or an array with the keys 'path', 'query', 'fragment'. - */ -function drupal_delete_execute($destination = FALSE) { - _drupal_delete('execute', '', array('destination' => $destination)); -} - -/** - * Register post-deletion callback functions for a package. The functions are called after the package - * has been deleted. Useful for miscellaneous cleanup, user messages, etc. - * - * @code - * drupal_delete_add_callback( - * array( - * 'node_delete_post' => array($node->nid, $node->title, $node->type), - * ) - * ); - * @endcode - * - * @param $callbacks - * An associative array of callback functions, key = name of function, - * value = an array of arguments to pass to the function. - */ -function drupal_delete_add_callback($callbacks) { - _drupal_delete('callback', '', $callbacks); -} - -/** - * Pass metadata related to the deletion or package to the API. This is made - * available to all hooks called during the deletion cycle. - * - * @code - * drupal_delete_add_metadata( - * array( - * 'comment_messages' => $messages, - * ) - * ); - * @endcode - * - * @param $metadata - * An associative array of metadata. - */ -function drupal_delete_add_metadata($metadata) { - _drupal_delete('metadata', '', $metadata); -} - -/** - * Pass in a package-specific set of form elements, to be displayed in the - * confirm form. Use this in multiple deletion scenarios where the confirm - * information shouldn't be displayed if the package is aborted. - * - * @code - * drupal_delete_add_form_elements( - * array( - * "node_$node->nid" => array( - * '#value' => check_plain($node->title), - * '#prefix' => '<li>', - * '#suffix' => "</li>\n", - * ), - * ) - * ); - * @endcode - * - * @param $elements - * An array representing the package-specific form elements to pass to the confirm form. - */ -function drupal_delete_add_form_elements($elements) { - _drupal_delete('form', '', $elements); -} - -/** - * @} End of "ingroup deletionapi". - */ - -/** * Create/build/execute deletion packages. * * Note that this function should not be called directly, but through the following helper functions: @@ -3096,8 +2948,8 @@ function _drupal_delete($op, $id = '') { // Generate the confirm form if any packages remain. if ($count) { $question = isset($args['question']) ? $args['question'] : t('Delete the item?'); - $path = isset($args['destination']) ? $args['destination'] : '<front>'; - unset($args['question'], $args['destination']); + $path = isset($args['path']) ? $args['path'] : 'node'; + unset($args['question'], $args['path']); $args['name'] = 'delete'; // Submit handler - triggers execute operation for the API. $form['#submit'] = array('delete_confirm_submit'); @@ -3108,12 +2960,12 @@ function _drupal_delete($op, $id = '') { drupal_goto($abort_destination); } // Fallback to cancel path. - elseif (isset($args['cancel'])) { - drupal_goto($args['cancel']); + elseif (isset($args['path'])) { + drupal_goto($args['path']); } - // Last fallback, submit destination. + // Last fallback, front page. else { - drupal_goto($path); + drupal_goto('<front>'); } } } @@ -3521,4 +3373,4 @@ function drupal_implode_tags($tags) { $encoded_tags[] = $tag; } return implode(', ', $encoded_tags); -}
\ No newline at end of file +} diff --git a/includes/form.inc b/includes/form.inc index b9648e236..f29d95e7d 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -485,7 +485,17 @@ function drupal_redirect_form($form, $redirect = NULL) { if ($goto !== FALSE && isset($form['#redirect'])) { $goto = $form['#redirect']; } - drupal_redirect(isset($goto) ? $goto : NULL); + if (!isset($goto) || ($goto !== FALSE)) { + if (isset($goto)) { + if (is_array($goto)) { + call_user_func_array('drupal_goto', $goto); + } + else { + drupal_goto($goto); + } + } + drupal_goto($_GET['q']); + } } /** diff --git a/includes/locale.inc b/includes/locale.inc index 8c364e958..5dd97f730 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -393,9 +393,7 @@ function locale_languages_delete_form(&$form_state, $langcode) { } else { $form['langcode'] = array('#type' => 'value', '#value' => $langcode); - $options = array('description' => t('Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.')); - - return confirm_form($form, t('Are you sure you want to delete the language %name?', array('%name' => t($languages[$langcode]->name))), 'admin/settings/language', $options); + return confirm_form($form, t('Are you sure you want to delete the language %name?', array('%name' => t($languages[$langcode]->name))), 'admin/settings/language', t('Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.'), t('Delete'), t('Cancel')); } } diff --git a/modules/block/block.module b/modules/block/block.module index 72ae78d0e..10f3bf1a5 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -566,7 +566,7 @@ function block_box_delete(&$form_state, $bid = 0) { $form['info'] = array('#type' => 'hidden', '#value' => $box['info'] ? $box['info'] : $box['title']); $form['bid'] = array('#type' => 'hidden', '#value' => $bid); - return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $box['info'])), 'admin/build/block'); + return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $box['info'])), 'admin/build/block', '', t('Delete'), t('Cancel')); } /** diff --git a/modules/book/book.module b/modules/book/book.module index 8fea8fd7c..f21e574f8 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -466,10 +466,10 @@ function book_nodeapi(&$node, $op, $teaser, $page) { } break; case 'delete revision': - drupal_delete_add_query('DELETE FROM {book} WHERE vid = %d', $node->vid); + db_query('DELETE FROM {book} WHERE vid = %d', $node->vid); break; case 'delete': - drupal_delete_add_query('DELETE FROM {book} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {book} WHERE nid = %d', $node->nid); break; } } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 8266aebfa..495637b94 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -231,8 +231,7 @@ function comment_menu() { $items['comment/delete'] = array( 'title' => 'Delete comment', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('comment_delete', 2), + 'page callback' => 'comment_delete', 'access arguments' => array('administer comments'), 'type' => MENU_CALLBACK, ); @@ -474,8 +473,8 @@ function comment_nodeapi(&$node, $op, $arg = 0) { break; case 'delete': - drupal_delete_add_query('DELETE FROM {comments} WHERE nid = %d', $node->nid); - drupal_delete_add_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid); break; case 'update index': @@ -1093,43 +1092,50 @@ function comment_render($node, $cid = 0) { /** * Menu callback; delete a comment. */ -function comment_delete(&$form_state, $cid = NULL) { +function comment_delete($cid = NULL) { $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid)); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - if (is_object($comment) && is_numeric($comment->cid)) { - drupal_delete_initiate('comment', $comment->cid); - drupal_delete_add_callback( - array( - 'comment_delete_post' => array($comment), - // Clear the cache so an anonymous poster can see the node being deleted. - 'cache_clear_all' => array(), - ) - ); - - // Delete comment and its replies. - _comment_delete_thread($comment); + $output = ''; - return drupal_delete_confirm( - array( - 'question' => t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)), - 'destination' => 'node/'. $comment->nid, - 'description' => t('Any replies to this comment will be lost. This action cannot be undone.'), - ) - ); + if (is_object($comment) && is_numeric($comment->cid)) { + $output = drupal_get_form('comment_confirm_delete', $comment); } else { - drupal_set_message(t('The comment no longer exists.'), 'error'); - drupal_goto('<front>'); + drupal_set_message(t('The comment no longer exists.')); } + + return $output; +} + +function comment_confirm_delete(&$form_state, $comment) { + $form = array(); + $form['#comment'] = $comment; + return confirm_form( + $form, + t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)), + 'node/'. $comment->nid, + t('Any replies to this comment will be lost. This action cannot be undone.'), + t('Delete'), + t('Cancel'), + 'comment_confirm_delete'); } -function comment_delete_post($comment) { +function comment_confirm_delete_submit($form, &$form_state) { + drupal_set_message(t('The comment and all its replies have been deleted.')); - drupal_set_message(t('The comment %subject and all its replies have been deleted.', array('%subject' => $comment->subject))); - watchdog('content', 'Comment: deleted %subject and all its replies.', array('%subject' => $comment->subject)); + $comment = $form['#comment']; + + // Delete comment and its replies. + _comment_delete_thread($comment); _comment_update_node_statistics($comment->nid); + + // Clear the cache so an anonymous user sees that his comment was deleted. + cache_clear_all(); + + $form_state['redirect'] = "node/$comment->nid"; + return; } /** @@ -1342,8 +1348,9 @@ function comment_multiple_delete_confirm(&$form_state) { array( 'form' => $form, 'question' => t('Are you sure you want to delete these comments and all their children?'), - 'destination' => 'admin/content/comment', + 'path' => 'admin/content/comment', 'yes' => t('Delete all'), + 'destination' => 'admin/content/comment', ) ); } @@ -1917,7 +1924,8 @@ function _comment_delete_thread($comment) { } // Delete the comment: - drupal_delete_add_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid); + db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid); + watchdog('content', 'Comment: deleted %subject.', array('%subject' => $comment->subject)); comment_invoke_comment($comment, 'delete'); diff --git a/modules/contact/contact.module b/modules/contact/contact.module index 7b53d6be6..cb628bbac 100644 --- a/modules/contact/contact.module +++ b/modules/contact/contact.module @@ -265,7 +265,7 @@ function contact_admin_delete(&$form_state, $cid = NULL) { '#value' => $info->category, ); - return confirm_form($form, t('Are you sure you want to delete %category?', array('%category' => $info->category)), 'admin/build/contact'); + return confirm_form($form, t('Are you sure you want to delete %category?', array('%category' => $info->category)), 'admin/build/contact', t('This action cannot be undone.'), t('Delete'), t('Cancel')); } else { drupal_set_message(t('Category not found.'), 'error'); diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 7e0cc011f..f3c2e38ea 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -336,9 +336,7 @@ function filter_admin_delete() { $form['format'] = array('#type' => 'hidden', '#value' => $format->format); $form['name'] = array('#type' => 'hidden', '#value' => $format->name); - $options = array('description' => t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.')); - - return confirm_form($form, t('Are you sure you want to delete the input format %format?', array('%format' => $format->name)), 'admin/settings/filters', $options); + return confirm_form($form, t('Are you sure you want to delete the input format %format?', array('%format' => $format->name)), 'admin/settings/filters', t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.'), t('Delete'), t('Cancel')); } else { drupal_set_message(t('The default format cannot be deleted.')); diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 1352911b8..09519e390 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -169,7 +169,7 @@ function forum_perm() { function forum_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { case 'delete revision': - drupal_delete_add_query('DELETE FROM {forum} WHERE vid = %d', $node->vid); + db_query('DELETE FROM {forum} WHERE vid = %d', $node->vid); break; } } @@ -453,7 +453,7 @@ function forum_insert($node) { * Implementation of hook_delete(). */ function forum_delete(&$node) { - drupal_delete_add_query('DELETE FROM {forum} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid); } /** @@ -610,9 +610,7 @@ function forum_confirm_delete(&$form_state, $tid) { $form['tid'] = array('#type' => 'value', '#value' => $tid); $form['name'] = array('#type' => 'value', '#value' => $term->name); - $options = array('description' => t('Deleting a forum or container will delete all sub-forums and associated posts as well. This action cannot be undone.')); - - return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/content/forum', $options); + return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/content/forum', t('Deleting a forum or container will delete all sub-forums and associated posts as well. This action cannot be undone.'), t('Delete'), t('Cancel')); } /** diff --git a/modules/menu/menu.module b/modules/menu/menu.module index bc29cd928..6376cb111 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -464,7 +464,7 @@ function menu_item_delete_form(&$form_state, $mlid) { } $form['#item'] = $item; - return confirm_form($form, t('Are you sure you want to delete the custom menu item %item?', array('%item' => $item['link_title'])), 'admin/build/menu/'. $item['menu_name']); + return confirm_form($form, t('Are you sure you want to delete the custom menu item %item?', array('%item' => $item['link_title'])), 'admin/build/menu/'. $item['menu_name'], t('This action cannot be undone.'), t('Delete')); } /** @@ -488,11 +488,10 @@ function menu_reset_item(&$form_state, $mlid) { $options = array( 'description' => t('Any customizations will be lost. This action cannot be undone.'), - 'yes' => t('Reset'), - 'cancel' => 'admin/build/menu', + 'yes' => t('Reset') ); - return confirm_form($form, t('Are you sure you want to reset the item %item to its default values?', array('%item' => $item['link_title'])), 'admin/build/menu/navigation', $options); + return confirm_form($form, t('Are you sure you want to reset the item %item to its default values?', array('%item' => $item['link_title'])), 'admin/build/menu', $options); } else { drupal_not_found(); diff --git a/modules/node/content_types.inc b/modules/node/content_types.inc index 8340544c5..d4999d637 100644 --- a/modules/node/content_types.inc +++ b/modules/node/content_types.inc @@ -392,9 +392,7 @@ function node_type_delete_confirm(&$form_state, $type) { $caption .= '<p>'. t('This action cannot be undone.') .'</p>'; - $options = array('description' => $caption); - - return confirm_form($form, $message, 'admin/content/types', $options); + return confirm_form($form, $message, 'admin/content/types', $caption, t('Delete')); } /** diff --git a/modules/node/node.module b/modules/node/node.module index e2ef093e3..2d7d19021 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1089,13 +1089,8 @@ function node_configure_validate($form, &$form_state) { * Menu callback: confirm rebuilding of permissions. */ function node_configure_rebuild_confirm() { - $options = array( - 'description' => t('This will wipe all current node permissions and rebuild them based on current settings. Rebuilding the permissions may take a while so please be patient. This action cannot be undone.'), - 'yes' => t('Rebuild permissions') - ); - return confirm_form(array(), t('Are you sure you want to rebuild node permissions on the site?'), - 'admin/content/node-settings', $options); + 'admin/content/node-settings', t('This will wipe all current node permissions and rebuild them based on current settings. Rebuilding the permissions may take a while so please be patient. This action cannot be undone.'), t('Rebuild permissions'), t('Cancel')); } /** @@ -1751,8 +1746,9 @@ function node_multiple_delete_confirm(&$form_state) { array( 'form' => $form, 'question' => t('Are you sure you want to delete these items?'), - 'destination' => 'admin/content/node', + 'path' => 'admin/content/node', 'yes' => t('Delete all'), + 'destination' => 'admin/content/node', ) ); } @@ -2435,25 +2431,25 @@ function node_form_submit($form, &$form_state) { * Menu callback -- ask for confirmation of node deletion */ function node_delete_confirm(&$form_state, $node) { + $form['nid'] = array('#type' => 'value', '#value' => $node->nid); - drupal_delete_initiate('node', $node->nid); - drupal_delete_add_callback( - array( - 'node_delete_post' => array($node->nid, $node->title, $node->type), - // Clear the cache so an anonymous poster can see the node being deleted. - 'cache_clear_all' => array(), - ) - ); + return confirm_form($form, + t('Are you sure you want to delete %title?', array('%title' => $node->title)), + isset($_GET['destination']) ? $_GET['destination'] : 'node/'. $node->nid, + t('This action cannot be undone.'), + t('Delete'), t('Cancel')); +} - node_delete($node->nid, FALSE); +/** + * Execute node deletion + */ +function node_delete_confirm_submit($form, &$form_state) { + if ($form_state['values']['confirm']) { + node_delete($form_state['values']['nid']); + } - return drupal_delete_confirm( - array( - 'question' => t('Are you sure you want to delete %title?', array('%title' => $node->title)), - 'cancel' => isset($_GET['destination']) ? $_GET['destination'] : 'node/'. $node->nid, - 'destination' => isset($_GET['destination']) ? $_GET['destination'] : '<front>', - ) - ); + $form_state['redirect'] = '<front>'; + return; } /** @@ -2464,23 +2460,23 @@ function node_delete($nid) { $node = node_load($nid); if (node_access('delete', $node)) { - drupal_delete_add_query('DELETE FROM {node} WHERE nid = %d', $node->nid); - drupal_delete_add_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {node} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid); // Call the node-specific callback (if any): node_invoke($node, 'delete'); node_invoke_nodeapi($node, 'delete'); - } -} -function node_delete_post($nid, $title, $type) { + // Clear the cache so an anonymous poster can see the node being deleted. + cache_clear_all(); - // Remove this node from the search index if needed. - if (function_exists('search_wipe')) { - search_wipe($nid, 'node'); + // Remove this node from the search index if needed. + if (function_exists('search_wipe')) { + search_wipe($node->nid, 'node'); + } + drupal_set_message(t('%title has been deleted.', array('%title' => $node->title))); + watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title)); } - drupal_set_message(t('%title has been deleted.', array('%title' => $title))); - watchdog('content', '@type: deleted %title.', array('@type' => t($type), '%title' => $title)); } /** diff --git a/modules/path/path.module b/modules/path/path.module index e709df0e8..cd0643402 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -89,14 +89,13 @@ function path_admin_edit($pid = 0) { /** * Menu callback; confirms deleting an URL alias **/ -function path_admin_delete_confirm(&$form_state, $pid) { +function path_admin_delete_confirm($pid) { $path = path_load($pid); if (user_access('administer url aliases')) { $form['pid'] = array('#type' => 'value', '#value' => $pid); - $options = array('cancel' => isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path'); $output = confirm_form($form, t('Are you sure you want to delete path alias %title?', array('%title' => $path['dst'])), - 'admin/build/path', $options); + isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path'); } return $output; } @@ -126,12 +125,12 @@ function path_admin_delete($pid = 0) { function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') { if ($path && !$alias) { // Delete based on path - drupal_delete_add_query("DELETE FROM {url_alias} WHERE src = '%s' AND language = '%s'", $path, $language); + db_query("DELETE FROM {url_alias} WHERE src = '%s' AND language = '%s'", $path, $language); drupal_clear_path_cache(); } else if (!$path && $alias) { // Delete based on alias - drupal_delete_add_query("DELETE FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $alias, $language); + db_query("DELETE FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $alias, $language); drupal_clear_path_cache(); } else if ($path && $alias) { diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 4a4141c51..15585d90a 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -91,9 +91,9 @@ function poll_cron() { * Implementation of hook_delete(). */ function poll_delete($node) { - drupal_delete_add_query('DELETE FROM {poll} WHERE nid = %d', $node->nid); - drupal_delete_add_query('DELETE FROM {poll_choices} WHERE nid = %d', $node->nid); - drupal_delete_add_query('DELETE FROM {poll_votes} WHERE nid = %d', $node->nid); + db_query("DELETE FROM {poll} WHERE nid = %d", $node->nid); + db_query("DELETE FROM {poll_choices} WHERE nid = %d", $node->nid); + db_query("DELETE FROM {poll_votes} WHERE nid = %d", $node->nid); } /** diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 74a27513d..66ab22967 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -398,10 +398,10 @@ function profile_field_delete(&$form_state, $fid) { $form['fid'] = array('#type' => 'value', '#value' => $fid); $form['title'] = array('#type' => 'value', '#value' => $field->title); - $options = array('description' => t('This action cannot be undone. If users have entered values into this field in their profile, these entries will also be deleted. If you want to keep the user-entered data, instead of deleting the field you may wish to <a href="@edit-field">edit this field</a> and change it to a hidden profile field so that it may only be accessed by administrators.', array('@edit-field' => url('admin/user/profile/edit/'. $fid)))); - return confirm_form($form, - t('Are you sure you want to delete the field %field?', array('%field' => $field->title)), 'admin/user/profile', $options); + t('Are you sure you want to delete the field %field?', array('%field' => $field->title)), 'admin/user/profile', + t('This action cannot be undone. If users have entered values into this field in their profile, these entries will also be deleted. If you want to keep the user-entered data, instead of deleting the field you may wish to <a href="@edit-field">edit this field</a> and change it to a hidden profile field so that it may only be accessed by administrators.', array('@edit-field' => url('admin/user/profile/edit/'. $fid))), + t('Delete'), t('Cancel')); } /** diff --git a/modules/search/search.module b/modules/search/search.module index 1ae52e456..d19b6cd4b 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -262,13 +262,8 @@ function search_admin_settings() { * Menu callback: confirm wiping of the index. */ function search_wipe_confirm() { - $options = array( - 'description' => t(' The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed. This action cannot be undone.'), - 'yes' => t('Re-index site') - ); - return confirm_form(array(), t('Are you sure you want to re-index the site?'), - 'admin/settings/search', $options); + 'admin/settings/search', t(' The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed. This action cannot be undone.'), t('Re-index site'), t('Cancel')); } /** diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 8973736e9..ce12dd15a 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -553,7 +553,7 @@ function statistics_nodeapi(&$node, $op, $arg = 0) { switch ($op) { case 'delete': // clean up statistics table when node is deleted - drupal_delete_add_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid); } } diff --git a/modules/system/system.module b/modules/system/system.module index 73f83cb13..cb14f61f0 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1690,18 +1690,14 @@ function system_modules_confirm_form($modules, $storage) { $form['text'] = array('#value' => theme('item_list', $items)); if ($form) { - $options = array( - 'description' => t('Would you like to continue with enabling the above?'), - 'yes' => t('Continue'), - ); - // Set some default form values $form = confirm_form( $form, t('Some required modules must be enabled'), 'admin/build/modules', - $options); - + t('Would you like to continue with enabling the above?'), + t('Continue'), + t('Cancel')); return $form; } } @@ -1991,17 +1987,13 @@ function system_modules_uninstall_confirm_form($storage) { $form['#confirmed'] = TRUE; $form['uninstall']['#tree'] = TRUE; $form['modules'] = array('#value' => '<p>'. t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') .'</p>'. theme('item_list', $uninstall)); - - $options = array( - 'description' => t('Would you like to continue with uninstalling the above?'), - 'yes' => t('Uninstall') - ); - $form = confirm_form( $form, t('Confirm uninstall'), 'admin/build/modules/uninstall', - $options); + t('Would you like to continue with uninstalling the above?'), + t('Uninstall'), + t('Cancel')); return $form; } } @@ -2484,72 +2476,50 @@ function system_node_type($op, $info) { * @param $question * The question to ask the user (e.g. "Are you sure you want to delete the * block <em>foo</em>?"). - * @param $destination - * The page to go to if the confirm form is submitted, or the action is cancelled. - * The value can be either a Drupal path, or an array with the keys 'path', 'query', 'fragment'. - * - * Note: If a custom submit handler is being used, return the destination from the handler. - * @param $options - * An associative array of options, with the following key/value pairs: - * 'description' => Additional text to display. - * Default is "This action cannot be undone". - * 'yes' => A caption for the button which confirms the action (e.g. "Confirm", - * "Replace", ...). Default is "Delete". - * 'no' => A caption for the link which denies the action (e.g. "Cancel"). - * Default is "Cancel". - * 'name' => The internal name used to refer to the confirmation item. - * Default is "confirm". - * 'cancel' => Set a custom path for cancelling the form, -- can be either a Drupal path, - * or an array with the keys 'path', 'query', 'fragment'. - * + * @param $path + * The page to go to if the user denies the action. + * Can be either a drupal path, or an array with the keys 'path', 'query', 'fragment'. + * @param $description + * Additional text to display (defaults to "This action cannot be undone."). + * @param $yes + * A caption for the button which confirms the action (e.g. "Delete", + * "Replace", ...). + * @param $no + * A caption for the link which denies the action (e.g. "Cancel"). + * @param $name + * The internal name used to refer to the confirmation item. * @return * The form. */ -function confirm_form($form, $question, $destination, $options = array()) { - $description = isset($options['description']) ? $options['description'] : t('This action cannot be undone.'); - $name = isset($options['name']) ? $options['name'] : 'confirm'; - $cancel = isset($options['cancel']) ? $options['cancel'] : $destination; +function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') { + $description = isset($description) ? $description : t('This action cannot be undone.'); // Prepare cancel link $query = $fragment = NULL; - if (is_array($cancel)) { - $query = isset($cancel['query']) ? $cancel['query'] : NULL; - $fragment = isset($cancel['fragment']) ? $cancel['fragment'] : NULL; - $path = isset($cancel['path']) ? $cancel['path'] : NULL; + if (is_array($path)) { + $query = isset($path['query']) ? $path['query'] : NULL; + $fragment = isset($path['fragment']) ? $path['fragment'] : NULL; + $path = isset($path['path']) ? $path['path'] : NULL; } - else { - $path = $cancel; - } - $cancel_link = l(isset($options['no']) ? $options['no'] : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment)); + $cancel = l($no ? $no : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment)); drupal_set_title($question); + // Confirm form fails duplication check, as the form values rarely change -- so skip it. + $form['#skip_duplicate_check'] = TRUE; + $form['#attributes'] = array('class' => 'confirmation'); $form['description'] = array('#value' => $description); $form[$name] = array('#type' => 'hidden', '#value' => 1); - $form['destination'] = array('#type' => 'value', '#value' => $destination); $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => isset($options['yes']) ? $options['yes'] : t('Delete')); - $form['actions']['cancel'] = array('#value' => $cancel_link); - + $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm')); + $form['actions']['cancel'] = array('#value' => $cancel); $form['#theme'] = 'confirm_form'; return $form; } /** - * Executes confirmation pages for the Deletion API. - */ -function delete_confirm_submit($form, &$form_state) { - if ($form_state['values']['delete']) { - drupal_delete_execute(); - } - if (isset($form_state['values']['destination'])) { - $form_state['redirect'] = $form_state['values']['destination']; - } -} - -/** * Determine if a user is in compact mode. */ function system_admin_compact_mode() { diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 71fc80bef..03c164b47 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -384,14 +384,13 @@ function taxonomy_vocabulary_confirm_delete(&$form_state, $vid) { $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); $form['vid'] = array('#type' => 'value', '#value' => $vid); $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name); - - $options = array('description' => t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.')); - return confirm_form($form, t('Are you sure you want to delete the vocabulary %title?', array('%title' => $vocabulary->name)), 'admin/content/taxonomy', - $options); + t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), + t('Delete'), + t('Cancel')); } function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) { @@ -621,14 +620,13 @@ function taxonomy_term_confirm_delete(&$form_state, $tid) { $form['type'] = array('#type' => 'value', '#value' => 'term'); $form['name'] = array('#type' => 'value', '#value' => $term->name); $form['tid'] = array('#type' => 'value', '#value' => $tid); - - $options = array('description' => t('Deleting a term will delete all its children if there are any. This action cannot be undone.')); - return confirm_form($form, t('Are you sure you want to delete the term %title?', array('%title' => $term->name)), 'admin/content/taxonomy', - $options); + t('Deleting a term will delete all its children if there are any. This action cannot be undone.'), + t('Delete'), + t('Cancel')); } function taxonomy_term_confirm_delete_submit($form, &$form_state) { @@ -878,14 +876,14 @@ function taxonomy_node_save($node, $terms) { * Remove associations of a node to its terms. */ function taxonomy_node_delete($node) { - drupal_delete_add_query('DELETE FROM {term_node} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {term_node} WHERE nid = %d', $node->nid); } /** * Remove associations of a node to its terms. */ function taxonomy_node_delete_revision($node) { - drupal_delete_add_query('DELETE FROM {term_node} WHERE vid = %d', $node->vid); + db_query('DELETE FROM {term_node} WHERE vid = %d', $node->vid); } /** diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 43ae3f2f3..f8ddc5f86 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -575,44 +575,31 @@ function upload_delete($node) { } foreach ($files as $fid => $file) { - // Delete all file revision information associated with the node - drupal_delete_add_query('DELETE FROM {files} WHERE fid = %d', $fid); + // Delete all files associated with the node + db_query('DELETE FROM {files} WHERE fid = %d', $fid); + file_delete($file->filepath); } - // Delete all files associated with the node - drupal_delete_add_query('DELETE FROM {upload} WHERE nid = %d', $node->nid); - - // Register a callback to delete the files. - drupal_delete_add_callback(array('upload_delete_post' => array($files))); + // Delete all file revision information associated with the node + db_query('DELETE FROM {upload} WHERE nid = %d', $node->nid); } function upload_delete_revision($node) { if (is_array($node->files)) { - $files = array(); foreach ($node->files as $file) { // Check if the file will be used after this revision is deleted $count = db_result(db_query('SELECT COUNT(fid) FROM {upload} WHERE fid = %d', $file->fid)); // if the file won't be used, delete it if ($count < 2) { - drupal_delete_add_query('DELETE FROM {files} WHERE fid = %d', $file->fid); - $files[$file->fid] = $file; + db_query('DELETE FROM {files} WHERE fid = %d', $file->fid); + file_delete($file->filepath); } } } - // Delete the revision. - drupal_delete_add_query('DELETE FROM {upload} WHERE vid = %d', $node->vid); - - // Register a callback to delete the files. - drupal_delete_add_callback(array('upload_delete_post' => array($files))); -} - -function upload_delete_post($files) { - foreach ($files as $file) { - // Delete all files associated with the node or revision. - file_delete($file->filepath); - } + // delete the revision + db_query('DELETE FROM {upload} WHERE vid = %d', $node->vid); } function _upload_form($node) { diff --git a/modules/user/user.module b/modules/user/user.module index 188884290..baab4e935 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1621,15 +1621,12 @@ function user_edit($form_state, $category = 'account') { return $form; } -function user_confirm_delete(&$form_state, $name, $uid) { - $options = array( - 'description' => t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.'), - 'cancel' => 'user/'. $uid, - ); +function user_confirm_delete($name, $uid) { + $options = array('description' => t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.')); return confirm_form(array(), t('Are you sure you want to delete the account %name?', array('%name' => $name)), - 'admin/user/user', + 'user/'. $uid, $options); } @@ -1863,7 +1860,10 @@ function user_admin_access_delete_confirm($aid = 0) { $form['aid'] = array('#type' => 'hidden', '#value' => $aid); $output = confirm_form($form, t('Are you sure you want to delete the @type rule for %rule?', array('@type' => $access_types[$edit->type], '%rule' => $edit->mask)), - 'admin/user/rules'); + 'admin/user/rules', + t('This action cannot be undone.'), + t('Delete'), + t('Cancel')); return $output; } @@ -2464,11 +2464,10 @@ function user_multiple_delete_confirm(&$form_state) { } $form['operation'] = array('#type' => 'hidden', '#value' => 'delete'); - $options = array('yes' => t('Delete all')); - return confirm_form($form, t('Are you sure you want to delete these users?'), - 'admin/user/user', $options); + 'admin/user/user', t('This action cannot be undone.'), + t('Delete all'), t('Cancel')); } function user_multiple_delete_confirm_submit($form, &$form_state) { |