You are here

function analytics_cron in Analytics 7

Implements hook_cron().

File

./analytics.module, line 192

Code

function analytics_cron() {
  if (!variable_get('analytics_cache_urls', FALSE)) {
    variable_del('analytics_cached_urls');
    return;
  }
  $directory = 'public://analytics';
  if (!file_prepare_directory($directory)) {
    variable_del('analytics_cached_urls');
    return;
  }
  $cached_urls = array();
  foreach (analytics_service_load_enabled() as $service) {
    if ($urls = $service
      ->getCacheableUrls()) {
      $destination = 'public://analytics/' . $service
        ->getMachineName();
      foreach ($urls as $url) {
        if (isset($cached_urls[$url])) {

          // If this file has already been cached, don't download it again.
          continue;
        }
        if (!file_prepare_directory($destination)) {
          continue;
        }
        if ($file = system_retrieve_file($url, $destination, FALSE, FILE_EXISTS_REPLACE)) {
          $cached_urls[$url] = $file;
        }
      }
    }
  }
  variable_set('analytics_cached_urls', $cached_urls);
}