summaryrefslogtreecommitdiffstats
path: root/application/controllers/file.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-03-08 19:27:20 +0100
committerFlorian Pritz <bluewind@xinu.at>2015-03-08 19:27:20 +0100
commita4a7a0e88fc07d06ea955274bcc75e8bf03cb078 (patch)
treeec4cdae4a194538dd2aa7cf516d96611abc75d20 /application/controllers/file.php
parentf4f108a41281037370eaec6c7b8fb3e6e35a30f5 (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/controllers/file.php')
-rw-r--r--application/controllers/file.php43
1 files changed, 19 insertions, 24 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index e258f2ffb..0dd6eaffe 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -966,39 +966,34 @@ class File extends MY_Controller {
}
}
- // 0 age disables age checks
- if ($this->config->item('upload_max_age') == 0) return;
-
$oldest_time = (time() - $this->config->item('upload_max_age'));
$oldest_session_time = (time() - $this->config->item("sess_expiration"));
+ $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"),
+ );
+
+ $query = $this->db->select('hash, id, user, date')
+ ->from('files')
+ ->where("user", 0)
+ ->where("date <", $oldest_session_time)
+ ->get()->result_array();
+
+ foreach($query as $row) {
+ \service\files::valid_id($row, $config, $this->mfile, time());
+ }
- $small_upload_size = $this->config->item('small_upload_size');
+ // 0 age disables age checks
+ if ($this->config->item('upload_max_age') == 0) return;
- $query = $this->db->select('hash, id, user')
+ $query = $this->db->select('hash, id, user, date')
->from('files')
->where('date <', $oldest_time)
- ->or_where('('.$this->db->_protect_identifiers('user').' = 0 AND '
- .$this->db->_protect_identifiers('date')." < $oldest_session_time)")
->get()->result_array();
foreach($query as $row) {
- $file = $this->mfile->file($row['hash']);
- if (!file_exists($file)) {
- $this->mfile->delete_id($row["id"]);
- continue;
- }
-
- if ($row["user"] == 0 || filesize($file) > $small_upload_size) {
- if (filemtime($file) < $oldest_time) {
- unlink($file);
- $this->mfile->delete_hash($row["hash"]);
- } else {
- $this->mfile->delete_id($row["id"]);
- if ($this->mfile->stale_hash($row["hash"])) {
- unlink($file);
- }
- }
- }
+ \service\files::valid_id($row, $config, $this->mfile, time());
}
}