@@ -22,245 +22,245 @@ |
||
| 22 | 22 | class CacheService |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Traverse all files and initialize cache values. |
|
| 27 | - * |
|
| 28 | - * @return int |
|
| 29 | - */ |
|
| 30 | - public function warmUp() |
|
| 31 | - { |
|
| 32 | - /** @var QueryBuilder $queryBuilder */ |
|
| 33 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 34 | - $rows = $queryBuilder |
|
| 35 | - ->select('*') |
|
| 36 | - ->from('sys_file') |
|
| 37 | - ->where('storage > 0') |
|
| 38 | - ->execute() |
|
| 39 | - ->fetchAll(); |
|
| 40 | - |
|
| 41 | - $counter = 0; |
|
| 42 | - foreach ($rows as $row) { |
|
| 43 | - |
|
| 44 | - $fileIdentifier = $row['uid']; |
|
| 45 | - $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
| 46 | - |
|
| 47 | - $values = array( |
|
| 48 | - 'number_of_references' => $totalNumberOfReferences |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - $this->getDataService()->update( |
|
| 52 | - 'sys_file', |
|
| 53 | - $values, |
|
| 54 | - [ |
|
| 55 | - 'uid' => $fileIdentifier |
|
| 56 | - ] |
|
| 57 | - ); |
|
| 58 | - $counter++; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $counter; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Clear all possible cache related to a file. |
|
| 66 | - * This method is useful when replacing a file for instance. |
|
| 67 | - * |
|
| 68 | - * @param File $file |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function clearCache(File $file) |
|
| 72 | - { |
|
| 73 | - |
|
| 74 | - $this->clearCachePages($file); |
|
| 75 | - $this->flushProcessedFiles($file); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Remove all processed files that belong to the given File object. |
|
| 80 | - * |
|
| 81 | - * @param File $file |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - protected function flushProcessedFiles(File $file) |
|
| 85 | - { |
|
| 86 | - |
|
| 87 | - /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
| 88 | - foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
| 89 | - if ($processedFile->exists()) { |
|
| 90 | - $processedFile->delete(true); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $this->getDataService()->delete( |
|
| 94 | - 'sys_file_processedfile', |
|
| 95 | - [ |
|
| 96 | - 'uid' => (int)$processedFile->getUid() |
|
| 97 | - ] |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Return a processed file repository |
|
| 104 | - * |
|
| 105 | - * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
| 106 | - */ |
|
| 107 | - protected function getProcessedFileRepository() |
|
| 108 | - { |
|
| 109 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Returns the file references. |
|
| 114 | - * |
|
| 115 | - * @param File $file |
|
| 116 | - * @return void |
|
| 117 | - */ |
|
| 118 | - protected function clearCachePages($file) |
|
| 119 | - { |
|
| 120 | - |
|
| 121 | - /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 122 | - $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
| 123 | - $tce->start([], []); |
|
| 124 | - |
|
| 125 | - #$pages = array_merge( |
|
| 126 | - # $this->findPagesWithFileReferences($file), |
|
| 127 | - # $this->findPagesWithSoftReferences($file) |
|
| 128 | - #); |
|
| 129 | - |
|
| 130 | - // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
| 131 | - // It is adviced to use "registerPageCacheClearing" but how? |
|
| 132 | - #foreach (array_unique($pages) as $page) { |
|
| 133 | - # $tce->clear_cache('pages', $page); |
|
| 134 | - #} |
|
| 135 | - $tce->clear_cacheCmd('pages'); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Find all pages which contains file references to the given $file. |
|
| 140 | - * |
|
| 141 | - * @param File $file |
|
| 142 | - * @return array |
|
| 143 | - */ |
|
| 144 | - protected function findPagesWithFileReferences($file) |
|
| 145 | - { |
|
| 146 | - |
|
| 147 | - /** @var QueryBuilder $queryBuilder */ |
|
| 148 | - $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
| 149 | - $rows = $queryBuilder |
|
| 150 | - ->select('pid') |
|
| 151 | - ->from('sys_file_reference') |
|
| 152 | - ->groupBy('pid') // no support for distinct |
|
| 153 | - ->andWhere( |
|
| 154 | - 'pid > 0', |
|
| 155 | - 'uid_local = ' . $file->getUid() |
|
| 156 | - ) |
|
| 157 | - ->execute() |
|
| 158 | - ->fetchAll(); |
|
| 159 | - |
|
| 160 | - foreach ($rows as $row) { |
|
| 161 | - $pages[] = $row['pid']; |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $pages; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Find all pages which have soft references to the given $file. |
|
| 170 | - * |
|
| 171 | - * @param File $file |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - #protected function findPagesWithSoftReferences(File $file) |
|
| 175 | - #{ |
|
| 176 | - # $subClauseParts = array( |
|
| 177 | - # 'deleted = 0', |
|
| 178 | - # '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 179 | - # 'ref_table = "sys_file"', |
|
| 180 | - # 'tablename = "tt_content"', |
|
| 181 | - # 'ref_uid = ' . $file->getUid(), |
|
| 182 | - # ); |
|
| 183 | - # |
|
| 184 | - # $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 185 | - # 'DISTINCT pid', |
|
| 186 | - # 'tt_content', |
|
| 187 | - # sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 188 | - # implode(' AND ', $subClauseParts), |
|
| 189 | - # $this->getWhereClauseForEnabledFields('tt_content') |
|
| 190 | - # ) |
|
| 191 | - # ); |
|
| 192 | - # |
|
| 193 | - # // Compute result |
|
| 194 | - # $pages = []; |
|
| 195 | - # while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 196 | - # $pages[] = $affectedPage['pid']; |
|
| 197 | - # } |
|
| 198 | - # |
|
| 199 | - # return $pages; |
|
| 200 | - #} |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 204 | - * |
|
| 205 | - * @param string $tableName |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - protected function getWhereClauseForEnabledFields($tableName) |
|
| 209 | - { |
|
| 210 | - if ($this->isFrontendMode()) { |
|
| 211 | - // frontend context |
|
| 212 | - $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 213 | - } else { |
|
| 214 | - // backend context |
|
| 215 | - $whereClause = BackendUtility::deleteClause($tableName); |
|
| 216 | - } |
|
| 217 | - return $whereClause; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Returns whether the current mode is Frontend |
|
| 222 | - * |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - protected function isFrontendMode() |
|
| 226 | - { |
|
| 227 | - return TYPO3_MODE == 'FE'; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Returns an instance of the page repository. |
|
| 232 | - * |
|
| 233 | - * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 234 | - */ |
|
| 235 | - protected function getPageRepository() |
|
| 236 | - { |
|
| 237 | - return $GLOBALS['TSFE']->sys_page; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param string $tableName |
|
| 242 | - * @return object|QueryBuilder |
|
| 243 | - */ |
|
| 244 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
| 245 | - { |
|
| 246 | - /** @var ConnectionPool $connectionPool */ |
|
| 247 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 248 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @return object|DataService |
|
| 253 | - */ |
|
| 254 | - protected function getDataService(): DataService |
|
| 255 | - { |
|
| 256 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 261 | - */ |
|
| 262 | - protected function getFileReferenceService() |
|
| 263 | - { |
|
| 264 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 265 | - } |
|
| 25 | + /** |
|
| 26 | + * Traverse all files and initialize cache values. |
|
| 27 | + * |
|
| 28 | + * @return int |
|
| 29 | + */ |
|
| 30 | + public function warmUp() |
|
| 31 | + { |
|
| 32 | + /** @var QueryBuilder $queryBuilder */ |
|
| 33 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 34 | + $rows = $queryBuilder |
|
| 35 | + ->select('*') |
|
| 36 | + ->from('sys_file') |
|
| 37 | + ->where('storage > 0') |
|
| 38 | + ->execute() |
|
| 39 | + ->fetchAll(); |
|
| 40 | + |
|
| 41 | + $counter = 0; |
|
| 42 | + foreach ($rows as $row) { |
|
| 43 | + |
|
| 44 | + $fileIdentifier = $row['uid']; |
|
| 45 | + $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
| 46 | + |
|
| 47 | + $values = array( |
|
| 48 | + 'number_of_references' => $totalNumberOfReferences |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + $this->getDataService()->update( |
|
| 52 | + 'sys_file', |
|
| 53 | + $values, |
|
| 54 | + [ |
|
| 55 | + 'uid' => $fileIdentifier |
|
| 56 | + ] |
|
| 57 | + ); |
|
| 58 | + $counter++; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $counter; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Clear all possible cache related to a file. |
|
| 66 | + * This method is useful when replacing a file for instance. |
|
| 67 | + * |
|
| 68 | + * @param File $file |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function clearCache(File $file) |
|
| 72 | + { |
|
| 73 | + |
|
| 74 | + $this->clearCachePages($file); |
|
| 75 | + $this->flushProcessedFiles($file); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Remove all processed files that belong to the given File object. |
|
| 80 | + * |
|
| 81 | + * @param File $file |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + protected function flushProcessedFiles(File $file) |
|
| 85 | + { |
|
| 86 | + |
|
| 87 | + /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
| 88 | + foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
| 89 | + if ($processedFile->exists()) { |
|
| 90 | + $processedFile->delete(true); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $this->getDataService()->delete( |
|
| 94 | + 'sys_file_processedfile', |
|
| 95 | + [ |
|
| 96 | + 'uid' => (int)$processedFile->getUid() |
|
| 97 | + ] |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Return a processed file repository |
|
| 104 | + * |
|
| 105 | + * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
| 106 | + */ |
|
| 107 | + protected function getProcessedFileRepository() |
|
| 108 | + { |
|
| 109 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Returns the file references. |
|
| 114 | + * |
|
| 115 | + * @param File $file |
|
| 116 | + * @return void |
|
| 117 | + */ |
|
| 118 | + protected function clearCachePages($file) |
|
| 119 | + { |
|
| 120 | + |
|
| 121 | + /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 122 | + $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
| 123 | + $tce->start([], []); |
|
| 124 | + |
|
| 125 | + #$pages = array_merge( |
|
| 126 | + # $this->findPagesWithFileReferences($file), |
|
| 127 | + # $this->findPagesWithSoftReferences($file) |
|
| 128 | + #); |
|
| 129 | + |
|
| 130 | + // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
| 131 | + // It is adviced to use "registerPageCacheClearing" but how? |
|
| 132 | + #foreach (array_unique($pages) as $page) { |
|
| 133 | + # $tce->clear_cache('pages', $page); |
|
| 134 | + #} |
|
| 135 | + $tce->clear_cacheCmd('pages'); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Find all pages which contains file references to the given $file. |
|
| 140 | + * |
|
| 141 | + * @param File $file |
|
| 142 | + * @return array |
|
| 143 | + */ |
|
| 144 | + protected function findPagesWithFileReferences($file) |
|
| 145 | + { |
|
| 146 | + |
|
| 147 | + /** @var QueryBuilder $queryBuilder */ |
|
| 148 | + $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
| 149 | + $rows = $queryBuilder |
|
| 150 | + ->select('pid') |
|
| 151 | + ->from('sys_file_reference') |
|
| 152 | + ->groupBy('pid') // no support for distinct |
|
| 153 | + ->andWhere( |
|
| 154 | + 'pid > 0', |
|
| 155 | + 'uid_local = ' . $file->getUid() |
|
| 156 | + ) |
|
| 157 | + ->execute() |
|
| 158 | + ->fetchAll(); |
|
| 159 | + |
|
| 160 | + foreach ($rows as $row) { |
|
| 161 | + $pages[] = $row['pid']; |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return $pages; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Find all pages which have soft references to the given $file. |
|
| 170 | + * |
|
| 171 | + * @param File $file |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + #protected function findPagesWithSoftReferences(File $file) |
|
| 175 | + #{ |
|
| 176 | + # $subClauseParts = array( |
|
| 177 | + # 'deleted = 0', |
|
| 178 | + # '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 179 | + # 'ref_table = "sys_file"', |
|
| 180 | + # 'tablename = "tt_content"', |
|
| 181 | + # 'ref_uid = ' . $file->getUid(), |
|
| 182 | + # ); |
|
| 183 | + # |
|
| 184 | + # $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 185 | + # 'DISTINCT pid', |
|
| 186 | + # 'tt_content', |
|
| 187 | + # sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 188 | + # implode(' AND ', $subClauseParts), |
|
| 189 | + # $this->getWhereClauseForEnabledFields('tt_content') |
|
| 190 | + # ) |
|
| 191 | + # ); |
|
| 192 | + # |
|
| 193 | + # // Compute result |
|
| 194 | + # $pages = []; |
|
| 195 | + # while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 196 | + # $pages[] = $affectedPage['pid']; |
|
| 197 | + # } |
|
| 198 | + # |
|
| 199 | + # return $pages; |
|
| 200 | + #} |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 204 | + * |
|
| 205 | + * @param string $tableName |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + protected function getWhereClauseForEnabledFields($tableName) |
|
| 209 | + { |
|
| 210 | + if ($this->isFrontendMode()) { |
|
| 211 | + // frontend context |
|
| 212 | + $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 213 | + } else { |
|
| 214 | + // backend context |
|
| 215 | + $whereClause = BackendUtility::deleteClause($tableName); |
|
| 216 | + } |
|
| 217 | + return $whereClause; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Returns whether the current mode is Frontend |
|
| 222 | + * |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + protected function isFrontendMode() |
|
| 226 | + { |
|
| 227 | + return TYPO3_MODE == 'FE'; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Returns an instance of the page repository. |
|
| 232 | + * |
|
| 233 | + * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 234 | + */ |
|
| 235 | + protected function getPageRepository() |
|
| 236 | + { |
|
| 237 | + return $GLOBALS['TSFE']->sys_page; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param string $tableName |
|
| 242 | + * @return object|QueryBuilder |
|
| 243 | + */ |
|
| 244 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
| 245 | + { |
|
| 246 | + /** @var ConnectionPool $connectionPool */ |
|
| 247 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 248 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return object|DataService |
|
| 253 | + */ |
|
| 254 | + protected function getDataService(): DataService |
|
| 255 | + { |
|
| 256 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 261 | + */ |
|
| 262 | + protected function getFileReferenceService() |
|
| 263 | + { |
|
| 264 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 265 | + } |
|
| 266 | 266 | } |
@@ -1,30 +1,30 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $EM_CONF[$_EXTKEY] = [ |
| 4 | - 'title' => 'Media management', |
|
| 5 | - 'description' => 'Media management system for TYPO3 CMS.', |
|
| 6 | - 'category' => 'module', |
|
| 7 | - 'author' => 'Fabien Udriot', |
|
| 8 | - 'author_email' => '[email protected]', |
|
| 9 | - 'state' => 'stable', |
|
| 10 | - 'version' => '5.2.0-dev', |
|
| 11 | - 'autoload' => [ |
|
| 12 | - 'psr-4' => ['Fab\\Media\\' => 'Classes'] |
|
| 13 | - ], |
|
| 14 | - 'constraints' => |
|
| 15 | - [ |
|
| 16 | - 'depends' => |
|
| 17 | - [ |
|
| 18 | - 'typo3' => '9.5.0-9.5.99', |
|
| 19 | - 'vidi' => '4.0.0-0.0.0', |
|
| 20 | - ], |
|
| 21 | - 'conflicts' => |
|
| 22 | - [ |
|
| 23 | - ], |
|
| 24 | - 'suggests' => |
|
| 25 | - [ |
|
| 26 | - 'metadata' => '', |
|
| 27 | - 'filemetadata' => '', |
|
| 28 | - ], |
|
| 29 | - ] |
|
| 4 | + 'title' => 'Media management', |
|
| 5 | + 'description' => 'Media management system for TYPO3 CMS.', |
|
| 6 | + 'category' => 'module', |
|
| 7 | + 'author' => 'Fabien Udriot', |
|
| 8 | + 'author_email' => '[email protected]', |
|
| 9 | + 'state' => 'stable', |
|
| 10 | + 'version' => '5.2.0-dev', |
|
| 11 | + 'autoload' => [ |
|
| 12 | + 'psr-4' => ['Fab\\Media\\' => 'Classes'] |
|
| 13 | + ], |
|
| 14 | + 'constraints' => |
|
| 15 | + [ |
|
| 16 | + 'depends' => |
|
| 17 | + [ |
|
| 18 | + 'typo3' => '9.5.0-9.5.99', |
|
| 19 | + 'vidi' => '4.0.0-0.0.0', |
|
| 20 | + ], |
|
| 21 | + 'conflicts' => |
|
| 22 | + [ |
|
| 23 | + ], |
|
| 24 | + 'suggests' => |
|
| 25 | + [ |
|
| 26 | + 'metadata' => '', |
|
| 27 | + 'filemetadata' => '', |
|
| 28 | + ], |
|
| 29 | + ] |
|
| 30 | 30 | ]; |