summaryrefslogtreecommitdiffstats
path: root/application/models/mfile.php
diff options
context:
space:
mode:
authorRafael Bodill <rafi@sortex.co.il>2014-09-19 18:31:11 +0200
committerRafael Bodill <rafi@sortex.co.il>2014-09-19 18:31:11 +0200
commit40fa09dcf09611afb34434a5c5c087b64f3fe8b6 (patch)
tree241069ecc414923f1ed45ba174b755e7524c83cc /application/models/mfile.php
parentd98ba32e9717a5e325d439e785c967f8cc44d095 (diff)
Fixing multipaste delete queries
Diffstat (limited to 'application/models/mfile.php')
-rw-r--r--application/models/mfile.php56
1 files changed, 31 insertions, 25 deletions
diff --git a/application/models/mfile.php b/application/models/mfile.php
index 68f8ab299..8dc4772d9 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -327,19 +327,17 @@ class Mfile extends CI_Model {
// Note that this does not delete all relations in multipaste_file_map
// which is actually done by a SQL contraint.
// TODO: make it work properly without the constraint
- if (strpos($this->db->dbdriver, 'postgre') === FALSE) {
- $this->db->query('
- DELETE m, mfm, f
- FROM files f
- LEFT JOIN multipaste_file_map mfm ON f.id = mfm.file_url_id
- LEFT JOIN multipaste m ON mfm.multipaste_id = m.multipaste_id
- WHERE f.id = ?
- ', array($id));
- } else {
- // TODO.rafi: Deletes files + multipaste_file_map
- // but not a multipaste.
- $this->db->where('id', $id)
- ->delete('files');
+ $map = $this->db->select('multipaste_id')
+ ->from('multipaste_file_map')
+ ->where('file_url_id', $id)
+ ->get()->row_array();
+
+ $this->db->where('id', $id)
+ ->delete('files');
+
+ if ( ! empty($map['multipaste_id'])) {
+ $this->db->where('multipaste_id', $map['multipaste_id'])
+ ->delete('multipaste');
}
if ($this->id_exists($id)) {
@@ -365,18 +363,26 @@ class Mfile extends CI_Model {
// Note that this does not delete all relations in multipaste_file_map
// which is actually done by a SQL contraint.
// TODO: make it work properly without the constraint
- if (strpos($this->db->dbdriver, 'postgre') === FALSE) {
- $this->db->query('
- DELETE m, mfm, f
- FROM files f
- LEFT JOIN multipaste_file_map mfm ON f.id = mfm.file_url_id
- LEFT JOIN multipaste m ON mfm.multipaste_id = m.multipaste_id
- WHERE f.hash = ?
- ', array($hash));
- } else {
- // TODO.rafi: Test
- $this->db->where('hash', $hash)
- ->delete('files');
+ $file = $this->db->select('id')
+ ->from('files')
+ ->where('hash', $hash)
+ ->get()->row_array();
+
+ if (empty($file['id'])) {
+ return false;
+ }
+
+ $map = $this->db->select('multipaste_id')
+ ->from('multipaste_file_map')
+ ->where('file_url_id', $file['id'])
+ ->get()->row_array();
+
+ $this->db->where('hash', $hash)
+ ->delete('files');
+
+ if ( ! empty($map['multipaste_id'])) {
+ $this->db->where('multipaste_id', $map['multipaste_id'])
+ ->delete('multipaste');
}
if (file_exists($this->file($hash))) {