| 62 |
'#theme' => 'delete_all_checkboxes', |
'#theme' => 'delete_all_checkboxes', |
| 63 |
), |
), |
| 64 |
); |
); |
| 65 |
$form['method'] = array( |
$form['method-fieldset'] = array( |
| 66 |
'#type' => 'select', |
'#type' => 'fieldset', |
| 67 |
'#title' => t('Method'), |
'#title' => t('Method'), |
| 68 |
'#options' => array('normal' => t('Normal'), 'quick' => t('Quick')), |
'#collapsible' => TRUE, |
| 69 |
'#default_value' => 'normal', |
'#collapsed' => TRUE, |
| 70 |
'#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.'), |
'method' => array( |
| 71 |
|
'#type' => 'radios', |
| 72 |
|
'#title' => t('Method'), |
| 73 |
|
'#options' => array('normal' => t('Normal'), 'quick' => t('Quick')), |
| 74 |
|
'#default_value' => 'normal', |
| 75 |
|
'#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.'), |
| 76 |
|
), |
| 77 |
); |
); |
| 78 |
$form['confirm'] = array( |
$form['confirm'] = array( |
| 79 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 178 |
function _delete_all_quick($types) { |
function _delete_all_quick($types) { |
| 179 |
$deleted = 0; |
$deleted = 0; |
| 180 |
foreach ($types as $type) { |
foreach ($types as $type) { |
| 181 |
|
// keep this alive |
| 182 |
|
set_time_limit(240); |
| 183 |
|
|
| 184 |
// determine how many items will be deleted |
// determine how many items will be deleted |
| 185 |
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = '%s'", $type)); |
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = '%s'", $type)); |
| 186 |
if ($count) { |
if ($count) { // should always be positive |
| 187 |
/** |
/** |
| 188 |
* build a list of tables that need to be deleted from |
* build a list of tables that need to be deleted from |
| 189 |
* |
* |
| 193 |
|
|
| 194 |
$nid_vid = array('nid', 'vid'); |
$nid_vid = array('nid', 'vid'); |
| 195 |
$nid = array('nid'); |
$nid = array('nid'); |
| 196 |
$tables = array('node_revisions' => $nid_vid, $comments => $nid); |
$tables = array('node_revisions' => $nid_vid, 'comments' => $nid); |
| 197 |
$tables[_content_tablename($type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE)] = $nid_vid; |
$tables[_content_tablename($type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE)] = $nid_vid; |
| 198 |
$content = content_types($type); |
$content = content_types($type); |
| 199 |
if (count($content->fields)) { |
if (count($content->fields)) { |
| 203 |
} |
} |
| 204 |
} |
} |
| 205 |
|
|
| 206 |
// find all other related modules that might be related |
// find all other tables that might be related |
| 207 |
// @TODO: inspect the database and look for nid fields |
switch ($GLOBALS['db_type']) { |
| 208 |
if (module_exists('og')) { |
case 'mysql': |
| 209 |
$tables['og'] = $nid; |
case 'mysqli': |
| 210 |
$tables['og_uid'] = $nid; |
$result_tables = db_query("SHOW TABLES"); |
| 211 |
$tables['og_ancestry'] = $nid; |
while ($data = db_fetch_array($result_tables)) { |
| 212 |
|
$table = array_pop($data); |
| 213 |
|
if (isset($tables[$table]) || substr($table, 0, 8) == 'content_') { |
| 214 |
|
continue; |
| 215 |
|
} |
| 216 |
|
$result_cols = db_query("SHOW COLUMNS FROM %s", $table); |
| 217 |
|
$cols = array(); |
| 218 |
|
while ($data = db_fetch_array($result_cols)) { |
| 219 |
|
$cols[$data['Field']] = $data; |
| 220 |
|
} |
| 221 |
|
if (isset($cols['nid'])) { |
| 222 |
|
$tables[$table] = isset($cols['vid']) ? $nid_vid : $nid; |
| 223 |
|
} |
| 224 |
|
} |
| 225 |
|
break; |
| 226 |
|
|
| 227 |
|
case 'pgsql': |
| 228 |
|
// @TODO: inspect the database and look for nid fields |
| 229 |
|
break; |
| 230 |
} |
} |
| 231 |
|
|
| 232 |
// delete from all of the content tables in one sql statement |
// delete from all of the content tables in one sql statement |
| 233 |
$sql = array('delete' => array(), 'from' => array(), 'where' => array()); |
$sql = array('delete' => array(), 'from' => array(), 'where' => array()); |
| 234 |
$index = 0; |
$index = 0; |
| 235 |
foreach (array_unique($tables) as $table => $cols) { |
foreach ($tables as $table => $cols) { |
| 236 |
$table = '{'. $table .'}'; |
$table = '{'. $table .'}'; |
| 237 |
$sql['cols'][] = "t$index.*"; |
$sql['cols'][] = "t$index.*"; |
| 238 |
|
|
| 246 |
$sql['join'][] = " LEFT JOIN $table t$index ON ". implode(' AND ', $on); |
$sql['join'][] = " LEFT JOIN $table t$index ON ". implode(' AND ', $on); |
| 247 |
$index ++; |
$index ++; |
| 248 |
} |
} |
| 249 |
db_query("DELETE n.*, ". implode(', ', $sql['cols']) ." FROM {node} n ". implode(' ', $sql['join']) ." WHERE n.type = '%s'", $type); |
$delete_sql = "DELETE n.*, ". implode(', ', $sql['cols']) ." FROM {node} n ". implode(' ', $sql['join']); |
| 250 |
|
db_query($delete_sql ." WHERE n.type = '%s'", $type); |
| 251 |
|
|
| 252 |
$deleted += $count; |
$deleted += $count; |
| 253 |
} |
} |