function file_download_counter_cron in File Download 8
Implements hook_cron().
File
- modules/
file_download_counter/ file_download_counter.module, line 26 - Logs and displays content file_download_counter for a site.
Code
function file_download_counter_cron() {
$file_download_counter_timestamp = \Drupal::state()
->get('file_download_counter.day_timestamp') ?: 0;
if (\Drupal::time()
->getRequestTime() - $file_download_counter_timestamp >= 86400) {
// Reset day counts.
\Drupal::database()
->update('file_download_counter')
->fields([
'daycount' => 0,
])
->execute();
\Drupal::state()
->set('file_download_counter.day_timestamp', \Drupal::time()
->getRequestTime());
}
// Calculate the maximum of node views, for node search ranking.
\Drupal::state()
->set('file_download_counter.node_counter_scale', 1.0 / max(1.0, \Drupal::database()
->query('SELECT MAX(totalcount) FROM {file_download_counter}')
->fetchField()));
}