You are here

function statistics_counter_cron in Statistics Counter 7

Same name and namespace in other branches
  1. 8 statistics_counter.module \statistics_counter_cron()

Implements hook_cron().

File

./statistics_counter.module, line 11
Statistics Counter

Code

function statistics_counter_cron() {

  // Get timestamps.
  $statistics_timestamp = variable_get('statistics_counter_timestamp', '');

  // Get date.
  $week = date('W') | 0;
  $month = date('n') | 0;
  $year = date('Y') | 0;
  $last_week = date('W', $statistics_timestamp) | 0;
  $last_month = date('n', $statistics_timestamp) | 0;
  $last_year = date('Y', $statistics_timestamp) | 0;
  $fields = array();
  if ($week != $last_week || $year != $last_year) {

    // Reset week counts.
    $fields['weekcount'] = 0;
  }
  if ($month != $last_month || $year != $last_year) {

    // Reset month counts.
    $fields['monthcount'] = 0;
  }
  if ($year != $last_year) {

    // Reset year counts.
    $fields['yearcount'] = 0;
  }
  if (!empty($fields)) {

    // Reset year counts.
    db_update('node_counter')
      ->fields($fields)
      ->execute();
  }
  variable_set('statistics_counter_timestamp', REQUEST_TIME);
}