From 0f1e9b6bd1f67e682443cdd47966b3d0ba0aef20 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Sat, 10 Aug 2013 18:09:34 -0400 Subject: [PATCH] Adjusted pastes for trending updates to be more database agnostic --- htdocs/application/models/pastes.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/application/models/pastes.php b/htdocs/application/models/pastes.php index cc2d3ff..fcccd44 100644 --- a/htdocs/application/models/pastes.php +++ b/htdocs/application/models/pastes.php @@ -293,14 +293,20 @@ 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() , ); - $insert_query = $this->db->insert_string('trending', $hits_data); - $insert_query = str_replace('INSERT INTO', 'INSERT IGNORE INTO', $insert_query); - $this->db->query($insert_query); + $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); + } if (mktime() > (60 + $data['hits_updated'])) {