[!!!][TASK] Remove sys_domain and LegacyDomains
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Hooks / SiteDataHandlerCacheHook.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Hooks;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\Cache\CacheManager;
20 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
21 use TYPO3\CMS\Core\DataHandling\DataHandler;
22 use TYPO3\CMS\Core\Routing\SiteMatcher;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25 /**
26 * When a sys_domain or sys_language record is modified, the Site Handling caches should be flushed.
27 * Also, if pages on root level are changed, site handling caches need flush.
28 *
29 * @internal This class is a hook implementation and is not part of the TYPO3 Core API.
30 */
31 class SiteDataHandlerCacheHook
32 {
33 /**
34 * Called after a record was edited or added.
35 *
36 * @param string $status DataHandler operation status, either 'new' or 'update'
37 * @param string $table The DB table the operation was carried out on
38 * @param mixed $recordId The record's uid for update records, a string to look the record's uid up after it has been created
39 * @param array $updatedFields Array of changed fields and their new values
40 * @param DataHandler $dataHandler DataHandler parent object
41 */
42 public function processDatamap_afterDatabaseOperations(string $status, string $table, $recordId, array $updatedFields, DataHandler $dataHandler)
43 {
44 if ($table === 'sys_language'
45 || ($status === 'new' && $table === 'pages' && (int)$updatedFields['pid'] === 0)
46 ) {
47 $this->getCache()->remove('pseudo-sites');
48 // After evicting caches, we need to make sure these are re-initialized within the
49 // current request if needed. Easiest solution is to purge the SiteMatcher singleton.
50 GeneralUtility::removeSingletonInstance(SiteMatcher::class, GeneralUtility::makeInstance(SiteMatcher::class));
51 }
52 }
53
54 /**
55 * Called after a record was deleted, moved or restored.
56 *
57 * @param string $command the cmd which was executed
58 * @param string $table The DB table the operation was carried out on
59 * @param mixed $id the ID which was operated on
60 * @param mixed $value
61 * @param DataHandler $dataHandler
62 * @param mixed $pasteUpdate
63 * @param array $pasteDatamap
64 */
65 public function processCmdmap_postProcess(string $command, string $table, $id, $value, DataHandler $dataHandler, $pasteUpdate, array $pasteDatamap)
66 {
67 if ($table === 'sys_language') {
68 $this->getCache()->remove('pseudo-sites');
69 }
70 }
71
72 /**
73 * Shorthand method to flush the related caches
74 * @return FrontendInterface
75 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
76 */
77 protected function getCache(): FrontendInterface
78 {
79 return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
80 }
81 }