You are here

function adserve_cache_increment in Advertisement 7

Same name and namespace in other branches
  1. 5.2 adcache.inc \adserve_cache_increment()
  2. 6.3 adcache.inc \adserve_cache_increment()
  3. 6.2 adcache.inc \adserve_cache_increment()

Increment action directly in the database.

File

./adcache.inc, line 294

Code

function adserve_cache_increment($action, $aid) {

  /* TODO: Update to Drupal 7
    $hostid = adserve_variable('hostid');
    _debug_echo("adserve_cache_increment action($action) aid($aid) hostid($hostid)");

    // be sure that drupal is bootstrapped
    adserve_bootstrap();

    // allow add-on modules to implement their own statistics granularity
    $extra = adserve_invoke_hook('increment_extra', 'merge', $action, $aid);
    if (is_array($extra)) {
      $extra = implode('|,|', $extra);
    }
    adserve_variable('extra', $extra);
    _debug_echo("adserve_cache_increment extra($extra)");

    // update statistics
    $result = db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE aid = :aid AND action = :action AND date = :date AND adgroup = :adgroup AND extra = :extra AND hostid = :hostid",
      array(':aid' => $aid, ':action' => $action, ':date' => date('YmdH'), ':adgroup' => adserve_variable('group'), ':extra' => $extra, ':hostid' => $hostid));
    // if column doesn't already exist, add it
    if (!$result->rowCount()) {
      db_query("INSERT INTO {ad_statistics} (aid, date, action, adgroup, extra, hostid, count) VALUES(%d, %d, '%s', '%s', '%s', '%s', 1)", $aid, date('YmdH'), $action, adserve_variable('group'), $extra, $hostid);
      if (!db_affected_rows()) {
        // we lost a race to add it, increment it
        db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE aid = %d AND action = '%s' AND date = %d AND adgroup = '%s' AND extra = '%s' AND hostid = '%s'", $aid, $action, date('YmdH'), adserve_variable('group'), $extra, $hostid);
      }
    }

    if ($action == 'view') {
      $ad = db_query('SELECT maxviews, activated FROM {ads} WHERE aid = %d', $aid)->fetch();
      // See if we need to perform additional queries.
      if ($ad->maxviews) {
        $views = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, date('YmdH', $ad->activated))->fetchField();
        if ($views >= $ad->maxviews) {
          db_query("UPDATE {ads} SET adstatus = 'expired', autoexpire = 0, autoexpired = %d, expired = %d WHERE aid = %d", time(), time(), $aid);
          ad_statistics_increment($aid, 'autoexpired');
          ad_statistics_increment($aid, 'expired');
        }
      }
    }
  */
}