diff --git a/Classes/Service/RegisterService.php b/Classes/Service/RegisterService.php index fe0a7a3f86d03bab395cc7c62d3fc5bc9b000274..df540cd54fb9703e5155816792944eee3c046122 100644 --- a/Classes/Service/RegisterService.php +++ b/Classes/Service/RegisterService.php @@ -27,8 +27,10 @@ namespace SGalinski\SgMail\Service; ***************************************************************/ use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\ObjectManager; /** * Provides an api for registering your mail templates @@ -82,6 +84,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { $entry = $cache->get($cacheId); if (!$entry) { + $this->clearCaches(); $entry = $this->registerExtensions(); if ($entry === NULL) { @@ -141,12 +144,12 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { // get file name without folders $pathAsArray = GeneralUtility::trimExplode('/', $pathToRegistrationFile); - $filename = $pathAsArray[\count($pathAsArray)-1]; + $filename = $pathAsArray[\count($pathAsArray) - 1]; $filenameWithoutHash = GeneralUtility::trimExplode('_', $filename)[1]; $hash = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $filenameWithoutHash); // if the filename doesnt start with the hash value, ignore it if (strpos($filename, $hash) !== 0) { - continue; + continue; } $configArray = (include $pathToRegistrationFile); @@ -244,5 +247,20 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { // get the location where automatic registrations should be stored return 'EXT:' . $tsSettings['mail']['configurationLocation'] . '/' . RegisterService::CONFIG_PATH; } + + /** + * Clear the sgmail register cache + * + * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException + */ + private function clearCaches() { + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + $cacheManager = $objectManager->get(CacheManager::class); + + /** @var FrontendInterface $cache */ + $cache = $cacheManager->getCache(RegisterService::CACHE_NAME); + /** @var FrontendInterface $cache */ + $cache->flush(); + } }