You are here

function forward_update_1 in Forward 5

Same name and namespace in other branches
  1. 6 forward.install \forward_update_1()
  2. 7 forward.install \forward_update_1()

Changed node_comment_statistics to use node->changed to avoid future timestamps.

File

./forward.install, line 56

Code

function forward_update_1() {

  // initialize table
  $ret[] = update_sql("CREATE TABLE {forward_statistics} (\n    nid int(10) unsigned NOT NULL,\n    last_forward_timestamp int(11) NOT NULL default '0',\n    forward_count int(10) unsigned NOT NULL default '0',\n    clickthrough_count int(10) unsigned NOT NULL default '0',\n    PRIMARY KEY (nid),\n    KEY (last_forward_timestamp)\n  );");
  $ret[] = update_sql("INSERT INTO {forward_statistics} (nid, last_forward_timestamp, forward_count, clickthrough_count) values(0, 0, 0, 0)");
  $ret[] = update_sql("INSERT INTO {forward_statistics} (nid, last_forward_timestamp, forward_count, clickthrough_count) SELECT n.nid, 0, 0, 0 FROM {node} n");

  // fill table
  $forwards = db_query("SELECT f.nid, f.timestamp, COUNT(f.nid) as forward_count FROM {node} n LEFT JOIN {forward_log} f ON f.nid = n.nid WHERE f.type = 'SENT' GROUP BY f.nid, f.timestamp");
  while ($forward = db_fetch_object($forwards)) {
    $forward_count = db_result(db_query("SELECT COUNT(nid) FROM {forward_log} WHERE nid = %d AND type = '%s'", $forward->nid, 'SENT'));
    $clickthrough_count = db_result(db_query("SELECT COUNT(nid) FROM {forward_log} WHERE nid = %d AND type = '%s'", $forward->nid, 'REF'));
    db_query("UPDATE {forward_statistics} SET forward_count = %d, clickthrough_count = %d, last_forward_timestamp = %d WHERE nid = %d", $forward_count, $clickthrough_count, $forward->timestamp, $forward->nid);
  }
  return $ret;
}