summaryrefslogtreecommitdiff
path: root/modules/statistics/statistics.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/statistics/statistics.module')
-rw-r--r--modules/statistics/statistics.module28
1 files changed, 21 insertions, 7 deletions
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index 06bfef5c3..4242aec5b 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -51,17 +51,31 @@ function statistics_exit() {
// We are counting content views.
if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') {
// A node has been viewed, so update the node's counters.
- db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1));
- // If we affected 0 rows, this is the first time viewing the node.
- if (!db_affected_rows()) {
- // We must create a new row to store counters for the new node.
- db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time());
- }
+ $fields = array(
+ 'daycount' => 1,
+ 'totalcount' => 1,
+ 'nid' => arg(1),
+ 'timestamp' => time(),
+ );
+ db_merge('node_counter')
+ ->fields($fields)
+ ->expression('daycount', 'daycount + 1')
+ ->expression('totalcount', 'totalcount + 1')
+ ->execute();
}
}
if (variable_get('statistics_enable_access_log', 0)) {
// Log this page access.
- db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), ip_address(), $user->uid, session_id(), timer_read('page'), time());
+ db_insert('accesslog')->fields(array(
+ 'title' => strip_tags(drupal_get_title()),
+ 'path' => $_GET['q'],
+ 'url' => referer_uri(),
+ 'hostname' => ip_address(),
+ 'uid' => $user->uid,
+ 'sid' => session_id(),
+ 'timer' => timer_read('page'),
+ 'timestamp' => time(),
+ ))->execute();
}
}