From d3e4184537de165de37b48c43b4112aad7b4ad88 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 3 Nov 2014 18:18:19 +0100 Subject: 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 --- application/models/mfile.php | 34 +++------------------------------- 1 file 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) -- cgit v1.2.3-24-g4f1b