function delete_all_content in Delete all 7
Same name and namespace in other branches
- 5 delete_all.module \delete_all_content()
- 6 delete_all.module \delete_all_content()
2 string references to 'delete_all_content'
- delete_all_menu in ./delete_all.module
- @file
Delete all 7.x module
- delete_all_users in ./delete_all.module
File
- ./delete_all.module, line 47
- Delete all 7.x module
Code
function delete_all_content() {
$result = db_query("SELECT type, COUNT(*) AS num FROM {node} GROUP BY type");
$count = array();
foreach ($result as $data) {
$count[$data->type] = $data->num;
}
$types = array();
foreach (node_type_get_types() as $type => $info) {
if (array_key_exists($type, $count)) {
$types[$type] = $info->name . ' (' . $count[$type] . ')';
}
}
asort($types);
if (module_exists('taxonomy')) {
$result = db_query("SELECT taxonomy_vocabulary.machine_name AS vocabulary, COUNT(*) AS num FROM {taxonomy_vocabulary} INNER JOIN {taxonomy_term_data} USING (vid) GROUP BY vocabulary");
$taxocount = array();
foreach ($result as $data) {
$taxocount[$data->vocabulary] = $data->num;
}
$vocabularies = array();
foreach (taxonomy_get_vocabularies() as $vocabulary) {
$name = $vocabulary->machine_name;
if (array_key_exists($name, $taxocount)) {
$vocabularies[$name] = $vocabulary->name . ' (' . $taxocount[$name] . ')';
}
}
asort($vocabularies);
}
if (empty($types) && empty($vocabularies)) {
$form = array();
$form['no_content_types'] = array(
'#prefix' => '<p>',
'#suffix' => '</p>',
'#value' => t('There are no content types with content available to delete. You must <a href="@node-add">create some content</a> in order to delete it.', array(
'@node-add' => url('node/add'),
)),
);
if (module_exists('devel')) {
$form['generate_content_suggestion'] = array(
'#prefix' => '<p>',
'#suffix' => '</p>',
'#value' => t('You can generate content quickly at the <a href="@generate-content-page">generate content page</a>.', array(
'@generate-content-page' => url('admin/generate/content'),
)),
);
}
return $form;
}
drupal_add_js(drupal_get_path('module', 'delete_all') . '/delete_all.js');
$form = array();
$form['all'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => t('Delete All Content'),
'#description' => t('Select to delete all content'),
'#attributes' => array(
'class' => array(
'delete-all',
),
),
);
if (module_exists('taxonomy')) {
$form['taxonomy'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => t('Delete all Taxonomy'),
'#description' => t('Select to delete all taxonomy terms'),
'#attributes' => array(
'class' => array(
'delete-all',
),
),
);
}
$form['reset'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => t('Reset node count'),
'#description' => t('Select to reset the node count'),
'#attributes' => array(
'class' => array(
'delete-reset',
),
),
);
$form['type-fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Node types'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'types' => array(
'#type' => 'checkboxes',
'#options' => $types,
'#description' => t('Select the types of node content to delete'),
),
);
if (module_exists('taxonomy')) {
$form['taxonomy-fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Taxonomy'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'vocabularies' => array(
'#type' => 'checkboxes',
'#options' => $vocabularies,
'#description' => t('Select the taxonomy vocabularies to delete'),
),
);
}
$form['method-fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Method'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'method' => array(
'#type' => 'radios',
'#title' => t('Method'),
'#options' => array(
'normal' => t('Normal'),
'quick' => t('Quick'),
),
'#default_value' => 'normal',
'#description' => t('Normal node delete calls node_delete() on every node in the database. If you have only a few hundred nodes, this can take a very long time. Use the quick node delete method to get around this problem. This method deletes directly from the database, skipping the extra php processing. The downside is that it can miss related tables that are normally handled by module hook_delete\'s.'),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
);
$form['#action'] = url('admin/content/delete_content/confirm');
return $form;
}