| 1 |
<?php |
<?php |
| 2 |
// $Id: delete_all.module,v 1.1.2.8 2008/03/04 18:23:43 douggreen Exp $ |
// $Id: delete_all.module,v 1.1.2.9 2008/05/27 22:16:07 kbahey Exp $ |
| 3 |
|
|
| 4 |
function delete_all_menu($maycache) { |
function delete_all_menu($maycache) { |
| 5 |
$items = array(); |
$items = array(); |
| 21 |
'callback arguments' => array('delete_all_users'), |
'callback arguments' => array('delete_all_users'), |
| 22 |
'access' => user_access('administer users'), |
'access' => user_access('administer users'), |
| 23 |
'type' => MENU_NORMAL_ITEM); |
'type' => MENU_NORMAL_ITEM); |
| 24 |
|
|
| 25 |
|
// Bulk Delete Form |
| 26 |
|
$items[] = array( |
| 27 |
|
'path' => 'admin/settings/bulk_delete', |
| 28 |
|
'title' => t('Bulk delete'), |
| 29 |
|
'description' => t('Bulk deletes nodes, taxonomy terms and users based on the their types.'), |
| 30 |
|
'callback' => 'drupal_get_form', |
| 31 |
|
'callback arguments' => array('delete_all_bulk_delete_content'), |
| 32 |
|
'access' => user_access('administer content'), |
| 33 |
|
'type' => MENU_NORMAL_ITEM |
| 34 |
|
); |
| 35 |
|
|
| 36 |
|
// Bulk Delete Complete |
| 37 |
|
$items[] = array( |
| 38 |
|
'title' => t('Items Deleted'), |
| 39 |
|
'path' => 'admin/settings/bulk_delete/complete', |
| 40 |
|
'callback' => 'delete_all_bulk_delete_content_complete', |
| 41 |
|
'type' => MENU_CALLBACK, |
| 42 |
|
'access' => user_access('administer content') |
| 43 |
|
); |
| 44 |
return $items; |
return $items; |
| 45 |
} |
} |
| 46 |
|
|
| 47 |
|
/** |
| 48 |
|
* Form function for bulk delete content page |
| 49 |
|
**/ |
| 50 |
|
function delete_all_bulk_delete_content($form_values = array()) { |
| 51 |
|
$form_id = 'delete_all_bulk_delete_content'; |
| 52 |
|
$form = array(); |
| 53 |
|
//Fieldset for deleting taxonomy forms |
| 54 |
|
$form['taxonomy'] = array( |
| 55 |
|
'#type' => 'fieldset', |
| 56 |
|
'#access' => user_access('administer content'), |
| 57 |
|
'#title' => t('Delete Taxonomy Terms'), |
| 58 |
|
'#collapsible' => FALSE |
| 59 |
|
); |
| 60 |
|
$form['taxonomy']['vocabulary'] = array( |
| 61 |
|
'#title' => t('Taxonomy Vocabulary'), |
| 62 |
|
'#type' => 'checkboxes', |
| 63 |
|
'#description' => t('Select which taxonomy vocabulary terms you wish to delete. This will not delete the vocabulary, only the terms within the vocabulary.'), |
| 64 |
|
'#options' => _delete_all_get_vocabulary() |
| 65 |
|
); |
| 66 |
|
//Fieldset for deleting nodes |
| 67 |
|
$form['nodes'] = array( |
| 68 |
|
'#type' => 'fieldset', |
| 69 |
|
'#access' => user_access('administer content'), |
| 70 |
|
'#title' => t('Delete Nodes'), |
| 71 |
|
'#collapsible' => FALSE |
| 72 |
|
); |
| 73 |
|
$form['nodes']['node_types'] = array( |
| 74 |
|
'#type' => 'checkboxes', |
| 75 |
|
'#title' => t('Node types to delete'), |
| 76 |
|
'#description' => t('Select which node types you wish to delete'), |
| 77 |
|
'#options' => _delete_all_get_node_types() |
| 78 |
|
); |
| 79 |
|
return confirm_form( |
| 80 |
|
$form, |
| 81 |
|
t('Are you sure you wish to delete the content?'), |
| 82 |
|
'admin/settings/bulk_delete', |
| 83 |
|
'Are you sure you wish to delete the items?', |
| 84 |
|
t('Delete'), |
| 85 |
|
t('Cancel'), |
| 86 |
|
'delete_all_bulk_delete_content_confirm' |
| 87 |
|
); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
/** |
| 91 |
|
* Implementation of hook_submit for bulk_delete_content form |
| 92 |
|
**/ |
| 93 |
|
function delete_all_bulk_delete_content_submit($form_id,$form_values) { |
| 94 |
|
//TODO: Display message with deletion statistics |
| 95 |
|
//Iterate and delete any taxonomy terms if present |
| 96 |
|
if(isset($form_values['vocabulary'])) { |
| 97 |
|
$vocabulary = $form_values['vocabulary']; |
| 98 |
|
foreach($vocabulary as $v) { |
| 99 |
|
if($v > 0) { |
| 100 |
|
//Get Vocabulary Info for message. |
| 101 |
|
$vocabulary_info = taxonomy_get_vocabulary($v); |
| 102 |
|
//Get Array of terms to delete |
| 103 |
|
$terms = _delete_all_get_terms_by_vid($v); |
| 104 |
|
//Iterate through terms and delete them |
| 105 |
|
foreach($terms as $term) { |
| 106 |
|
taxonomy_del_term($term); |
| 107 |
|
} |
| 108 |
|
drupal_set_message("You have deleted " . count($terms) . ' terms of type ' . $vocabulary_info->name . '.'); |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
} |
| 112 |
|
//Iterate and delete nodes by type |
| 113 |
|
if(isset($form_values['node_types'])) { |
| 114 |
|
$node_types = $form_values['node_types']; |
| 115 |
|
//$nodes = array(); |
| 116 |
|
foreach($node_types as $t) { |
| 117 |
|
if(gettype($t) == 'string') { |
| 118 |
|
$nodes = _delete_all_get_nodes_by_type($t); |
| 119 |
|
foreach($nodes as $n) { |
| 120 |
|
node_delete($n); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
} |
| 124 |
|
} |
| 125 |
|
return "admin/settings/bulk_delete/complete"; |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
/** |
| 129 |
|
* Function to display deletion complete message |
| 130 |
|
**/ |
| 131 |
|
function delete_all_bulk_delete_content_complete() { |
| 132 |
|
return t("Request has successfully been completed!"); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
/** |
| 136 |
|
* Function to get an array of terms by vocabulary |
| 137 |
|
* |
| 138 |
|
* TODO: Is this an API function I couldn't find? |
| 139 |
|
**/ |
| 140 |
|
function _delete_all_get_terms_by_vid($vid) { |
| 141 |
|
$terms = array(); |
| 142 |
|
$result = db_query('SELECT t.tid from {term_data} t WHERE t.vid = %d',$vid); |
| 143 |
|
while($term = db_fetch_object($result)) { |
| 144 |
|
$terms[] = $term->tid; |
| 145 |
|
} |
| 146 |
|
return $terms; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
/** |
| 150 |
|
* Function to get an array of nodes by type |
| 151 |
|
* |
| 152 |
|
* TODO: Is this an API function I couldn't find? |
| 153 |
|
**/ |
| 154 |
|
function _delete_all_get_nodes_by_type($type) { |
| 155 |
|
$nodes = array(); |
| 156 |
|
$result = db_query("SELECT n.nid from {node} n WHERE n.type = '%s'",$type); |
| 157 |
|
while($node = db_fetch_object($result)) { |
| 158 |
|
$nodes[] = $node->nid; |
| 159 |
|
} |
| 160 |
|
return $nodes; |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
/** |
| 164 |
|
* Function to get array of taxonomy terms |
| 165 |
|
**/ |
| 166 |
|
function _delete_all_get_vocabulary() { |
| 167 |
|
$terms = taxonomy_get_vocabularies(); |
| 168 |
|
$options = array(); |
| 169 |
|
foreach($terms as $term) { |
| 170 |
|
$options[$term->vid] = $term->name; |
| 171 |
|
} |
| 172 |
|
return $options; |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
/** |
| 176 |
|
* Function to get an array of node types |
| 177 |
|
**/ |
| 178 |
|
function _delete_all_get_node_types() { |
| 179 |
|
$node_types = node_get_types(); |
| 180 |
|
$options = array(); |
| 181 |
|
foreach($node_types as $nt) { |
| 182 |
|
$options[$nt->type] = $nt->name; |
| 183 |
|
} |
| 184 |
|
return $options; |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
/** Original delete_all functions **/ |
| 189 |
function delete_all_content() { |
function delete_all_content() { |
| 190 |
drupal_add_js(drupal_get_path('module', 'delete_all') .'/delete_all.js'); |
drupal_add_js(drupal_get_path('module', 'delete_all') .'/delete_all.js'); |
| 191 |
$form = array(); |
$form = array(); |