summaryrefslogtreecommitdiffstats
path: root/application/controllers/Main.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-05-03 20:04:28 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-05-03 20:04:28 +0200
commit85c8e395c60dda0f7000ac6a5342be92b7f56eb5 (patch)
treee45c11215baff0fc1a9deb72eef2071cc3fd27be /application/controllers/Main.php
parentc12318a99e9ba44a6774f72f647c7a3c41ee24e4 (diff)
file/clean_stale_files: Remove database entries without files
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers/Main.php')
-rw-r--r--application/controllers/Main.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/application/controllers/Main.php b/application/controllers/Main.php
index 6389b1039..28582d821 100644
--- a/application/controllers/Main.php
+++ b/application/controllers/Main.php
@@ -941,6 +941,25 @@ class Main extends MY_Controller {
}
closedir($outer_dh);
+ $chunk = 500;
+ $total = $this->db->count_all("file_storage");
+
+ for ($limit = 0; $limit < $total; $limit += $chunk) {
+ $query = $this->db->select('hash, id')
+ ->from('file_storage')
+ ->limit($chunk, $limit)
+ ->get()->result_array();
+
+ foreach ($query as $key => $item) {
+ $data_id = $item["hash"].'-'.$item['id'];
+ $file = $this->mfile->file($data_id);
+
+ if (!$this->mfile->file_exists($file)) {
+ $this->mfile->delete_data_id($data_id);
+ }
+ }
+ }
+
// TODO: clean up special/multipaste-tarballs? cron() already expires
// after a rather short time, do we really need this here then?
}