最后,我创建了自己的名为 drush_delete
在drush_delete.drush.inc
文件中放入以下代码:
<?php
/**
* @file
* The Drush Delete drush commands.
*/
/**
* Implements hook_drush_command().
*/
function drush_delete_drush_command() {
$items['node-delete'] = array(
'description' => dt("Delete nodes."),
'aliases' => array('nd'),
'arguments' => array(
'nids' => dt('The nids of the nodes to delete'),
),
'examples' => array(
'drush node-delete 1' => dt('Delete the node with nid = 1.'),
'drush node-delete 1 2 3' => dt('Delete the nodes with nid = 1, 2 and 3.'),
),
);
return $items;
}
/**
* Callback for the node-delete command
*/
function drush_drush_delete_node_delete() {
$nids = func_get_args();
$nids = array_filter($nids, 'is_numeric');
$nids = array_map('intval', $nids);
$nids = array_unique($nids);
$nids = array_values($nids);
$cant = count($nids);
if ($cant > 0) {
node_delete_multiple($nids);
drush_print(dt("Deleted nodes:"));
drush_print(implode(' ', $nids));
}
else {
drush_set_error('DRUSH_ERROR_CODE', dt("You must enter at least one nid"));
}
}
安装模块,运行drush cc drush
以清除刷新缓存,并使用如下命令:
要删除节点,请使用:
drush node-delete 1
drush nd 1
要删除多个节点,请使用:
drush node-delete 1 2 3
drush nd 1 2 3
您可以在以下模块中找到该命令:
https://github.com/adrian-cid/drush_commands