summaryrefslogtreecommitdiffstats
path: root/application/models
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-11-03 18:18:19 +0100
committerFlorian Pritz <bluewind@xinu.at>2014-11-03 18:18:19 +0100
commitd3e4184537de165de37b48c43b4112aad7b4ad88 (patch)
treeba547cd604f489ec35a9e762be54fccf6f5e21e1 /application/models
parent8c43c5bd16b59eb510076edce828468c1940629a (diff)
Simplify mfile->delete_hash
This probably increases the database queries a bit, but greatly simplifies the code and fixes the missing deletion of multipaste tarballs (delete_id handles that). Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/models')
-rw-r--r--application/models/mfile.php34
1 files changed, 3 insertions, 31 deletions
diff --git a/application/models/mfile.php b/application/models/mfile.php
index 8a514c292..eef37c4b3 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -252,42 +252,14 @@ class Mfile extends CI_Model {
public function delete_hash($hash)
{
- // Delete all files with this hash and all multipastes using any of those files
- // 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
- $file = $this->db->select('id')
+ $ids = $this->db->select('id')
->from('files')
->where('hash', $hash)
- ->get()->row_array();
-
- if (empty($file['id'])) {
- return false;
- }
-
- $map = $this->db->select('multipaste_id')
- ->distinct()
- ->from('multipaste_file_map')
- ->where('file_url_id', $file['id'])
->get()->result_array();
- $this->db->where('hash', $hash)
- ->delete('files');
-
- foreach ($map as $entry) {
- assert(!empty($entry['multipaste_id']));
- $this->db->where('multipaste_id', $entry['multipaste_id'])
- ->delete('multipaste');
- }
-
- if (file_exists($this->file($hash))) {
- unlink($this->file($hash));
- $dir = $this->folder($hash);
- if (count(scandir($dir)) == 2) {
- rmdir($dir);
- }
+ foreach ($ids as $entry) {
+ $this->delete_id($entry["id"]);
}
- return true;
}
public function get_owner($id)