Commit b4644f8e authored by Dries's avatar Dries

- Patch #36250 by hunmonk: admin batch delete broken, node_delete needs reworked.

  This commit changes the node_delete() API.  A list of affected modules is available at http://drupal.org/node/36250#comment-52963.
parent 2ad97f02
......@@ -318,7 +318,7 @@ function blogapi_blogger_delete_post($appkey, $postid, $username, $password, $co
return blogapi_error($user);
}
node_delete(array('nid' => $postid, 'confirm' => 1));
node_delete($postid);
return true;
}
......
......@@ -318,7 +318,7 @@ function blogapi_blogger_delete_post($appkey, $postid, $username, $password, $co
return blogapi_error($user);
}
node_delete(array('nid' => $postid, 'confirm' => 1));
node_delete($postid);
return true;
}
......
......@@ -154,9 +154,7 @@ function forum_taxonomy($op, $type, $object = NULL) {
if ($op == 'delete' && $type == 'term' && $object->vid == _forum_get_vid()) {
$results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $object->tid);
while ($node = db_fetch_object($results)) {
$edit['nid'] = $node->nid;
$edit['confirm'] = TRUE;
node_delete($edit);
node_delete($node->nid);
}
}
elseif ($op == 'delete' && $type == 'vocabulary' && $object->vid == _forum_get_vid()) {
......
......@@ -154,9 +154,7 @@ function forum_taxonomy($op, $type, $object = NULL) {
if ($op == 'delete' && $type == 'term' && $object->vid == _forum_get_vid()) {
$results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $object->tid);
while ($node = db_fetch_object($results)) {
$edit['nid'] = $node->nid;
$edit['confirm'] = TRUE;
node_delete($edit);
node_delete($node->nid);
}
}
elseif ($op == 'delete' && $type == 'vocabulary' && $object->vid == _forum_get_vid()) {
......
......@@ -900,7 +900,7 @@ function node_menu($may_cache) {
'weight' => 1,
'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'node/'. arg(1) .'/delete', 'title' => t('delete'),
'callback' => 'node_delete_page',
'callback' => 'node_delete_confirm',
'access' => node_access('delete', $node),
'weight' => 1,
'type' => MENU_CALLBACK);
......@@ -1103,8 +1103,8 @@ function node_admin_nodes_execute($form_id, $edit) {
}
}
drupal_set_message(t('The update has been performed.'));
drupal_goto('admin/node');
}
drupal_goto('admin/node');
}
function node_admin_nodes_validate($form_id, $edit) {
......@@ -1192,11 +1192,11 @@ function theme_node_admin_nodes($form) {
function node_multiple_delete_form() {
global $form_values;
$form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>');
$form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
foreach ($form_values['nodes'] as $nid => $value) {
if ($value) {
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
$form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#tree' => TRUE, '#prefix' => '<li>', '#suffix' => check_plain($title) .'</li>');
$form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#prefix' => '<li>', '#suffix' => check_plain($title) .'</li>');
}
}
$form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
......@@ -1211,7 +1211,7 @@ function node_multiple_delete_form() {
function node_multiple_delete_form_execute($form_id, $edit) {
if ($edit['confirm']) {
foreach ($edit['nodes'] as $nid => $value) {
node_delete(array('nid' => $nid, 'confirm' => 1));
node_delete($nid);
}
drupal_set_message(t('The items have been deleted.'));
}
......@@ -1833,13 +1833,15 @@ function node_form_execute($form_id, $edit) {
}
/**
* Ask for confirmation, and delete the node.
* Menu callback -- ask for confirmation of node deletion
*/
function node_delete($edit) {
function node_delete_confirm() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$node = node_load($edit['nid']);
if (node_access('delete', $node)) {
$form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
$form['nid'] = array('#type' => 'value', '#value' => $node->nid);
$output = confirm_form('node_delete_confirm', $form,
t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $node->title))),
$_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid, t('This action cannot be undone.'),
......@@ -1849,32 +1851,41 @@ function node_delete($edit) {
return $output;
}
function node_delete_confirm_execute() {
global $form_values;
$node = node_load($form_values['nid']);
/**
* Execute node deletion
*/
function node_delete_confirm_execute($form_id, $form_values) {
if ($form_values['confirm']) {
node_delete($form_values['nid']);
drupal_goto('node');
}
}
if (node_access('delete', $node)) {
/**
* Delete a node.
*/
function node_delete($nid) {
if ($form_values['confirm']) {
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
$node = node_load($nid);
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
node_invoke_nodeapi($node, 'delete');
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);
// Clear the cache so an anonymous poster can see the node being deleted.
cache_clear_all();
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
node_invoke_nodeapi($node, 'delete');
// Remove this node from the search index if needed.
if (function_exists('search_wipe')) {
search_wipe($node->nid, 'node');
}
// Clear the cache so an anonymous poster can see the node being deleted.
cache_clear_all();
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))));
// 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' => theme('placeholder', $node->title))));
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))));
}
drupal_goto('node');
}
/**
......@@ -1995,20 +2006,6 @@ function node_page() {
}
}
/**
* Menu callback; the page for deleting a single node.
*/
function node_delete_page() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$node = node_load($edit['nid']);
if (!($output = node_delete($edit))) {
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', $node->title))));
drupal_goto('');
}
return $output;
}
/**
* Implementation of hook_update_index().
*/
......
......@@ -900,7 +900,7 @@ function node_menu($may_cache) {
'weight' => 1,
'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'node/'. arg(1) .'/delete', 'title' => t('delete'),
'callback' => 'node_delete_page',
'callback' => 'node_delete_confirm',
'access' => node_access('delete', $node),
'weight' => 1,
'type' => MENU_CALLBACK);
......@@ -1103,8 +1103,8 @@ function node_admin_nodes_execute($form_id, $edit) {
}
}
drupal_set_message(t('The update has been performed.'));
drupal_goto('admin/node');
}
drupal_goto('admin/node');
}
function node_admin_nodes_validate($form_id, $edit) {
......@@ -1192,11 +1192,11 @@ function theme_node_admin_nodes($form) {
function node_multiple_delete_form() {
global $form_values;
$form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>');
$form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
foreach ($form_values['nodes'] as $nid => $value) {
if ($value) {
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
$form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#tree' => TRUE, '#prefix' => '<li>', '#suffix' => check_plain($title) .'</li>');
$form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#prefix' => '<li>', '#suffix' => check_plain($title) .'</li>');
}
}
$form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
......@@ -1211,7 +1211,7 @@ function node_multiple_delete_form() {
function node_multiple_delete_form_execute($form_id, $edit) {
if ($edit['confirm']) {
foreach ($edit['nodes'] as $nid => $value) {
node_delete(array('nid' => $nid, 'confirm' => 1));
node_delete($nid);
}
drupal_set_message(t('The items have been deleted.'));
}
......@@ -1833,13 +1833,15 @@ function node_form_execute($form_id, $edit) {
}
/**
* Ask for confirmation, and delete the node.
* Menu callback -- ask for confirmation of node deletion
*/
function node_delete($edit) {
function node_delete_confirm() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$node = node_load($edit['nid']);
if (node_access('delete', $node)) {
$form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
$form['nid'] = array('#type' => 'value', '#value' => $node->nid);
$output = confirm_form('node_delete_confirm', $form,
t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $node->title))),
$_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid, t('This action cannot be undone.'),
......@@ -1849,32 +1851,41 @@ function node_delete($edit) {
return $output;
}
function node_delete_confirm_execute() {
global $form_values;
$node = node_load($form_values['nid']);
/**
* Execute node deletion
*/
function node_delete_confirm_execute($form_id, $form_values) {
if ($form_values['confirm']) {
node_delete($form_values['nid']);
drupal_goto('node');
}
}
if (node_access('delete', $node)) {
/**
* Delete a node.
*/
function node_delete($nid) {
if ($form_values['confirm']) {
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
$node = node_load($nid);
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
node_invoke_nodeapi($node, 'delete');
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);
// Clear the cache so an anonymous poster can see the node being deleted.
cache_clear_all();
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
node_invoke_nodeapi($node, 'delete');
// Remove this node from the search index if needed.
if (function_exists('search_wipe')) {
search_wipe($node->nid, 'node');
}
// Clear the cache so an anonymous poster can see the node being deleted.
cache_clear_all();
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))));
// 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' => theme('placeholder', $node->title))));
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))));
}
drupal_goto('node');
}
/**
......@@ -1995,20 +2006,6 @@ function node_page() {
}
}
/**
* Menu callback; the page for deleting a single node.
*/
function node_delete_page() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$node = node_load($edit['nid']);
if (!($output = node_delete($edit))) {
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', $node->title))));
drupal_goto('');
}
return $output;
}
/**
* Implementation of hook_update_index().
*/
......
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