You are here

function simplenews_statistics_cron in Simplenews Statistics 6.3

Same name and namespace in other branches
  1. 7.2 simplenews_statistics.module \simplenews_statistics_cron()
  2. 7 simplenews_statistics.module \simplenews_statistics_cron()

Implements hook_cron().

File

./simplenews_statistics.module, line 354
Main simplenews statistics file.

Code

function simplenews_statistics_cron() {
  $days = variable_get('simplenews_statistics_decrypt_shorturl_days', 0);
  if (is_numeric($days) && $days > 0) {
    $query = 'SELECT lid, orig_url FROM {shorturl_link} WHERE created>%d AND orig_url LIKE "%/simplenews/statistics/click?p=%" LIMIT 25000';
    $result = db_query($query, $days * 86400);
    $n = 0;
    while ($row = db_fetch_array($result)) {
      $values = array();
      $q = parse_url($row['orig_url'], PHP_URL_QUERY);
      parse_str($q, $values);
      $stat = _simplenews_statistics_decode($values);
      $query = 'UPDATE {shorturl_link} SET orig_url="%s" WHERE lid=%d';
      db_query($query, $stat['url'], $row['lid']);
      $n++;
    }
    watchdog('simplenews_statistics', "Decrypted {$n} old URLs in table shorturl_link.");
  }
}