function _delete_all_quick in Delete all 6
Same name and namespace in other branches
- 5 delete_all.module \_delete_all_quick()
- 7 delete_all.module \_delete_all_quick()
1 call to _delete_all_quick()
- delete_all_content_confirm_submit in ./delete_all.module
File
- ./delete_all.module, line 257
Code
function _delete_all_quick($types) {
$deleted = 0;
foreach ($types as $type) {
set_time_limit(240);
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = '%s'", $type));
if ($count) {
$nid_vid = array(
'nid',
'vid',
);
$nid = array(
'nid',
);
$tables = array(
'node_revisions' => $nid_vid,
'comments' => $nid,
);
$tables[_content_tablename($type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE)] = $nid_vid;
$content = content_types($type);
if (count($content['fields'])) {
foreach ($content['fields'] as $field) {
$field_info = content_database_info($field);
$tables[$field_info['table']] = $nid_vid;
}
}
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$result_tables = db_query("SHOW TABLES");
while ($data = db_fetch_array($result_tables)) {
$table = array_pop($data);
if (isset($tables[$table]) || substr($table, 0, 8) == 'content_') {
continue;
}
$result_cols = db_query("SHOW COLUMNS FROM %s", $table);
$cols = array();
while ($data = db_fetch_array($result_cols)) {
$cols[$data['Field']] = $data;
}
if (isset($cols['nid'])) {
$tables[$table] = isset($cols['vid']) ? $nid_vid : $nid;
}
}
break;
case 'pgsql':
break;
}
$sql = array(
'delete' => array(),
'from' => array(),
'where' => array(),
);
$index = 0;
foreach ($tables as $table => $cols) {
$table = '{' . $table . '}';
$sql['cols'][] = "t{$index}.*";
$on = array();
foreach ($cols as $col) {
$on[] = "t{$index}.{$col} = n.{$col}";
}
$sql['join'][] = " LEFT JOIN {$table} t{$index} ON " . implode(' AND ', $on);
$index++;
}
$delete_sql = "DELETE n.*, " . implode(', ', $sql['cols']) . " FROM {node} n " . implode(' ', $sql['join']);
db_query($delete_sql . " WHERE n.type = '%s'", $type);
$deleted += $count;
}
}
return $deleted;
}