From a4a7a0e88fc07d06ea955274bcc75e8bf03cb078 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 8 Mar 2015 19:27:20 +0100 Subject: Unify file/cron and mfile->valid_id Create a testable function doing all the verification/removal, add tests and use it for both cases. Signed-off-by: Florian Pritz --- application/models/mfile.php | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'application/models') diff --git a/application/models/mfile.php b/application/models/mfile.php index f0a594609..bf6d0f9dc 100644 --- a/application/models/mfile.php +++ b/application/models/mfile.php @@ -130,36 +130,29 @@ class Mfile extends CI_Model { if (!$filedata) { return false; } - $file = $this->file($filedata['hash']); - if (!file_exists($file)) { - $this->delete_hash($filedata["hash"]); - return false; - } - - // 0 age disables age checks - if ($this->config->item('upload_max_age') == 0) return true; + $config = array( + "upload_max_age" => $this->config->item("upload_max_age"), + "small_upload_size" => $this->config->item("small_upload_size"), + "sess_expiration" => $this->config->item("sess_expiration"), + ); - // small files don't expire - if (filesize($file) <= $this->config->item("small_upload_size")) { - return true; - } + return \service\files::valid_id($filedata, $config, $this, time()); + } - // files older than this should be removed - $remove_before = (time()-$this->config->item('upload_max_age')); + public function file_exists($file) + { + return file_exists($file); + } - if ($filedata["date"] < $remove_before) { - // if the file has been uploaded multiple times the mtime is the time - // of the last upload - if (filemtime($file) < $remove_before) { - $this->delete_hash($filedata["hash"]); - } else { - $this->delete_id($id); - } - return false; - } + public function filemtime($file) + { + return filemtime($file); + } - return true; + public function filesize($file) + { + return filesize($file); } public function get_timeout($id) -- cgit v1.2.3-24-g4f1b