0

I'm trying to delete a Drupal node based on its title with Drush.

The delete_poi.php script I'm calling looks like this:

<?php
// get the name of the POI that is entered with the Drush command
$poi_title = drush_get_option('poi');

// query the database for the node with type poi and title poi_title and delete it
$sql = db_query("SELECT nid FROM node WHERE title = '" . $poi_title . "';");
while ($node = db_fetch_object($sql)) {
   node_delete($node->nid);
   drush_print('deleted poi ' . $node->title);
}

The Drush command I'm using is:

drush scr delete_poi.php --poi='Historium'

When running the script, I get the following output (I have also tried using php-script):

Drush command terminated abnormally due to an unrecoverable error.                                                                                       
Error: Call to undefined function db_query() in /vagrant/site/delete_poi.php, line 6

I have been following this tutorial for the script https://coderwall.com/p/stbxbw, and have been searching the Drupal forums and Stackexchange for an answer, but haven't been able to find a solution.

I'm guessing there's a problem with bootstrapping Drupal, since methods of the Drupal API (like db_query) are not recognized. When I try to enable modules with drush en module_name, I get the following error:

Command pm-enable needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment to run this command.
The drush command 'en delete_all' could not be executed.                                                             
A Drupal installation directory could not be found       

Have you got any ideas? Let me know if you need more info.

silvdb
  • 193
  • 1
  • 4
  • 11
  • Follow as example this module: https://www.drupal.org/project/delete_all as we don't have idea what you did behind code you provided. – hugronaphor Jul 08 '14 at 16:14
  • Thanks, @CornelAndreev, that module might come in handy. I have tried installing and enabling it with Drush however, and I get the `Command pm-enable needs a higher bootstrap level to run` error when trying to enable it. – silvdb Jul 09 '14 at 07:19

0 Answers0