-
Notifications
You must be signed in to change notification settings - Fork 1
/
cron.php
executable file
·48 lines (36 loc) · 1.39 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
use nullupload\DB;
echo "\n==NULLUPLOAD CRON START ".date("Y-m-d H:i:s")." ==";
require 'vendor/autoload.php';
$settings = require __DIR__ . '/src/settings.php';
try{
DB::init($settings['settings']['database']);
}catch (PDOException $e){
$c->logger->addError($e->getMessage());
die("Database connection error");
}
$stm = DB::getDB()->prepare("select * from files");
$stm->execute();
//TODO: select already files to be deleted, do not check it in PHP
$files = $stm->fetchAll();
foreach ($files as $file) {
if (strtotime($file['deleteDate']) < time() ||
(strtotime('+1 day', strtotime($file['uploadDate'])) < time() && (int) $file['nDownloads'] < 2) ||
(!empty($file['lastDownload']) && strtotime('+90 day', strtotime($file['lastDownload'])) < time())) {
echo "\n->Deleting file id: " . $file['id'];
$path = "uploads/" . $file['filename'];
if (file_exists($path)) {
unlink($path);
echo " -> Deleted.";
} else {
echo " -> Warning: file <" . $path . '> does not exist';
}
$stm = DB::getDB()->prepare("delete from files where id = ? limit 1");
$stm->bindParam(1,$file['id'], PDO::PARAM_INT);
$stm->execute();
echo " -> Done.";
}
}
$totalsize = IOHelper::get_total_size("uploads");
DB::setConfig(DB::$histoTotalFileSize, $totalsize);
echo "\n==NULLUPLOAD CRON END== \n";