From 1e104592a4a1487b5f8d91737c092f04c4f1ccfb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 13 Feb 2022 09:41:37 +0100 Subject: [PATCH] Add 24.3: Creating a CLI Command --- src/Command/CommentCleanupCommand.php | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Command/CommentCleanupCommand.php diff --git a/src/Command/CommentCleanupCommand.php b/src/Command/CommentCleanupCommand.php new file mode 100644 index 0000000..aed63d1 --- /dev/null +++ b/src/Command/CommentCleanupCommand.php @@ -0,0 +1,49 @@ +commentRepository = $commentRepository; + + parent::__construct(); + } + + protected function configure() + { + $this + ->setDescription('Deletes rejected and spam comments from the database') + ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Dry run') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + if ($input->getOption('dry-run')) { + $io->note('Dry mode enabled'); + + $count = $this->commentRepository->countOldRejected(); + } else { + $count = $this->commentRepository->deleteOldRejected(); + } + + $io->success(sprintf('Deleted "%d" old rejected/spam comments.', $count)); + + return 0; + } +}