function biblio_import_batch_operations in Bibliography Module 6.2
Same name and namespace in other branches
- 6 biblio.import.export.inc \biblio_import_batch_operations()
- 7 includes/biblio.import.export.inc \biblio_import_batch_operations()
- 7.2 includes/biblio.import.export.inc \biblio_import_batch_operations()
1 string reference to 'biblio_import_batch_operations'
- biblio_import_form_submit in includes/
biblio.import.export.inc
File
- includes/
biblio.import.export.inc, line 275 - Functions that are used to import and export biblio data.
Code
function biblio_import_batch_operations($session_id, $user, $userid, $terms, &$context) {
$limit = 10;
if (empty($context['sandbox'])) {
// Initiate multistep processing.
$context['results']['session_id'] = $session_id;
$context['results']['userid'] = $userid;
$context['results']['user'] = $user;
$context['results']['terms'] = $terms;
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_id'] = 0;
$context['results']['nids'] = array();
$context['sandbox']['max'] = db_result(db_query("SELECT COUNT(DISTINCT(id)) FROM {biblio_import_cache} WHERE session_id = '%s'", $session_id));
$context['sandbox']['itters'] = $context['sandbox']['max'] / $limit;
$context['sandbox']['eta'] = 0;
}
if ($context['sandbox']['max'] == 0) {
return;
}
timer_start('biblio_import');
$result = db_query_range("SELECT id, data FROM {biblio_import_cache} WHERE id > %d AND session_id = '%s' ORDER BY id ASC", $context['sandbox']['current_id'], $session_id, 0, $limit);
while ($row = db_fetch_array($result)) {
if ($node = unserialize(base64_decode($row['data']))) {
biblio_save_node($node);
$context['results']['nids'][] = $node->nid;
}
$context['sandbox']['progress']++;
$context['sandbox']['current_id'] = $row['id'];
}
$looptime = timer_stop('biblio_import');
$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>Nodes saved: %progress <br> Time remaining: %eta min.<br>', array(
'%progress' => $progress,
'%eta' => $eta,
));
}
// Multistep processing : report progress.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}