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