@@ -127,7 +127,7 @@ |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * @return int |
|
| 130 | + * @return boolean |
|
| 131 | 131 | */ |
| 132 | 132 | protected function isNewProcessedFile() |
| 133 | 133 | { |
@@ -22,248 +22,248 @@ |
||
| 22 | 22 | class ThumbnailGenerator |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var int |
|
| 27 | - */ |
|
| 28 | - protected $numberOfTraversedFiles = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var int |
|
| 32 | - */ |
|
| 33 | - protected $numberOfProcessedFiles = 0; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - protected $numberOfMissingFiles = 0; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $configuration = []; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var ResourceStorage |
|
| 47 | - */ |
|
| 48 | - protected $storage = null; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var Selection |
|
| 52 | - */ |
|
| 53 | - protected $selection = null; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - protected $resultSet = []; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - protected $newProcessedFileIdentifiers = []; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Internal variable |
|
| 67 | - * |
|
| 68 | - * @var int |
|
| 69 | - */ |
|
| 70 | - protected $lastInsertedProcessedFile = 0; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Generate |
|
| 74 | - * |
|
| 75 | - * @param int $limit |
|
| 76 | - * @param int $offset |
|
| 77 | - * @return void |
|
| 78 | - * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException |
|
| 79 | - * @throws \InvalidArgumentException |
|
| 80 | - * @throws \Fab\Media\Exception\InvalidKeyInArrayException |
|
| 81 | - * @throws \Fab\Media\Exception\MissingTcaConfigurationException |
|
| 82 | - */ |
|
| 83 | - public function generate($limit = 0, $offset = 0) |
|
| 84 | - { |
|
| 85 | - |
|
| 86 | - // Compute a possible limit and offset for the query. |
|
| 87 | - //$limitAndOffset = ''; |
|
| 88 | - //if ($limit > 0 || $offset > 0) { |
|
| 89 | - // $limitAndOffset = $limit . ' OFFSET ' . $offset; |
|
| 90 | - //} |
|
| 91 | - |
|
| 92 | - $rows = $this->getDataService() |
|
| 93 | - ->getRecords( |
|
| 94 | - 'sys_file', |
|
| 95 | - [ |
|
| 96 | - 'storage' => $this->storage->getUid() |
|
| 97 | - ] // todo add limit and offset |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - foreach ($rows as $row) { |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row); |
|
| 104 | - |
|
| 105 | - if ($file->exists()) { |
|
| 106 | - |
|
| 107 | - $thumbnailUri = $this->getThumbnailService($file) |
|
| 108 | - ->setOutputType(ThumbnailInterface::OUTPUT_URI) |
|
| 109 | - ->setConfiguration($this->configuration) |
|
| 110 | - ->create(); |
|
| 111 | - |
|
| 112 | - $this->resultSet[$file->getUid()] = array( |
|
| 113 | - 'fileUid' => $file->getUid(), |
|
| 114 | - 'fileIdentifier' => $file->getIdentifier(), |
|
| 115 | - 'thumbnailUri' => strpos($thumbnailUri, '_processed_') > 0 ? $thumbnailUri : '', // only returns the thumbnail uri if a processed file has been created. |
|
| 116 | - ); |
|
| 117 | - |
|
| 118 | - //if ($this->isNewProcessedFile()) { // todo restore me |
|
| 119 | - // $this->incrementNumberOfProcessedFiles(); |
|
| 120 | - // $this->newProcessedFileIdentifiers[$file->getUid()] = $this->lastInsertedProcessedFile; |
|
| 121 | - //} |
|
| 122 | - |
|
| 123 | - $this->incrementNumberOfTraversedFiles(); |
|
| 124 | - } else { |
|
| 125 | - $this->incrementNumberOfMissingFiles(); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return int |
|
| 133 | - */ |
|
| 134 | - protected function isNewProcessedFile() |
|
| 135 | - { |
|
| 136 | - $isNewProcessedFile = false; |
|
| 137 | - $lastInsertedId = $this->getDatabaseConnection()->sql_insert_id(); |
|
| 138 | - if ($lastInsertedId > 0 && $lastInsertedId !== $this->lastInsertedProcessedFile) { |
|
| 139 | - $this->lastInsertedProcessedFile = $lastInsertedId; |
|
| 140 | - $isNewProcessedFile = true; |
|
| 141 | - } |
|
| 142 | - return $isNewProcessedFile; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @return int |
|
| 147 | - */ |
|
| 148 | - public function getNumberOfTraversedFiles() |
|
| 149 | - { |
|
| 150 | - return $this->numberOfTraversedFiles; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @return int |
|
| 155 | - */ |
|
| 156 | - public function getNumberOfProcessedFiles() |
|
| 157 | - { |
|
| 158 | - return $this->numberOfProcessedFiles; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return int |
|
| 163 | - */ |
|
| 164 | - public function getTotalNumberOfFiles() |
|
| 165 | - { |
|
| 166 | - return $this->getDataService() |
|
| 167 | - ->count( |
|
| 168 | - 'sys_file', |
|
| 169 | - [ |
|
| 170 | - 'storage' => $this->storage->getUid() |
|
| 171 | - ] |
|
| 172 | - ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function getResultSet() |
|
| 179 | - { |
|
| 180 | - return $this->resultSet; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @return array |
|
| 185 | - */ |
|
| 186 | - public function getNewProcessedFileIdentifiers() |
|
| 187 | - { |
|
| 188 | - return $this->newProcessedFileIdentifiers; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @return int |
|
| 193 | - */ |
|
| 194 | - public function getNumberOfMissingFiles() |
|
| 195 | - { |
|
| 196 | - return $this->numberOfMissingFiles; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
| 201 | - * @return $this |
|
| 202 | - */ |
|
| 203 | - public function setStorage($storage) |
|
| 204 | - { |
|
| 205 | - $this->storage = $storage; |
|
| 206 | - return $this; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param \Fab\Vidi\Domain\Model\Selection $selection |
|
| 211 | - * @return $this |
|
| 212 | - */ |
|
| 213 | - public function setSelection($selection) |
|
| 214 | - { |
|
| 215 | - $this->selection = $selection; |
|
| 216 | - return $this; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param array $configuration |
|
| 221 | - * @return $this |
|
| 222 | - */ |
|
| 223 | - public function setConfiguration($configuration) |
|
| 224 | - { |
|
| 225 | - $this->configuration = $configuration; |
|
| 226 | - return $this; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @param File $file |
|
| 231 | - * @return object|ThumbnailService |
|
| 232 | - */ |
|
| 233 | - protected function getThumbnailService(File $file) |
|
| 234 | - { |
|
| 235 | - return GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @return void |
|
| 240 | - */ |
|
| 241 | - protected function incrementNumberOfTraversedFiles() |
|
| 242 | - { |
|
| 243 | - $this->numberOfTraversedFiles++; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @return void |
|
| 248 | - */ |
|
| 249 | - protected function incrementNumberOfMissingFiles() |
|
| 250 | - { |
|
| 251 | - $this->numberOfMissingFiles++; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - protected function incrementNumberOfProcessedFiles() |
|
| 258 | - { |
|
| 259 | - $this->numberOfProcessedFiles++; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @return object|DataService |
|
| 264 | - */ |
|
| 265 | - protected function getDataService(): DataService |
|
| 266 | - { |
|
| 267 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 268 | - } |
|
| 25 | + /** |
|
| 26 | + * @var int |
|
| 27 | + */ |
|
| 28 | + protected $numberOfTraversedFiles = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var int |
|
| 32 | + */ |
|
| 33 | + protected $numberOfProcessedFiles = 0; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + protected $numberOfMissingFiles = 0; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $configuration = []; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var ResourceStorage |
|
| 47 | + */ |
|
| 48 | + protected $storage = null; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var Selection |
|
| 52 | + */ |
|
| 53 | + protected $selection = null; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + protected $resultSet = []; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + protected $newProcessedFileIdentifiers = []; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Internal variable |
|
| 67 | + * |
|
| 68 | + * @var int |
|
| 69 | + */ |
|
| 70 | + protected $lastInsertedProcessedFile = 0; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Generate |
|
| 74 | + * |
|
| 75 | + * @param int $limit |
|
| 76 | + * @param int $offset |
|
| 77 | + * @return void |
|
| 78 | + * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException |
|
| 79 | + * @throws \InvalidArgumentException |
|
| 80 | + * @throws \Fab\Media\Exception\InvalidKeyInArrayException |
|
| 81 | + * @throws \Fab\Media\Exception\MissingTcaConfigurationException |
|
| 82 | + */ |
|
| 83 | + public function generate($limit = 0, $offset = 0) |
|
| 84 | + { |
|
| 85 | + |
|
| 86 | + // Compute a possible limit and offset for the query. |
|
| 87 | + //$limitAndOffset = ''; |
|
| 88 | + //if ($limit > 0 || $offset > 0) { |
|
| 89 | + // $limitAndOffset = $limit . ' OFFSET ' . $offset; |
|
| 90 | + //} |
|
| 91 | + |
|
| 92 | + $rows = $this->getDataService() |
|
| 93 | + ->getRecords( |
|
| 94 | + 'sys_file', |
|
| 95 | + [ |
|
| 96 | + 'storage' => $this->storage->getUid() |
|
| 97 | + ] // todo add limit and offset |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + foreach ($rows as $row) { |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row); |
|
| 104 | + |
|
| 105 | + if ($file->exists()) { |
|
| 106 | + |
|
| 107 | + $thumbnailUri = $this->getThumbnailService($file) |
|
| 108 | + ->setOutputType(ThumbnailInterface::OUTPUT_URI) |
|
| 109 | + ->setConfiguration($this->configuration) |
|
| 110 | + ->create(); |
|
| 111 | + |
|
| 112 | + $this->resultSet[$file->getUid()] = array( |
|
| 113 | + 'fileUid' => $file->getUid(), |
|
| 114 | + 'fileIdentifier' => $file->getIdentifier(), |
|
| 115 | + 'thumbnailUri' => strpos($thumbnailUri, '_processed_') > 0 ? $thumbnailUri : '', // only returns the thumbnail uri if a processed file has been created. |
|
| 116 | + ); |
|
| 117 | + |
|
| 118 | + //if ($this->isNewProcessedFile()) { // todo restore me |
|
| 119 | + // $this->incrementNumberOfProcessedFiles(); |
|
| 120 | + // $this->newProcessedFileIdentifiers[$file->getUid()] = $this->lastInsertedProcessedFile; |
|
| 121 | + //} |
|
| 122 | + |
|
| 123 | + $this->incrementNumberOfTraversedFiles(); |
|
| 124 | + } else { |
|
| 125 | + $this->incrementNumberOfMissingFiles(); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return int |
|
| 133 | + */ |
|
| 134 | + protected function isNewProcessedFile() |
|
| 135 | + { |
|
| 136 | + $isNewProcessedFile = false; |
|
| 137 | + $lastInsertedId = $this->getDatabaseConnection()->sql_insert_id(); |
|
| 138 | + if ($lastInsertedId > 0 && $lastInsertedId !== $this->lastInsertedProcessedFile) { |
|
| 139 | + $this->lastInsertedProcessedFile = $lastInsertedId; |
|
| 140 | + $isNewProcessedFile = true; |
|
| 141 | + } |
|
| 142 | + return $isNewProcessedFile; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @return int |
|
| 147 | + */ |
|
| 148 | + public function getNumberOfTraversedFiles() |
|
| 149 | + { |
|
| 150 | + return $this->numberOfTraversedFiles; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @return int |
|
| 155 | + */ |
|
| 156 | + public function getNumberOfProcessedFiles() |
|
| 157 | + { |
|
| 158 | + return $this->numberOfProcessedFiles; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @return int |
|
| 163 | + */ |
|
| 164 | + public function getTotalNumberOfFiles() |
|
| 165 | + { |
|
| 166 | + return $this->getDataService() |
|
| 167 | + ->count( |
|
| 168 | + 'sys_file', |
|
| 169 | + [ |
|
| 170 | + 'storage' => $this->storage->getUid() |
|
| 171 | + ] |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function getResultSet() |
|
| 179 | + { |
|
| 180 | + return $this->resultSet; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @return array |
|
| 185 | + */ |
|
| 186 | + public function getNewProcessedFileIdentifiers() |
|
| 187 | + { |
|
| 188 | + return $this->newProcessedFileIdentifiers; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @return int |
|
| 193 | + */ |
|
| 194 | + public function getNumberOfMissingFiles() |
|
| 195 | + { |
|
| 196 | + return $this->numberOfMissingFiles; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
| 201 | + * @return $this |
|
| 202 | + */ |
|
| 203 | + public function setStorage($storage) |
|
| 204 | + { |
|
| 205 | + $this->storage = $storage; |
|
| 206 | + return $this; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param \Fab\Vidi\Domain\Model\Selection $selection |
|
| 211 | + * @return $this |
|
| 212 | + */ |
|
| 213 | + public function setSelection($selection) |
|
| 214 | + { |
|
| 215 | + $this->selection = $selection; |
|
| 216 | + return $this; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param array $configuration |
|
| 221 | + * @return $this |
|
| 222 | + */ |
|
| 223 | + public function setConfiguration($configuration) |
|
| 224 | + { |
|
| 225 | + $this->configuration = $configuration; |
|
| 226 | + return $this; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @param File $file |
|
| 231 | + * @return object|ThumbnailService |
|
| 232 | + */ |
|
| 233 | + protected function getThumbnailService(File $file) |
|
| 234 | + { |
|
| 235 | + return GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @return void |
|
| 240 | + */ |
|
| 241 | + protected function incrementNumberOfTraversedFiles() |
|
| 242 | + { |
|
| 243 | + $this->numberOfTraversedFiles++; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @return void |
|
| 248 | + */ |
|
| 249 | + protected function incrementNumberOfMissingFiles() |
|
| 250 | + { |
|
| 251 | + $this->numberOfMissingFiles++; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + protected function incrementNumberOfProcessedFiles() |
|
| 258 | + { |
|
| 259 | + $this->numberOfProcessedFiles++; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @return object|DataService |
|
| 264 | + */ |
|
| 265 | + protected function getDataService(): DataService |
|
| 266 | + { |
|
| 267 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -21,139 +21,139 @@ discard block |
||
| 21 | 21 | class ConfigurationWarning extends AbstractComponentView |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $notAllowedMountPoints = []; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Renders a button for uploading assets. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function render() |
|
| 35 | - { |
|
| 36 | - |
|
| 37 | - $result = ''; |
|
| 38 | - |
|
| 39 | - // Check whether storage is configured or not. |
|
| 40 | - if ($this->checkStorageNotConfigured()) { |
|
| 41 | - $this->configureStorage(); |
|
| 42 | - $result .= $this->formatMessageForStorageConfigured(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // Check whether storage is online or not. |
|
| 46 | - if ($this->checkStorageOffline()) { |
|
| 47 | - $result .= $this->formatMessageForStorageOffline(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // Check all mount points of the storage are available |
|
| 51 | - if (!$this->checkMountPoints()) { |
|
| 52 | - $result .= $this->formatMessageForMountPoints(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Check all mount points of the storage are available |
|
| 56 | - if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
| 57 | - if ($this->canBeInitializedSilently() < 2000) { |
|
| 58 | - $numberOfFiles = $this->getCacheService()->warmUp(); |
|
| 59 | - $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
| 60 | - touch($this->getWarmUpSemaphoreFile()); |
|
| 61 | - } else { |
|
| 62 | - $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return $result; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return \Fab\Media\Cache\CacheService|object |
|
| 71 | - */ |
|
| 72 | - protected function getCacheService() |
|
| 73 | - { |
|
| 74 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return boolean |
|
| 79 | - */ |
|
| 80 | - protected function configureStorage() |
|
| 81 | - { |
|
| 82 | - $tableName = 'sys_file_storage'; |
|
| 83 | - $fields = array( |
|
| 84 | - 'maximum_dimension_original_image', |
|
| 85 | - 'extension_allowed_file_type_1', |
|
| 86 | - 'extension_allowed_file_type_2', |
|
| 87 | - 'extension_allowed_file_type_3', |
|
| 88 | - 'extension_allowed_file_type_4', |
|
| 89 | - 'extension_allowed_file_type_5', |
|
| 90 | - ); |
|
| 91 | - |
|
| 92 | - $values = []; |
|
| 93 | - foreach ($fields as $field) { |
|
| 94 | - $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 98 | - $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 104 | - protected function hasBeenWarmedUp() |
|
| 105 | - { |
|
| 106 | - return is_file(($this->getWarmUpSemaphoreFile())); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - protected function getWarmUpSemaphoreFile() |
|
| 113 | - { |
|
| 114 | - return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Check whether the storage is correctly configured. |
|
| 119 | - * |
|
| 120 | - * @return boolean |
|
| 121 | - */ |
|
| 122 | - protected function checkStorageNotConfigured() |
|
| 123 | - { |
|
| 124 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 125 | - $storageRecord = $currentStorage->getStorageRecord(); |
|
| 126 | - |
|
| 127 | - // Take the storage fields and check whether some data was initialized. |
|
| 128 | - $fields = array( |
|
| 129 | - 'extension_allowed_file_type_1', |
|
| 130 | - 'extension_allowed_file_type_2', |
|
| 131 | - 'extension_allowed_file_type_3', |
|
| 132 | - 'extension_allowed_file_type_4', |
|
| 133 | - 'extension_allowed_file_type_5', |
|
| 134 | - ); |
|
| 135 | - |
|
| 136 | - $result = true; |
|
| 137 | - foreach ($fields as $fieldName) { |
|
| 138 | - // true means the storage has data and thus was configured / saved once. |
|
| 139 | - if (!empty($storageRecord[$fieldName])) { |
|
| 140 | - $result = false; |
|
| 141 | - break; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - return $result; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Format a message whenever the storage is offline. |
|
| 149 | - * |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - protected function formatMessageForStorageConfigured() |
|
| 153 | - { |
|
| 154 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 155 | - |
|
| 156 | - $result = <<< EOF |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $notAllowedMountPoints = []; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Renders a button for uploading assets. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function render() |
|
| 35 | + { |
|
| 36 | + |
|
| 37 | + $result = ''; |
|
| 38 | + |
|
| 39 | + // Check whether storage is configured or not. |
|
| 40 | + if ($this->checkStorageNotConfigured()) { |
|
| 41 | + $this->configureStorage(); |
|
| 42 | + $result .= $this->formatMessageForStorageConfigured(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // Check whether storage is online or not. |
|
| 46 | + if ($this->checkStorageOffline()) { |
|
| 47 | + $result .= $this->formatMessageForStorageOffline(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // Check all mount points of the storage are available |
|
| 51 | + if (!$this->checkMountPoints()) { |
|
| 52 | + $result .= $this->formatMessageForMountPoints(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Check all mount points of the storage are available |
|
| 56 | + if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
| 57 | + if ($this->canBeInitializedSilently() < 2000) { |
|
| 58 | + $numberOfFiles = $this->getCacheService()->warmUp(); |
|
| 59 | + $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
| 60 | + touch($this->getWarmUpSemaphoreFile()); |
|
| 61 | + } else { |
|
| 62 | + $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return $result; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return \Fab\Media\Cache\CacheService|object |
|
| 71 | + */ |
|
| 72 | + protected function getCacheService() |
|
| 73 | + { |
|
| 74 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return boolean |
|
| 79 | + */ |
|
| 80 | + protected function configureStorage() |
|
| 81 | + { |
|
| 82 | + $tableName = 'sys_file_storage'; |
|
| 83 | + $fields = array( |
|
| 84 | + 'maximum_dimension_original_image', |
|
| 85 | + 'extension_allowed_file_type_1', |
|
| 86 | + 'extension_allowed_file_type_2', |
|
| 87 | + 'extension_allowed_file_type_3', |
|
| 88 | + 'extension_allowed_file_type_4', |
|
| 89 | + 'extension_allowed_file_type_5', |
|
| 90 | + ); |
|
| 91 | + |
|
| 92 | + $values = []; |
|
| 93 | + foreach ($fields as $field) { |
|
| 94 | + $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 98 | + $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | + protected function hasBeenWarmedUp() |
|
| 105 | + { |
|
| 106 | + return is_file(($this->getWarmUpSemaphoreFile())); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + protected function getWarmUpSemaphoreFile() |
|
| 113 | + { |
|
| 114 | + return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Check whether the storage is correctly configured. |
|
| 119 | + * |
|
| 120 | + * @return boolean |
|
| 121 | + */ |
|
| 122 | + protected function checkStorageNotConfigured() |
|
| 123 | + { |
|
| 124 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 125 | + $storageRecord = $currentStorage->getStorageRecord(); |
|
| 126 | + |
|
| 127 | + // Take the storage fields and check whether some data was initialized. |
|
| 128 | + $fields = array( |
|
| 129 | + 'extension_allowed_file_type_1', |
|
| 130 | + 'extension_allowed_file_type_2', |
|
| 131 | + 'extension_allowed_file_type_3', |
|
| 132 | + 'extension_allowed_file_type_4', |
|
| 133 | + 'extension_allowed_file_type_5', |
|
| 134 | + ); |
|
| 135 | + |
|
| 136 | + $result = true; |
|
| 137 | + foreach ($fields as $fieldName) { |
|
| 138 | + // true means the storage has data and thus was configured / saved once. |
|
| 139 | + if (!empty($storageRecord[$fieldName])) { |
|
| 140 | + $result = false; |
|
| 141 | + break; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + return $result; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Format a message whenever the storage is offline. |
|
| 149 | + * |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + protected function formatMessageForStorageConfigured() |
|
| 153 | + { |
|
| 154 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 155 | + |
|
| 156 | + $result = <<< EOF |
|
| 157 | 157 | <div class="alert alert-info"> |
| 158 | 158 | <div class="alert-title"> |
| 159 | 159 | Storage has been configured. |
@@ -166,29 +166,29 @@ discard block |
||
| 166 | 166 | </div> |
| 167 | 167 | EOF; |
| 168 | 168 | |
| 169 | - return $result; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Check whether the storage is online or not. |
|
| 174 | - * |
|
| 175 | - * @return boolean |
|
| 176 | - */ |
|
| 177 | - protected function checkStorageOffline() |
|
| 178 | - { |
|
| 179 | - return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Format a message whenever the storage is offline. |
|
| 184 | - * |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - protected function formatMessageForStorageOffline() |
|
| 188 | - { |
|
| 189 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 190 | - |
|
| 191 | - $result = <<< EOF |
|
| 169 | + return $result; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Check whether the storage is online or not. |
|
| 174 | + * |
|
| 175 | + * @return boolean |
|
| 176 | + */ |
|
| 177 | + protected function checkStorageOffline() |
|
| 178 | + { |
|
| 179 | + return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Format a message whenever the storage is offline. |
|
| 184 | + * |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + protected function formatMessageForStorageOffline() |
|
| 188 | + { |
|
| 189 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 190 | + |
|
| 191 | + $result = <<< EOF |
|
| 192 | 192 | <div class="alert alert-warning"> |
| 193 | 193 | <div class="alert-title"> |
| 194 | 194 | Storage is currently offline |
@@ -200,85 +200,85 @@ discard block |
||
| 200 | 200 | </div> |
| 201 | 201 | EOF; |
| 202 | 202 | |
| 203 | - return $result; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Check whether mount points privilege are ok. |
|
| 208 | - * |
|
| 209 | - * @return boolean |
|
| 210 | - */ |
|
| 211 | - protected function checkMountPoints() |
|
| 212 | - { |
|
| 213 | - if (!$this->getBackendUser()->isAdmin()) { |
|
| 214 | - |
|
| 215 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 216 | - |
|
| 217 | - $fileMountIdentifiers = []; |
|
| 218 | - foreach ($fileMounts as $fileMount) { |
|
| 219 | - $fileMountIdentifiers[] = $fileMount['uid']; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 223 | - $storageRecord = $storage->getStorageRecord(); |
|
| 224 | - $fieldNames = array( |
|
| 225 | - 'mount_point_file_type_1', |
|
| 226 | - 'mount_point_file_type_2', |
|
| 227 | - 'mount_point_file_type_3', |
|
| 228 | - 'mount_point_file_type_4', |
|
| 229 | - 'mount_point_file_type_5', |
|
| 230 | - ); |
|
| 231 | - foreach ($fieldNames as $fileName) { |
|
| 232 | - $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
| 233 | - if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
| 234 | - $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
| 235 | - } else { |
|
| 236 | - # $fileMountIdentifier |
|
| 237 | - $folder = $storage->getRootLevelFolder(); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - return empty($this->notAllowedMountPoints); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Return a mount point according to an file mount identifier. |
|
| 246 | - * |
|
| 247 | - * @param string $identifier |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - protected function fetchMountPoint($identifier) |
|
| 251 | - { |
|
| 252 | - /** @var QueryBuilder $queryBuilder */ |
|
| 253 | - $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
| 254 | - return $queryBuilder |
|
| 255 | - ->select('*') |
|
| 256 | - ->from('sys_filemounts') |
|
| 257 | - ->where('uid = ' . $identifier) |
|
| 258 | - ->execute() |
|
| 259 | - ->fetch(); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Format a message whenever mount points privilege are not OK. |
|
| 264 | - * |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - protected function formatMessageForMountPoints() |
|
| 268 | - { |
|
| 269 | - |
|
| 270 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 271 | - $backendUser = $this->getBackendUser(); |
|
| 272 | - |
|
| 273 | - foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
| 274 | - $list = sprintf('<li>"%s" with path %s</li>', |
|
| 275 | - $notAllowedMountPoints['title'], |
|
| 276 | - $notAllowedMountPoints['path'] |
|
| 277 | - ); |
|
| 278 | - |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - $result = <<< EOF |
|
| 203 | + return $result; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Check whether mount points privilege are ok. |
|
| 208 | + * |
|
| 209 | + * @return boolean |
|
| 210 | + */ |
|
| 211 | + protected function checkMountPoints() |
|
| 212 | + { |
|
| 213 | + if (!$this->getBackendUser()->isAdmin()) { |
|
| 214 | + |
|
| 215 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 216 | + |
|
| 217 | + $fileMountIdentifiers = []; |
|
| 218 | + foreach ($fileMounts as $fileMount) { |
|
| 219 | + $fileMountIdentifiers[] = $fileMount['uid']; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 223 | + $storageRecord = $storage->getStorageRecord(); |
|
| 224 | + $fieldNames = array( |
|
| 225 | + 'mount_point_file_type_1', |
|
| 226 | + 'mount_point_file_type_2', |
|
| 227 | + 'mount_point_file_type_3', |
|
| 228 | + 'mount_point_file_type_4', |
|
| 229 | + 'mount_point_file_type_5', |
|
| 230 | + ); |
|
| 231 | + foreach ($fieldNames as $fileName) { |
|
| 232 | + $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
| 233 | + if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
| 234 | + $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
| 235 | + } else { |
|
| 236 | + # $fileMountIdentifier |
|
| 237 | + $folder = $storage->getRootLevelFolder(); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + return empty($this->notAllowedMountPoints); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Return a mount point according to an file mount identifier. |
|
| 246 | + * |
|
| 247 | + * @param string $identifier |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + protected function fetchMountPoint($identifier) |
|
| 251 | + { |
|
| 252 | + /** @var QueryBuilder $queryBuilder */ |
|
| 253 | + $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
| 254 | + return $queryBuilder |
|
| 255 | + ->select('*') |
|
| 256 | + ->from('sys_filemounts') |
|
| 257 | + ->where('uid = ' . $identifier) |
|
| 258 | + ->execute() |
|
| 259 | + ->fetch(); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Format a message whenever mount points privilege are not OK. |
|
| 264 | + * |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + protected function formatMessageForMountPoints() |
|
| 268 | + { |
|
| 269 | + |
|
| 270 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 271 | + $backendUser = $this->getBackendUser(); |
|
| 272 | + |
|
| 273 | + foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
| 274 | + $list = sprintf('<li>"%s" with path %s</li>', |
|
| 275 | + $notAllowedMountPoints['title'], |
|
| 276 | + $notAllowedMountPoints['path'] |
|
| 277 | + ); |
|
| 278 | + |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + $result = <<< EOF |
|
| 282 | 282 | <div class="alert alert-warning"> |
| 283 | 283 | <div class="alert-title"> |
| 284 | 284 | File mount are wrongly configured for user "{$backendUser->user['username']}". |
@@ -293,54 +293,54 @@ discard block |
||
| 293 | 293 | </div> |
| 294 | 294 | EOF; |
| 295 | 295 | |
| 296 | - return $result; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * @return boolean |
|
| 301 | - */ |
|
| 302 | - protected function canBeInitializedSilently() |
|
| 303 | - { |
|
| 304 | - /** @var QueryBuilder $queryBuilder */ |
|
| 305 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 306 | - $count = $queryBuilder |
|
| 307 | - ->count('*') |
|
| 308 | - ->from('sys_file') |
|
| 309 | - ->execute() |
|
| 310 | - ->fetchColumn(0); |
|
| 311 | - return (int)$count; |
|
| 312 | - |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Check whether the column "total_of_references" has been already processed once. |
|
| 317 | - * |
|
| 318 | - * @return boolean |
|
| 319 | - */ |
|
| 320 | - protected function checkColumnNumberOfReferences() |
|
| 321 | - { |
|
| 322 | - /** @var QueryBuilder $queryBuilder */ |
|
| 323 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 324 | - $file = $queryBuilder |
|
| 325 | - ->select('*') |
|
| 326 | - ->from('sys_file') |
|
| 327 | - ->where('number_of_references > 0') |
|
| 328 | - ->execute() |
|
| 329 | - ->fetch(); |
|
| 330 | - |
|
| 331 | - return !empty($file); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Format a message if columns "total_of_references" looks wrong. |
|
| 336 | - * |
|
| 337 | - * @param int $numberOfFile |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 340 | - protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
| 341 | - { |
|
| 342 | - |
|
| 343 | - $result = <<< EOF |
|
| 296 | + return $result; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return boolean |
|
| 301 | + */ |
|
| 302 | + protected function canBeInitializedSilently() |
|
| 303 | + { |
|
| 304 | + /** @var QueryBuilder $queryBuilder */ |
|
| 305 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 306 | + $count = $queryBuilder |
|
| 307 | + ->count('*') |
|
| 308 | + ->from('sys_file') |
|
| 309 | + ->execute() |
|
| 310 | + ->fetchColumn(0); |
|
| 311 | + return (int)$count; |
|
| 312 | + |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Check whether the column "total_of_references" has been already processed once. |
|
| 317 | + * |
|
| 318 | + * @return boolean |
|
| 319 | + */ |
|
| 320 | + protected function checkColumnNumberOfReferences() |
|
| 321 | + { |
|
| 322 | + /** @var QueryBuilder $queryBuilder */ |
|
| 323 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 324 | + $file = $queryBuilder |
|
| 325 | + ->select('*') |
|
| 326 | + ->from('sys_file') |
|
| 327 | + ->where('number_of_references > 0') |
|
| 328 | + ->execute() |
|
| 329 | + ->fetch(); |
|
| 330 | + |
|
| 331 | + return !empty($file); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Format a message if columns "total_of_references" looks wrong. |
|
| 336 | + * |
|
| 337 | + * @param int $numberOfFile |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | + protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
| 341 | + { |
|
| 342 | + |
|
| 343 | + $result = <<< EOF |
|
| 344 | 344 | <div class="alert alert-success"> |
| 345 | 345 | <div class="alert-title"> |
| 346 | 346 | Initialized column "number_of_references" for ${numberOfFile} files |
@@ -357,19 +357,19 @@ discard block |
||
| 357 | 357 | </div> |
| 358 | 358 | EOF; |
| 359 | 359 | |
| 360 | - return $result; |
|
| 361 | - } |
|
| 360 | + return $result; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * Format a message if columns "total_of_references" looks wrong. |
|
| 366 | - * |
|
| 367 | - * @return string |
|
| 368 | - */ |
|
| 369 | - protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
| 370 | - { |
|
| 364 | + /** |
|
| 365 | + * Format a message if columns "total_of_references" looks wrong. |
|
| 366 | + * |
|
| 367 | + * @return string |
|
| 368 | + */ |
|
| 369 | + protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
| 370 | + { |
|
| 371 | 371 | |
| 372 | - $result = <<< EOF |
|
| 372 | + $result = <<< EOF |
|
| 373 | 373 | <div class="alert alert-warning"> |
| 374 | 374 | <div class="alert-title"> |
| 375 | 375 | Column "number_of_references" requires to be initialized. |
@@ -388,36 +388,36 @@ discard block |
||
| 388 | 388 | </div> |
| 389 | 389 | EOF; |
| 390 | 390 | |
| 391 | - return $result; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Returns an instance of the current Backend User. |
|
| 396 | - * |
|
| 397 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 398 | - */ |
|
| 399 | - protected function getBackendUser() |
|
| 400 | - { |
|
| 401 | - return $GLOBALS['BE_USER']; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * @param string $tableName |
|
| 406 | - * @return object|QueryBuilder |
|
| 407 | - */ |
|
| 408 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
| 409 | - { |
|
| 410 | - /** @var ConnectionPool $connectionPool */ |
|
| 411 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 412 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @return MediaModule|object |
|
| 417 | - */ |
|
| 418 | - protected function getMediaModule() |
|
| 419 | - { |
|
| 420 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 421 | - } |
|
| 391 | + return $result; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Returns an instance of the current Backend User. |
|
| 396 | + * |
|
| 397 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 398 | + */ |
|
| 399 | + protected function getBackendUser() |
|
| 400 | + { |
|
| 401 | + return $GLOBALS['BE_USER']; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * @param string $tableName |
|
| 406 | + * @return object|QueryBuilder |
|
| 407 | + */ |
|
| 408 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
| 409 | + { |
|
| 410 | + /** @var ConnectionPool $connectionPool */ |
|
| 411 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 412 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @return MediaModule|object |
|
| 417 | + */ |
|
| 418 | + protected function getMediaModule() |
|
| 419 | + { |
|
| 420 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | 423 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $storage = $this->getMediaModule()->getCurrentStorage(); |
| 98 | - $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 98 | + $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = '.$storage->getUid(), $values); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | protected function getWarmUpSemaphoreFile() |
| 113 | 113 | { |
| 114 | - return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 114 | + return PATH_site.'typo3temp/.media_cache_warmed_up'; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | return $queryBuilder |
| 255 | 255 | ->select('*') |
| 256 | 256 | ->from('sys_filemounts') |
| 257 | - ->where('uid = ' . $identifier) |
|
| 257 | + ->where('uid = '.$identifier) |
|
| 258 | 258 | ->execute() |
| 259 | 259 | ->fetch(); |
| 260 | 260 | } |
@@ -23,311 +23,311 @@ |
||
| 23 | 23 | class DataHandlerHook |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Store indexed file before the Data Handler start "working". |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $beforeDataHandlerProcessFileIdentifiers = []; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Store indexed file after the Data Handler has done its job. |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $afterDataHandlerProcessFileIdentifiers = []; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Internal key for the Cache Manager. |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $registerKey = 'media-hook-elementsToKeepTrack'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * First procedures to launch before all operations in DataHandler. |
|
| 49 | - * |
|
| 50 | - * Feed variable $this->beforeDataHandlerProcessFileIdentifiers |
|
| 51 | - * |
|
| 52 | - * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function processDatamap_beforeStart(DataHandler $caller) |
|
| 56 | - { |
|
| 57 | - |
|
| 58 | - // Use a register to keep track of files. |
|
| 59 | - // It is required according to TCEMain behaviour which register "elements to be deleted". |
|
| 60 | - // Those element must not be forgotten. |
|
| 61 | - $this->initializeFileRegister(); |
|
| 62 | - $this->registerFilesToKeepTrack(); |
|
| 63 | - |
|
| 64 | - foreach ($caller->datamap as $tableName => $configuration) { |
|
| 65 | - |
|
| 66 | - $id = key($configuration); |
|
| 67 | - if (!MathUtility::canBeInterpretedAsInteger($id)) { |
|
| 68 | - continue; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
| 72 | - $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
| 73 | - if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
| 74 | - $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
| 75 | - } |
|
| 76 | - $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
| 77 | - |
|
| 78 | - // Make sure $index is an array. |
|
| 79 | - if (!is_array($indexes)) { |
|
| 80 | - $indexes = []; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $fileIdentifiers = $this->lookForFiles($indexes); |
|
| 84 | - $this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Last procedures to launch after all operations in DataHandler. |
|
| 90 | - * |
|
| 91 | - * Process field "number_of_references" which may require updates. |
|
| 92 | - * |
|
| 93 | - * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function processDatamap_afterAllOperations(DataHandler $caller) |
|
| 97 | - { |
|
| 98 | - |
|
| 99 | - // First collect files which have been involved. |
|
| 100 | - foreach ($caller->datamap as $tableName => $configuration) { |
|
| 101 | - |
|
| 102 | - $id = key($configuration); |
|
| 103 | - |
|
| 104 | - /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
| 105 | - $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
| 106 | - if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
| 107 | - $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
| 108 | - } |
|
| 109 | - $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
| 110 | - |
|
| 111 | - // Make sure $index is an array. |
|
| 112 | - if (!is_array($indexes)) { |
|
| 113 | - $indexes = []; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $fileIdentifiers = $this->lookForFiles($indexes); |
|
| 117 | - $this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // After collecting files, update the column "number_of_references". |
|
| 121 | - foreach ($this->getFileToProcess() as $fileIdentifier) { |
|
| 122 | - try { |
|
| 123 | - $file = ResourceFactory::getInstance()->getFileObject($fileIdentifier); |
|
| 124 | - $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
| 125 | - |
|
| 126 | - $values = array( |
|
| 127 | - 'number_of_references' => $numberOfReferences |
|
| 128 | - ); |
|
| 129 | - $this->getDataService()->update('sys_file', $values, ['uid' => $file->getUid()]); |
|
| 130 | - } catch (FileDoesNotExistException $fileDoesNotExistException) { |
|
| 131 | - // Do nothing here. A file that does not exist needs no update. |
|
| 132 | - // See https://github.com/fabarea/media/issues/159 for more information. |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - protected function initializeFileRegister() |
|
| 141 | - { |
|
| 142 | - |
|
| 143 | - $items = $this->getMemoryCache()->get($this->registerKey); |
|
| 144 | - if (!is_array($items)) { |
|
| 145 | - $this->getMemoryCache()->set($this->registerKey, []); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return void |
|
| 151 | - */ |
|
| 152 | - protected function registerFilesToKeepTrack() |
|
| 153 | - { |
|
| 154 | - $fileIdentifiers = []; |
|
| 155 | - $elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted'); |
|
| 156 | - if (is_array($elementsToBeDeleted)) { |
|
| 157 | - foreach ($elementsToBeDeleted as $tableName => $element) { |
|
| 158 | - |
|
| 159 | - if ($tableName === 'sys_file_reference') { |
|
| 160 | - |
|
| 161 | - $fileReferenceIdentifier = key($element); |
|
| 162 | - if ($element[$fileReferenceIdentifier] === true) { |
|
| 163 | - $fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier); |
|
| 164 | - $fileIdentifiers[] = $fileIdentifier; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Put back in the memory cache the value. |
|
| 171 | - $items = $this->getMemoryCache()->get($this->registerKey); |
|
| 172 | - $mergedItems = array_merge($items, $fileIdentifiers); |
|
| 173 | - $this->getMemoryCache()->set($this->registerKey, $mergedItems); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @return array |
|
| 178 | - */ |
|
| 179 | - protected function getRegisteredFiles() |
|
| 180 | - { |
|
| 181 | - $files = $this->getMemoryCache()->get($this->registerKey); |
|
| 182 | - return $files; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Look for file which are within the reference index. |
|
| 187 | - * |
|
| 188 | - * @return array |
|
| 189 | - */ |
|
| 190 | - protected function getFileToProcess() |
|
| 191 | - { |
|
| 192 | - $fileIdentifiers = array_merge( |
|
| 193 | - $this->beforeDataHandlerProcessFileIdentifiers, |
|
| 194 | - $this->afterDataHandlerProcessFileIdentifiers, |
|
| 195 | - $this->getRegisteredFiles() |
|
| 196 | - ); |
|
| 197 | - return array_unique($fileIdentifiers); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @param array $fileIdentifiers |
|
| 202 | - * @return void |
|
| 203 | - */ |
|
| 204 | - protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
| 205 | - { |
|
| 206 | - $this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param array $fileIdentifiers |
|
| 211 | - * @return void |
|
| 212 | - */ |
|
| 213 | - protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
| 214 | - { |
|
| 215 | - $this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Look for file which are within the reference index. |
|
| 220 | - * |
|
| 221 | - * @param array $indexes |
|
| 222 | - * @return array |
|
| 223 | - */ |
|
| 224 | - protected function lookForFiles(array $indexes) |
|
| 225 | - { |
|
| 226 | - |
|
| 227 | - $fileIdentifiers = []; |
|
| 228 | - if (isset($indexes['relations'])) { |
|
| 229 | - |
|
| 230 | - foreach ($indexes['relations'] as $index) { |
|
| 231 | - if (is_array($index)) { |
|
| 232 | - if ($this->isSoftReferenceImage($index)) { |
|
| 233 | - $fileIdentifiers[] = $index['ref_uid']; |
|
| 234 | - } elseif ($this->isSoftReferenceLink($index)) { |
|
| 235 | - $fileIdentifiers[] = $index['ref_uid']; |
|
| 236 | - } elseif ($this->isFileReference($index)) { |
|
| 237 | - $fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return $fileIdentifiers; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param array $index |
|
| 248 | - * @return bool |
|
| 249 | - */ |
|
| 250 | - public function isFileReference(array $index) |
|
| 251 | - { |
|
| 252 | - return $index['ref_table'] === 'sys_file_reference'; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @param array $index |
|
| 257 | - * @return bool |
|
| 258 | - */ |
|
| 259 | - public function isSoftReferenceLink(array $index) |
|
| 260 | - { |
|
| 261 | - return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file'; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @param array $index |
|
| 266 | - * @return bool |
|
| 267 | - */ |
|
| 268 | - public function isSoftReferenceImage(array $index) |
|
| 269 | - { |
|
| 270 | - return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file'; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Retrieve the File identifier. |
|
| 275 | - * |
|
| 276 | - * @param $fileReferenceIdentifier |
|
| 277 | - * @return int |
|
| 278 | - * @throws \Exception |
|
| 279 | - */ |
|
| 280 | - protected function findFileByFileReference($fileReferenceIdentifier) |
|
| 281 | - { |
|
| 282 | - $record = $this->getDataService()->getRecord( |
|
| 283 | - 'sys_file_reference', |
|
| 284 | - [ |
|
| 285 | - 'uid' => $fileReferenceIdentifier |
|
| 286 | - ] |
|
| 287 | - ); |
|
| 288 | - |
|
| 289 | - if (empty($record)) { |
|
| 290 | - throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $fileIdentifier = $record['uid_local']; |
|
| 294 | - return $fileIdentifier; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 299 | - */ |
|
| 300 | - protected function getFileReferenceService() |
|
| 301 | - { |
|
| 302 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Gets an instance of the memory cache. |
|
| 307 | - * |
|
| 308 | - * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend |
|
| 309 | - */ |
|
| 310 | - protected function getMemoryCache() |
|
| 311 | - { |
|
| 312 | - return $this->getCacheManager()->getCache('cache_runtime'); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Create and returns an instance of the CacheManager |
|
| 317 | - * |
|
| 318 | - * @return \TYPO3\CMS\Core\Cache\CacheManager|object |
|
| 319 | - */ |
|
| 320 | - protected function getCacheManager() |
|
| 321 | - { |
|
| 322 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * @return object|DataService |
|
| 327 | - */ |
|
| 328 | - protected function getDataService(): DataService |
|
| 329 | - { |
|
| 330 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 331 | - } |
|
| 26 | + /** |
|
| 27 | + * Store indexed file before the Data Handler start "working". |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $beforeDataHandlerProcessFileIdentifiers = []; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Store indexed file after the Data Handler has done its job. |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $afterDataHandlerProcessFileIdentifiers = []; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Internal key for the Cache Manager. |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $registerKey = 'media-hook-elementsToKeepTrack'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * First procedures to launch before all operations in DataHandler. |
|
| 49 | + * |
|
| 50 | + * Feed variable $this->beforeDataHandlerProcessFileIdentifiers |
|
| 51 | + * |
|
| 52 | + * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function processDatamap_beforeStart(DataHandler $caller) |
|
| 56 | + { |
|
| 57 | + |
|
| 58 | + // Use a register to keep track of files. |
|
| 59 | + // It is required according to TCEMain behaviour which register "elements to be deleted". |
|
| 60 | + // Those element must not be forgotten. |
|
| 61 | + $this->initializeFileRegister(); |
|
| 62 | + $this->registerFilesToKeepTrack(); |
|
| 63 | + |
|
| 64 | + foreach ($caller->datamap as $tableName => $configuration) { |
|
| 65 | + |
|
| 66 | + $id = key($configuration); |
|
| 67 | + if (!MathUtility::canBeInterpretedAsInteger($id)) { |
|
| 68 | + continue; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
| 72 | + $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
| 73 | + if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
| 74 | + $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
| 75 | + } |
|
| 76 | + $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
| 77 | + |
|
| 78 | + // Make sure $index is an array. |
|
| 79 | + if (!is_array($indexes)) { |
|
| 80 | + $indexes = []; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $fileIdentifiers = $this->lookForFiles($indexes); |
|
| 84 | + $this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Last procedures to launch after all operations in DataHandler. |
|
| 90 | + * |
|
| 91 | + * Process field "number_of_references" which may require updates. |
|
| 92 | + * |
|
| 93 | + * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function processDatamap_afterAllOperations(DataHandler $caller) |
|
| 97 | + { |
|
| 98 | + |
|
| 99 | + // First collect files which have been involved. |
|
| 100 | + foreach ($caller->datamap as $tableName => $configuration) { |
|
| 101 | + |
|
| 102 | + $id = key($configuration); |
|
| 103 | + |
|
| 104 | + /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
| 105 | + $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
| 106 | + if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
| 107 | + $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
| 108 | + } |
|
| 109 | + $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
| 110 | + |
|
| 111 | + // Make sure $index is an array. |
|
| 112 | + if (!is_array($indexes)) { |
|
| 113 | + $indexes = []; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $fileIdentifiers = $this->lookForFiles($indexes); |
|
| 117 | + $this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // After collecting files, update the column "number_of_references". |
|
| 121 | + foreach ($this->getFileToProcess() as $fileIdentifier) { |
|
| 122 | + try { |
|
| 123 | + $file = ResourceFactory::getInstance()->getFileObject($fileIdentifier); |
|
| 124 | + $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
| 125 | + |
|
| 126 | + $values = array( |
|
| 127 | + 'number_of_references' => $numberOfReferences |
|
| 128 | + ); |
|
| 129 | + $this->getDataService()->update('sys_file', $values, ['uid' => $file->getUid()]); |
|
| 130 | + } catch (FileDoesNotExistException $fileDoesNotExistException) { |
|
| 131 | + // Do nothing here. A file that does not exist needs no update. |
|
| 132 | + // See https://github.com/fabarea/media/issues/159 for more information. |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + protected function initializeFileRegister() |
|
| 141 | + { |
|
| 142 | + |
|
| 143 | + $items = $this->getMemoryCache()->get($this->registerKey); |
|
| 144 | + if (!is_array($items)) { |
|
| 145 | + $this->getMemoryCache()->set($this->registerKey, []); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return void |
|
| 151 | + */ |
|
| 152 | + protected function registerFilesToKeepTrack() |
|
| 153 | + { |
|
| 154 | + $fileIdentifiers = []; |
|
| 155 | + $elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted'); |
|
| 156 | + if (is_array($elementsToBeDeleted)) { |
|
| 157 | + foreach ($elementsToBeDeleted as $tableName => $element) { |
|
| 158 | + |
|
| 159 | + if ($tableName === 'sys_file_reference') { |
|
| 160 | + |
|
| 161 | + $fileReferenceIdentifier = key($element); |
|
| 162 | + if ($element[$fileReferenceIdentifier] === true) { |
|
| 163 | + $fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier); |
|
| 164 | + $fileIdentifiers[] = $fileIdentifier; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Put back in the memory cache the value. |
|
| 171 | + $items = $this->getMemoryCache()->get($this->registerKey); |
|
| 172 | + $mergedItems = array_merge($items, $fileIdentifiers); |
|
| 173 | + $this->getMemoryCache()->set($this->registerKey, $mergedItems); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @return array |
|
| 178 | + */ |
|
| 179 | + protected function getRegisteredFiles() |
|
| 180 | + { |
|
| 181 | + $files = $this->getMemoryCache()->get($this->registerKey); |
|
| 182 | + return $files; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Look for file which are within the reference index. |
|
| 187 | + * |
|
| 188 | + * @return array |
|
| 189 | + */ |
|
| 190 | + protected function getFileToProcess() |
|
| 191 | + { |
|
| 192 | + $fileIdentifiers = array_merge( |
|
| 193 | + $this->beforeDataHandlerProcessFileIdentifiers, |
|
| 194 | + $this->afterDataHandlerProcessFileIdentifiers, |
|
| 195 | + $this->getRegisteredFiles() |
|
| 196 | + ); |
|
| 197 | + return array_unique($fileIdentifiers); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @param array $fileIdentifiers |
|
| 202 | + * @return void |
|
| 203 | + */ |
|
| 204 | + protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
| 205 | + { |
|
| 206 | + $this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param array $fileIdentifiers |
|
| 211 | + * @return void |
|
| 212 | + */ |
|
| 213 | + protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
| 214 | + { |
|
| 215 | + $this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Look for file which are within the reference index. |
|
| 220 | + * |
|
| 221 | + * @param array $indexes |
|
| 222 | + * @return array |
|
| 223 | + */ |
|
| 224 | + protected function lookForFiles(array $indexes) |
|
| 225 | + { |
|
| 226 | + |
|
| 227 | + $fileIdentifiers = []; |
|
| 228 | + if (isset($indexes['relations'])) { |
|
| 229 | + |
|
| 230 | + foreach ($indexes['relations'] as $index) { |
|
| 231 | + if (is_array($index)) { |
|
| 232 | + if ($this->isSoftReferenceImage($index)) { |
|
| 233 | + $fileIdentifiers[] = $index['ref_uid']; |
|
| 234 | + } elseif ($this->isSoftReferenceLink($index)) { |
|
| 235 | + $fileIdentifiers[] = $index['ref_uid']; |
|
| 236 | + } elseif ($this->isFileReference($index)) { |
|
| 237 | + $fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return $fileIdentifiers; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param array $index |
|
| 248 | + * @return bool |
|
| 249 | + */ |
|
| 250 | + public function isFileReference(array $index) |
|
| 251 | + { |
|
| 252 | + return $index['ref_table'] === 'sys_file_reference'; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @param array $index |
|
| 257 | + * @return bool |
|
| 258 | + */ |
|
| 259 | + public function isSoftReferenceLink(array $index) |
|
| 260 | + { |
|
| 261 | + return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file'; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @param array $index |
|
| 266 | + * @return bool |
|
| 267 | + */ |
|
| 268 | + public function isSoftReferenceImage(array $index) |
|
| 269 | + { |
|
| 270 | + return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file'; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Retrieve the File identifier. |
|
| 275 | + * |
|
| 276 | + * @param $fileReferenceIdentifier |
|
| 277 | + * @return int |
|
| 278 | + * @throws \Exception |
|
| 279 | + */ |
|
| 280 | + protected function findFileByFileReference($fileReferenceIdentifier) |
|
| 281 | + { |
|
| 282 | + $record = $this->getDataService()->getRecord( |
|
| 283 | + 'sys_file_reference', |
|
| 284 | + [ |
|
| 285 | + 'uid' => $fileReferenceIdentifier |
|
| 286 | + ] |
|
| 287 | + ); |
|
| 288 | + |
|
| 289 | + if (empty($record)) { |
|
| 290 | + throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + $fileIdentifier = $record['uid_local']; |
|
| 294 | + return $fileIdentifier; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 299 | + */ |
|
| 300 | + protected function getFileReferenceService() |
|
| 301 | + { |
|
| 302 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Gets an instance of the memory cache. |
|
| 307 | + * |
|
| 308 | + * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend |
|
| 309 | + */ |
|
| 310 | + protected function getMemoryCache() |
|
| 311 | + { |
|
| 312 | + return $this->getCacheManager()->getCache('cache_runtime'); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Create and returns an instance of the CacheManager |
|
| 317 | + * |
|
| 318 | + * @return \TYPO3\CMS\Core\Cache\CacheManager|object |
|
| 319 | + */ |
|
| 320 | + protected function getCacheManager() |
|
| 321 | + { |
|
| 322 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * @return object|DataService |
|
| 327 | + */ |
|
| 328 | + protected function getDataService(): DataService |
|
| 329 | + { |
|
| 330 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | 333 | } |
@@ -22,247 +22,247 @@ |
||
| 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 | - |
|
| 177 | - // todo here... |
|
| 178 | - $subClauseParts = array( |
|
| 179 | - 'deleted = 0', |
|
| 180 | - '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 181 | - 'ref_table = "sys_file"', |
|
| 182 | - 'tablename = "tt_content"', |
|
| 183 | - 'ref_uid = ' . $file->getUid(), |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 187 | - 'DISTINCT pid', |
|
| 188 | - 'tt_content', |
|
| 189 | - sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 190 | - implode(' AND ', $subClauseParts), |
|
| 191 | - $this->getWhereClauseForEnabledFields('tt_content') |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - // Compute result |
|
| 196 | - $pages = []; |
|
| 197 | - while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 198 | - $pages[] = $affectedPage['pid']; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $pages; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 206 | - * |
|
| 207 | - * @param string $tableName |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - protected function getWhereClauseForEnabledFields($tableName) |
|
| 211 | - { |
|
| 212 | - if ($this->isFrontendMode()) { |
|
| 213 | - // frontend context |
|
| 214 | - $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 215 | - } else { |
|
| 216 | - // backend context |
|
| 217 | - $whereClause = BackendUtility::deleteClause($tableName); |
|
| 218 | - } |
|
| 219 | - return $whereClause; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Returns whether the current mode is Frontend |
|
| 224 | - * |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - protected function isFrontendMode() |
|
| 228 | - { |
|
| 229 | - return TYPO3_MODE == 'FE'; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Returns an instance of the page repository. |
|
| 234 | - * |
|
| 235 | - * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 236 | - */ |
|
| 237 | - protected function getPageRepository() |
|
| 238 | - { |
|
| 239 | - return $GLOBALS['TSFE']->sys_page; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param string $tableName |
|
| 244 | - * @return object|QueryBuilder |
|
| 245 | - */ |
|
| 246 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
| 247 | - { |
|
| 248 | - /** @var ConnectionPool $connectionPool */ |
|
| 249 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 250 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @return object|DataService |
|
| 255 | - */ |
|
| 256 | - protected function getDataService(): DataService |
|
| 257 | - { |
|
| 258 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 263 | - */ |
|
| 264 | - protected function getFileReferenceService() |
|
| 265 | - { |
|
| 266 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 267 | - } |
|
| 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 | + |
|
| 177 | + // todo here... |
|
| 178 | + $subClauseParts = array( |
|
| 179 | + 'deleted = 0', |
|
| 180 | + '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 181 | + 'ref_table = "sys_file"', |
|
| 182 | + 'tablename = "tt_content"', |
|
| 183 | + 'ref_uid = ' . $file->getUid(), |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 187 | + 'DISTINCT pid', |
|
| 188 | + 'tt_content', |
|
| 189 | + sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 190 | + implode(' AND ', $subClauseParts), |
|
| 191 | + $this->getWhereClauseForEnabledFields('tt_content') |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + // Compute result |
|
| 196 | + $pages = []; |
|
| 197 | + while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 198 | + $pages[] = $affectedPage['pid']; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $pages; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 206 | + * |
|
| 207 | + * @param string $tableName |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + protected function getWhereClauseForEnabledFields($tableName) |
|
| 211 | + { |
|
| 212 | + if ($this->isFrontendMode()) { |
|
| 213 | + // frontend context |
|
| 214 | + $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 215 | + } else { |
|
| 216 | + // backend context |
|
| 217 | + $whereClause = BackendUtility::deleteClause($tableName); |
|
| 218 | + } |
|
| 219 | + return $whereClause; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Returns whether the current mode is Frontend |
|
| 224 | + * |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + protected function isFrontendMode() |
|
| 228 | + { |
|
| 229 | + return TYPO3_MODE == 'FE'; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Returns an instance of the page repository. |
|
| 234 | + * |
|
| 235 | + * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 236 | + */ |
|
| 237 | + protected function getPageRepository() |
|
| 238 | + { |
|
| 239 | + return $GLOBALS['TSFE']->sys_page; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param string $tableName |
|
| 244 | + * @return object|QueryBuilder |
|
| 245 | + */ |
|
| 246 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
| 247 | + { |
|
| 248 | + /** @var ConnectionPool $connectionPool */ |
|
| 249 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 250 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @return object|DataService |
|
| 255 | + */ |
|
| 256 | + protected function getDataService(): DataService |
|
| 257 | + { |
|
| 258 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 263 | + */ |
|
| 264 | + protected function getFileReferenceService() |
|
| 265 | + { |
|
| 266 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | ->groupBy('pid') // no support for distinct |
| 153 | 153 | ->andWhere( |
| 154 | 154 | 'pid > 0', |
| 155 | - 'uid_local = ' . $file->getUid() |
|
| 155 | + 'uid_local = '.$file->getUid() |
|
| 156 | 156 | ) |
| 157 | 157 | ->execute() |
| 158 | 158 | ->fetchAll(); |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
| 181 | 181 | 'ref_table = "sys_file"', |
| 182 | 182 | 'tablename = "tt_content"', |
| 183 | - 'ref_uid = ' . $file->getUid(), |
|
| 183 | + 'ref_uid = '.$file->getUid(), |
|
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | 186 | $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
@@ -27,207 +27,207 @@ |
||
| 27 | 27 | class FilePermissionsAspect |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Post-process the matcher object to respect the file storages. |
|
| 32 | - * |
|
| 33 | - * @param Matcher $matcher |
|
| 34 | - * @param string $dataType |
|
| 35 | - * @return void |
|
| 36 | - * @throws \InvalidArgumentException |
|
| 37 | - */ |
|
| 38 | - public function addFilePermissionsForFileStorages(Matcher $matcher, $dataType) |
|
| 39 | - { |
|
| 40 | - if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
| 41 | - |
|
| 42 | - if ($this->isFolderConsidered()) { |
|
| 43 | - |
|
| 44 | - $folder = $this->getMediaModule()->getCurrentFolder(); |
|
| 45 | - |
|
| 46 | - if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
| 47 | - |
|
| 48 | - // Only add like condition if needed. |
|
| 49 | - if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
| 50 | - $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
| 51 | - } |
|
| 52 | - } else { |
|
| 53 | - |
|
| 54 | - // Browse only currently |
|
| 55 | - $files = $this->getFileUids($folder); |
|
| 56 | - $matcher->in('uid', $files); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
| 60 | - } else { |
|
| 61 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 62 | - |
|
| 63 | - // Set the storage identifier only if the storage is on-line. |
|
| 64 | - $identifier = -1; |
|
| 65 | - if ($storage->isOnline()) { |
|
| 66 | - $identifier = $storage->getUid(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
| 70 | - |
|
| 71 | - $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
| 72 | - $collectedFiles = []; |
|
| 73 | - foreach ($fileMounts as $fileMount) { |
|
| 74 | - |
|
| 75 | - $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
| 76 | - $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
| 77 | - |
|
| 78 | - $files = $this->getFileUids($folder); |
|
| 79 | - $collectedFiles = array_merge($collectedFiles, $files); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $matcher->in('uid', $collectedFiles); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $matcher->equals('storage', $identifier); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - protected function isPermissionNecessary() |
|
| 94 | - { |
|
| 95 | - |
|
| 96 | - $isNecessary = true; |
|
| 97 | - |
|
| 98 | - $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
| 99 | - |
|
| 100 | - if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
| 101 | - $isNecessary = false; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
| 105 | - $isNecessary = false; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return $isNecessary; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return bool |
|
| 113 | - */ |
|
| 114 | - protected function isFolderConsidered() |
|
| 115 | - { |
|
| 116 | - return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param Folder $folder |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - protected function getFileUids(Folder $folder) |
|
| 124 | - { |
|
| 125 | - $files = []; |
|
| 126 | - foreach ($folder->getFiles() as $file) { |
|
| 127 | - $files[] = $file->getUid(); |
|
| 128 | - } |
|
| 129 | - return $files; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Post-process the constraints object to respect the file mounts. |
|
| 134 | - * |
|
| 135 | - * @param Query $query |
|
| 136 | - * @param ConstraintInterface|null $constraints |
|
| 137 | - * @param ConstraintContainer $constraintContainer |
|
| 138 | - * @throws \InvalidArgumentException |
|
| 139 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
| 140 | - */ |
|
| 141 | - public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
| 142 | - { |
|
| 143 | - if ($query->getType() === 'sys_file') { |
|
| 144 | - if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
| 145 | - $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param Query $query |
|
| 152 | - * @param ConstraintInterface|null $constraints |
|
| 153 | - * @param ConstraintContainer $constraintContainer |
|
| 154 | - * @return array |
|
| 155 | - * @throws \InvalidArgumentException |
|
| 156 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
| 157 | - */ |
|
| 158 | - protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
| 159 | - { |
|
| 160 | - $tableName = 'sys_filemounts'; |
|
| 161 | - |
|
| 162 | - // Get the file mount identifiers for the current Backend User. |
|
| 163 | - $fileMounts = GeneralUtility::trimExplode(',', $this->getCurrentBackendUser()->dataLists['filemount_list']); |
|
| 164 | - $fileMountUids = implode(',', array_filter($fileMounts)); |
|
| 165 | - |
|
| 166 | - // Fetch the records. |
|
| 167 | - $fileMountRecords = $this->getDataService()->getRecords( |
|
| 168 | - $tableName, |
|
| 169 | - [ |
|
| 170 | - 'uid' => $fileMountUids |
|
| 171 | - ] |
|
| 172 | - ); |
|
| 173 | - $constraintsRespectingFileMounts = []; |
|
| 174 | - foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
| 175 | - if ($fileMountRecord['path']) { |
|
| 176 | - $constraintsRespectingFileMounts[] = $query->like( |
|
| 177 | - 'identifier', |
|
| 178 | - $fileMountRecord['path'] . '%' |
|
| 179 | - ); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
| 184 | - |
|
| 185 | - if ($constraints) { |
|
| 186 | - $constraints = $query->logicalAnd( |
|
| 187 | - $constraints, |
|
| 188 | - $logicalOrForRespectingFileMounts |
|
| 189 | - ); |
|
| 190 | - } else { |
|
| 191 | - $constraints = $logicalOrForRespectingFileMounts; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $constraintContainer->setConstraint($constraints); |
|
| 195 | - |
|
| 196 | - return [$query, $constraints, $constraintContainer]; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 201 | - */ |
|
| 202 | - protected function getCurrentBackendUser() |
|
| 203 | - { |
|
| 204 | - return $GLOBALS['BE_USER']; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @return object|DataService |
|
| 209 | - */ |
|
| 210 | - protected function getDataService(): DataService |
|
| 211 | - { |
|
| 212 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @return MediaModule|object |
|
| 217 | - * @throws \InvalidArgumentException |
|
| 218 | - */ |
|
| 219 | - protected function getMediaModule() |
|
| 220 | - { |
|
| 221 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Get the Vidi Module Loader. |
|
| 226 | - * |
|
| 227 | - * @return object|ModuleLoader |
|
| 228 | - */ |
|
| 229 | - protected function getModuleLoader() |
|
| 230 | - { |
|
| 231 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 232 | - } |
|
| 30 | + /** |
|
| 31 | + * Post-process the matcher object to respect the file storages. |
|
| 32 | + * |
|
| 33 | + * @param Matcher $matcher |
|
| 34 | + * @param string $dataType |
|
| 35 | + * @return void |
|
| 36 | + * @throws \InvalidArgumentException |
|
| 37 | + */ |
|
| 38 | + public function addFilePermissionsForFileStorages(Matcher $matcher, $dataType) |
|
| 39 | + { |
|
| 40 | + if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
| 41 | + |
|
| 42 | + if ($this->isFolderConsidered()) { |
|
| 43 | + |
|
| 44 | + $folder = $this->getMediaModule()->getCurrentFolder(); |
|
| 45 | + |
|
| 46 | + if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
| 47 | + |
|
| 48 | + // Only add like condition if needed. |
|
| 49 | + if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
| 50 | + $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
| 51 | + } |
|
| 52 | + } else { |
|
| 53 | + |
|
| 54 | + // Browse only currently |
|
| 55 | + $files = $this->getFileUids($folder); |
|
| 56 | + $matcher->in('uid', $files); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
| 60 | + } else { |
|
| 61 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 62 | + |
|
| 63 | + // Set the storage identifier only if the storage is on-line. |
|
| 64 | + $identifier = -1; |
|
| 65 | + if ($storage->isOnline()) { |
|
| 66 | + $identifier = $storage->getUid(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
| 70 | + |
|
| 71 | + $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
| 72 | + $collectedFiles = []; |
|
| 73 | + foreach ($fileMounts as $fileMount) { |
|
| 74 | + |
|
| 75 | + $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
| 76 | + $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
| 77 | + |
|
| 78 | + $files = $this->getFileUids($folder); |
|
| 79 | + $collectedFiles = array_merge($collectedFiles, $files); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $matcher->in('uid', $collectedFiles); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $matcher->equals('storage', $identifier); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + protected function isPermissionNecessary() |
|
| 94 | + { |
|
| 95 | + |
|
| 96 | + $isNecessary = true; |
|
| 97 | + |
|
| 98 | + $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
| 99 | + |
|
| 100 | + if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
| 101 | + $isNecessary = false; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
| 105 | + $isNecessary = false; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return $isNecessary; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return bool |
|
| 113 | + */ |
|
| 114 | + protected function isFolderConsidered() |
|
| 115 | + { |
|
| 116 | + return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param Folder $folder |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + protected function getFileUids(Folder $folder) |
|
| 124 | + { |
|
| 125 | + $files = []; |
|
| 126 | + foreach ($folder->getFiles() as $file) { |
|
| 127 | + $files[] = $file->getUid(); |
|
| 128 | + } |
|
| 129 | + return $files; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Post-process the constraints object to respect the file mounts. |
|
| 134 | + * |
|
| 135 | + * @param Query $query |
|
| 136 | + * @param ConstraintInterface|null $constraints |
|
| 137 | + * @param ConstraintContainer $constraintContainer |
|
| 138 | + * @throws \InvalidArgumentException |
|
| 139 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
| 140 | + */ |
|
| 141 | + public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
| 142 | + { |
|
| 143 | + if ($query->getType() === 'sys_file') { |
|
| 144 | + if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
| 145 | + $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param Query $query |
|
| 152 | + * @param ConstraintInterface|null $constraints |
|
| 153 | + * @param ConstraintContainer $constraintContainer |
|
| 154 | + * @return array |
|
| 155 | + * @throws \InvalidArgumentException |
|
| 156 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
| 157 | + */ |
|
| 158 | + protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
| 159 | + { |
|
| 160 | + $tableName = 'sys_filemounts'; |
|
| 161 | + |
|
| 162 | + // Get the file mount identifiers for the current Backend User. |
|
| 163 | + $fileMounts = GeneralUtility::trimExplode(',', $this->getCurrentBackendUser()->dataLists['filemount_list']); |
|
| 164 | + $fileMountUids = implode(',', array_filter($fileMounts)); |
|
| 165 | + |
|
| 166 | + // Fetch the records. |
|
| 167 | + $fileMountRecords = $this->getDataService()->getRecords( |
|
| 168 | + $tableName, |
|
| 169 | + [ |
|
| 170 | + 'uid' => $fileMountUids |
|
| 171 | + ] |
|
| 172 | + ); |
|
| 173 | + $constraintsRespectingFileMounts = []; |
|
| 174 | + foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
| 175 | + if ($fileMountRecord['path']) { |
|
| 176 | + $constraintsRespectingFileMounts[] = $query->like( |
|
| 177 | + 'identifier', |
|
| 178 | + $fileMountRecord['path'] . '%' |
|
| 179 | + ); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
| 184 | + |
|
| 185 | + if ($constraints) { |
|
| 186 | + $constraints = $query->logicalAnd( |
|
| 187 | + $constraints, |
|
| 188 | + $logicalOrForRespectingFileMounts |
|
| 189 | + ); |
|
| 190 | + } else { |
|
| 191 | + $constraints = $logicalOrForRespectingFileMounts; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $constraintContainer->setConstraint($constraints); |
|
| 195 | + |
|
| 196 | + return [$query, $constraints, $constraintContainer]; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 201 | + */ |
|
| 202 | + protected function getCurrentBackendUser() |
|
| 203 | + { |
|
| 204 | + return $GLOBALS['BE_USER']; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @return object|DataService |
|
| 209 | + */ |
|
| 210 | + protected function getDataService(): DataService |
|
| 211 | + { |
|
| 212 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @return MediaModule|object |
|
| 217 | + * @throws \InvalidArgumentException |
|
| 218 | + */ |
|
| 219 | + protected function getMediaModule() |
|
| 220 | + { |
|
| 221 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Get the Vidi Module Loader. |
|
| 226 | + * |
|
| 227 | + * @return object|ModuleLoader |
|
| 228 | + */ |
|
| 229 | + protected function getModuleLoader() |
|
| 230 | + { |
|
| 231 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 232 | + } |
|
| 233 | 233 | } |
@@ -21,129 +21,129 @@ |
||
| 21 | 21 | class MissingFilesFinderTool extends AbstractTool |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Display the title of the tool on the welcome screen. |
|
| 26 | - * |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function getTitle() |
|
| 30 | - { |
|
| 31 | - return 'Find missing files'; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Display the description of the tool in the welcome screen. |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function getDescription() |
|
| 40 | - { |
|
| 41 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
|
| 42 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 43 | - $view->assign('sitePath', PATH_site); |
|
| 44 | - return $view->render(); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Do the job: analyse Index. |
|
| 49 | - * |
|
| 50 | - * @param array $arguments |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function work(array $arguments = []) |
|
| 54 | - { |
|
| 55 | - |
|
| 56 | - // Possible clean up of missing files if the User has clicked so. |
|
| 57 | - if (!empty($arguments['deleteMissingFiles'])) { |
|
| 58 | - $this->deleteMissingFilesAction($arguments['files']); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/WorkResult.html'; |
|
| 62 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 63 | - |
|
| 64 | - $missingReports = []; |
|
| 65 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 66 | - |
|
| 67 | - if ($storage->isOnline()) { |
|
| 68 | - $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
| 69 | - |
|
| 70 | - $missingReports[] = array( |
|
| 71 | - 'storage' => $storage, |
|
| 72 | - 'missingFiles' => $missingFiles, |
|
| 73 | - 'numberOfMissingFiles' => count($missingFiles), |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $view->assign('missingReports', $missingReports); |
|
| 79 | - |
|
| 80 | - return $view->render(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Delete files given as parameter. |
|
| 85 | - * This is a special case as we have a missing file in the file system |
|
| 86 | - * As a result, we can't use $fileObject->delete(); which will |
|
| 87 | - * raise exception "Error while fetching permissions". |
|
| 88 | - * |
|
| 89 | - * @param array $files |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - protected function deleteMissingFilesAction(array $files = []) |
|
| 93 | - { |
|
| 94 | - |
|
| 95 | - foreach ($files as $fileUid) { |
|
| 96 | - |
|
| 97 | - /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
| 98 | - try { |
|
| 99 | - $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
| 100 | - if ($file) { |
|
| 101 | - // The case is special as we have a missing file in the file system |
|
| 102 | - // As a result, we can't use $fileObject->delete(); which will |
|
| 103 | - // raise exception "Error while fetching permissions" |
|
| 104 | - $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 105 | - } |
|
| 106 | - } catch (\Exception $e) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Return a pointer to the database. |
|
| 114 | - * |
|
| 115 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
| 116 | - */ |
|
| 117 | - protected function getIndexAnalyser() |
|
| 118 | - { |
|
| 119 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return StorageRepository|object |
|
| 124 | - */ |
|
| 125 | - protected function getStorageRepository() |
|
| 126 | - { |
|
| 127 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Tell whether the tools should be displayed according to the context. |
|
| 132 | - * |
|
| 133 | - * @return bool |
|
| 134 | - */ |
|
| 135 | - public function isShown() |
|
| 136 | - { |
|
| 137 | - return $this->getBackendUser()->isAdmin(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return object|DataService |
|
| 142 | - */ |
|
| 143 | - protected function getDataService(): DataService |
|
| 144 | - { |
|
| 145 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 146 | - } |
|
| 24 | + /** |
|
| 25 | + * Display the title of the tool on the welcome screen. |
|
| 26 | + * |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function getTitle() |
|
| 30 | + { |
|
| 31 | + return 'Find missing files'; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Display the description of the tool in the welcome screen. |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function getDescription() |
|
| 40 | + { |
|
| 41 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
|
| 42 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 43 | + $view->assign('sitePath', PATH_site); |
|
| 44 | + return $view->render(); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Do the job: analyse Index. |
|
| 49 | + * |
|
| 50 | + * @param array $arguments |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function work(array $arguments = []) |
|
| 54 | + { |
|
| 55 | + |
|
| 56 | + // Possible clean up of missing files if the User has clicked so. |
|
| 57 | + if (!empty($arguments['deleteMissingFiles'])) { |
|
| 58 | + $this->deleteMissingFilesAction($arguments['files']); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/WorkResult.html'; |
|
| 62 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 63 | + |
|
| 64 | + $missingReports = []; |
|
| 65 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 66 | + |
|
| 67 | + if ($storage->isOnline()) { |
|
| 68 | + $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
| 69 | + |
|
| 70 | + $missingReports[] = array( |
|
| 71 | + 'storage' => $storage, |
|
| 72 | + 'missingFiles' => $missingFiles, |
|
| 73 | + 'numberOfMissingFiles' => count($missingFiles), |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $view->assign('missingReports', $missingReports); |
|
| 79 | + |
|
| 80 | + return $view->render(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Delete files given as parameter. |
|
| 85 | + * This is a special case as we have a missing file in the file system |
|
| 86 | + * As a result, we can't use $fileObject->delete(); which will |
|
| 87 | + * raise exception "Error while fetching permissions". |
|
| 88 | + * |
|
| 89 | + * @param array $files |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + protected function deleteMissingFilesAction(array $files = []) |
|
| 93 | + { |
|
| 94 | + |
|
| 95 | + foreach ($files as $fileUid) { |
|
| 96 | + |
|
| 97 | + /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
| 98 | + try { |
|
| 99 | + $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
| 100 | + if ($file) { |
|
| 101 | + // The case is special as we have a missing file in the file system |
|
| 102 | + // As a result, we can't use $fileObject->delete(); which will |
|
| 103 | + // raise exception "Error while fetching permissions" |
|
| 104 | + $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 105 | + } |
|
| 106 | + } catch (\Exception $e) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Return a pointer to the database. |
|
| 114 | + * |
|
| 115 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
| 116 | + */ |
|
| 117 | + protected function getIndexAnalyser() |
|
| 118 | + { |
|
| 119 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return StorageRepository|object |
|
| 124 | + */ |
|
| 125 | + protected function getStorageRepository() |
|
| 126 | + { |
|
| 127 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Tell whether the tools should be displayed according to the context. |
|
| 132 | + * |
|
| 133 | + * @return bool |
|
| 134 | + */ |
|
| 135 | + public function isShown() |
|
| 136 | + { |
|
| 137 | + return $this->getBackendUser()->isAdmin(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return object|DataService |
|
| 142 | + */ |
|
| 143 | + protected function getDataService(): DataService |
|
| 144 | + { |
|
| 145 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | 148 | } |
| 149 | 149 | |
@@ -20,206 +20,206 @@ |
||
| 20 | 20 | class DuplicateFilesFinderTool extends AbstractTool |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Display the title of the tool on the welcome screen. |
|
| 25 | - * |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function getTitle() |
|
| 29 | - { |
|
| 30 | - return 'Find duplicate Files'; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Display the description of the tool in the welcome screen. |
|
| 35 | - * |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getDescription() |
|
| 39 | - { |
|
| 40 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
|
| 41 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 42 | - $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
|
| 43 | - $view->assign('sitePath', PATH_site); |
|
| 44 | - return $view->render(); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Do the job: analyse Index. |
|
| 49 | - * |
|
| 50 | - * @param array $arguments |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function work(array $arguments = []) |
|
| 54 | - { |
|
| 55 | - |
|
| 56 | - // Possible clean up of missing files if the User has clicked so. |
|
| 57 | - if (!empty($arguments['deleteDuplicateFiles'])) { |
|
| 58 | - $this->deleteMissingFilesAction($arguments['files']); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/WorkResult.html'; |
|
| 62 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 63 | - |
|
| 64 | - $duplicateFilesReports = []; |
|
| 65 | - |
|
| 66 | - if ($this->getBackendUser()->isAdmin()) { |
|
| 67 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 68 | - if ($storage->isOnline()) { |
|
| 69 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 70 | - $duplicateFilesReports[] = array( |
|
| 71 | - 'storage' => $storage, |
|
| 72 | - 'duplicateFiles' => $duplicateFiles, |
|
| 73 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - |
|
| 79 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 80 | - |
|
| 81 | - $allowedStorages = []; |
|
| 82 | - foreach ($fileMounts as $fileMount) { |
|
| 83 | - if ((bool)$fileMount['read_only']) { |
|
| 84 | - continue; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (!isset($allowedStorages[$fileMount['base']])) { |
|
| 88 | - $allowedStorages[$fileMount['base']] = []; |
|
| 89 | - } |
|
| 90 | - if (!in_array($fileMount['base'], $allowedStorages)) { |
|
| 91 | - $allowedStorages[$fileMount['base']][] = $fileMount['path']; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - foreach ($allowedStorages as $storageIdentifier => $allowedMountPoints) { |
|
| 96 | - $storage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier); |
|
| 97 | - |
|
| 98 | - if ($storage->isOnline()) { |
|
| 99 | - |
|
| 100 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 101 | - |
|
| 102 | - // Filter duplicates files |
|
| 103 | - foreach ($duplicateFiles as $key => $files) { |
|
| 104 | - |
|
| 105 | - $filteredFiles = []; |
|
| 106 | - foreach ($files as $file) { |
|
| 107 | - |
|
| 108 | - foreach ($allowedMountPoints as $allowedMountPoint) { |
|
| 109 | - |
|
| 110 | - $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
| 111 | - if (preg_match($pattern, $file['identifier'])) { |
|
| 112 | - $filteredFiles[] = $file; |
|
| 113 | - break; // no need to further loop around, stop the loop. |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // We need more than 1 files to be shown as duplicate. |
|
| 119 | - if (count($filteredFiles) > 1) { |
|
| 120 | - $duplicateFiles[$key] = $filteredFiles; |
|
| 121 | - } else { |
|
| 122 | - unset($duplicateFiles[$key]); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - $duplicateFilesReports[] = array( |
|
| 126 | - 'storage' => $storage, |
|
| 127 | - 'duplicateFiles' => $duplicateFiles, |
|
| 128 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 129 | - ); |
|
| 130 | - |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $view->assign('duplicateFilesReports', $duplicateFilesReports); |
|
| 136 | - |
|
| 137 | - return $view->render(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Delete files given as parameter. |
|
| 142 | - * This is a special case as we have a missing file in the file system |
|
| 143 | - * As a result, we can't use $fileObject->delete(); which will |
|
| 144 | - * raise exception "Error while fetching permissions". |
|
| 145 | - * |
|
| 146 | - * @param array $files |
|
| 147 | - * @return void |
|
| 148 | - */ |
|
| 149 | - protected function deleteMissingFilesAction(array $files = []) |
|
| 150 | - { |
|
| 151 | - |
|
| 152 | - foreach ($files as $fileUid) { |
|
| 153 | - |
|
| 154 | - /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
| 155 | - try { |
|
| 156 | - $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
| 157 | - if ($file->exists()) { |
|
| 158 | - |
|
| 159 | - $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
| 160 | - if ($numberOfReferences === 0) { |
|
| 161 | - $file->delete(); |
|
| 162 | - } |
|
| 163 | - } else { |
|
| 164 | - $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 165 | - } |
|
| 166 | - } catch (\Exception $e) { |
|
| 167 | - continue; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Return a pointer to the database. |
|
| 174 | - * |
|
| 175 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
| 176 | - */ |
|
| 177 | - protected function getIndexAnalyser() |
|
| 178 | - { |
|
| 179 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
| 184 | - */ |
|
| 185 | - protected function getThumbnailGenerator() |
|
| 186 | - { |
|
| 187 | - return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @return StorageRepository|object |
|
| 192 | - */ |
|
| 193 | - protected function getStorageRepository() |
|
| 194 | - { |
|
| 195 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Tell whether the tools should be displayed according to the context. |
|
| 200 | - * |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 203 | - public function isShown() |
|
| 204 | - { |
|
| 205 | - return true; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 210 | - */ |
|
| 211 | - protected function getFileReferenceService() |
|
| 212 | - { |
|
| 213 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @return object|DataService |
|
| 218 | - */ |
|
| 219 | - protected function getDataService(): DataService |
|
| 220 | - { |
|
| 221 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 222 | - } |
|
| 23 | + /** |
|
| 24 | + * Display the title of the tool on the welcome screen. |
|
| 25 | + * |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function getTitle() |
|
| 29 | + { |
|
| 30 | + return 'Find duplicate Files'; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Display the description of the tool in the welcome screen. |
|
| 35 | + * |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getDescription() |
|
| 39 | + { |
|
| 40 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
|
| 41 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 42 | + $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
|
| 43 | + $view->assign('sitePath', PATH_site); |
|
| 44 | + return $view->render(); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Do the job: analyse Index. |
|
| 49 | + * |
|
| 50 | + * @param array $arguments |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function work(array $arguments = []) |
|
| 54 | + { |
|
| 55 | + |
|
| 56 | + // Possible clean up of missing files if the User has clicked so. |
|
| 57 | + if (!empty($arguments['deleteDuplicateFiles'])) { |
|
| 58 | + $this->deleteMissingFilesAction($arguments['files']); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/WorkResult.html'; |
|
| 62 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 63 | + |
|
| 64 | + $duplicateFilesReports = []; |
|
| 65 | + |
|
| 66 | + if ($this->getBackendUser()->isAdmin()) { |
|
| 67 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 68 | + if ($storage->isOnline()) { |
|
| 69 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 70 | + $duplicateFilesReports[] = array( |
|
| 71 | + 'storage' => $storage, |
|
| 72 | + 'duplicateFiles' => $duplicateFiles, |
|
| 73 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + |
|
| 79 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 80 | + |
|
| 81 | + $allowedStorages = []; |
|
| 82 | + foreach ($fileMounts as $fileMount) { |
|
| 83 | + if ((bool)$fileMount['read_only']) { |
|
| 84 | + continue; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (!isset($allowedStorages[$fileMount['base']])) { |
|
| 88 | + $allowedStorages[$fileMount['base']] = []; |
|
| 89 | + } |
|
| 90 | + if (!in_array($fileMount['base'], $allowedStorages)) { |
|
| 91 | + $allowedStorages[$fileMount['base']][] = $fileMount['path']; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + foreach ($allowedStorages as $storageIdentifier => $allowedMountPoints) { |
|
| 96 | + $storage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier); |
|
| 97 | + |
|
| 98 | + if ($storage->isOnline()) { |
|
| 99 | + |
|
| 100 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 101 | + |
|
| 102 | + // Filter duplicates files |
|
| 103 | + foreach ($duplicateFiles as $key => $files) { |
|
| 104 | + |
|
| 105 | + $filteredFiles = []; |
|
| 106 | + foreach ($files as $file) { |
|
| 107 | + |
|
| 108 | + foreach ($allowedMountPoints as $allowedMountPoint) { |
|
| 109 | + |
|
| 110 | + $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
| 111 | + if (preg_match($pattern, $file['identifier'])) { |
|
| 112 | + $filteredFiles[] = $file; |
|
| 113 | + break; // no need to further loop around, stop the loop. |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // We need more than 1 files to be shown as duplicate. |
|
| 119 | + if (count($filteredFiles) > 1) { |
|
| 120 | + $duplicateFiles[$key] = $filteredFiles; |
|
| 121 | + } else { |
|
| 122 | + unset($duplicateFiles[$key]); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + $duplicateFilesReports[] = array( |
|
| 126 | + 'storage' => $storage, |
|
| 127 | + 'duplicateFiles' => $duplicateFiles, |
|
| 128 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 129 | + ); |
|
| 130 | + |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $view->assign('duplicateFilesReports', $duplicateFilesReports); |
|
| 136 | + |
|
| 137 | + return $view->render(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Delete files given as parameter. |
|
| 142 | + * This is a special case as we have a missing file in the file system |
|
| 143 | + * As a result, we can't use $fileObject->delete(); which will |
|
| 144 | + * raise exception "Error while fetching permissions". |
|
| 145 | + * |
|
| 146 | + * @param array $files |
|
| 147 | + * @return void |
|
| 148 | + */ |
|
| 149 | + protected function deleteMissingFilesAction(array $files = []) |
|
| 150 | + { |
|
| 151 | + |
|
| 152 | + foreach ($files as $fileUid) { |
|
| 153 | + |
|
| 154 | + /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
| 155 | + try { |
|
| 156 | + $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
| 157 | + if ($file->exists()) { |
|
| 158 | + |
|
| 159 | + $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
| 160 | + if ($numberOfReferences === 0) { |
|
| 161 | + $file->delete(); |
|
| 162 | + } |
|
| 163 | + } else { |
|
| 164 | + $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 165 | + } |
|
| 166 | + } catch (\Exception $e) { |
|
| 167 | + continue; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Return a pointer to the database. |
|
| 174 | + * |
|
| 175 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
| 176 | + */ |
|
| 177 | + protected function getIndexAnalyser() |
|
| 178 | + { |
|
| 179 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
| 184 | + */ |
|
| 185 | + protected function getThumbnailGenerator() |
|
| 186 | + { |
|
| 187 | + return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @return StorageRepository|object |
|
| 192 | + */ |
|
| 193 | + protected function getStorageRepository() |
|
| 194 | + { |
|
| 195 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Tell whether the tools should be displayed according to the context. |
|
| 200 | + * |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | + public function isShown() |
|
| 204 | + { |
|
| 205 | + return true; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 210 | + */ |
|
| 211 | + protected function getFileReferenceService() |
|
| 212 | + { |
|
| 213 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @return object|DataService |
|
| 218 | + */ |
|
| 219 | + protected function getDataService(): DataService |
|
| 220 | + { |
|
| 221 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | } |
| 225 | 225 | |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | |
| 108 | 108 | foreach ($allowedMountPoints as $allowedMountPoint) { |
| 109 | 109 | |
| 110 | - $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
| 110 | + $pattern = '%^'.$allowedMountPoint.'%isU'; |
|
| 111 | 111 | if (preg_match($pattern, $file['identifier'])) { |
| 112 | 112 | $filteredFiles[] = $file; |
| 113 | 113 | break; // no need to further loop around, stop the loop. |
@@ -18,125 +18,125 @@ |
||
| 18 | 18 | class ThumbnailGeneratorTool extends AbstractTool |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Display the title of the tool on the welcome screen. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function getTitle() |
|
| 27 | - { |
|
| 28 | - return 'Generate thumbnails'; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Display the description of the tool in the welcome screen. |
|
| 33 | - * |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function getDescription() |
|
| 37 | - { |
|
| 38 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/Launcher.html'; |
|
| 39 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 40 | - $view->assign('sitePath', PATH_site); |
|
| 41 | - return $view->render(); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Do the job: analyse Index. |
|
| 46 | - * |
|
| 47 | - * @param array $arguments |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function work(array $arguments = []) |
|
| 51 | - { |
|
| 52 | - |
|
| 53 | - $reports = []; |
|
| 54 | - |
|
| 55 | - $limit = 500; // default value |
|
| 56 | - $newOffset = 0; |
|
| 57 | - |
|
| 58 | - // Possible clean up of missing files if the User has clicked so. |
|
| 59 | - if (isset($arguments['limit']) && isset($arguments['offset'])) { |
|
| 60 | - |
|
| 61 | - $limit = (int)$arguments['limit']; |
|
| 62 | - $offset = (int)$arguments['offset']; |
|
| 63 | - |
|
| 64 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 65 | - |
|
| 66 | - if ($storage->isOnline()) { |
|
| 67 | - |
|
| 68 | - $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
| 69 | - $thumbnailGenerator |
|
| 70 | - ->setStorage($storage) |
|
| 71 | - ->generate($limit, $offset); |
|
| 72 | - |
|
| 73 | - $formattedResultSet = []; |
|
| 74 | - $resultSet = $thumbnailGenerator->getResultSet(); |
|
| 75 | - $processedFileIdentifiers = $thumbnailGenerator->getNewProcessedFileIdentifiers(); |
|
| 76 | - |
|
| 77 | - foreach ($processedFileIdentifiers as $fileIdentifier => $processedFileIdentifier) { |
|
| 78 | - $result = $resultSet[$fileIdentifier]; |
|
| 79 | - $formattedResultSet[] = sprintf('* File "%s": %s %s', |
|
| 80 | - $result['fileUid'], |
|
| 81 | - $result['fileIdentifier'], |
|
| 82 | - empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $reports[] = array( |
|
| 87 | - 'storage' => $storage, |
|
| 88 | - 'isStorageOnline' => true, |
|
| 89 | - 'resultSet' => $formattedResultSet, |
|
| 90 | - 'numberOfProcessedFiles' => $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
| 91 | - 'numberOfTraversedFiles' => $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
| 92 | - 'numberOfMissingFiles' => $thumbnailGenerator->getNumberOfMissingFiles(), |
|
| 93 | - 'totalNumberOfFiles' => $thumbnailGenerator->getTotalNumberOfFiles(), |
|
| 94 | - ); |
|
| 95 | - } else { |
|
| 96 | - $reports[] = array( |
|
| 97 | - 'storage' => $storage, |
|
| 98 | - 'isStorageOnline' => false, |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $newOffset = $limit + $offset; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/WorkResult.html'; |
|
| 107 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 108 | - |
|
| 109 | - $view->assign('limit', $limit); |
|
| 110 | - $view->assign('offset', $newOffset); |
|
| 111 | - $view->assign('reports', $reports); |
|
| 112 | - return $view->render(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
| 117 | - */ |
|
| 118 | - protected function getThumbnailGenerator() |
|
| 119 | - { |
|
| 120 | - return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return StorageRepository|object |
|
| 125 | - */ |
|
| 126 | - protected function getStorageRepository() |
|
| 127 | - { |
|
| 128 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Tell whether the tools should be displayed according to the context. |
|
| 133 | - * |
|
| 134 | - * @return bool |
|
| 135 | - */ |
|
| 136 | - public function isShown() |
|
| 137 | - { |
|
| 138 | - return $this->getBackendUser()->isAdmin(); |
|
| 139 | - } |
|
| 21 | + /** |
|
| 22 | + * Display the title of the tool on the welcome screen. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function getTitle() |
|
| 27 | + { |
|
| 28 | + return 'Generate thumbnails'; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Display the description of the tool in the welcome screen. |
|
| 33 | + * |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function getDescription() |
|
| 37 | + { |
|
| 38 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/Launcher.html'; |
|
| 39 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 40 | + $view->assign('sitePath', PATH_site); |
|
| 41 | + return $view->render(); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Do the job: analyse Index. |
|
| 46 | + * |
|
| 47 | + * @param array $arguments |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function work(array $arguments = []) |
|
| 51 | + { |
|
| 52 | + |
|
| 53 | + $reports = []; |
|
| 54 | + |
|
| 55 | + $limit = 500; // default value |
|
| 56 | + $newOffset = 0; |
|
| 57 | + |
|
| 58 | + // Possible clean up of missing files if the User has clicked so. |
|
| 59 | + if (isset($arguments['limit']) && isset($arguments['offset'])) { |
|
| 60 | + |
|
| 61 | + $limit = (int)$arguments['limit']; |
|
| 62 | + $offset = (int)$arguments['offset']; |
|
| 63 | + |
|
| 64 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 65 | + |
|
| 66 | + if ($storage->isOnline()) { |
|
| 67 | + |
|
| 68 | + $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
| 69 | + $thumbnailGenerator |
|
| 70 | + ->setStorage($storage) |
|
| 71 | + ->generate($limit, $offset); |
|
| 72 | + |
|
| 73 | + $formattedResultSet = []; |
|
| 74 | + $resultSet = $thumbnailGenerator->getResultSet(); |
|
| 75 | + $processedFileIdentifiers = $thumbnailGenerator->getNewProcessedFileIdentifiers(); |
|
| 76 | + |
|
| 77 | + foreach ($processedFileIdentifiers as $fileIdentifier => $processedFileIdentifier) { |
|
| 78 | + $result = $resultSet[$fileIdentifier]; |
|
| 79 | + $formattedResultSet[] = sprintf('* File "%s": %s %s', |
|
| 80 | + $result['fileUid'], |
|
| 81 | + $result['fileIdentifier'], |
|
| 82 | + empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $reports[] = array( |
|
| 87 | + 'storage' => $storage, |
|
| 88 | + 'isStorageOnline' => true, |
|
| 89 | + 'resultSet' => $formattedResultSet, |
|
| 90 | + 'numberOfProcessedFiles' => $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
| 91 | + 'numberOfTraversedFiles' => $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
| 92 | + 'numberOfMissingFiles' => $thumbnailGenerator->getNumberOfMissingFiles(), |
|
| 93 | + 'totalNumberOfFiles' => $thumbnailGenerator->getTotalNumberOfFiles(), |
|
| 94 | + ); |
|
| 95 | + } else { |
|
| 96 | + $reports[] = array( |
|
| 97 | + 'storage' => $storage, |
|
| 98 | + 'isStorageOnline' => false, |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $newOffset = $limit + $offset; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/WorkResult.html'; |
|
| 107 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 108 | + |
|
| 109 | + $view->assign('limit', $limit); |
|
| 110 | + $view->assign('offset', $newOffset); |
|
| 111 | + $view->assign('reports', $reports); |
|
| 112 | + return $view->render(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
| 117 | + */ |
|
| 118 | + protected function getThumbnailGenerator() |
|
| 119 | + { |
|
| 120 | + return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return StorageRepository|object |
|
| 125 | + */ |
|
| 126 | + protected function getStorageRepository() |
|
| 127 | + { |
|
| 128 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Tell whether the tools should be displayed according to the context. |
|
| 133 | + * |
|
| 134 | + * @return bool |
|
| 135 | + */ |
|
| 136 | + public function isShown() |
|
| 137 | + { |
|
| 138 | + return $this->getBackendUser()->isAdmin(); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | |
@@ -19,86 +19,86 @@ |
||
| 19 | 19 | class DuplicateRecordsFinderTool extends AbstractTool |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Display the title of the tool on the welcome screen. |
|
| 24 | - * |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function getTitle() |
|
| 28 | - { |
|
| 29 | - return 'Find duplicate Records'; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Display the description of the tool in the welcome screen. |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getDescription() |
|
| 38 | - { |
|
| 39 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/Launcher.html'; |
|
| 40 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 41 | - $view->assign('sitePath', PATH_site); |
|
| 42 | - return $view->render(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Do the job: analyse Index. |
|
| 47 | - * |
|
| 48 | - * @param array $arguments |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function work(array $arguments = []) |
|
| 52 | - { |
|
| 53 | - |
|
| 54 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/WorkResult.html'; |
|
| 55 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 56 | - |
|
| 57 | - $duplicateRecordsReports = []; |
|
| 58 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 59 | - |
|
| 60 | - if ($storage->isOnline()) { |
|
| 61 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
| 62 | - $duplicateRecordsReports[] = array( |
|
| 63 | - 'storage' => $storage, |
|
| 64 | - 'duplicateFiles' => $duplicateFiles, |
|
| 65 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $view->assign('duplicateRecordsReports', $duplicateRecordsReports); |
|
| 71 | - |
|
| 72 | - return $view->render(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Return a pointer to the database. |
|
| 77 | - * |
|
| 78 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
| 79 | - */ |
|
| 80 | - protected function getIndexAnalyser() |
|
| 81 | - { |
|
| 82 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return StorageRepository|object |
|
| 87 | - */ |
|
| 88 | - protected function getStorageRepository() |
|
| 89 | - { |
|
| 90 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Tell whether the tools should be displayed according to the context. |
|
| 95 | - * |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 98 | - public function isShown() |
|
| 99 | - { |
|
| 100 | - return $this->getBackendUser()->isAdmin(); |
|
| 101 | - } |
|
| 22 | + /** |
|
| 23 | + * Display the title of the tool on the welcome screen. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function getTitle() |
|
| 28 | + { |
|
| 29 | + return 'Find duplicate Records'; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Display the description of the tool in the welcome screen. |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getDescription() |
|
| 38 | + { |
|
| 39 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/Launcher.html'; |
|
| 40 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 41 | + $view->assign('sitePath', PATH_site); |
|
| 42 | + return $view->render(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Do the job: analyse Index. |
|
| 47 | + * |
|
| 48 | + * @param array $arguments |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function work(array $arguments = []) |
|
| 52 | + { |
|
| 53 | + |
|
| 54 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/WorkResult.html'; |
|
| 55 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 56 | + |
|
| 57 | + $duplicateRecordsReports = []; |
|
| 58 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 59 | + |
|
| 60 | + if ($storage->isOnline()) { |
|
| 61 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
| 62 | + $duplicateRecordsReports[] = array( |
|
| 63 | + 'storage' => $storage, |
|
| 64 | + 'duplicateFiles' => $duplicateFiles, |
|
| 65 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $view->assign('duplicateRecordsReports', $duplicateRecordsReports); |
|
| 71 | + |
|
| 72 | + return $view->render(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Return a pointer to the database. |
|
| 77 | + * |
|
| 78 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
| 79 | + */ |
|
| 80 | + protected function getIndexAnalyser() |
|
| 81 | + { |
|
| 82 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return StorageRepository|object |
|
| 87 | + */ |
|
| 88 | + protected function getStorageRepository() |
|
| 89 | + { |
|
| 90 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Tell whether the tools should be displayed according to the context. |
|
| 95 | + * |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | + public function isShown() |
|
| 99 | + { |
|
| 100 | + return $this->getBackendUser()->isAdmin(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |