summaryrefslogtreecommitdiff
path: root/modules/node/node.module
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2007-06-22 05:44:21 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2007-06-22 05:44:21 +0000
commit38a1300df2005f9f054f19d8d2bd41518a8e7ad8 (patch)
tree0dc73c018fc63f74500593f7c533c902bbd5f54d /modules/node/node.module
parentc5443d739e8caa07a55080acc06d806c0d0758fa (diff)
downloadbrdo-38a1300df2005f9f054f19d8d2bd41518a8e7ad8.tar.gz
brdo-38a1300df2005f9f054f19d8d2bd41518a8e7ad8.tar.bz2
#147723: Deletion API (by hunmonk). Woop woop.
Diffstat (limited to 'modules/node/node.module')
-rw-r--r--modules/node/node.module184
1 files changed, 117 insertions, 67 deletions
diff --git a/modules/node/node.module b/modules/node/node.module
index c253610d9..7bc971b97 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1685,29 +1685,67 @@ function theme_node_admin_nodes($form) {
function node_multiple_delete_confirm(&$form_state) {
$edit = $form_state['post'];
- $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
- // array_filter returns only elements with TRUE values
- foreach (array_filter($edit['nodes']) as $nid => $value) {
- $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
- $form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#prefix' => '<li>', '#suffix' => check_plain($title) ."</li>\n");
+ $form['nodes']['#tree'] = TRUE;
+ $form['prefix'] = array('#value' => '<ul>');
+
+ // array_filter() returns only elements with TRUE values.
+ $nids = array_filter($edit['nodes']);
+ $nodes = db_query('SELECT nid, title, type FROM {node} WHERE nid IN(%s)', implode(', ', $nids));
+ while ($node = db_fetch_object($nodes)) {
+
+ // This is a placeholder -- preserves proper ordering in the confirm form.
+ $form["node_$node->nid"] = array();
+
+ // Start a new package for each node.
+ drupal_delete_initiate('node', $node->nid);
+
+ // Add the confirm form piece for this node.
+ drupal_delete_add_form_elements(
+ array(
+ "node_$node->nid" => array(
+ '#value' => check_plain($node->title),
+ '#prefix' => '<li>',
+ '#suffix' => "</li>\n",
+ ),
+ 'nodes' => array(
+ "node_$node->nid" => array(
+ '#type' => 'hidden',
+ '#value' => $node->nid,
+ )
+ )
+ )
+ );
+ drupal_delete_add_callback(array('node_delete_post' => array($node->nid, $node->title, $node->type)));
+ node_delete($node->nid);
}
- $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
+ $form['suffix'] = array('#value' => '</ul>');
+
+ $form['operation'] = array(
+ '#type' => 'hidden',
+ '#value' => 'delete',
+ );
- return confirm_form($form,
- t('Are you sure you want to delete these items?'),
- 'admin/content/node', t('This action cannot be undone.'),
- t('Delete all'), t('Cancel'));
+ // New package for the main admin callback.
+ drupal_delete_initiate('node', 'admin');
+
+ // Add the main callback for the mass deletion last.
+ drupal_delete_add_callback(array('node_multiple_delete_confirm_post' => array()));
+
+ return drupal_delete_confirm(
+ array(
+ 'form' => $form,
+ 'question' => t('Are you sure you want to delete these items?'),
+ 'path' => 'admin/content/node',
+ 'yes' => t('Delete all'),
+ 'destination' => 'admin/content/node',
+ )
+ );
}
-function node_multiple_delete_confirm_submit($form, &$form_state) {
- if ($form_state['values']['confirm']) {
- foreach ($form_state['values']['nodes'] as $nid => $value) {
- node_delete($nid);
- }
- drupal_set_message(t('The items have been deleted.'));
- }
- $form_state['redirect'] = 'admin/content/node';
- return;
+function node_multiple_delete_confirm_post() {
+ // Clear the cache so an anonymous poster can see the nodes being deleted.
+ cache_clear_all();
+ drupal_set_message(t('The items have been deleted.'));
}
/**
@@ -1789,32 +1827,44 @@ function node_revision_revert($nid, $revision) {
* revision is deleted.
*/
function node_revision_delete($nid, $revision) {
- if (user_access('administer nodes')) {
- $node = node_load($nid);
- if (node_access('delete', $node)) {
- // Don't delete the current revision
- if ($revision != $node->vid) {
- $node = node_load($nid, $revision);
-
- db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $nid, $revision);
- node_invoke_nodeapi($node, 'delete revision');
- drupal_set_message(t('Deleted %title revision %revision.', array('%title' => $node->title, '%revision' => $revision)));
- watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node->type, '%title' => $node->title, '%revision' => $revision));
- }
+ $node = node_load($nid);
- else {
- drupal_set_message(t('Deletion failed. You tried to delete the current revision.'));
- }
- if (db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', $nid)) > 1) {
- drupal_goto("node/$nid/revisions");
- }
- else {
- drupal_goto("node/$nid");
- }
+ if (user_access('administer nodes') && node_access('delete', $node)) {
+
+ // Don't delete the current revision
+ if ($revision != $node->vid) {
+ $node = node_load($nid, $revision);
+
+ drupal_delete_initiate('node_revision', $revision);
+ drupal_delete_add_callback(array('node_revision_delete_post' => array($node, $revision)));
+ drupal_delete_add_query('DELETE FROM {node_revisions} WHERE vid = %d', $revision);
+ node_invoke_nodeapi($node, 'delete revision');
+ drupal_delete_execute();
+ }
+ else {
+ drupal_set_message(t('Deletion failed. You tried to delete the current revision.'));
}
}
+ else {
+ drupal_access_denied();
+ }
+}
- drupal_access_denied();
+/**
+ * Post revision deletion opertations.
+ */
+function node_revision_delete_post($node, $revision) {
+
+ drupal_set_message(t('Deleted %title revision %revision.', array('%title' => $node->title, '%revision' => $revision)));
+ watchdog('content', '@type: deleted %title revision %revision.', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $revision));
+
+
+ if (db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', $node->nid)) > 1) {
+ drupal_goto("node/$node->nid/revisions");
+ }
+ else {
+ drupal_goto("node/$node->nid");
+ }
}
/**
@@ -2371,25 +2421,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);
- 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'));
-}
+ 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(),
+ )
+ );
-/**
- * Execute node deletion
- */
-function node_delete_confirm_submit($form, &$form_state) {
- if ($form_state['values']['confirm']) {
- node_delete($form_state['values']['nid']);
- }
+ node_delete($node->nid, FALSE);
- $form_state['redirect'] = '<front>';
- return;
+ return drupal_delete_confirm(
+ array(
+ 'question' => t('Are you sure you want to delete %title?', array('%title' => $node->title)),
+ 'path' => isset($_GET['destination']) ? $_GET['destination'] : 'node/'. $node->nid,
+ 'destination' => isset($_GET['destination']) ? $_GET['destination'] : '<front>',
+ )
+ );
}
/**
@@ -2400,23 +2450,23 @@ function node_delete($nid) {
$node = node_load($nid);
if (node_access('delete', $node)) {
- db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
- db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
+ 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);
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
node_invoke_nodeapi($node, 'delete');
+ }
+}
- // Clear the cache so an anonymous poster can see the node being deleted.
- cache_clear_all();
+function node_delete_post($nid, $title, $type) {
- // 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));
+ // Remove this node from the search index if needed.
+ if (function_exists('search_wipe')) {
+ search_wipe($nid, 'node');
}
+ drupal_set_message(t('%title has been deleted.', array('%title' => $title)));
+ watchdog('content', '@type: deleted %title.', array('@type' => t($type), '%title' => $title));
}
/**