| 1 |
<?php |
| 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 |
namespace Liuch\DmarcSrg; |
| 36 |
|
| 37 |
use Liuch\DmarcSrg\Report\ReportList; |
| 38 |
use Liuch\DmarcSrg\Exception\RuntimeException; |
| 39 |
|
| 40 |
require realpath(__DIR__ . '/..') . '/init.php'; |
| 41 |
|
| 42 |
if (Core::isWEB()) { |
| 43 |
echo 'Forbidden'; |
| 44 |
exit(1); |
| 45 |
} |
| 46 |
|
| 47 |
$core = Core::instance(); |
| 48 |
$core->setCurrentUser('admin'); |
| 49 |
|
| 50 |
$days = $core->config('cleaner/reports/days_old', -1); |
| 51 |
if (gettype($days) !== 'integer' || $days < 0) { |
| 52 |
exit(0); |
| 53 |
} |
| 54 |
$days_date = (new DateTime())->sub(new \DateInterval("P{$days}D")); |
| 55 |
|
| 56 |
$maximum = $core->config('cleaner/reports/delete_maximum', 0); |
| 57 |
if (gettype($maximum) !== 'integer' || $maximum < 0) { |
| 58 |
exit(0); |
| 59 |
} |
| 60 |
|
| 61 |
$leave = $core->config('cleaner/reports/leave_minimum', 0); |
| 62 |
if (gettype($leave) !== 'integer' || $leave < 0) { |
| 63 |
exit(0); |
| 64 |
} |
| 65 |
|
| 66 |
try { |
| 67 |
$rl = new ReportList($core->getCurrentUser()); |
| 68 |
$cnt = $rl->count() - $leave; |
| 69 |
if ($cnt > 0) { |
| 70 |
$rl->setFilter([ 'before_time' => $days_date ]); |
| 71 |
if ($leave * $maximum !== 0) { |
| 72 |
if ($maximum > 0 && $cnt > $maximum) { |
| 73 |
$cnt = $maximum; |
| 74 |
} |
| 75 |
$rl->setMaxCount($cnt); |
| 76 |
$rl->setOrder(ReportList::ORDER_BEGIN_TIME, ReportList::ORDER_ASCENT); |
| 77 |
} |
| 78 |
$rl->delete(); |
| 79 |
} |
| 80 |
} catch (RuntimeException $e) { |
| 81 |
echo ErrorHandler::exceptionText($e); |
| 82 |
exit(1); |
| 83 |
} |
| 84 |
|
| 85 |
exit(0); |