function biblio_batch_uninstall in Bibliography Module 6.2
Same name and namespace in other branches
- 7 biblio.install \biblio_batch_uninstall()
1 string reference to 'biblio_batch_uninstall'
- biblio_uninstall in ./
biblio.install - Implements hook_uninstall().
File
- ./
biblio.install, line 106 - Install, update, and uninstall functions for the biblio module.
Code
function biblio_batch_uninstall(&$context) {
$limit = 5;
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_node'] = 0;
$context['sandbox']['max'] = db_result(db_query("SELECT COUNT(DISTINCT nid) FROM {node} WHERE type='biblio'"));
$context['sandbox']['itters'] = $context['sandbox']['max'] / $limit;
$context['sandbox']['eta'] = 0;
}
// Bail out if the cache is empty.
if ($context['sandbox']['max'] == 0) {
$context['finished'] = 1;
return;
}
timer_start('biblio_delete');
$current = $context['sandbox']['current_node'];
$sql = "SELECT nid FROM {node} WHERE nid > %d and type='biblio' ORDER BY nid ASC";
$result = db_query_range($sql, $current, 0, $limit);
while ($row = db_fetch_object($result)) {
$node = node_delete($row->nid);
if (function_exists('search_wipe')) {
search_wipe($row->nid, 'node');
}
$context['sandbox']['progress']++;
$context['sandbox']['current_node'] = $row->nid;
}
$looptime = timer_stop('biblio_delete');
$context['sandbox']['eta'] += $looptime['time'];
$itters = $context['sandbox']['progress'] / $limit;
if ($itters) {
$average_time = $context['sandbox']['eta'] / $itters;
$eta = ($context['sandbox']['itters'] * $average_time - $average_time * $itters) / 1000;
if ($eta >= 60) {
$min = (int) $eta / 60;
}
else {
$min = 0;
}
$sec = $eta % 60;
$eta = sprintf("%d:%02d", $min, $sec);
$progress = sprintf("%d / %d", $context['sandbox']['progress'], $context['sandbox']['max']);
$context['message'] = t('<br>Biblio nodes deleted: %progress <br> Time remaining: %eta min.<br>', array(
'%progress' => $progress,
'%eta' => $eta,
));
}
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}