diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-03-08 19:27:20 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-03-08 19:27:20 +0100 |
commit | a4a7a0e88fc07d06ea955274bcc75e8bf03cb078 (patch) | |
tree | ec4cdae4a194538dd2aa7cf516d96611abc75d20 /application/models | |
parent | f4f108a41281037370eaec6c7b8fb3e6e35a30f5 (diff) |
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 <bluewind@xinu.at>
Diffstat (limited to 'application/models')
-rw-r--r-- | application/models/mfile.php | 43 |
1 files changed, 18 insertions, 25 deletions
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) |