You are here

function delete_all_content in Delete all 5

Same name and namespace in other branches
  1. 6 delete_all.module \delete_all_content()
  2. 7 delete_all.module \delete_all_content()

Original delete_all functions *

2 string references to 'delete_all_content'
delete_all_menu in ./delete_all.module
delete_all_users in ./delete_all.module

File

./delete_all.module, line 188

Code

function delete_all_content() {
  drupal_add_js(drupal_get_path('module', 'delete_all') . '/delete_all.js');
  $form = array();
  $form['all'] = array(
    '#type' => 'checkbox',
    '#default_value' => TRUE,
    '#title' => t('Delete All Content'),
    '#description' => t('Select to delete all content'),
    '#attributes' => array(
      'class' => 'delete-all',
    ),
  );

  // count how many nodes we have of each type
  $result = db_query("SELECT type, COUNT(*) AS num FROM {node} GROUP BY type");
  $count = array();
  while ($data = db_fetch_object($result)) {
    $count[$data->type] = $data->num;
  }

  // add the types to the form
  $types = array();
  foreach (node_get_types() as $type => $info) {
    if ($count[$type] > 0) {
      $types[$type] = $info->name . ' (' . $count[$type] . ')';
    }
  }
  asort($types);
  $form['type-fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Types'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    'types' => array(
      '#type' => 'checkboxes',
      '#options' => $types,
      '#description' => t('Select the types of content to delete'),
      '#theme' => 'delete_all_checkboxes',
    ),
  );
  $form['method-fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Method'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '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['confirm'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete Confirmation'),
    '#description' => t('Please check this box to confirm that you understand you are deleting node content.  This should only be done in a development environment.'),
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
  );
  $form['#submit'] = array(
    'delete_all_content_submit' => array(),
  );
  return $form;
}