Created
May 4, 2012 14:31
-
-
Save bjeavons/2595133 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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