diff --git a/Classes/Agents/PageMovedAgent.php b/Classes/Agents/PageMovedAgent.php new file mode 100644 index 0000000..a4c44b9 --- /dev/null +++ b/Classes/Agents/PageMovedAgent.php @@ -0,0 +1,34 @@ +pageMovedInTree($changedFields)) { + $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class); + $pages = $queryGenerator->getTreeList($uid, 99, 0, 1); + $pagesUidList = array_merge($pagesUidList, explode(',', $pages)); + } + } + + return $pagesUidList; + } + + /** + * Returns true, if the page was moved via the page tree + * + * @param array $changedFields + * @return bool + */ + protected function pageMovedInTree(array $changedFields): bool + { + return array_keys($changedFields) === ['uid']; + } +} diff --git a/Classes/Hook/DataHandlerDetector.php b/Classes/Hook/DataHandlerDetector.php index a47b7d7..13aa7aa 100644 --- a/Classes/Hook/DataHandlerDetector.php +++ b/Classes/Hook/DataHandlerDetector.php @@ -58,7 +58,32 @@ public function __construct() */ public function processDatamap_afterDatabaseOperations($status, string $table, $id, array $changedFields, DataHandler $dataHandler) { - // @codingStandardsIgnoreEnd + $this->clearCachedPagesFoundByAgents($table, $id, $changedFields); + + } + + /** + * @param string $status The status of the record + * @param string $table Database table name + * @param int|string $id The uid of the record or something like "NEW59785a1ec52" if the record is new + * @param int $pageIdentifier The id of the page + * @throws \Exception + */ + public function processCmdmap_postProcess($status, $table, $id, $pageIdentifier) + { + $this->clearCachedPagesFoundByAgents($table, $id, ['uid' => $pageIdentifier]); + + } + + /** + * @param string $table + * @param $id + * @param array $changedFields of an array containing just the uid of a page + * @throws \Exception + */ + protected function clearCachedPagesFoundByAgents(string $table, $id, array $changedFields) + { +// @codingStandardsIgnoreEnd $expiredPages = []; if ($this->configuration->isConfigured($table)) { $agentConfigurations = $this->configuration->getAgentsForTable($table); @@ -74,7 +99,13 @@ public function processDatamap_afterDatabaseOperations($status, string $table, $ } if (count($expiredPages) !== 0) { - $this->cacheService->clearPageCache(array_unique($expiredPages)); + $expiredPages = array_unique($expiredPages); + // TODO: use new API in TYPO3 V9 + $extensionConfiguration = $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['cache_automation']); + $arrayChunks = array_chunk($expiredPages, $extensionConfiguration['numberOfCachedPagesToClear']); + foreach ($arrayChunks as $singleChunk) { + $this->cacheService->clearPageCache($singleChunk); + } } } } diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..d34c889 --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,2 @@ +# cat=basic/enable; type=string; label=Number of cached pages that will be cleared in one chunk +numberOfCachedPagesToClear = \ No newline at end of file