0

我正在尝试使用 Drush 根据其标题删除 Drupal 节点。

我正在调用的delete_poi.php脚本如下所示:

<?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);
}

我正在使用的 Drush 命令是:

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

运行脚本时,我得到以下输出(我也尝试过使用 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

我一直在关注脚本https://coderwall.com/p/stbxbw的本教程,并且一直在搜索 Drupal 论坛和 Stackexchange 以寻找答案,但未能找到解决方案。

我猜测引导 Drupal 存在问题,因为 Drupal API(如 db_query)的方法无法识别。当我尝试使用 启用模块时drush en module_name,出现以下错误:

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       

你有什么想法吗?如果您需要更多信息,请告诉我。

4

0 回答 0