function biblio_pm_cron in Bibliography Module 6.2
Same name and namespace in other branches
- 7 modules/pubmed/biblio_pm.module \biblio_pm_cron()
- 7.2 modules/pubmed/biblio_pm.module \biblio_pm_cron()
File
- modules/
pubmed/ biblio_pm.module, line 6
Code
function biblio_pm_cron() {
if (variable_get('biblio_pm_auto_update', 0)) {
$interval = variable_get('biblio_pm_update_interval', 3600);
// defaults to once per hour
$count_limit = variable_get('biblio_pm_update_limit', 100);
// only update 100 at a time
$age = variable_get('biblio_pm_age_limit', 2419200);
// defaults to one month since last update
$age_limit = time() - $age;
if (time() >= variable_get('biblio_pm_update_next_execution', 0)) {
$ids = array();
$sql = 'SELECT nid, biblio_pubmed_id FROM {biblio_pubmed} WHERE biblio_pm_changed < %d ORDER BY nid ASC LIMIT %d';
$result = db_query($sql, $age_limit, $count_limit);
while ($pm = db_fetch_object($result)) {
$ids[$pm->nid] = $pm->biblio_pubmed_id;
}
if (count($ids)) {
list($nids, $dups) = biblio_pm_import_ids($ids);
if (count($nids)) {
foreach ($nids as $nid) {
$message = '';
$message = t('!nid was updated due to changes originating at !url', array(
'!nid' => l($nid, 'node/' . $nid),
'!url' => l('PubMed', 'http://www.ncbi.nlm.nih.gov/pubmed/' . $ids[$nid]),
));
watchdog('biblio_pm', $message, array(), WATCHDOG_WARNING);
}
}
if (count($dups)) {
$count = count($dups);
$message = format_plural($count, 'One duplicate PubMed entry was checked, but no changes were found.', '@count PubMed entries were checked, but no changes were found.');
watchdog('biblio_pm', $message, array(
'@count' => $count,
), WATCHDOG_INFO);
$now = time();
$sql = 'UPDATE {biblio_pubmed} SET biblio_pm_changed=%d WHERE nid IN (' . implode(',', $dups) . ')';
db_query($sql, $now);
}
}
$message = t('There were no PubMed entries older than @age to check.', array(
'@age' => format_interval($age),
));
watchdog('biblio_pm', $message, array(), WATCHDOG_INFO);
variable_set('biblio_pm_update_next_execution', time() + $interval);
}
}
}