‪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\Attribute\AsCommand;
21 use Symfony\Component\Console\Command\Command;
22 use Symfony\Component\Console\Helper\Table;
23 use Symfony\Component\Console\Input\InputArgument;
24 use Symfony\Component\Console\Input\InputInterface;
25 use Symfony\Component\Console\Output\OutputInterface;
29 
30 #[AsCommand('redirects:checkintegrity', 'Check integrity of redirects')]
31 class ‪CheckIntegrityCommand extends Command
32 {
33  private const ‪REGISTRY_NAMESPACE = 'tx_redirects';
34  public const ‪REGISTRY_KEY_CONFLICTING_REDIRECTS = 'conflicting_redirects';
35  public const ‪REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY = 'redirects_check_integrity_last_check';
36  private const ‪LANGUAGE_FILE_PATH = 'LLL:EXT:redirects/Resources/Private/Language/locallang_db.xlf';
37 
38  public function ‪__construct(
39  private readonly ‪Registry $registry,
40  private readonly ‪IntegrityService $integrityService
41  ) {
42  parent::__construct();
43  }
44 
45  protected function ‪configure(): void
46  {
47  $this->addArgument(
48  'site',
49  InputArgument::OPTIONAL,
50  'If set, then only pages of a specific site are checked',
51  ''
52  );
53  }
54 
58  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
59  {
60  $this->registry->remove(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_CONFLICTING_REDIRECTS);
61  $this->registry->remove(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY);
62 
63  $conflictingRedirects = [];
64  $list = [];
65  $site = $input->getArgument('site') ?: null;
66 
67  $table = new Table(‪$output);
68  $table->setHeaders(
69  [
71  self::LANGUAGE_FILE_PATH . ':sys_redirect.uid'
72  ),
74  self::LANGUAGE_FILE_PATH . ':sys_redirect.source_host'
75  ),
77  self::LANGUAGE_FILE_PATH . ':sys_redirect.source_path'
78  ),
80  self::LANGUAGE_FILE_PATH . ':sys_redirect.target'
81  ),
83  self::LANGUAGE_FILE_PATH . ':sys_redirect.integrity_status'
84  ),
85  ]
86  );
87 
88  $integrityStatusLabel = ':sys_redirect.integrity_status.';
89  foreach ($this->integrityService->findConflictingRedirects($site) as $conflict) {
90  $conflictingRedirects[] = [
91  $conflict['redirect']['uid'],
92  $conflict['redirect']['source_host'],
93  $conflict['redirect']['source_path'],
94  $conflict['uri'],
96  self::LANGUAGE_FILE_PATH . $integrityStatusLabel . $conflict['redirect']['integrity_status']
97  ),
98  ];
99  $list[] = $conflict;
100  $this->integrityService->setIntegrityStatus($conflict['redirect']);
101  }
102 
103  if ($conflictingRedirects !== []) {
104  $table->setRows($conflictingRedirects);
105  $table->render();
106  }
107 
108  $this->registry->set(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_CONFLICTING_REDIRECTS, $list);
109  $this->registry->set(self::REGISTRY_NAMESPACE, self::REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY, time());
110  return Command::SUCCESS;
111  }
112 }
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: CheckIntegrityCommand.php:58
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:35
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\REGISTRY_NAMESPACE
‪const REGISTRY_NAMESPACE
Definition: CheckIntegrityCommand.php:33
‪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:35
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\LANGUAGE_FILE_PATH
‪const LANGUAGE_FILE_PATH
Definition: CheckIntegrityCommand.php:36
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\__construct
‪__construct(private readonly Registry $registry, private readonly IntegrityService $integrityService)
Definition: CheckIntegrityCommand.php:38
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\REGISTRY_KEY_CONFLICTING_REDIRECTS
‪const REGISTRY_KEY_CONFLICTING_REDIRECTS
Definition: CheckIntegrityCommand.php:34
‪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:32
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\configure
‪configure()
Definition: CheckIntegrityCommand.php:45
‪TYPO3\CMS\Redirects\Service\IntegrityService
Definition: IntegrityService.php:33