From a7e6d1426d8f4c33653a7f2dd5ab8e62089b04a5 Mon Sep 17 00:00:00 2001 From: Armin Pleisch Date: Fri, 16 Jun 2023 13:39:03 +0200 Subject: [PATCH] feat: Add cleanup maintenance command --- .../Command/CleanupProcessDataCommand.php | 15 +++++-------- .../Controller/ProcessController.php | 22 ++++++++++++++++++- .../Maintenance/CleanupTask.php | 15 +++---------- .../Resources/config/services.yml | 6 +++-- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/ProcessManagerBundle/Command/CleanupProcessDataCommand.php b/src/ProcessManagerBundle/Command/CleanupProcessDataCommand.php index 23a4a10..d539e68 100644 --- a/src/ProcessManagerBundle/Command/CleanupProcessDataCommand.php +++ b/src/ProcessManagerBundle/Command/CleanupProcessDataCommand.php @@ -25,13 +25,8 @@ class CleanupProcessDataCommand extends AbstractCommand { - private CleanupService $cleanupService; - private string $logDirectory; - - public function __construct(CleanupService $cleanupService, string $logDirectory) { + public function __construct(private CleanupService $cleanupService, private string $logDirectory) { parent::__construct(); - $this->cleanupService = $cleanupService; - $this->logDirectory = $logDirectory; } protected function configure(): void @@ -75,14 +70,14 @@ public function execute(InputInterface $input, OutputInterface $output): int } // start deleting database entries older than x seconds - $this->output->writeln('start cleaning database entries older than ' . $seconds . ' seconds'); + $output->writeln('start cleaning database entries older than ' . $seconds . ' seconds'); $this->cleanupService->cleanupDbEntries($seconds); - $this->output->writeln('finish cleaning database entries older than ' . $seconds . ' seconds'); + $output->writeln('finish cleaning database entries older than ' . $seconds . ' seconds'); // start deleting log files older than x seconds - $this->output->writeln('start cleaning log files older than ' . $seconds . ' seconds'); + $output->writeln('start cleaning log files older than ' . $seconds . ' seconds'); $this->cleanupService->cleanupLogFiles($this->logDirectory, $seconds, $keepLogs); - $this->output->writeln('finish cleaning logfile entries older than ' . $seconds . ' seconds'); + $output->writeln('finish cleaning logfile entries older than ' . $seconds . ' seconds'); return Command::SUCCESS; } } diff --git a/src/ProcessManagerBundle/Controller/ProcessController.php b/src/ProcessManagerBundle/Controller/ProcessController.php index 56241cf..b25a13c 100644 --- a/src/ProcessManagerBundle/Controller/ProcessController.php +++ b/src/ProcessManagerBundle/Controller/ProcessController.php @@ -14,7 +14,16 @@ namespace ProcessManagerBundle\Controller; +use CoreShop\Bundle\ResourceBundle\Controller\EventDispatcherInterface; use CoreShop\Bundle\ResourceBundle\Controller\ResourceController; +use CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface; +use CoreShop\Bundle\ResourceBundle\Controller\ViewHandler; +use CoreShop\Bundle\ResourceBundle\Form\Helper\ErrorSerializer; +use CoreShop\Component\Resource\Factory\FactoryInterface; +use CoreShop\Component\Resource\Metadata\MetadataInterface; +use CoreShop\Component\Resource\Repository\RepositoryInterface; +use Doctrine\Persistence\ObjectManager; +use Pimcore\Db; use ProcessManagerBundle\Model\Process; use ProcessManagerBundle\Model\ProcessInterface; use ProcessManagerBundle\Service\CleanupService; @@ -34,6 +43,17 @@ public function listAction(Request $request): JsonResponse * @var Process\Listing $list */ $list = new $listingClass(); + if ($filterString = $request->get('filter')) { + $db = Db::get(); + $filters = json_decode($filterString); + $conditionParts = []; + foreach ($filters as $f) { + $fieldname = $f->property; + $conditionParts[] = $db->quoteIdentifier($fieldname) . ' LIKE ' . $db->quote('%' . $f->value . '%'); + } + $condition = implode(' AND ', $conditionParts); + $list->setCondition($condition); + } if ($sort = $request->get('sort')) { $sort = json_decode($sort)[0]; $list->setOrderKey($sort->property); @@ -113,7 +133,7 @@ public function clearAction(Request $request): JsonResponse $keepLogs = $this->container->getParameter('process_manager.keep_logs'); /** @var CleanupService $cleanupService */ - $cleanupService = $this->get('process_manager.cleanup_service'); + $cleanupService = $this->container->get('process_manager.cleanup_service'); $cleanupService->cleanupDbEntries($seconds); $cleanupService->cleanupLogFiles($logDirectory, $seconds, $keepLogs); return $this->json(['success' => true]); diff --git a/src/ProcessManagerBundle/Maintenance/CleanupTask.php b/src/ProcessManagerBundle/Maintenance/CleanupTask.php index cda9f53..b804b0b 100644 --- a/src/ProcessManagerBundle/Maintenance/CleanupTask.php +++ b/src/ProcessManagerBundle/Maintenance/CleanupTask.php @@ -16,23 +16,14 @@ use Pimcore\Maintenance\TaskInterface; use ProcessManagerBundle\Service\CleanupService; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; class CleanupTask implements TaskInterface { - private CleanupService $cleanupService; - private ParameterBagInterface $parameterBag; - - public function __construct(CleanupService $cleanupService, ParameterBagInterface $parameterBag) { - $this->cleanupService = $cleanupService; - $this->parameterBag = $parameterBag; + public function __construct(private CleanupService $cleanupService, private string $logDirectory, private int $seconds, private bool $keepLogs) { } public function execute(): void { - $seconds = $this->parameterBag->get('process_manager.seconds'); - $logDirectory = $this->parameterBag->get('process_manager.log_directory'); - $keepLogs = $this->parameterBag->get('process_manager.keep_logs'); - $this->cleanupService->cleanupDbEntries($seconds); - $this->cleanupService->cleanupLogFiles($logDirectory, $seconds, $keepLogs); + $this->cleanupService->cleanupDbEntries($this->seconds); + $this->cleanupService->cleanupLogFiles($this->logDirectory, $this->seconds, $this->keepLogs); } } diff --git a/src/ProcessManagerBundle/Resources/config/services.yml b/src/ProcessManagerBundle/Resources/config/services.yml index 5d80082..d1b0e1c 100644 --- a/src/ProcessManagerBundle/Resources/config/services.yml +++ b/src/ProcessManagerBundle/Resources/config/services.yml @@ -55,8 +55,10 @@ services: ProcessManagerBundle\Maintenance\CleanupTask: arguments: - - '@process_manager.cleanup_service' - - '@parameter_bag' + - '@ProcessManagerBundle\Service\CleanupService' + - '%process_manager.log_directory%' + - '%process_manager.seconds%' + - '%process_manager.keep_logs%' tags: - { name: pimcore.maintenance.task, type: process_manager.maintenance.cleanup }