Closed (fixed)
Project:
Drush
Version:
6.x-2.0-alpha2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
21 Jul 2009 at 09:45 UTC
Updated:
29 Jun 2010 at 00:05 UTC
hi i want to implement drush node delete but for some reason it dosen't work;
i get the printend message that the node was deleted but the deletion don't take place.
Any idea why?
here's the code:
<?php
/**
* Implementation of hook_drush_command().
*/
function mymodule_drush_command() {
$items = array();
$items['delete nodes'] = array(
'callback' => 'delete_nodes_callback',
'arguments' => array(
'nid' => 'node nid to be deleted.',
),
'description' => "delete nodes.",
);
return $items;
}
/**
* Implementation of hook_drush_help().
*/
function mymodule_drush_help($section) {
switch ($section) {
case 'drush:delete nodes':
return dt("delete nodes");
}
}
function delete_nodes_callback() {
$args = func_get_args();
if (count($args) > 0) {
foreach ($args as $nid) {
drush_print(dt('delete node #') . $nid);
node_delete($node->nid);
}
} else {
drush_die('no nids');
}
}
Comments
Comment #1
yhager commentedTry
node_delete($nid);Comment #2
yhager commentedAlso note this might not work if the anonymous user cannot delete nodes, since node_delete checks exactly that in its beginning.
Comment #3
bcmiller0 commentedyou can always run "drush -u admin" and then have rights to do as you wish
Comment #4
patoshi commentedhow would i use this as a drush command? what command do i type?
Comment #5
bcmiller0 commentedwell you could do 'drush -u admin php-eval "node_delete(12314);"' to delete nid=1234.
My point was just that you have to pass drush -u admin to run with admin permissions, or drush runs as an anonymous type user without permissions to do anything, as