| 
 | 1 | +<?php  | 
 | 2 | + | 
 | 3 | +namespace Pixel\Module\Sucuri\Command;  | 
 | 4 | + | 
 | 5 | +use Exception;  | 
 | 6 | +use Pixel\Module\Sucuri\Model\Api;  | 
 | 7 | +use Symfony\Component\Console\Command\Command;  | 
 | 8 | +use Symfony\Component\Console\Input\InputArgument;  | 
 | 9 | +use Symfony\Component\Console\Input\InputInterface;  | 
 | 10 | +use Symfony\Component\Console\Output\OutputInterface;  | 
 | 11 | +use Symfony\Component\Translation\TranslatorInterface;  | 
 | 12 | + | 
 | 13 | +class LogClean extends Command  | 
 | 14 | +{  | 
 | 15 | +    private Api $api;  | 
 | 16 | + | 
 | 17 | +    private TranslatorInterface $translator;  | 
 | 18 | + | 
 | 19 | +    public function __construct(  | 
 | 20 | +        Api $api,  | 
 | 21 | +        TranslatorInterface $translator,  | 
 | 22 | +        string $name = null  | 
 | 23 | +    ) {  | 
 | 24 | +        $this->api = $api;  | 
 | 25 | +        $this->translator = $translator;  | 
 | 26 | + | 
 | 27 | +        parent::__construct($name);  | 
 | 28 | +    }  | 
 | 29 | + | 
 | 30 | +    protected function configure()  | 
 | 31 | +    {  | 
 | 32 | +        $this->setName('sucuri:log-clean')  | 
 | 33 | +            ->setDescription('Clean Sucuri logs')  | 
 | 34 | +            ->addArgument('retention', InputArgument::OPTIONAL, 'Log retention (days)', 60);  | 
 | 35 | +    }  | 
 | 36 | + | 
 | 37 | +    protected function execute(InputInterface $input, OutputInterface $output)  | 
 | 38 | +    {  | 
 | 39 | +        try {  | 
 | 40 | +            $retention = (int)$input->getArgument('retention');  | 
 | 41 | +            if ($retention) {  | 
 | 42 | +                $total = $this->api->cleanLog($retention);  | 
 | 43 | +                $output->writeln(  | 
 | 44 | +                    $this->translator->trans('%s logs purged for a %s-day retention period', [$total, $retention], 'Modules.Pixelsucuri.Admin')  | 
 | 45 | +                );  | 
 | 46 | +            }  | 
 | 47 | +        } catch (Exception $exception) {  | 
 | 48 | +            $output->writeln(  | 
 | 49 | +                $this->translator->trans('Unable to clean the logs: %s', [$exception->getMessage()], 'Modules.Pixelsucuri.Admin')  | 
 | 50 | +            );  | 
 | 51 | +        }  | 
 | 52 | +    }  | 
 | 53 | +}  | 
0 commit comments