‪TYPO3CMS  ‪main
CleanupRedirectsCommand.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\Console\Attribute\AsCommand;
21 use Symfony\Component\Console\Command\Command;
22 use Symfony\Component\Console\Input\InputInterface;
23 use Symfony\Component\Console\Input\InputOption;
24 use Symfony\Component\Console\Output\OutputInterface;
29 
30 #[AsCommand('redirects:cleanup', 'Cleanup old redirects periodically for given constraints like days, hit count or domains.')]
31 class ‪CleanupRedirectsCommand extends Command
32 {
34 
35  public function ‪__construct(
36  protected readonly ‪RedirectRepository $redirectRepository,
37  protected readonly ‪LanguageServiceFactory $languageServiceFactory
38  ) {
39  $this->languageService = $languageServiceFactory->create('default');
40  parent::__construct();
41  }
42 
43  protected function ‪configure(): void
44  {
45  $this
46  ->addOption(
47  'domain',
48  'd',
49  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
50  $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang.xlf:cleanupRedirectsCommand.label.domain'),
51  null
52  )
53  ->addOption(
54  'statusCode',
55  's',
56  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
57  $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang.xlf:cleanupRedirectsCommand.label.statusCode'),
58  null
59  )
60  ->addOption(
61  'days',
62  'a',
63  InputOption::VALUE_OPTIONAL,
64  $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang.xlf:cleanupRedirectsCommand.label.days'),
65  null
66  )
67  ->addOption(
68  'hitCount',
69  'c',
70  InputOption::VALUE_OPTIONAL,
71  $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang.xlf:cleanupRedirectsCommand.label.hitCount'),
72  null
73  )
74  ->addOption(
75  'path',
76  'p',
77  InputOption::VALUE_OPTIONAL,
78  $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang.xlf:cleanupRedirectsCommand.label.path'),
79  null
80  )
81  ->addOption(
82  'creationType',
83  't',
84  InputOption::VALUE_OPTIONAL,
85  $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang.xlf:cleanupRedirectsCommand.label.creationType'),
86  null
87  )
88  ->addOption(
89  'integrityStatus',
90  'i',
91  InputOption::VALUE_OPTIONAL,
92  $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang.xlf:cleanupRedirectsCommand.label.integrityStatus'),
93  null
94  )
95  ;
96  }
97 
98  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
99  {
100  $this->redirectRepository->removeByDemand(‪Demand::fromCommandInput($input));
101  return Command::SUCCESS;
102  }
103 }
‪TYPO3\CMS\Redirects\Repository\Demand
Definition: Demand.php:29
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Redirects\Command\CleanupRedirectsCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: CleanupRedirectsCommand.php:98
‪TYPO3\CMS\Redirects\Command
Definition: CheckIntegrityCommand.php:18
‪TYPO3\CMS\Redirects\Repository\RedirectRepository
Definition: RedirectRepository.php:31
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Redirects\Repository\Demand\fromCommandInput
‪static fromCommandInput(InputInterface $input)
Definition: Demand.php:116
‪TYPO3\CMS\Redirects\Command\CleanupRedirectsCommand\configure
‪configure()
Definition: CleanupRedirectsCommand.php:43
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Redirects\Command\CleanupRedirectsCommand\$languageService
‪LanguageService $languageService
Definition: CleanupRedirectsCommand.php:33
‪TYPO3\CMS\Redirects\Command\CleanupRedirectsCommand\__construct
‪__construct(protected readonly RedirectRepository $redirectRepository, protected readonly LanguageServiceFactory $languageServiceFactory)
Definition: CleanupRedirectsCommand.php:35
‪TYPO3\CMS\Redirects\Command\CleanupRedirectsCommand
Definition: CleanupRedirectsCommand.php:32