You are here

function delete_all_content_submit in Delete all 5

File

./delete_all.module, line 277

Code

function delete_all_content_submit($form_id, &$form) {
  $types = array();
  if (!$form['all']) {
    foreach ($form['types'] as $type => $checked) {
      if ($checked) {
        $types[] = $type;
      }
    }
  }
  switch ($form['method']) {
    case 'normal':
      $count = _delete_all_normal($form['all'], $types);
      break;
    case 'quick':

      // the quick method doesn't support an all option,
      // so just get all the content types and delete all of those
      if ($form['all']) {
        $result = db_query("SELECT DISTINCT type FROM {node}");
        while ($data = db_fetch_object($result)) {
          $types[] = $type;
        }
      }
      $count = _delete_all_quick($types);
      break;
  }
  if ($form['all']) {

    // Delete the URL aliases
    db_query("DELETE FROM {url_alias} WHERE src LIKE 'node/%%'");

    // Reset the sequences
    db_query("UPDATE {sequences} SET id = 1 WHERE name = 'node_nid'");
    db_query("UPDATE {sequences} SET id = 1 WHERE name = 'comment_cid'");
    drupal_set_message(t('All nodes, comments and URL aliases have been deleted. Number of nodes deleted: !count.', array(
      '!count' => $count,
    )));
  }
  else {
    drupal_set_message(t('Nodes and comments of type @type have been deleted. Number of nodes deleted: !count.', array(
      '!count' => $count,
      '@type' => implode(', ', $types),
    )));
  }
  drupal_goto('admin');
}