‪TYPO3CMS  ‪main
RedirectStatus.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 Psr\Http\Message\ServerRequestInterface;
32 
37 {
38  public function ‪__construct(
39  protected readonly ‪BackendViewFactory $backendViewFactory,
40  protected readonly ‪RedirectRepository $redirectRepository,
41  protected readonly ‪Registry $registry,
42  protected readonly ‪CheckIntegrityConfiguration $checkIntegrityConfiguration,
43  ) {}
44 
62  public function ‪getStatus(ServerRequestInterface $request = null): array
63  {
64  if ($request === null) {
65  return [];
66  }
67  if ($this->redirectRepository->countActiveRedirects() === 0) {
68  return ['Conflicts' => $this->‪getNoRedirectsStatus($request)];
69  }
70  $statusArray = ['Conflicts' => $this->‪getConflictingRedirectsStatus($request)];
71  $lastCheckIntegrityStatus = $this->‪getLastCheckIntegrityStatus();
72  if ($lastCheckIntegrityStatus !== null) {
73  $statusArray['Last checkintegrity'] = $lastCheckIntegrityStatus;
74  }
75  return $statusArray;
76  }
77 
78  public function ‪getLabel(): string
79  {
80  return 'LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:statusProvider';
81  }
82 
83  protected function ‪getNoRedirectsStatus(ServerRequestInterface $request): ‪Status
84  {
85  $view = $this->backendViewFactory->create($request, ['typo3/cms-redirects']);
86  $view->assignMultiple([
87  'count' => 0,
88  'reportedConflicts' => [],
89  ]);
90 
91  return GeneralUtility::makeInstance(
92  Status::class,
93  $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.conflictingRedirects'),
94  $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.conflictingRedirects.none'),
95  $view->render('Report/RedirectStatus'),
96  ContextualFeedbackSeverity::OK
97  );
98  }
99 
100  protected function ‪getConflictingRedirectsStatus(ServerRequestInterface $request): ‪Status
101  {
102  $value = $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.conflictingRedirects.none');
103  $severity = ContextualFeedbackSeverity::OK;
104 
105  $reportedConflicts = $this->‪getConflictingRedirects();
106  $count = count($reportedConflicts);
107  if ($count > 0) {
108  $value = sprintf($this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.conflictingRedirects.count'), $count);
109  $severity = ContextualFeedbackSeverity::WARNING;
110  }
111 
112  $view = $this->backendViewFactory->create($request, ['typo3/cms-redirects']);
113  $view->assignMultiple([
114  'count' => $count,
115  'reportedConflicts' => $reportedConflicts,
116  ]);
117 
118  return GeneralUtility::makeInstance(
119  Status::class,
120  $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.conflictingRedirects'),
121  $value,
122  $view->render('Report/RedirectStatus'),
123  $severity
124  );
125  }
126 
128  {
129  if (!$this->checkIntegrityConfiguration->showInfoInReports) {
130  return null;
131  }
132  $lastCheck = $this->‪getCheckIntegrityLastCheckTimestamp();
133  $hasCheckedBefore = $lastCheck > 0;
134  $checkPoint = time() - $this->checkIntegrityConfiguration->seconds;
135  $lastCheckIsWithinCheckPeriod = $lastCheck >= $checkPoint;
136  if (!$hasCheckedBefore || !$lastCheckIsWithinCheckPeriod) {
137  return GeneralUtility::makeInstance(
138  Status::class,
139  $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.checkIntegrityResultState'),
140  $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.checkIntegrityResultState.title'),
141  $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_reports.xlf:status.checkIntegrityResultState.message'),
142  ContextualFeedbackSeverity::INFO
143  );
144  }
145  return null;
146  }
147 
148  protected function ‪getConflictingRedirects(): array
149  {
150  return $this->registry->get('tx_redirects', ‪CheckIntegrityCommand::REGISTRY_KEY_CONFLICTING_REDIRECTS, []);
151  }
152 
153  protected function ‪getCheckIntegrityLastCheckTimestamp(): int
154  {
155  return $this->registry->get('tx_redirects', ‪CheckIntegrityCommand::REGISTRY_KEY_LAST_TIMESTAMP_CHECK_INTEGRITY, 0);
156  }
157 
159  {
160  return ‪$GLOBALS['LANG'];
161  }
162 }
‪TYPO3\CMS\Reports\StatusProviderInterface
Definition: StatusProviderInterface.php:22
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus
Definition: RedirectStatus.php:37
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\getNoRedirectsStatus
‪getNoRedirectsStatus(ServerRequestInterface $request)
Definition: RedirectStatus.php:83
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\getConflictingRedirects
‪getConflictingRedirects()
Definition: RedirectStatus.php:148
‪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\Report\Status\RedirectStatus\getStatus
‪Status[] getStatus(ServerRequestInterface $request=null)
Definition: RedirectStatus.php:62
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\__construct
‪__construct(protected readonly BackendViewFactory $backendViewFactory, protected readonly RedirectRepository $redirectRepository, protected readonly Registry $registry, protected readonly CheckIntegrityConfiguration $checkIntegrityConfiguration,)
Definition: RedirectStatus.php:38
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\getCheckIntegrityLastCheckTimestamp
‪getCheckIntegrityLastCheckTimestamp()
Definition: RedirectStatus.php:153
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\getLabel
‪getLabel()
Definition: RedirectStatus.php:78
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand\REGISTRY_KEY_CONFLICTING_REDIRECTS
‪const REGISTRY_KEY_CONFLICTING_REDIRECTS
Definition: CheckIntegrityCommand.php:34
‪TYPO3\CMS\Redirects\Command\CheckIntegrityCommand
Definition: CheckIntegrityCommand.php:32
‪TYPO3\CMS\Redirects\Report\Status
Definition: RedirectStatus.php:18
‪TYPO3\CMS\Redirects\Repository\RedirectRepository
Definition: RedirectRepository.php:31
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\getLastCheckIntegrityStatus
‪getLastCheckIntegrityStatus()
Definition: RedirectStatus.php:127
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\getConflictingRedirectsStatus
‪getConflictingRedirectsStatus(ServerRequestInterface $request)
Definition: RedirectStatus.php:100
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Reports\RequestAwareStatusProviderInterface
Definition: RequestAwareStatusProviderInterface.php:26
‪TYPO3\CMS\Redirects\Configuration\CheckIntegrityConfiguration
Definition: CheckIntegrityConfiguration.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Redirects\Report\Status\RedirectStatus\getLanguageService
‪getLanguageService()
Definition: RedirectStatus.php:158