Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LogCleanUp | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| log | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| startProcessing | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 5 | **/ |
| 6 | |
| 7 | declare(strict_types=1); |
| 8 | |
| 9 | namespace BO\Zmsdb\Helper; |
| 10 | |
| 11 | use BO\Zmsdb\Config as ConfigRepository; |
| 12 | use BO\Zmsdb\Log; |
| 13 | |
| 14 | class LogCleanUp |
| 15 | { |
| 16 | protected $verbose = false; |
| 17 | |
| 18 | public function __construct($verbose = false) |
| 19 | { |
| 20 | if ($verbose) { |
| 21 | $this->verbose = true; |
| 22 | $this->log("INFO: Delete old logs"); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | protected function log($message) |
| 27 | { |
| 28 | if ($this->verbose) { |
| 29 | error_log($message); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | public static function startProcessing($commit = false) |
| 34 | { |
| 35 | error_log("Starting log cleanup process..."); |
| 36 | |
| 37 | $config = (new ConfigRepository())->readEntity(); |
| 38 | $olderThan = $config->getPreference('log', 'deleteOlderThanDays') ?? 90; |
| 39 | $olderThanDate = (new \DateTime())->modify('-' . $olderThan . ' days'); |
| 40 | error_log("Config loaded, older than: $olderThan days (Datum: " . $olderThanDate->format('Y-m-d H:i:s') . ")"); |
| 41 | |
| 42 | $logRepo = new Log(); |
| 43 | if ($commit) { |
| 44 | error_log("Executing cleanup with commit..."); |
| 45 | $result = $logRepo->clearLogsOlderThan((int) $olderThan); |
| 46 | error_log("Cleanup completed. Result: " . ($result ? "success" : "failed")); |
| 47 | } |
| 48 | } |
| 49 | } |