コード例 #1
0
 /**
  * @test
  */
 public function clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce()
 {
     $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTag')->with('pages', 'pageId_2');
     $this->cacheManagerMock->expects($this->at(1))->method('flushCachesInGroupByTag')->with('pages', 'pageId_15');
     $this->cacheManagerMock->expects($this->at(2))->method('flushCachesInGroupByTag')->with('pages', 'pageId_8');
     $this->cacheManagerMock->expects($this->exactly(3))->method('flushCachesInGroupByTag');
     $this->cacheService->getPageIdStack()->push(8);
     $this->cacheService->getPageIdStack()->push(15);
     $this->cacheService->getPageIdStack()->push(15);
     $this->cacheService->getPageIdStack()->push(2);
     $this->cacheService->getPageIdStack()->push(2);
     $this->cacheService->clearCachesOfRegisteredPageIds();
 }
コード例 #2
0
 /**
  * Clear the TYPO3 page cache for the given record.
  * If the record lies on a page, then we clear the cache of this page.
  * If the record has no PID column, we clear the cache of the current page as best-effort.
  *
  * Much of this functionality is taken from DataHandler::clear_cache() which unfortunately only works with logged-in BE user.
  *
  * @param string $tableName Table name of the record
  * @param int $uid UID of the record
  * @return void
  */
 protected function clearPageCache($tableName, $uid)
 {
     $frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
     if (isset($frameworkConfiguration['persistence']['enableAutomaticCacheClearing']) && $frameworkConfiguration['persistence']['enableAutomaticCacheClearing'] === '1') {
     } else {
         // if disabled, return
         return;
     }
     $pageIdsToClear = [];
     $storagePage = null;
     $columns = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName)->getSchemaManager()->listTableColumns($tableName);
     if (array_key_exists('pid', $columns)) {
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
         $queryBuilder->getRestrictions()->removeAll();
         $result = $queryBuilder->select('pid')->from($tableName)->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))->execute();
         if ($row = $result->fetch()) {
             $storagePage = $row['pid'];
             $pageIdsToClear[] = $storagePage;
         }
     } elseif (isset($GLOBALS['TSFE'])) {
         // No PID column - we can do a best-effort to clear the cache of the current page if in FE
         $storagePage = $GLOBALS['TSFE']->id;
         $pageIdsToClear[] = $storagePage;
     }
     if ($storagePage === null) {
         return;
     }
     if (!isset($this->pageTSConfigCache[$storagePage])) {
         $this->pageTSConfigCache[$storagePage] = BackendUtility::getPagesTSconfig($storagePage);
     }
     if (isset($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd'])) {
         $clearCacheCommands = GeneralUtility::trimExplode(',', strtolower($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd']), true);
         $clearCacheCommands = array_unique($clearCacheCommands);
         foreach ($clearCacheCommands as $clearCacheCommand) {
             if (MathUtility::canBeInterpretedAsInteger($clearCacheCommand)) {
                 $pageIdsToClear[] = $clearCacheCommand;
             }
         }
     }
     foreach ($pageIdsToClear as $pageIdToClear) {
         $this->cacheService->getPageIdStack()->push($pageIdToClear);
     }
 }
コード例 #3
0
ファイル: Typo3DbBackend.php プロジェクト: plan2net/TYPO3.CMS
 /**
  * Clear the TYPO3 page cache for the given record.
  * If the record lies on a page, then we clear the cache of this page.
  * If the record has no PID column, we clear the cache of the current page as best-effort.
  *
  * Much of this functionality is taken from DataHandler::clear_cache() which unfortunately only works with logged-in BE user.
  *
  * @param string $tableName Table name of the record
  * @param int $uid UID of the record
  * @return void
  */
 protected function clearPageCache($tableName, $uid)
 {
     $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
     if (isset($frameworkConfiguration['persistence']['enableAutomaticCacheClearing']) && $frameworkConfiguration['persistence']['enableAutomaticCacheClearing'] === '1') {
     } else {
         // if disabled, return
         return;
     }
     $pageIdsToClear = array();
     $storagePage = NULL;
     $columns = $this->databaseHandle->admin_get_fields($tableName);
     if (array_key_exists('pid', $columns)) {
         $result = $this->databaseHandle->exec_SELECTquery('pid', $tableName, 'uid=' . (int) $uid);
         if ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
             $storagePage = $row['pid'];
             $pageIdsToClear[] = $storagePage;
         }
     } elseif (isset($GLOBALS['TSFE'])) {
         // No PID column - we can do a best-effort to clear the cache of the current page if in FE
         $storagePage = $GLOBALS['TSFE']->id;
         $pageIdsToClear[] = $storagePage;
     }
     if ($storagePage === NULL) {
         return;
     }
     if (!isset($this->pageTSConfigCache[$storagePage])) {
         $this->pageTSConfigCache[$storagePage] = BackendUtility::getPagesTSconfig($storagePage);
     }
     if (isset($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd'])) {
         $clearCacheCommands = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', strtolower($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd']), TRUE);
         $clearCacheCommands = array_unique($clearCacheCommands);
         foreach ($clearCacheCommands as $clearCacheCommand) {
             if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($clearCacheCommand)) {
                 $pageIdsToClear[] = $clearCacheCommand;
             }
         }
     }
     foreach ($pageIdsToClear as $pageIdToClear) {
         $this->cacheService->getPageIdStack()->push($pageIdToClear);
     }
 }