function download_count_cron in Download Count 7.3
Same name and namespace in other branches
- 8 download_count.module \download_count_cron()
Implements hook_cron().
Daily file download counts are cached for convenience.
File
- ./
download_count.module, line 221 - Tracks file downloads for files stored in the drupal files table using the private files setting or custom private filefield.
Code
function download_count_cron() {
$time = REQUEST_TIME;
$status = 0;
$count = 0;
$last_cron = variable_get('download_count_last_cron', 0);
$result = db_query('SELECT fid, type, id, UNIX_TIMESTAMP(DATE(FROM_UNIXTIME(timestamp))) as date, COUNT(dcid) as count FROM {download_count} WHERE timestamp > :last_cron GROUP BY type, id, fid, DATE(FROM_UNIXTIME(timestamp))', array(
':last_cron' => $last_cron,
));
$queue = DrupalQueue::get('download_count');
foreach ($result as $record) {
$queue
->createItem($record);
$count++;
}
if ($count > 0) {
watchdog('download_count', 'Download count queued %count new entries for caching.', array(
'%count' => $count,
), WATCHDOG_NOTICE);
}
variable_set('download_count_last_cron', $time);
}