function biblio_import_batch_operations in Bibliography Module 6
Same name and namespace in other branches
- 6.2 includes/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 ./
biblio.import.export.inc - Implementation of hook_submit() for the biblio_import_form.
File
- ./
biblio.import.export.inc, line 241 - 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 (!isset($context['sandbox']['biblio'])) {
// 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']['biblio']['current_id'] = 0;
$context['results']['nids'] = array();
$context['sandbox']['biblio']['max'] = db_result(db_query("SELECT COUNT(DISTINCT(id)) FROM {biblio_import_cache} WHERE session_id = '%s'", $session_id));
$context['sandbox']['biblio']['itters'] = $context['sandbox']['biblio']['max'] / $limit;
$context['sandbox']['biblio']['eta'] = 0;
}
if ($context['sandbox']['biblio']['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']['biblio']['current_id'], $session_id, 0, $limit);
while ($row = db_fetch_array($result)) {
if ($node = unserialize(base64_decode($row['data']))) {
$nid = biblio_save_node($node);
if (isset($nid)) {
$context['results']['nids'][] = $nid;
}
}
$context['sandbox']['progress']++;
$context['sandbox']['biblio']['current_id'] = $row['id'];
}
$looptime = timer_stop('biblio_import');
$context['sandbox']['biblio']['eta'] += $looptime['time'];
$itters = $context['sandbox']['progress'] / $limit;
if ($itters) {
$average_time = $context['sandbox']['biblio']['eta'] / $itters;
$eta = ($context['sandbox']['biblio']['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']['biblio']['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']['biblio']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['biblio']['max'];
}
}