‪TYPO3CMS  11.5
RecordHistoryRollbackController.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\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
30 
35 {
38 
40  {
41  $this->languageServiceFactory = ‪$languageServiceFactory;
42  }
43 
44  public function ‪revertCorrelation(ServerRequestInterface $request): ResponseInterface
45  {
46  $this->languageService = $this->languageServiceFactory->createFromUserPreferences(‪$GLOBALS['BE_USER']);
47  $revertedCorrelationTypes = [];
48  $correlationIds = $request->getQueryParams()['correlation_ids'] ?? [];
50  $correlationIds = array_map(
51  static function (string $correlationId) {
52  return ‪CorrelationId::fromString($correlationId);
53  },
54  $correlationIds
55  );
56  foreach ($correlationIds as $correlationId) {
57  $aspects = $correlationId->getAspects();
58  if (count($aspects) < 2 || $aspects[0] !== ‪SlugService::CORRELATION_ID_IDENTIFIER) {
59  continue;
60  }
61  $revertedCorrelationTypes[] = $correlationId->getAspects()[1];
62  $this->‪rollBackCorrelation($correlationId);
63  }
64  $result = [
65  'status' => 'error',
66  'title' => $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_slug_service.xlf:redirects_error_title'),
67  'message' => $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_slug_service.xlf:redirects_error_message'),
68  ];
69  if (in_array('redirect', $revertedCorrelationTypes, true)) {
70  $result = [
71  'status' => 'ok',
72  'title' => $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_slug_service.xlf:revert_redirects_success_title'),
73  'message' => $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_slug_service.xlf:revert_redirects_success_message'),
74  ];
75  if (in_array('slug', $revertedCorrelationTypes, true)) {
76  $result = [
77  'status' => 'ok',
78  'title' => $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_slug_service.xlf:revert_update_success_title'),
79  'message' => $this->languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_slug_service.xlf:revert_update_success_message'),
80  ];
81  }
82  }
83  return new ‪JsonResponse($result);
84  }
85 
86  protected function ‪rollBackCorrelation(‪CorrelationId $correlationId): void
87  {
88  $recordHistoryRollback = GeneralUtility::makeInstance(RecordHistoryRollback::class);
89  foreach (GeneralUtility::makeInstance(RecordHistory::class)->findEventsForCorrelation((string)$correlationId) as $recordHistoryEntry) {
90  $element = $recordHistoryEntry['tablename'] . ':' . $recordHistoryEntry['recuid'];
91  $tempRecordHistory = GeneralUtility::makeInstance(RecordHistory::class, $element);
92  $tempRecordHistory->setLastHistoryEntryNumber((int)$recordHistoryEntry['uid']);
93  $recordHistoryRollback->performRollback('ALL', $tempRecordHistory->getDiff($tempRecordHistory->getChangeLog()));
94  }
95  }
96 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Redirects\Service\SlugService\CORRELATION_ID_IDENTIFIER
‪const CORRELATION_ID_IDENTIFIER
Definition: SlugService.php:52
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId\fromString
‪static static fromString(string $correlationId)
Definition: CorrelationId.php:75
‪TYPO3\CMS\Backend\History\RecordHistoryRollback
Definition: RecordHistoryRollback.php:29
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId
Definition: CorrelationId.php:29
‪TYPO3\CMS\Backend\History\RecordHistory
Definition: RecordHistory.php:32
‪TYPO3\CMS\Redirects\Controller\RecordHistoryRollbackController\$languageService
‪LanguageService $languageService
Definition: RecordHistoryRollbackController.php:36
‪TYPO3\CMS\Redirects\Controller\RecordHistoryRollbackController\rollBackCorrelation
‪rollBackCorrelation(CorrelationId $correlationId)
Definition: RecordHistoryRollbackController.php:86
‪TYPO3\CMS\Redirects\Controller\RecordHistoryRollbackController\__construct
‪__construct(LanguageServiceFactory $languageServiceFactory)
Definition: RecordHistoryRollbackController.php:39
‪TYPO3\CMS\Redirects\Controller\RecordHistoryRollbackController
Definition: RecordHistoryRollbackController.php:35
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Redirects\Controller\RecordHistoryRollbackController\$languageServiceFactory
‪LanguageServiceFactory $languageServiceFactory
Definition: RecordHistoryRollbackController.php:37
‪TYPO3\CMS\Redirects\Controller\RecordHistoryRollbackController\revertCorrelation
‪revertCorrelation(ServerRequestInterface $request)
Definition: RecordHistoryRollbackController.php:44
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Redirects\Controller
Definition: ManagementController.php:18
‪TYPO3\CMS\Redirects\Service\SlugService
Definition: SlugService.php:46