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