function google_analytics_counter_cron in Google Analytics Counter 7.2
Same name and namespace in other branches
- 8.3 google_analytics_counter.module \google_analytics_counter_cron()
- 7.3 google_analytics_counter.module \google_analytics_counter_cron()
Implements hook_cron().
File
- ./
google_analytics_counter.module, line 257 - Basic functions for this module.
Code
function google_analytics_counter_cron() {
// Set a watchdog error if there is no Google Analytics profile enabled.
// It's a weak test but better than none.
if (variable_get('google_analytics_counter_profile_id') == '') {
watchdog(t('Google Analytics Counter'), t('No Google Analytics profile has been authenticated! Google Analytics Counter can not fetch any new data. Please authenticate <a href="/admin/config/system/google_analytics_counter/authentication">here</a>.'), NULL, WATCHDOG_ERROR);
return;
}
// Defaults to an hourly interval. Of course, cron has to be running at least hourly for this to work.
$interval = 60 * variable_get('google_analytics_counter_cron_interval', 60);
// $interval must contain value in seconds.
// We don't want to act every time cron runs (which could be every minute) so keep a time for the next run in a variable.
if (REQUEST_TIME >= variable_get('google_analytics_counter_cron_next_execution', 0)) {
// Important to set it before the job because if they take long and there is another cron triggered...
variable_set('google_analytics_counter_cron_next_execution', REQUEST_TIME + $interval);
// Retrieve path with counts from Google Analytics into a local table.
google_analytics_counter_update_path_counts();
// Now also update the node_counter table from the local table with the GA data.
google_analytics_counter_update_node_counter();
}
}