4baa5d8d0be5f7a03f9ebfd69575da5802ec4a8e
[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\Utility\GeneralUtility;
23
24 /**
25 * Whenever a sys_domain or sys_language record is modified, the Site Handling caches should be flushed.
26 * @internal
27 */
28 class SiteDataHandlerCacheHook
29 {
30 /**
31 * Called after a record was edited or added.
32 *
33 * @param string $status DataHandler operation status, either 'new' or 'update'
34 * @param string $table The DB table the operation was carried out on
35 * @param mixed $recordId The record's uid for update records, a string to look the record's uid up after it has been created
36 * @param array $updatedFields Array of changed fields and their new values
37 * @param DataHandler $dataHandler DataHandler parent object
38 */
39 public function processDatamap_afterDatabaseOperations(string $status, string $table, $recordId, array $updatedFields, DataHandler $dataHandler)
40 {
41 if ($table === 'sys_domain' || $table === 'sys_language') {
42 $this->getCache()->remove('pseudo-sites');
43 $this->getCache()->remove('legacy-domains');
44 }
45 }
46
47 /**
48 * Called after a record was deleted, moved or restored.
49 *
50 * @param string $command the cmd which was executed
51 * @param string $table The DB table the operation was carried out on
52 * @param mixed $id the ID which was operated on
53 * @param mixed $value
54 * @param DataHandler $dataHandler
55 * @param mixed $pasteUpdate
56 * @param array $pasteDatamap
57 */
58 public function processCmdmap_postProcess(string $command, string $table, $id, $value, DataHandler $dataHandler, $pasteUpdate, array $pasteDatamap)
59 {
60 if ($table === 'sys_domain' || $table === 'sys_language') {
61 $this->getCache()->remove('pseudo-sites');
62 $this->getCache()->remove('legacy-domains');
63 }
64 }
65
66 /**
67 * Shorthand method to flush the related caches
68 * @return FrontendInterface
69 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
70 */
71 protected function getCache(): FrontendInterface
72 {
73 return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
74 }
75 }