summaryrefslogtreecommitdiffstats
path: root/application/models
diff options
context:
space:
mode:
authorRafael Bodill <rafi@sortex.co.il>2014-09-19 17:37:40 +0200
committerRafael Bodill <rafi@sortex.co.il>2014-09-19 17:37:40 +0200
commiteffdc57264f62c3422b91d295f29a8c4e77c3db5 (patch)
treee080a86c51f43ce55147fc579a2d884e7093fb11 /application/models
parent8082cc98e7ebc9a27dcf8a8a4e6ee24dc71af1f3 (diff)
WIP: Cascading delete
Diffstat (limited to 'application/models')
-rw-r--r--application/models/mfile.php41
-rw-r--r--application/models/mmultipaste.php19
2 files changed, 40 insertions, 20 deletions
diff --git a/application/models/mfile.php b/application/models/mfile.php
index 1d4340410..68f8ab299 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -327,13 +327,20 @@ 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
- $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));
+ 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');
+ }
if ($this->id_exists($id)) {
return false;
@@ -358,13 +365,19 @@ 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
- $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));
+ 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');
+ }
if (file_exists($this->file($hash))) {
unlink($this->file($hash));
diff --git a/application/models/mmultipaste.php b/application/models/mmultipaste.php
index 723132a50..9b1a7b16e 100644
--- a/application/models/mmultipaste.php
+++ b/application/models/mmultipaste.php
@@ -90,12 +90,19 @@ class Mmultipaste extends CI_Model {
public function delete_id($id)
{
- $this->db->query('
- DELETE m, mfm
- FROM multipaste m
- LEFT JOIN multipaste_file_map mfm ON mfm.multipaste_id = m.multipaste_id
- WHERE m.url_id = ?
- ', array($id));
+ if (strpos($this->db->dbdriver, 'postgre') === FALSE) {
+ $this->db->query('
+ DELETE m, mfm
+ FROM multipaste m
+ LEFT JOIN multipaste_file_map mfm ON mfm.multipaste_id = m.multipaste_id
+ WHERE m.url_id = ?
+ ', array($id));
+ } else {
+ // TODO.rafi: Deletes multipaste + multipaste_file_map
+ // but not files. Is it supposed to?
+ $this->db->where('url_id', $id)
+ ->delete('multipaste');
+ }
if ($this->id_exists($id)) {
return false;