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

yhager’s picture

Status: Active » Closed (fixed)

Try node_delete($nid);

yhager’s picture

Also note this might not work if the anonymous user cannot delete nodes, since node_delete checks exactly that in its beginning.

bcmiller0’s picture

you can always run "drush -u admin" and then have rights to do as you wish

patoshi’s picture

how would i use this as a drush command? what command do i type?

bcmiller0’s picture

well 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