| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace Opentalent\OtTemplating\Utility;
- use Opentalent\OtTemplating\Page\OtPageRepository;
- use Psr\Http\Message\ResponseInterface;
- use RuntimeException;
- use TYPO3\CMS\Core\Service\OpcodeCacheService;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Install\Service\ClearCacheService;
- use TYPO3\CMS\Install\Service\Typo3tempFileService;
- use TYPO3\CMS\Core\Cache\CacheManager;
- class OtCacheManager
- {
- /**
- * Clears the page cache
- *
- * @param int $pageUid
- */
- public static function clearPageCache(int $pageUid) {
- $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
- $cacheManager->flushCachesInGroupByTag(
- 'pages',
- 'pageId_' . $pageUid
- );
- }
- /**
- * Clears cache for each page of the site
- *
- * @param int $pageUid
- */
- public static function clearSiteCache(int $pageUid) {
- $pageRepository = new OtPageRepository();
- $rootPage = $pageRepository->getRootPageFor($pageUid);
- $pages = $pageRepository->getAllSubpagesForPage($rootPage['uid']);
- $pages[] = $rootPage;
- $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
- $tags = array_map(function ($page) {
- return 'pageId_' . $page['uid'];
- }, $pages);
- $cacheManager->flushCachesInGroupByTags('pages', $tags);
- }
- /**
- * Clear cache framework and opcode caches
- * (@see TYPO3\CMS\Install\Controller\MaintenanceController )
- */
- public static function clearAllCache(): ResponseInterface
- {
- GeneralUtility::makeInstance(ClearCacheService::class)->clearAll();
- GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
- }
- /**
- * Clear typo3temp/assets
- * (@see TYPO3\CMS\Install\Controller\MaintenanceController )
- */
- public static function clearAssetsTempfiles()
- {
- $typo3tempFileService = GeneralUtility::makeInstance(Typo3tempFileService::class);
- try {
- $typo3tempFileService->clearAssetsFolder("/typo3temp/assets/css");
- } catch (RuntimeException $e) {
- // 1501781454 code means directory does not exist, we can ignore this error
- if ($e->getCode() != 1501781454) {
- throw $e;
- }
- }
- try {
- $typo3tempFileService->clearAssetsFolder("/typo3temp/assets/js");
- } catch (RuntimeException $e) {
- // 1501781454 code means directory does not exist, we can ignore this error
- if ($e->getCode() != 1501781454) {
- throw $e;
- }
- }
- }
- }
|