biblio_advanced_import.batch.inc in Biblio Advanced Import 6
Same filename and directory in other branches
Batch process to update existing biblio nodes
@author Markus Kalkbrenner | Cocomore AG
File
biblio_advanced_import.batch.incView source
<?php
/**
* @file
* Batch process to update existing biblio nodes
*
* @see biblio_advanced_import.module
* @see biblio.module
*
* @author Markus Kalkbrenner | Cocomore AG
* @see http://drupal.org/user/124705
*/
/**
* Updates the hashes of all biblio nodes as batch process.
*
* @see biblio_advanced_import_settings_form_submit()
*
* @param $context
* drupal batch process context
*/
function biblio_advanced_import_update_hashes_batch(&$context) {
if (empty($context['biblio_advanced_import_update_hashes_batch'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_nid'] = 0;
$context['sandbox']['max_nid'] = db_result(db_query('SELECT MAX(nid) FROM {biblio}'));
$context['sandbox']['num_nids'] = db_result(db_query('SELECT COUNT(DISTINCT nid) FROM {biblio}'));
$context['sandbox']['limit'] = $context['sandbox']['num_nids'] > 20 ? 5 : 1;
}
if ($context['sandbox']['current_nid'] >= $context['sandbox']['max_nid']) {
$context['sandbox']['progress'] = $context['sandbox']['num_nids'];
$context['finished'] = 1;
}
else {
$result = db_query_range("SELECT nid FROM {biblio} JOIN {node} USING (nid,vid) WHERE nid > %d AND nid <= %d ORDER BY nid ASC", $context['sandbox']['current_nid'], $context['sandbox']['max_nid'], 0, $context['sandbox']['limit']);
while ($row = db_fetch_object($result)) {
$node = node_load($row['nid'], NULL, TRUE);
biblio_advanced_import_update_hash($node);
$context['results'][] = $node->nid . ' : ' . $node->biblio_md5;
$context['sandbox']['progress']++;
$context['sandbox']['current_nid'] = $node->nid;
$context['message'] = $node->nid . ' : ' . $node->title;
}
if ($context['sandbox']['progress'] != $context['sandbox']['num_nids']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['num_nids'];
}
}
}
/**
* Clean-up after hashes of all biblio nodes have been updated
* in a batch process.
*
* @see biblio_advanced_import_settings_form_submit()
*/
function biblio_advanced_import_update_hashes_batch_finished($success, $results, $operations) {
if ($success) {
$message = format_plural(count($results), 'Updated one biblio hash.', 'Updates @count biblio hashes.');
}
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
// TODO re-enable import and creation of new biblio nodes
}
Functions
Name | Description |
---|---|
biblio_advanced_import_update_hashes_batch | Updates the hashes of all biblio nodes as batch process. |
biblio_advanced_import_update_hashes_batch_finished | Clean-up after hashes of all biblio nodes have been updated in a batch process. |