Skip to content

Instantly share code, notes, and snippets.

@bjeavons
Created May 4, 2012 14:31
Show Gist options
  • Save bjeavons/2595133 to your computer and use it in GitHub Desktop.
Save bjeavons/2595133 to your computer and use it in GitHub Desktop.
<?php
function localdev_drush_command() {
$items = array();
$items['lcld'] = array(
'description' => 'Delete nodes',
'callback' => 'drush_lcld',
'options' => array(
'type' => 'node type',
),
);
return $items;
}
function drush_lcld() {
$type = drush_get_option('type');
if (!isset($type)) {
drush_set_error('missing argument type', 'Pass node type to delete');
return FALSE;
}
$nids = _localdev_get_nids_by_type($type);
$count = count($nids);
if ($count) {
$prompt = dt("Delete !count nodes?", array("!count" => $count));
if (drush_confirm($prompt)) {
node_delete_multiple($nids);
}
else {
drush_print("okay, not deleting");
}
}
}
function _localdev_get_nids_by_type($type) {
$nids = array();
$result = db_query('SELECT nid FROM {node} WHERE type = :type', array(':type' => $type));
foreach ($result as $record) {
$nids[] = $record->nid;
}
return $nids;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment