‪TYPO3CMS  ‪main
CheckIntegrityCommand.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\Command\Command;
21 use Symfony\Component\Console\Helper\Table;
22 use Symfony\Component\Console\Input\InputArgument;
23 use Symfony\Component\Console\Input\InputInterface;
24 use Symfony\Component\Console\Output\OutputInterface;
28 
29 class ‪CheckIntegrityCommand extends Command
30 {
31  private const ‪REGISTRY_NAMESPACE = 'tx_redirects';
32  public const ‪REGISTRY_KEY_CONFLICTING_REDIRECTS = 'conflicting_redirects';
33  public const ‪REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY = 'redirects_check_integrity_last_check';
34 
35  public function ‪__construct(
36  private readonly ‪Registry $registry,
37  private readonly ‪IntegrityService $integrityService
38  ) {
39  parent::__construct();
40  }
41 
42  protected function ‪configure(): void
43  {
44  $this->addArgument(
45  'site',
46  InputArgument::OPTIONAL,
47  'If set, then only pages of a specific site are checked',
48  ''
49  );
50  }
51 
55  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
56  {
57  $this->registry->remove(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_CONFLICTING_REDIRECTS);
58  $this->registry->remove(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY);
59 
60  $conflictingRedirects = [];
61  $list = [];
62  $site = $input->getArgument('site') ?: null;
63 
64  $table = new Table(‪$output);
65  $table->setHeaders(
66  [
68  'LLL:EXT:redirects/Resources/Private/Language/locallang_db.xlf:sys_redirect.source_host'
69  ),
71  'LLL:EXT:redirects/Resources/Private/Language/locallang_db.xlf:sys_redirect.source_path'
72  ),
74  'LLL:EXT:redirects/Resources/Private/Language/locallang_db.xlf:sys_redirect.target'
75  ),
76  ]
77  );
78 
79  foreach ($this->integrityService->findConflictingRedirects($site) as $conflict) {
80  $conflictingRedirects[] = [
81  $conflict['redirect']['source_host'],
82  $conflict['redirect']['source_path'],
83  $conflict['uri'],
84  ];
85  $list[] = $conflict;
86  }
87 
88  if ($conflictingRedirects !== []) {
89  $table->setRows($conflictingRedirects);
90  $table->render();
91  }
92 
93  $this->registry->set(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_CONFLICTING_REDIRECTS, $list);
94  $this->registry->set(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY, time());
95  return Command::SUCCESS;
96  }
97 }
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: CheckIntegrityCommand.php:55
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:35
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\REGISTRY_NAMESPACE
‪const REGISTRY_NAMESPACE
Definition: CheckIntegrityCommand.php:31
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Redirects\Command
Definition: CheckIntegrityCommand.php:18
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY
‪const REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY
Definition: CheckIntegrityCommand.php:33
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\__construct
‪__construct(private readonly Registry $registry, private readonly IntegrityService $integrityService)
Definition: CheckIntegrityCommand.php:35
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\REGISTRY_KEY_CONFLICTING_REDIRECTS
‪const REGISTRY_KEY_CONFLICTING_REDIRECTS
Definition: CheckIntegrityCommand.php:32
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, Locale|string $languageKey=null)
Definition: LocalizationUtility.php:47
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand
Definition: CheckIntegrityCommand.php:30
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\configure
‪configure()
Definition: CheckIntegrityCommand.php:42
‪TYPO3\CMS\Redirects\Service\IntegrityService
Definition: IntegrityService.php:32