You are here

function delete_all_drush_delete in Delete all 7

Same name and namespace in other branches
  1. 6 delete_all.drush.inc \delete_all_drush_delete()

Drush callback to delete content

1 string reference to 'delete_all_drush_delete'
delete_all_drush_command in ./delete_all.drush.inc
Implementation of hook_drush_command().

File

./delete_all.drush.inc, line 44
delete all Drush command

Code

function delete_all_drush_delete() {
  $types = func_get_args();
  if ($types) {
    if (in_array('users', $types)) {
      if (!$types[1] && drush_get_option('roles')) {
        $choices = user_roles();
        $role = drush_choice($choices, dt("Choose a role to delete."));
        if ($role == 0) {
          return;
        }
      }
      else {
        $role = $types[1];
        if (strpos($role, ',')) {
          $role = explode(',', $role);
        }
      }
      drush_print('Deleted ' . delete_all_users_delete($role) . ' users');
    }
    elseif (in_array('all', $types)) {
      db_query("DELETE FROM {url_alias} WHERE source LIKE 'node/%%'");
      drush_print('Deleted ' . _delete_all_normal(TRUE, FALSE) . ' nodes');
      if (drush_get_option('reset')) {
        db_query("ALTER TABLE node AUTO_INCREMENT=1");
        db_query("ALTER TABLE node_revision AUTO_INCREMENT=1");
        if (module_exists('comment')) {
          db_query("ALTER TABLE comment AUTO_INCREMENT=1");
          drush_print('All node, revision and comment counts have been reset.');
        }
        else {
          drush_print('All node and revision counts have been reset.');
        }
      }
    }
    else {
      $results = _delete_all_normal(FALSE, $types);
      foreach ($results as $type => $count) {
        drush_print('Deleted ' . $count . ' ' . $type);
      }
    }
  }
  else {
    drush_print('Content types and number of nodes:');

    // This should be refactored back into delete_all_content
    $result = db_query("SELECT type, COUNT(*) AS num FROM {node} GROUP BY type");
    $count = array();
    foreach ($result as $record) {
      $count[$record->type] = $record->num;
    }
    foreach (node_type_get_types() as $type => $info) {
      drush_print($info->type . ' ' . ($count[$type] + 0));
    }
  }
}