Lines 0.00% 0 / 18
Methods 0.00% 0 / 3
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 0.00% 0 / 3 0.00% 0 / 1 6
 log 0.00% 0 / 2 0.00% 0 / 1 6
 startProcessing 0.00% 0 / 13 0.00% 0 / 1 6
14class LogCleanUp
15{
16    protected $verbose = false;
17
18    public function __construct(bool $verbose = false)
19    {
20        if ($verbose) {
21            $this->verbose = true;
22            $this->log("INFO: Delete old logs");
23        }
24    }
25
26    protected function log(string $message): void
27    {
28        if ($this->verbose) {
29            \App::$log->info($message);
30        }
31    }
32
33    public static function startProcessing(bool $commit = false): void
34    {
35        \App::$log->info('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        \App::$log->info('Log cleanup config loaded', [
41            'olderThanDays' => $olderThan,
42            'olderThanDate' => $olderThanDate->format('Y-m-d H:i:s'),
43        ]);
44
45        $logRepo = new \BO\Zmsbackend\Log\Service\Log();
46        if ($commit) {
47            \App::$log->info('Executing log cleanup with commit');
48            $result = $logRepo->clearLogsOlderThan((int) $olderThan);
49            \App::$log->info('Log cleanup completed', ['success' => $result]);
50        }
51    }
52}