From f3730cacda091037db700ff57896bf7d188e9bd1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 7 Nov 2013 14:59:54 +0100 Subject: [PATCH] https://github.com/claudehohl/Stikked/pull/94 works. --- htdocs/application/models/pastes.php | 21 +++++++++++++-------- htdocs/index.php | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/htdocs/application/models/pastes.php b/htdocs/application/models/pastes.php index fcccd44..acbcfbc 100644 --- a/htdocs/application/models/pastes.php +++ b/htdocs/application/models/pastes.php @@ -293,19 +293,24 @@ class Pastes extends CI_Model } // hits - $hits_where = array( - 'paste_id' => $pid, - ); $hits_data = array( 'paste_id' => $pid, 'ip_address' => $this->input->ip_address() , 'created' => mktime() , ); - $update_query = $this->db->update_string('trending', $hits_data, $hits_where); - $this->db->query($update_query); - if ($this->db->affected_rows() == 0) { - $insert_query = $this->db->insert_string('trending', $hits_data); - $this->db->query($insert_query); + $hits_where = array( + 'paste_id' => $pid, + 'ip_address' => $this->input->ip_address() , + ); + + // First check if record already exists. If it does, do not insert. + // INSERT IGNORE INTO does not work for postgres. + + $query = $this->db->get('trending', $hits_where); + + if ($query->num_rows == 0) + { + $this->db->insert('trending', $hits_data); } if (mktime() > (60 + $data['hits_updated'])) diff --git a/htdocs/index.php b/htdocs/index.php index 1ca3a29..b2cfcb4 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -18,7 +18,7 @@ * NOTE: If you change these, also change the error_reporting() code below * */ - define('ENVIRONMENT', 'production'); + define('ENVIRONMENT', 'development'); /* *--------------------------------------------------------------- * ERROR REPORTING