@@ -23,151 +23,151 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class MediaIndexer |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var ResourceStorage |
|
| 28 | - */ |
|
| 29 | - protected $storage = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @param ResourceStorage $storage |
|
| 33 | - */ |
|
| 34 | - public function __construct(ResourceStorage $storage) |
|
| 35 | - { |
|
| 36 | - $this->storage = $storage; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param File $file |
|
| 41 | - * @return $this |
|
| 42 | - */ |
|
| 43 | - public function updateIndex(File $file) |
|
| 44 | - { |
|
| 45 | - $this->getCoreIndexer()->updateIndexEntry($file); |
|
| 46 | - return $this; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param File $file |
|
| 51 | - * @return $this |
|
| 52 | - */ |
|
| 53 | - public function extractMetadata(File $file) |
|
| 54 | - { |
|
| 55 | - $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
| 56 | - |
|
| 57 | - $newMetaData = array( |
|
| 58 | - 0 => $file->getMetaData()->get() |
|
| 59 | - ); |
|
| 60 | - |
|
| 61 | - foreach ($extractionServices as $services) { |
|
| 62 | - if (is_array($services)) { |
|
| 63 | - foreach ($services as $service) { |
|
| 64 | - if ($service->canProcess($file)) { |
|
| 65 | - $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } else { |
|
| 69 | - $service = $services; |
|
| 70 | - // We could optimise here for not repeating this bit |
|
| 71 | - if ($service->canProcess($file)) { |
|
| 72 | - $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - ksort($newMetaData); |
|
| 78 | - $metaData = []; |
|
| 79 | - foreach ($newMetaData as $data) { |
|
| 80 | - $metaData = array_merge($metaData, $data); |
|
| 81 | - } |
|
| 82 | - $file->updateProperties($metaData); |
|
| 83 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 84 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 85 | - |
|
| 86 | - return $this; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param File $file |
|
| 91 | - * @return $this |
|
| 92 | - */ |
|
| 93 | - public function applyDefaultCategories(File $file) |
|
| 94 | - { |
|
| 95 | - $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
| 96 | - $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
| 97 | - |
|
| 98 | - foreach ($categories as $category) { |
|
| 99 | - $values = array( |
|
| 100 | - 'uid_local' => $category, |
|
| 101 | - 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
| 102 | - 'tablenames' => 'sys_file_metadata', |
|
| 103 | - 'fieldname' => 'categories', |
|
| 104 | - ); |
|
| 105 | - $this->getDataService()->insert('sys_category_record_mm', $values); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $metaData['categories'] = count($categories); |
|
| 109 | - $file->updateProperties($metaData); |
|
| 110 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 111 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 112 | - return $this; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Retrieve the file metadata uid which is different from the file uid. |
|
| 117 | - * |
|
| 118 | - * @param File $file |
|
| 119 | - * @return int |
|
| 120 | - */ |
|
| 121 | - protected function getFileMetadataIdentifier(File $file) |
|
| 122 | - { |
|
| 123 | - $metadataProperties = $file->getMetaData()->get(); |
|
| 124 | - return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Returns an instance of the FileIndexRepository |
|
| 130 | - * |
|
| 131 | - * @return FileIndexRepository |
|
| 132 | - */ |
|
| 133 | - protected function getFileIndexRepository() |
|
| 134 | - { |
|
| 135 | - return GeneralUtility::makeInstance(FileIndexRepository::class); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Returns an instance of the FileIndexRepository |
|
| 140 | - * |
|
| 141 | - * @return MetaDataRepository |
|
| 142 | - */ |
|
| 143 | - protected function getMetaDataRepository() |
|
| 144 | - { |
|
| 145 | - return GeneralUtility::makeInstance(MetaDataRepository::class); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Returns an instance of the FileIndexRepository |
|
| 150 | - * |
|
| 151 | - * @return ExtractorRegistry |
|
| 152 | - */ |
|
| 153 | - protected function getExtractorRegistry() |
|
| 154 | - { |
|
| 155 | - return GeneralUtility::makeInstance(ExtractorRegistry::class); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @return object|DataService |
|
| 160 | - */ |
|
| 161 | - protected function getDataService(): DataService |
|
| 162 | - { |
|
| 163 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return Indexer|object |
|
| 168 | - */ |
|
| 169 | - protected function getCoreIndexer() |
|
| 170 | - { |
|
| 171 | - return GeneralUtility::makeInstance(Indexer::class, $this->storage); |
|
| 172 | - } |
|
| 26 | + /** |
|
| 27 | + * @var ResourceStorage |
|
| 28 | + */ |
|
| 29 | + protected $storage = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @param ResourceStorage $storage |
|
| 33 | + */ |
|
| 34 | + public function __construct(ResourceStorage $storage) |
|
| 35 | + { |
|
| 36 | + $this->storage = $storage; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param File $file |
|
| 41 | + * @return $this |
|
| 42 | + */ |
|
| 43 | + public function updateIndex(File $file) |
|
| 44 | + { |
|
| 45 | + $this->getCoreIndexer()->updateIndexEntry($file); |
|
| 46 | + return $this; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param File $file |
|
| 51 | + * @return $this |
|
| 52 | + */ |
|
| 53 | + public function extractMetadata(File $file) |
|
| 54 | + { |
|
| 55 | + $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
| 56 | + |
|
| 57 | + $newMetaData = array( |
|
| 58 | + 0 => $file->getMetaData()->get() |
|
| 59 | + ); |
|
| 60 | + |
|
| 61 | + foreach ($extractionServices as $services) { |
|
| 62 | + if (is_array($services)) { |
|
| 63 | + foreach ($services as $service) { |
|
| 64 | + if ($service->canProcess($file)) { |
|
| 65 | + $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } else { |
|
| 69 | + $service = $services; |
|
| 70 | + // We could optimise here for not repeating this bit |
|
| 71 | + if ($service->canProcess($file)) { |
|
| 72 | + $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + ksort($newMetaData); |
|
| 78 | + $metaData = []; |
|
| 79 | + foreach ($newMetaData as $data) { |
|
| 80 | + $metaData = array_merge($metaData, $data); |
|
| 81 | + } |
|
| 82 | + $file->updateProperties($metaData); |
|
| 83 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 84 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 85 | + |
|
| 86 | + return $this; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param File $file |
|
| 91 | + * @return $this |
|
| 92 | + */ |
|
| 93 | + public function applyDefaultCategories(File $file) |
|
| 94 | + { |
|
| 95 | + $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
| 96 | + $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
| 97 | + |
|
| 98 | + foreach ($categories as $category) { |
|
| 99 | + $values = array( |
|
| 100 | + 'uid_local' => $category, |
|
| 101 | + 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
| 102 | + 'tablenames' => 'sys_file_metadata', |
|
| 103 | + 'fieldname' => 'categories', |
|
| 104 | + ); |
|
| 105 | + $this->getDataService()->insert('sys_category_record_mm', $values); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $metaData['categories'] = count($categories); |
|
| 109 | + $file->updateProperties($metaData); |
|
| 110 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 111 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 112 | + return $this; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Retrieve the file metadata uid which is different from the file uid. |
|
| 117 | + * |
|
| 118 | + * @param File $file |
|
| 119 | + * @return int |
|
| 120 | + */ |
|
| 121 | + protected function getFileMetadataIdentifier(File $file) |
|
| 122 | + { |
|
| 123 | + $metadataProperties = $file->getMetaData()->get(); |
|
| 124 | + return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Returns an instance of the FileIndexRepository |
|
| 130 | + * |
|
| 131 | + * @return FileIndexRepository |
|
| 132 | + */ |
|
| 133 | + protected function getFileIndexRepository() |
|
| 134 | + { |
|
| 135 | + return GeneralUtility::makeInstance(FileIndexRepository::class); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Returns an instance of the FileIndexRepository |
|
| 140 | + * |
|
| 141 | + * @return MetaDataRepository |
|
| 142 | + */ |
|
| 143 | + protected function getMetaDataRepository() |
|
| 144 | + { |
|
| 145 | + return GeneralUtility::makeInstance(MetaDataRepository::class); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Returns an instance of the FileIndexRepository |
|
| 150 | + * |
|
| 151 | + * @return ExtractorRegistry |
|
| 152 | + */ |
|
| 153 | + protected function getExtractorRegistry() |
|
| 154 | + { |
|
| 155 | + return GeneralUtility::makeInstance(ExtractorRegistry::class); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @return object|DataService |
|
| 160 | + */ |
|
| 161 | + protected function getDataService(): DataService |
|
| 162 | + { |
|
| 163 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return Indexer|object |
|
| 168 | + */ |
|
| 169 | + protected function getCoreIndexer() |
|
| 170 | + { |
|
| 171 | + return GeneralUtility::makeInstance(Indexer::class, $this->storage); |
|
| 172 | + } |
|
| 173 | 173 | } |
@@ -22,170 +22,170 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class IndexAnalyser implements SingletonInterface |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * Return missing file for a given storage. |
|
| 27 | - * |
|
| 28 | - * @param ResourceStorage $storage |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function searchForMissingFiles(ResourceStorage $storage) |
|
| 32 | - { |
|
| 33 | - /** @var ConnectionPool $connectionPool */ |
|
| 34 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 35 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 36 | - |
|
| 37 | - $missingFiles = []; |
|
| 38 | - $statement = $queryBuilder |
|
| 39 | - ->select('*') |
|
| 40 | - ->from('sys_file') |
|
| 41 | - ->where( |
|
| 42 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 43 | - )->execute(); |
|
| 44 | - while ($row = $statement->fetchAssociative()) { |
|
| 45 | - // This task is very memory consuming on large data set e.g > 20'000 records. |
|
| 46 | - // We must think of having a pagination if there is the need for such thing. |
|
| 47 | - $file = $this->getResourceFactory()->getFileObject($row['uid'], $row); |
|
| 48 | - if (!$file->exists()) { |
|
| 49 | - $missingFiles[] = $file; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - return $missingFiles; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Deletes all missing files for a given storage. |
|
| 57 | - * |
|
| 58 | - * @param ResourceStorage $storage |
|
| 59 | - * @return array |
|
| 60 | - * @throws \InvalidArgumentException |
|
| 61 | - */ |
|
| 62 | - public function deleteMissingFiles(ResourceStorage $storage) |
|
| 63 | - { |
|
| 64 | - /** @var FileReferenceService $fileReferenceService */ |
|
| 65 | - $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
| 66 | - $missingFiles = $this->searchForMissingFiles($storage); |
|
| 67 | - $deletedFiles = []; |
|
| 68 | - |
|
| 69 | - /** @var ConnectionPool $connectionPool */ |
|
| 70 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 71 | - |
|
| 72 | - /** @var File $missingFile */ |
|
| 73 | - foreach ($missingFiles as $missingFile) { |
|
| 74 | - try { |
|
| 75 | - // if missingFile has no file references |
|
| 76 | - if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
| 77 | - // The case is special as we have a missing file in the file system |
|
| 78 | - // As a result, we can't use $fileObject->delete(); which will |
|
| 79 | - // raise exception "Error while fetching permissions" |
|
| 80 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 81 | - $queryBuilder->delete('sys_file') |
|
| 82 | - ->where($queryBuilder->expr()->eq('uid', $missingFile->getUid())) |
|
| 83 | - ->execute(); |
|
| 84 | - |
|
| 85 | - $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
| 86 | - } |
|
| 87 | - } catch (\Exception $e) { |
|
| 88 | - continue; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - return $deletedFiles; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /* |
|
| 25 | + /** |
|
| 26 | + * Return missing file for a given storage. |
|
| 27 | + * |
|
| 28 | + * @param ResourceStorage $storage |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function searchForMissingFiles(ResourceStorage $storage) |
|
| 32 | + { |
|
| 33 | + /** @var ConnectionPool $connectionPool */ |
|
| 34 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 35 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 36 | + |
|
| 37 | + $missingFiles = []; |
|
| 38 | + $statement = $queryBuilder |
|
| 39 | + ->select('*') |
|
| 40 | + ->from('sys_file') |
|
| 41 | + ->where( |
|
| 42 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 43 | + )->execute(); |
|
| 44 | + while ($row = $statement->fetchAssociative()) { |
|
| 45 | + // This task is very memory consuming on large data set e.g > 20'000 records. |
|
| 46 | + // We must think of having a pagination if there is the need for such thing. |
|
| 47 | + $file = $this->getResourceFactory()->getFileObject($row['uid'], $row); |
|
| 48 | + if (!$file->exists()) { |
|
| 49 | + $missingFiles[] = $file; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + return $missingFiles; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Deletes all missing files for a given storage. |
|
| 57 | + * |
|
| 58 | + * @param ResourceStorage $storage |
|
| 59 | + * @return array |
|
| 60 | + * @throws \InvalidArgumentException |
|
| 61 | + */ |
|
| 62 | + public function deleteMissingFiles(ResourceStorage $storage) |
|
| 63 | + { |
|
| 64 | + /** @var FileReferenceService $fileReferenceService */ |
|
| 65 | + $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
| 66 | + $missingFiles = $this->searchForMissingFiles($storage); |
|
| 67 | + $deletedFiles = []; |
|
| 68 | + |
|
| 69 | + /** @var ConnectionPool $connectionPool */ |
|
| 70 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 71 | + |
|
| 72 | + /** @var File $missingFile */ |
|
| 73 | + foreach ($missingFiles as $missingFile) { |
|
| 74 | + try { |
|
| 75 | + // if missingFile has no file references |
|
| 76 | + if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
| 77 | + // The case is special as we have a missing file in the file system |
|
| 78 | + // As a result, we can't use $fileObject->delete(); which will |
|
| 79 | + // raise exception "Error while fetching permissions" |
|
| 80 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 81 | + $queryBuilder->delete('sys_file') |
|
| 82 | + ->where($queryBuilder->expr()->eq('uid', $missingFile->getUid())) |
|
| 83 | + ->execute(); |
|
| 84 | + |
|
| 85 | + $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
| 86 | + } |
|
| 87 | + } catch (\Exception $e) { |
|
| 88 | + continue; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + return $deletedFiles; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /* |
|
| 95 | 95 | * Return duplicates file records |
| 96 | 96 | * |
| 97 | 97 | * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
| 98 | 98 | * @return array |
| 99 | 99 | */ |
| 100 | - public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
| 101 | - { |
|
| 102 | - /** @var ConnectionPool $connectionPool */ |
|
| 103 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 104 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 105 | - |
|
| 106 | - $statement = $queryBuilder |
|
| 107 | - ->select('*') |
|
| 108 | - ->from('sys_file') |
|
| 109 | - ->where( |
|
| 110 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 111 | - ) |
|
| 112 | - ->groupby('identifier') |
|
| 113 | - ->having('count(*) > 1') |
|
| 114 | - ->execute(); |
|
| 115 | - |
|
| 116 | - // Detect duplicate records. |
|
| 117 | - $duplicates = []; |
|
| 118 | - while ($row = $statement->fetchAssociative()) { |
|
| 119 | - $records = $queryBuilder |
|
| 120 | - ->select('*') |
|
| 121 | - ->from('sys_file') |
|
| 122 | - ->where( |
|
| 123 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 124 | - ) |
|
| 125 | - ->andWhere( |
|
| 126 | - $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier'])) |
|
| 127 | - ) |
|
| 128 | - ->execute(); |
|
| 129 | - $records = $records->fetchAllAssociative(); |
|
| 130 | - $duplicates[$row['identifier']] = $records; |
|
| 131 | - } |
|
| 132 | - return $duplicates; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Return duplicates file records |
|
| 137 | - * |
|
| 138 | - * @param ResourceStorage $storage |
|
| 139 | - * @return array |
|
| 140 | - */ |
|
| 141 | - public function searchForDuplicateSha1(ResourceStorage $storage) |
|
| 142 | - { |
|
| 143 | - /** @var ConnectionPool $connectionPool */ |
|
| 144 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 145 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 146 | - |
|
| 147 | - $statement = $queryBuilder |
|
| 148 | - ->select('*') |
|
| 149 | - ->from('sys_file') |
|
| 150 | - ->where( |
|
| 151 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 152 | - ) |
|
| 153 | - ->groupby('sha1') |
|
| 154 | - ->having('count(*) > 1') |
|
| 155 | - ->execute(); |
|
| 156 | - |
|
| 157 | - // Detect duplicate records. |
|
| 158 | - $duplicates = []; |
|
| 159 | - while ($row = $statement->fetchAssociative()) { |
|
| 160 | - $records = $queryBuilder |
|
| 161 | - ->select('*') |
|
| 162 | - ->from('sys_file') |
|
| 163 | - ->where( |
|
| 164 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 165 | - ) |
|
| 166 | - ->andWhere( |
|
| 167 | - $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1'])) |
|
| 168 | - ) |
|
| 169 | - ->execute(); |
|
| 170 | - $records = $records->fetchAllAssociative(); |
|
| 171 | - $duplicates[$row['sha1']] = $records; |
|
| 172 | - } |
|
| 173 | - return $duplicates; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param string $tableName |
|
| 178 | - * @return object|QueryBuilder |
|
| 179 | - */ |
|
| 180 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
| 181 | - { |
|
| 182 | - /** @var ConnectionPool $connectionPool */ |
|
| 183 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 184 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - protected function getResourceFactory(): ResourceFactory |
|
| 188 | - { |
|
| 189 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 190 | - } |
|
| 100 | + public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
| 101 | + { |
|
| 102 | + /** @var ConnectionPool $connectionPool */ |
|
| 103 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 104 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 105 | + |
|
| 106 | + $statement = $queryBuilder |
|
| 107 | + ->select('*') |
|
| 108 | + ->from('sys_file') |
|
| 109 | + ->where( |
|
| 110 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 111 | + ) |
|
| 112 | + ->groupby('identifier') |
|
| 113 | + ->having('count(*) > 1') |
|
| 114 | + ->execute(); |
|
| 115 | + |
|
| 116 | + // Detect duplicate records. |
|
| 117 | + $duplicates = []; |
|
| 118 | + while ($row = $statement->fetchAssociative()) { |
|
| 119 | + $records = $queryBuilder |
|
| 120 | + ->select('*') |
|
| 121 | + ->from('sys_file') |
|
| 122 | + ->where( |
|
| 123 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 124 | + ) |
|
| 125 | + ->andWhere( |
|
| 126 | + $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier'])) |
|
| 127 | + ) |
|
| 128 | + ->execute(); |
|
| 129 | + $records = $records->fetchAllAssociative(); |
|
| 130 | + $duplicates[$row['identifier']] = $records; |
|
| 131 | + } |
|
| 132 | + return $duplicates; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Return duplicates file records |
|
| 137 | + * |
|
| 138 | + * @param ResourceStorage $storage |
|
| 139 | + * @return array |
|
| 140 | + */ |
|
| 141 | + public function searchForDuplicateSha1(ResourceStorage $storage) |
|
| 142 | + { |
|
| 143 | + /** @var ConnectionPool $connectionPool */ |
|
| 144 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 145 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
| 146 | + |
|
| 147 | + $statement = $queryBuilder |
|
| 148 | + ->select('*') |
|
| 149 | + ->from('sys_file') |
|
| 150 | + ->where( |
|
| 151 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 152 | + ) |
|
| 153 | + ->groupby('sha1') |
|
| 154 | + ->having('count(*) > 1') |
|
| 155 | + ->execute(); |
|
| 156 | + |
|
| 157 | + // Detect duplicate records. |
|
| 158 | + $duplicates = []; |
|
| 159 | + while ($row = $statement->fetchAssociative()) { |
|
| 160 | + $records = $queryBuilder |
|
| 161 | + ->select('*') |
|
| 162 | + ->from('sys_file') |
|
| 163 | + ->where( |
|
| 164 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
| 165 | + ) |
|
| 166 | + ->andWhere( |
|
| 167 | + $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1'])) |
|
| 168 | + ) |
|
| 169 | + ->execute(); |
|
| 170 | + $records = $records->fetchAllAssociative(); |
|
| 171 | + $duplicates[$row['sha1']] = $records; |
|
| 172 | + } |
|
| 173 | + return $duplicates; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param string $tableName |
|
| 178 | + * @return object|QueryBuilder |
|
| 179 | + */ |
|
| 180 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
| 181 | + { |
|
| 182 | + /** @var ConnectionPool $connectionPool */ |
|
| 183 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 184 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + protected function getResourceFactory(): ResourceFactory |
|
| 188 | + { |
|
| 189 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 190 | + } |
|
| 191 | 191 | } |
@@ -20,124 +20,124 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class TitleMetadataExtractor implements ExtractorInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Returns an array of supported file types; |
|
| 25 | - * An empty array indicates all filetypes |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - public function getFileTypeRestrictions() |
|
| 30 | - { |
|
| 31 | - return []; |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Returns an array of supported file types; |
|
| 25 | + * An empty array indicates all filetypes |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + public function getFileTypeRestrictions() |
|
| 30 | + { |
|
| 31 | + return []; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get all supported DriverClasses |
|
| 36 | - * Since some extractors may only work for local files, and other extractors |
|
| 37 | - * are especially made for grabbing data from remote. |
|
| 38 | - * Returns array of string with driver names of Drivers which are supported, |
|
| 39 | - * If the driver did not register a name, it's the classname. |
|
| 40 | - * empty array indicates no restrictions |
|
| 41 | - * |
|
| 42 | - * @return array |
|
| 43 | - */ |
|
| 44 | - public function getDriverRestrictions() |
|
| 45 | - { |
|
| 46 | - return []; |
|
| 47 | - } |
|
| 34 | + /** |
|
| 35 | + * Get all supported DriverClasses |
|
| 36 | + * Since some extractors may only work for local files, and other extractors |
|
| 37 | + * are especially made for grabbing data from remote. |
|
| 38 | + * Returns array of string with driver names of Drivers which are supported, |
|
| 39 | + * If the driver did not register a name, it's the classname. |
|
| 40 | + * empty array indicates no restrictions |
|
| 41 | + * |
|
| 42 | + * @return array |
|
| 43 | + */ |
|
| 44 | + public function getDriverRestrictions() |
|
| 45 | + { |
|
| 46 | + return []; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Returns the data priority of the extraction Service. |
|
| 51 | - * Defines the precedence of Data if several extractors |
|
| 52 | - * extracted the same property. |
|
| 53 | - * Should be between 1 and 100, 100 is more important than 1 |
|
| 54 | - * |
|
| 55 | - * @return integer |
|
| 56 | - */ |
|
| 57 | - public function getPriority() |
|
| 58 | - { |
|
| 59 | - return 15; |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * Returns the data priority of the extraction Service. |
|
| 51 | + * Defines the precedence of Data if several extractors |
|
| 52 | + * extracted the same property. |
|
| 53 | + * Should be between 1 and 100, 100 is more important than 1 |
|
| 54 | + * |
|
| 55 | + * @return integer |
|
| 56 | + */ |
|
| 57 | + public function getPriority() |
|
| 58 | + { |
|
| 59 | + return 15; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Returns the execution priority of the extraction Service |
|
| 64 | - * Should be between 1 and 100, 100 means runs as first service, 1 runs at last service |
|
| 65 | - * |
|
| 66 | - * @return integer |
|
| 67 | - */ |
|
| 68 | - public function getExecutionPriority() |
|
| 69 | - { |
|
| 70 | - return 15; |
|
| 71 | - } |
|
| 62 | + /** |
|
| 63 | + * Returns the execution priority of the extraction Service |
|
| 64 | + * Should be between 1 and 100, 100 means runs as first service, 1 runs at last service |
|
| 65 | + * |
|
| 66 | + * @return integer |
|
| 67 | + */ |
|
| 68 | + public function getExecutionPriority() |
|
| 69 | + { |
|
| 70 | + return 15; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Checks if the given file can be processed by this Extractor |
|
| 75 | - * |
|
| 76 | - * @param File $file |
|
| 77 | - * @return boolean |
|
| 78 | - */ |
|
| 79 | - public function canProcess(File $file) |
|
| 80 | - { |
|
| 81 | - return true; |
|
| 82 | - } |
|
| 73 | + /** |
|
| 74 | + * Checks if the given file can be processed by this Extractor |
|
| 75 | + * |
|
| 76 | + * @param File $file |
|
| 77 | + * @return boolean |
|
| 78 | + */ |
|
| 79 | + public function canProcess(File $file) |
|
| 80 | + { |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * The actual processing TASK |
|
| 86 | - * Should return an array with database properties for sys_file_metadata to write |
|
| 87 | - * |
|
| 88 | - * @param File $file |
|
| 89 | - * @param array $previousExtractedData optional, contains the array of already extracted data |
|
| 90 | - * @return array |
|
| 91 | - */ |
|
| 92 | - public function extractMetaData(File $file, array $previousExtractedData = []) |
|
| 93 | - { |
|
| 94 | - $metadata = []; |
|
| 95 | - $title = $file->getProperty('title'); |
|
| 96 | - if (empty($title)) { |
|
| 97 | - $metadata = array('title' => $this->guessTitle($file->getName())); |
|
| 98 | - } |
|
| 99 | - return $metadata; |
|
| 100 | - } |
|
| 84 | + /** |
|
| 85 | + * The actual processing TASK |
|
| 86 | + * Should return an array with database properties for sys_file_metadata to write |
|
| 87 | + * |
|
| 88 | + * @param File $file |
|
| 89 | + * @param array $previousExtractedData optional, contains the array of already extracted data |
|
| 90 | + * @return array |
|
| 91 | + */ |
|
| 92 | + public function extractMetaData(File $file, array $previousExtractedData = []) |
|
| 93 | + { |
|
| 94 | + $metadata = []; |
|
| 95 | + $title = $file->getProperty('title'); |
|
| 96 | + if (empty($title)) { |
|
| 97 | + $metadata = array('title' => $this->guessTitle($file->getName())); |
|
| 98 | + } |
|
| 99 | + return $metadata; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Guess a title given a file name. Examples: |
|
| 104 | - * name: my-file-name.jpg -> title: My file name |
|
| 105 | - * name: myFileName.jpg -> title: My file name |
|
| 106 | - * |
|
| 107 | - * @param string $fileName |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - protected function guessTitle($fileName) |
|
| 111 | - { |
|
| 112 | - $fileNameWithoutExtension = $this->removeExtension($fileName); |
|
| 102 | + /** |
|
| 103 | + * Guess a title given a file name. Examples: |
|
| 104 | + * name: my-file-name.jpg -> title: My file name |
|
| 105 | + * name: myFileName.jpg -> title: My file name |
|
| 106 | + * |
|
| 107 | + * @param string $fileName |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + protected function guessTitle($fileName) |
|
| 111 | + { |
|
| 112 | + $fileNameWithoutExtension = $this->removeExtension($fileName); |
|
| 113 | 113 | |
| 114 | - $title = $fileNameWithoutExtension; |
|
| 115 | - // first case: the name is separated by _ or - |
|
| 116 | - // second case: this is an upper camel case name |
|
| 117 | - if (preg_match('/-|_/is', $fileNameWithoutExtension)) { |
|
| 118 | - $title = preg_replace('/-|_/is', ' ', $fileNameWithoutExtension); |
|
| 119 | - } elseif (preg_match('/[A-Z]/', $fileNameWithoutExtension)) { |
|
| 120 | - $parts = preg_split('/(?=[A-Z])/', $fileNameWithoutExtension, -1, PREG_SPLIT_NO_EMPTY); |
|
| 121 | - $title = implode(' ', $parts); |
|
| 122 | - } |
|
| 114 | + $title = $fileNameWithoutExtension; |
|
| 115 | + // first case: the name is separated by _ or - |
|
| 116 | + // second case: this is an upper camel case name |
|
| 117 | + if (preg_match('/-|_/is', $fileNameWithoutExtension)) { |
|
| 118 | + $title = preg_replace('/-|_/is', ' ', $fileNameWithoutExtension); |
|
| 119 | + } elseif (preg_match('/[A-Z]/', $fileNameWithoutExtension)) { |
|
| 120 | + $parts = preg_split('/(?=[A-Z])/', $fileNameWithoutExtension, -1, PREG_SPLIT_NO_EMPTY); |
|
| 121 | + $title = implode(' ', $parts); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - // Remove double space. |
|
| 125 | - $title = preg_replace('/\s+/', ' ', $title); |
|
| 126 | - return ucfirst($title); |
|
| 127 | - } |
|
| 124 | + // Remove double space. |
|
| 125 | + $title = preg_replace('/\s+/', ' ', $title); |
|
| 126 | + return ucfirst($title); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Remove extension of a file. |
|
| 131 | - * |
|
| 132 | - * @param string $fileName |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - protected function removeExtension($fileName) |
|
| 136 | - { |
|
| 137 | - $parts = explode('.', $fileName); |
|
| 138 | - if (!empty($parts)) { |
|
| 139 | - array_pop($parts); |
|
| 140 | - } |
|
| 141 | - return implode('.', $parts); |
|
| 142 | - } |
|
| 129 | + /** |
|
| 130 | + * Remove extension of a file. |
|
| 131 | + * |
|
| 132 | + * @param string $fileName |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + protected function removeExtension($fileName) |
|
| 136 | + { |
|
| 137 | + $parts = explode('.', $fileName); |
|
| 138 | + if (!empty($parts)) { |
|
| 139 | + array_pop($parts); |
|
| 140 | + } |
|
| 141 | + return implode('.', $parts); |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | { |
| 35 | 35 | // Get the base prefix. |
| 36 | 36 | $basePrefix = $this->getBasePrefix($this->getPrefix()); |
| 37 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
| 37 | + $filePath = ExtensionManagementUtility::extPath('media').'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
| 38 | 38 | |
| 39 | 39 | return sprintf( |
| 40 | 40 | file_get_contents($filePath), |
@@ -20,56 +20,56 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class FileUploadTceForms extends FileUpload |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected string $templateFile = 'Resources/Private/Standalone/FileUploadTceFormsTemplate.html'; |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected string $templateFile = 'Resources/Private/Standalone/FileUploadTceFormsTemplate.html'; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Fetch the JavaScript to be rendered and replace the markers with "live" variables. |
|
| 30 | - */ |
|
| 31 | - protected function getJavaScript(): string |
|
| 32 | - { |
|
| 33 | - // Get the base prefix. |
|
| 34 | - $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
| 35 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
| 28 | + /** |
|
| 29 | + * Fetch the JavaScript to be rendered and replace the markers with "live" variables. |
|
| 30 | + */ |
|
| 31 | + protected function getJavaScript(): string |
|
| 32 | + { |
|
| 33 | + // Get the base prefix. |
|
| 34 | + $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
| 35 | + $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
| 36 | 36 | |
| 37 | - return sprintf( |
|
| 38 | - file_get_contents($filePath), |
|
| 39 | - $basePrefix, |
|
| 40 | - $this->elementId, |
|
| 41 | - $this->getModuleUrl(), |
|
| 42 | - $this->getAllowedExtension(), |
|
| 43 | - GeneralUtility::getMaxUploadFileSize() * 1024, |
|
| 44 | - $this->getValue() |
|
| 45 | - ); |
|
| 46 | - } |
|
| 37 | + return sprintf( |
|
| 38 | + file_get_contents($filePath), |
|
| 39 | + $basePrefix, |
|
| 40 | + $this->elementId, |
|
| 41 | + $this->getModuleUrl(), |
|
| 42 | + $this->getAllowedExtension(), |
|
| 43 | + GeneralUtility::getMaxUploadFileSize() * 1024, |
|
| 44 | + $this->getValue() |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - protected function getModuleUrl(): string |
|
| 49 | - { |
|
| 50 | - $moduleSignature = MediaModule::getSignature(); |
|
| 51 | - return BackendUtility::getModuleUrl($moduleSignature); |
|
| 52 | - } |
|
| 48 | + protected function getModuleUrl(): string |
|
| 49 | + { |
|
| 50 | + $moduleSignature = MediaModule::getSignature(); |
|
| 51 | + return BackendUtility::getModuleUrl($moduleSignature); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get allowed extension. |
|
| 56 | - */ |
|
| 57 | - protected function getAllowedExtension(): string |
|
| 58 | - { |
|
| 59 | - return $this->file->getExtension(); |
|
| 60 | - } |
|
| 54 | + /** |
|
| 55 | + * Get allowed extension. |
|
| 56 | + */ |
|
| 57 | + protected function getAllowedExtension(): string |
|
| 58 | + { |
|
| 59 | + return $this->file->getExtension(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Returns additional file info. |
|
| 64 | - */ |
|
| 65 | - protected function getFileInfo(): string |
|
| 66 | - { |
|
| 67 | - /** @var MetadataView $metadataView */ |
|
| 68 | - $metadataView = GeneralUtility::makeInstance(MetadataView::class); |
|
| 62 | + /** |
|
| 63 | + * Returns additional file info. |
|
| 64 | + */ |
|
| 65 | + protected function getFileInfo(): string |
|
| 66 | + { |
|
| 67 | + /** @var MetadataView $metadataView */ |
|
| 68 | + $metadataView = GeneralUtility::makeInstance(MetadataView::class); |
|
| 69 | 69 | |
| 70 | - return sprintf( |
|
| 71 | - '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>', |
|
| 72 | - $metadataView->render($this->file) |
|
| 73 | - ); |
|
| 74 | - } |
|
| 70 | + return sprintf( |
|
| 71 | + '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>', |
|
| 72 | + $metadataView->render($this->file) |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | public function __construct() |
| 50 | 50 | { |
| 51 | 51 | $this->addLanguage(); |
| 52 | - $this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid(); |
|
| 52 | + $this->elementId = 'jquery-wrapped-fine-uploader-'.uniqid(); |
|
| 53 | 53 | |
| 54 | 54 | $this->template = <<<EOF |
| 55 | 55 | <div class="control-group control-group-upload" style="%s"> |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | /** @var PageRenderer $pageRenderer */ |
| 74 | 74 | $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
| 75 | - $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 75 | + $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media').'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | /** @var StandaloneView $view */ |
| 156 | 156 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
| 157 | 157 | |
| 158 | - $templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile; |
|
| 158 | + $templatePathAndFilename = ExtensionManagementUtility::extPath('media').$this->templateFile; |
|
| 159 | 159 | $view->setTemplatePathAndFilename($templatePathAndFilename); |
| 160 | 160 | |
| 161 | 161 | return $view; |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | // Get the base prefix |
| 172 | 172 | $basePrefix = $this->getBasePrefix($this->getPrefix()); |
| 173 | 173 | |
| 174 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js'; |
|
| 174 | + $filePath = ExtensionManagementUtility::extPath('media').'Resources/Private/Standalone/FileUpload.js'; |
|
| 175 | 175 | |
| 176 | 176 | return sprintf( |
| 177 | 177 | file_get_contents($filePath), |
@@ -181,8 +181,7 @@ discard block |
||
| 181 | 181 | $this->getAllowedExtensions(), |
| 182 | 182 | GeneralUtility::getMaxUploadFileSize() * 1024, |
| 183 | 183 | $this->isDrivenByFolder() ? |
| 184 | - $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : |
|
| 185 | - $this->getMediaModule()->getCurrentStorage()->getUid() . ':/' |
|
| 184 | + $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : $this->getMediaModule()->getCurrentStorage()->getUid().':/' |
|
| 186 | 185 | ); |
| 187 | 186 | } |
| 188 | 187 | |
@@ -28,24 +28,24 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | class FileUpload extends AbstractFormField |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $elementId; |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $elementId; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var File |
|
| 38 | - */ |
|
| 39 | - protected $file; |
|
| 36 | + /** |
|
| 37 | + * @var File |
|
| 38 | + */ |
|
| 39 | + protected $file; |
|
| 40 | 40 | |
| 41 | - protected string $templateFile = 'Resources/Private/Standalone/FileUploadTemplate.html'; |
|
| 41 | + protected string $templateFile = 'Resources/Private/Standalone/FileUploadTemplate.html'; |
|
| 42 | 42 | |
| 43 | - public function __construct() |
|
| 44 | - { |
|
| 45 | - $this->addLanguage(); |
|
| 46 | - $this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid(); |
|
| 43 | + public function __construct() |
|
| 44 | + { |
|
| 45 | + $this->addLanguage(); |
|
| 46 | + $this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid(); |
|
| 47 | 47 | |
| 48 | - $this->template = <<<EOF |
|
| 48 | + $this->template = <<<EOF |
|
| 49 | 49 | <div class="control-group control-group-upload" style="%s"> |
| 50 | 50 | <div class="container-thumbnail">%s</div> |
| 51 | 51 | %s |
@@ -57,196 +57,196 @@ discard block |
||
| 57 | 57 | </div> |
| 58 | 58 | |
| 59 | 59 | EOF; |
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Add language labels for JavaScript files |
|
| 64 | - */ |
|
| 65 | - protected function addLanguage() |
|
| 66 | - { |
|
| 67 | - /** @var PageRenderer $pageRenderer */ |
|
| 68 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 69 | - $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Render a file upload field. |
|
| 74 | - * |
|
| 75 | - * @throws EmptyPropertyException |
|
| 76 | - */ |
|
| 77 | - public function render(): string |
|
| 78 | - { |
|
| 79 | - // Instantiate the file object for the whole class if possible. |
|
| 80 | - if ($this->getValue()) { |
|
| 81 | - $this->file = $this->getResourceFactory()->getFileObject($this->getValue()); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $result = sprintf( |
|
| 85 | - $this->template, |
|
| 86 | - $this->getInlineStyle(), |
|
| 87 | - $this->getThumbnail(), |
|
| 88 | - $this->getFileInfo(), |
|
| 89 | - $this->elementId, |
|
| 90 | - $this->getJavaScriptTemplate(), |
|
| 91 | - $this->getJavaScript() |
|
| 92 | - ); |
|
| 93 | - return $result; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - protected function getInlineStyle(): string |
|
| 97 | - { |
|
| 98 | - $style = 'float: left'; |
|
| 99 | - if ($this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin()) { |
|
| 100 | - $style .= '; padding-left: 3px'; |
|
| 101 | - } |
|
| 102 | - return $style; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Get the javascript from a file and replace the markers with live variables. |
|
| 107 | - */ |
|
| 108 | - protected function getThumbnail(): string |
|
| 109 | - { |
|
| 110 | - $thumbnail = ''; |
|
| 111 | - if ($this->file) { |
|
| 112 | - /** @var $thumbnailService \Fab\Media\Thumbnail\ThumbnailService */ |
|
| 113 | - $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $this->file); |
|
| 114 | - $thumbnail = $thumbnailService |
|
| 115 | - ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED) |
|
| 116 | - ->setAppendTimeStamp(true) |
|
| 117 | - ->create(); |
|
| 118 | - } |
|
| 119 | - return $thumbnail; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Get the javascript from a file and replace the markers with live variables. |
|
| 124 | - */ |
|
| 125 | - protected function getJavaScriptTemplate(): string |
|
| 126 | - { |
|
| 127 | - $view = $this->getStandaloneView(); |
|
| 128 | - $view->assignMultiple( |
|
| 129 | - array( |
|
| 130 | - 'maximumUploadLabel' => $this->getMaximumUploadLabel(), |
|
| 131 | - ) |
|
| 132 | - ); |
|
| 133 | - return $view->render(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @return StandaloneView |
|
| 138 | - */ |
|
| 139 | - protected function getStandaloneView() |
|
| 140 | - { |
|
| 141 | - /** @var StandaloneView $view */ |
|
| 142 | - $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
| 143 | - |
|
| 144 | - $templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile; |
|
| 145 | - $view->setTemplatePathAndFilename($templatePathAndFilename); |
|
| 146 | - |
|
| 147 | - return $view; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Get the javascript from a file and replace the markers with live variables. |
|
| 152 | - */ |
|
| 153 | - protected function getJavaScript(): string |
|
| 154 | - { |
|
| 155 | - // Get the base prefix |
|
| 156 | - $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
| 157 | - |
|
| 158 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js'; |
|
| 159 | - |
|
| 160 | - return sprintf( |
|
| 161 | - file_get_contents($filePath), |
|
| 162 | - $basePrefix, |
|
| 163 | - $this->elementId, |
|
| 164 | - $this->getModuleUrl(), |
|
| 165 | - $this->getAllowedExtensions(), |
|
| 166 | - GeneralUtility::getMaxUploadFileSize() * 1024, |
|
| 167 | - $this->isDrivenByFolder() ? |
|
| 168 | - $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : |
|
| 169 | - $this->getMediaModule()->getCurrentStorage()->getUid() . ':/' |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @return bool |
|
| 175 | - */ |
|
| 176 | - protected function isDrivenByFolder() |
|
| 177 | - { |
|
| 178 | - return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - */ |
|
| 183 | - protected function getModuleUrl(): string |
|
| 184 | - { |
|
| 185 | - $moduleSignature = MediaModule::getSignature(); |
|
| 186 | - return BackendUtility::getModuleUrl($moduleSignature); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Returns the max upload file size in Mo. |
|
| 191 | - * |
|
| 192 | - */ |
|
| 193 | - protected function getMaximumUploadLabel(): string |
|
| 194 | - { |
|
| 195 | - $result = round(GeneralUtility::getMaxUploadFileSize() / 1024, 2); |
|
| 196 | - $label = LocalizationUtility::translate('max_upload_file', 'media'); |
|
| 197 | - $result = sprintf($label, $result); |
|
| 198 | - return $result; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Get allowed extension. |
|
| 203 | - * |
|
| 204 | - */ |
|
| 205 | - protected function getAllowedExtensions(): string |
|
| 206 | - { |
|
| 207 | - return implode("','", PermissionUtility::getInstance()->getAllowedExtensions()); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Compute the base prefix by removing the square brackets. |
|
| 212 | - * |
|
| 213 | - * @param string $prefix |
|
| 214 | - */ |
|
| 215 | - protected function getBasePrefix($prefix): string |
|
| 216 | - { |
|
| 217 | - $parts = explode('[', $prefix); |
|
| 218 | - return empty($parts) ? '' : $parts[0]; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Returns additional file info. |
|
| 223 | - * |
|
| 224 | - */ |
|
| 225 | - protected function getFileInfo(): string |
|
| 226 | - { |
|
| 227 | - return ''; // empty return here but check out Tceforms/FileUpload |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @return MediaModule|object |
|
| 232 | - */ |
|
| 233 | - protected function getMediaModule() |
|
| 234 | - { |
|
| 235 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Get the Vidi Module Loader. |
|
| 240 | - * |
|
| 241 | - * @return ModuleLoader|object |
|
| 242 | - */ |
|
| 243 | - protected function getModuleLoader() |
|
| 244 | - { |
|
| 245 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - protected function getResourceFactory(): ResourceFactory |
|
| 249 | - { |
|
| 250 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 251 | - } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Add language labels for JavaScript files |
|
| 64 | + */ |
|
| 65 | + protected function addLanguage() |
|
| 66 | + { |
|
| 67 | + /** @var PageRenderer $pageRenderer */ |
|
| 68 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 69 | + $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Render a file upload field. |
|
| 74 | + * |
|
| 75 | + * @throws EmptyPropertyException |
|
| 76 | + */ |
|
| 77 | + public function render(): string |
|
| 78 | + { |
|
| 79 | + // Instantiate the file object for the whole class if possible. |
|
| 80 | + if ($this->getValue()) { |
|
| 81 | + $this->file = $this->getResourceFactory()->getFileObject($this->getValue()); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $result = sprintf( |
|
| 85 | + $this->template, |
|
| 86 | + $this->getInlineStyle(), |
|
| 87 | + $this->getThumbnail(), |
|
| 88 | + $this->getFileInfo(), |
|
| 89 | + $this->elementId, |
|
| 90 | + $this->getJavaScriptTemplate(), |
|
| 91 | + $this->getJavaScript() |
|
| 92 | + ); |
|
| 93 | + return $result; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + protected function getInlineStyle(): string |
|
| 97 | + { |
|
| 98 | + $style = 'float: left'; |
|
| 99 | + if ($this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin()) { |
|
| 100 | + $style .= '; padding-left: 3px'; |
|
| 101 | + } |
|
| 102 | + return $style; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Get the javascript from a file and replace the markers with live variables. |
|
| 107 | + */ |
|
| 108 | + protected function getThumbnail(): string |
|
| 109 | + { |
|
| 110 | + $thumbnail = ''; |
|
| 111 | + if ($this->file) { |
|
| 112 | + /** @var $thumbnailService \Fab\Media\Thumbnail\ThumbnailService */ |
|
| 113 | + $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $this->file); |
|
| 114 | + $thumbnail = $thumbnailService |
|
| 115 | + ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED) |
|
| 116 | + ->setAppendTimeStamp(true) |
|
| 117 | + ->create(); |
|
| 118 | + } |
|
| 119 | + return $thumbnail; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Get the javascript from a file and replace the markers with live variables. |
|
| 124 | + */ |
|
| 125 | + protected function getJavaScriptTemplate(): string |
|
| 126 | + { |
|
| 127 | + $view = $this->getStandaloneView(); |
|
| 128 | + $view->assignMultiple( |
|
| 129 | + array( |
|
| 130 | + 'maximumUploadLabel' => $this->getMaximumUploadLabel(), |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | + return $view->render(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @return StandaloneView |
|
| 138 | + */ |
|
| 139 | + protected function getStandaloneView() |
|
| 140 | + { |
|
| 141 | + /** @var StandaloneView $view */ |
|
| 142 | + $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
| 143 | + |
|
| 144 | + $templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile; |
|
| 145 | + $view->setTemplatePathAndFilename($templatePathAndFilename); |
|
| 146 | + |
|
| 147 | + return $view; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Get the javascript from a file and replace the markers with live variables. |
|
| 152 | + */ |
|
| 153 | + protected function getJavaScript(): string |
|
| 154 | + { |
|
| 155 | + // Get the base prefix |
|
| 156 | + $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
| 157 | + |
|
| 158 | + $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js'; |
|
| 159 | + |
|
| 160 | + return sprintf( |
|
| 161 | + file_get_contents($filePath), |
|
| 162 | + $basePrefix, |
|
| 163 | + $this->elementId, |
|
| 164 | + $this->getModuleUrl(), |
|
| 165 | + $this->getAllowedExtensions(), |
|
| 166 | + GeneralUtility::getMaxUploadFileSize() * 1024, |
|
| 167 | + $this->isDrivenByFolder() ? |
|
| 168 | + $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : |
|
| 169 | + $this->getMediaModule()->getCurrentStorage()->getUid() . ':/' |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @return bool |
|
| 175 | + */ |
|
| 176 | + protected function isDrivenByFolder() |
|
| 177 | + { |
|
| 178 | + return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + */ |
|
| 183 | + protected function getModuleUrl(): string |
|
| 184 | + { |
|
| 185 | + $moduleSignature = MediaModule::getSignature(); |
|
| 186 | + return BackendUtility::getModuleUrl($moduleSignature); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Returns the max upload file size in Mo. |
|
| 191 | + * |
|
| 192 | + */ |
|
| 193 | + protected function getMaximumUploadLabel(): string |
|
| 194 | + { |
|
| 195 | + $result = round(GeneralUtility::getMaxUploadFileSize() / 1024, 2); |
|
| 196 | + $label = LocalizationUtility::translate('max_upload_file', 'media'); |
|
| 197 | + $result = sprintf($label, $result); |
|
| 198 | + return $result; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Get allowed extension. |
|
| 203 | + * |
|
| 204 | + */ |
|
| 205 | + protected function getAllowedExtensions(): string |
|
| 206 | + { |
|
| 207 | + return implode("','", PermissionUtility::getInstance()->getAllowedExtensions()); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Compute the base prefix by removing the square brackets. |
|
| 212 | + * |
|
| 213 | + * @param string $prefix |
|
| 214 | + */ |
|
| 215 | + protected function getBasePrefix($prefix): string |
|
| 216 | + { |
|
| 217 | + $parts = explode('[', $prefix); |
|
| 218 | + return empty($parts) ? '' : $parts[0]; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Returns additional file info. |
|
| 223 | + * |
|
| 224 | + */ |
|
| 225 | + protected function getFileInfo(): string |
|
| 226 | + { |
|
| 227 | + return ''; // empty return here but check out Tceforms/FileUpload |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @return MediaModule|object |
|
| 232 | + */ |
|
| 233 | + protected function getMediaModule() |
|
| 234 | + { |
|
| 235 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Get the Vidi Module Loader. |
|
| 240 | + * |
|
| 241 | + * @return ModuleLoader|object |
|
| 242 | + */ |
|
| 243 | + protected function getModuleLoader() |
|
| 244 | + { |
|
| 245 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + protected function getResourceFactory(): ResourceFactory |
|
| 249 | + { |
|
| 250 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 251 | + } |
|
| 252 | 252 | } |
@@ -20,47 +20,47 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class FileConverter extends AbstractTypeConverter |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var array<string> |
|
| 25 | - */ |
|
| 26 | - protected $sourceTypes = array('int'); |
|
| 23 | + /** |
|
| 24 | + * @var array<string> |
|
| 25 | + */ |
|
| 26 | + protected $sourceTypes = array('int'); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - protected $targetType = 'TYPO3\CMS\Core\Resource\File'; |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + protected $targetType = 'TYPO3\CMS\Core\Resource\File'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var integer |
|
| 35 | - */ |
|
| 36 | - protected $priority = 1; |
|
| 33 | + /** |
|
| 34 | + * @var integer |
|
| 35 | + */ |
|
| 36 | + protected $priority = 1; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Actually convert from $source to $targetType |
|
| 40 | - * |
|
| 41 | - * @param string $source |
|
| 42 | - * @param string $targetType |
|
| 43 | - * @param array $convertedChildProperties |
|
| 44 | - * @param PropertyMappingConfigurationInterface $configuration |
|
| 45 | - * @return File |
|
| 46 | - * @api |
|
| 47 | - */ |
|
| 48 | - public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) |
|
| 49 | - { |
|
| 50 | - /** @var $file File */ |
|
| 51 | - $file = $this->getResourceFactory()->getFileObject((int)$source); |
|
| 38 | + /** |
|
| 39 | + * Actually convert from $source to $targetType |
|
| 40 | + * |
|
| 41 | + * @param string $source |
|
| 42 | + * @param string $targetType |
|
| 43 | + * @param array $convertedChildProperties |
|
| 44 | + * @param PropertyMappingConfigurationInterface $configuration |
|
| 45 | + * @return File |
|
| 46 | + * @api |
|
| 47 | + */ |
|
| 48 | + public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) |
|
| 49 | + { |
|
| 50 | + /** @var $file File */ |
|
| 51 | + $file = $this->getResourceFactory()->getFileObject((int)$source); |
|
| 52 | 52 | |
| 53 | - if (!$file) { |
|
| 54 | - $message = sprintf('File with identifier "%s" could not be found.', $file); |
|
| 55 | - throw new \Exception($message, 1433529796); |
|
| 56 | - } |
|
| 53 | + if (!$file) { |
|
| 54 | + $message = sprintf('File with identifier "%s" could not be found.', $file); |
|
| 55 | + throw new \Exception($message, 1433529796); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $file->getType(); // force to internally know its mime-type. |
|
| 59 | - return $file; |
|
| 60 | - } |
|
| 58 | + $file->getType(); // force to internally know its mime-type. |
|
| 59 | + return $file; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - protected function getResourceFactory(): ResourceFactory |
|
| 63 | - { |
|
| 64 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 65 | - } |
|
| 62 | + protected function getResourceFactory(): ResourceFactory |
|
| 63 | + { |
|
| 64 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -20,33 +20,33 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class ContentToFileConverter implements SingletonInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Convert a file representation to File Resource. |
|
| 25 | - * |
|
| 26 | - * @param Content|int $fileRepresentation |
|
| 27 | - * @throws \RuntimeException |
|
| 28 | - * @return File |
|
| 29 | - */ |
|
| 30 | - public function convert($fileRepresentation) |
|
| 31 | - { |
|
| 32 | - if ($fileRepresentation instanceof Content) { |
|
| 33 | - $fileData = $fileRepresentation->toArray(); |
|
| 34 | - $fileData['modification_date'] = $fileData['tstamp']; |
|
| 23 | + /** |
|
| 24 | + * Convert a file representation to File Resource. |
|
| 25 | + * |
|
| 26 | + * @param Content|int $fileRepresentation |
|
| 27 | + * @throws \RuntimeException |
|
| 28 | + * @return File |
|
| 29 | + */ |
|
| 30 | + public function convert($fileRepresentation) |
|
| 31 | + { |
|
| 32 | + if ($fileRepresentation instanceof Content) { |
|
| 33 | + $fileData = $fileRepresentation->toArray(); |
|
| 34 | + $fileData['modification_date'] = $fileData['tstamp']; |
|
| 35 | 35 | |
| 36 | - if (!isset($fileData['storage']) && $fileData['storage'] === null) { |
|
| 37 | - throw new \RuntimeException('Storage identifier can not be null.', 1379946981); |
|
| 38 | - } |
|
| 36 | + if (!isset($fileData['storage']) && $fileData['storage'] === null) { |
|
| 37 | + throw new \RuntimeException('Storage identifier can not be null.', 1379946981); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $fileUid = $fileData['uid']; |
|
| 41 | - } else { |
|
| 42 | - $fileData = []; |
|
| 43 | - $fileUid = (int)$fileRepresentation; |
|
| 44 | - } |
|
| 45 | - return $this->getResourceFactory()->getFileObject($fileUid, $fileData); |
|
| 46 | - } |
|
| 40 | + $fileUid = $fileData['uid']; |
|
| 41 | + } else { |
|
| 42 | + $fileData = []; |
|
| 43 | + $fileUid = (int)$fileRepresentation; |
|
| 44 | + } |
|
| 45 | + return $this->getResourceFactory()->getFileObject($fileUid, $fileData); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - protected function getResourceFactory(): ResourceFactory |
|
| 49 | - { |
|
| 50 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 51 | - } |
|
| 48 | + protected function getResourceFactory(): ResourceFactory |
|
| 49 | + { |
|
| 50 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -24,199 +24,199 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class DuplicateFilesFinderTool extends AbstractTool |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * Display the title of the tool on the welcome screen. |
|
| 29 | - * |
|
| 30 | - * @return string |
|
| 31 | - */ |
|
| 32 | - public function getTitle() |
|
| 33 | - { |
|
| 34 | - return 'Find duplicate Files'; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Display the description of the tool in the welcome screen. |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function getDescription() |
|
| 43 | - { |
|
| 44 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
|
| 45 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 46 | - $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
|
| 47 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 48 | - return $view->render(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Do the job: analyse Index. |
|
| 53 | - * |
|
| 54 | - * @param array $arguments |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function work(array $arguments = []) |
|
| 58 | - { |
|
| 59 | - // Possible clean up of missing files if the User has clicked so. |
|
| 60 | - if (!empty($arguments['deleteDuplicateFiles'])) { |
|
| 61 | - $this->deleteMissingFilesAction($arguments['files']); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/WorkResult.html'; |
|
| 65 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 66 | - |
|
| 67 | - $duplicateFilesReports = []; |
|
| 68 | - |
|
| 69 | - if ($this->getBackendUser()->isAdmin()) { |
|
| 70 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 71 | - if ($storage->isOnline()) { |
|
| 72 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 73 | - $duplicateFilesReports[] = array( |
|
| 74 | - 'storage' => $storage, |
|
| 75 | - 'duplicateFiles' => $duplicateFiles, |
|
| 76 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } else { |
|
| 81 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 82 | - |
|
| 83 | - $allowedStorages = []; |
|
| 84 | - foreach ($fileMounts as $fileMount) { |
|
| 85 | - if ((bool)$fileMount['read_only']) { |
|
| 86 | - continue; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if (!isset($allowedStorages[$fileMount['base']])) { |
|
| 90 | - $allowedStorages[$fileMount['base']] = []; |
|
| 91 | - } |
|
| 92 | - if (!in_array($fileMount['base'], $allowedStorages)) { |
|
| 93 | - $allowedStorages[$fileMount['base']][] = $fileMount['path']; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - foreach ($allowedStorages as $storageIdentifier => $allowedMountPoints) { |
|
| 98 | - $storage = $this->getResourceFactory()->getStorageObject($storageIdentifier); |
|
| 99 | - |
|
| 100 | - if ($storage->isOnline()) { |
|
| 101 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 102 | - |
|
| 103 | - // Filter duplicates files |
|
| 104 | - foreach ($duplicateFiles as $key => $files) { |
|
| 105 | - $filteredFiles = []; |
|
| 106 | - foreach ($files as $file) { |
|
| 107 | - foreach ($allowedMountPoints as $allowedMountPoint) { |
|
| 108 | - $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
| 109 | - if (preg_match($pattern, $file['identifier'])) { |
|
| 110 | - $filteredFiles[] = $file; |
|
| 111 | - break; // no need to further loop around, stop the loop. |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // We need more than 1 files to be shown as duplicate. |
|
| 117 | - if (count($filteredFiles) > 1) { |
|
| 118 | - $duplicateFiles[$key] = $filteredFiles; |
|
| 119 | - } else { |
|
| 120 | - unset($duplicateFiles[$key]); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - $duplicateFilesReports[] = array( |
|
| 124 | - 'storage' => $storage, |
|
| 125 | - 'duplicateFiles' => $duplicateFiles, |
|
| 126 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 127 | - ); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $view->assign('duplicateFilesReports', $duplicateFilesReports); |
|
| 133 | - |
|
| 134 | - return $view->render(); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Delete files given as parameter. |
|
| 139 | - * This is a special case as we have a missing file in the file system |
|
| 140 | - * As a result, we can't use $fileObject->delete(); which will |
|
| 141 | - * raise exception "Error while fetching permissions". |
|
| 142 | - * |
|
| 143 | - * @param array $files |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - protected function deleteMissingFilesAction(array $files = []) |
|
| 147 | - { |
|
| 148 | - foreach ($files as $fileUid) { |
|
| 149 | - /** @var File $file */ |
|
| 150 | - try { |
|
| 151 | - $file = $this->getResourceFactory()->getFileObject($fileUid); |
|
| 152 | - if ($file->exists()) { |
|
| 153 | - $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
| 154 | - if ($numberOfReferences === 0) { |
|
| 155 | - $file->delete(); |
|
| 156 | - } |
|
| 157 | - } else { |
|
| 158 | - $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 159 | - } |
|
| 160 | - } catch (\Exception $e) { |
|
| 161 | - continue; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Return a pointer to the database. |
|
| 168 | - * |
|
| 169 | - * @return IndexAnalyser|object |
|
| 170 | - */ |
|
| 171 | - protected function getIndexAnalyser() |
|
| 172 | - { |
|
| 173 | - return GeneralUtility::makeInstance(IndexAnalyser::class); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @return ThumbnailGenerator|object |
|
| 178 | - */ |
|
| 179 | - protected function getThumbnailGenerator() |
|
| 180 | - { |
|
| 181 | - return GeneralUtility::makeInstance(ThumbnailGenerator::class); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @return StorageRepository|object |
|
| 186 | - */ |
|
| 187 | - protected function getStorageRepository() |
|
| 188 | - { |
|
| 189 | - return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Tell whether the tools should be displayed according to the context. |
|
| 194 | - * |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function isShown() |
|
| 198 | - { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @return FileReferenceService|object |
|
| 204 | - */ |
|
| 205 | - protected function getFileReferenceService() |
|
| 206 | - { |
|
| 207 | - return GeneralUtility::makeInstance(FileReferenceService::class); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @return object|DataService |
|
| 212 | - */ |
|
| 213 | - protected function getDataService(): DataService |
|
| 214 | - { |
|
| 215 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - protected function getResourceFactory(): ResourceFactory |
|
| 219 | - { |
|
| 220 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 221 | - } |
|
| 27 | + /** |
|
| 28 | + * Display the title of the tool on the welcome screen. |
|
| 29 | + * |
|
| 30 | + * @return string |
|
| 31 | + */ |
|
| 32 | + public function getTitle() |
|
| 33 | + { |
|
| 34 | + return 'Find duplicate Files'; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Display the description of the tool in the welcome screen. |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function getDescription() |
|
| 43 | + { |
|
| 44 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
|
| 45 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 46 | + $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
|
| 47 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 48 | + return $view->render(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Do the job: analyse Index. |
|
| 53 | + * |
|
| 54 | + * @param array $arguments |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function work(array $arguments = []) |
|
| 58 | + { |
|
| 59 | + // Possible clean up of missing files if the User has clicked so. |
|
| 60 | + if (!empty($arguments['deleteDuplicateFiles'])) { |
|
| 61 | + $this->deleteMissingFilesAction($arguments['files']); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/WorkResult.html'; |
|
| 65 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 66 | + |
|
| 67 | + $duplicateFilesReports = []; |
|
| 68 | + |
|
| 69 | + if ($this->getBackendUser()->isAdmin()) { |
|
| 70 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 71 | + if ($storage->isOnline()) { |
|
| 72 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 73 | + $duplicateFilesReports[] = array( |
|
| 74 | + 'storage' => $storage, |
|
| 75 | + 'duplicateFiles' => $duplicateFiles, |
|
| 76 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } else { |
|
| 81 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 82 | + |
|
| 83 | + $allowedStorages = []; |
|
| 84 | + foreach ($fileMounts as $fileMount) { |
|
| 85 | + if ((bool)$fileMount['read_only']) { |
|
| 86 | + continue; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if (!isset($allowedStorages[$fileMount['base']])) { |
|
| 90 | + $allowedStorages[$fileMount['base']] = []; |
|
| 91 | + } |
|
| 92 | + if (!in_array($fileMount['base'], $allowedStorages)) { |
|
| 93 | + $allowedStorages[$fileMount['base']][] = $fileMount['path']; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + foreach ($allowedStorages as $storageIdentifier => $allowedMountPoints) { |
|
| 98 | + $storage = $this->getResourceFactory()->getStorageObject($storageIdentifier); |
|
| 99 | + |
|
| 100 | + if ($storage->isOnline()) { |
|
| 101 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
| 102 | + |
|
| 103 | + // Filter duplicates files |
|
| 104 | + foreach ($duplicateFiles as $key => $files) { |
|
| 105 | + $filteredFiles = []; |
|
| 106 | + foreach ($files as $file) { |
|
| 107 | + foreach ($allowedMountPoints as $allowedMountPoint) { |
|
| 108 | + $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
| 109 | + if (preg_match($pattern, $file['identifier'])) { |
|
| 110 | + $filteredFiles[] = $file; |
|
| 111 | + break; // no need to further loop around, stop the loop. |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // We need more than 1 files to be shown as duplicate. |
|
| 117 | + if (count($filteredFiles) > 1) { |
|
| 118 | + $duplicateFiles[$key] = $filteredFiles; |
|
| 119 | + } else { |
|
| 120 | + unset($duplicateFiles[$key]); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + $duplicateFilesReports[] = array( |
|
| 124 | + 'storage' => $storage, |
|
| 125 | + 'duplicateFiles' => $duplicateFiles, |
|
| 126 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 127 | + ); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $view->assign('duplicateFilesReports', $duplicateFilesReports); |
|
| 133 | + |
|
| 134 | + return $view->render(); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Delete files given as parameter. |
|
| 139 | + * This is a special case as we have a missing file in the file system |
|
| 140 | + * As a result, we can't use $fileObject->delete(); which will |
|
| 141 | + * raise exception "Error while fetching permissions". |
|
| 142 | + * |
|
| 143 | + * @param array $files |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + protected function deleteMissingFilesAction(array $files = []) |
|
| 147 | + { |
|
| 148 | + foreach ($files as $fileUid) { |
|
| 149 | + /** @var File $file */ |
|
| 150 | + try { |
|
| 151 | + $file = $this->getResourceFactory()->getFileObject($fileUid); |
|
| 152 | + if ($file->exists()) { |
|
| 153 | + $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
| 154 | + if ($numberOfReferences === 0) { |
|
| 155 | + $file->delete(); |
|
| 156 | + } |
|
| 157 | + } else { |
|
| 158 | + $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 159 | + } |
|
| 160 | + } catch (\Exception $e) { |
|
| 161 | + continue; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Return a pointer to the database. |
|
| 168 | + * |
|
| 169 | + * @return IndexAnalyser|object |
|
| 170 | + */ |
|
| 171 | + protected function getIndexAnalyser() |
|
| 172 | + { |
|
| 173 | + return GeneralUtility::makeInstance(IndexAnalyser::class); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @return ThumbnailGenerator|object |
|
| 178 | + */ |
|
| 179 | + protected function getThumbnailGenerator() |
|
| 180 | + { |
|
| 181 | + return GeneralUtility::makeInstance(ThumbnailGenerator::class); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @return StorageRepository|object |
|
| 186 | + */ |
|
| 187 | + protected function getStorageRepository() |
|
| 188 | + { |
|
| 189 | + return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Tell whether the tools should be displayed according to the context. |
|
| 194 | + * |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function isShown() |
|
| 198 | + { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @return FileReferenceService|object |
|
| 204 | + */ |
|
| 205 | + protected function getFileReferenceService() |
|
| 206 | + { |
|
| 207 | + return GeneralUtility::makeInstance(FileReferenceService::class); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @return object|DataService |
|
| 212 | + */ |
|
| 213 | + protected function getDataService(): DataService |
|
| 214 | + { |
|
| 215 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + protected function getResourceFactory(): ResourceFactory |
|
| 219 | + { |
|
| 220 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 221 | + } |
|
| 222 | 222 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
| 45 | 45 | $view = $this->initializeStandaloneView($templateNameAndPath); |
| 46 | 46 | $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
| 47 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 47 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
| 48 | 48 | return $view->render(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $filteredFiles = []; |
| 106 | 106 | foreach ($files as $file) { |
| 107 | 107 | foreach ($allowedMountPoints as $allowedMountPoint) { |
| 108 | - $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
| 108 | + $pattern = '%^'.$allowedMountPoint.'%isU'; |
|
| 109 | 109 | if (preg_match($pattern, $file['identifier'])) { |
| 110 | 110 | $filteredFiles[] = $file; |
| 111 | 111 | break; // no need to further loop around, stop the loop. |
@@ -19,120 +19,120 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class ThumbnailGeneratorTool extends AbstractTool |
| 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 'Generate thumbnails'; |
|
| 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/ThumbnailGenerator/Launcher.html'; |
|
| 40 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 41 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 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 | - $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 | - $limit = (int)$arguments['limit']; |
|
| 61 | - $offset = (int)$arguments['offset']; |
|
| 62 | - |
|
| 63 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 64 | - if ($storage->isOnline()) { |
|
| 65 | - $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
| 66 | - $thumbnailGenerator |
|
| 67 | - ->setStorage($storage) |
|
| 68 | - ->generate($limit, $offset); |
|
| 69 | - |
|
| 70 | - $formattedResultSet = []; |
|
| 71 | - $resultSet = $thumbnailGenerator->getResultSet(); |
|
| 72 | - $processedFileIdentifiers = $thumbnailGenerator->getNewProcessedFileIdentifiers(); |
|
| 73 | - |
|
| 74 | - foreach ($processedFileIdentifiers as $fileIdentifier => $processedFileIdentifier) { |
|
| 75 | - $result = $resultSet[$fileIdentifier]; |
|
| 76 | - $formattedResultSet[] = sprintf( |
|
| 77 | - '* File "%s": %s %s', |
|
| 78 | - $result['fileUid'], |
|
| 79 | - $result['fileIdentifier'], |
|
| 80 | - empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $reports[] = array( |
|
| 85 | - 'storage' => $storage, |
|
| 86 | - 'isStorageOnline' => true, |
|
| 87 | - 'resultSet' => $formattedResultSet, |
|
| 88 | - 'numberOfProcessedFiles' => $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
| 89 | - 'numberOfTraversedFiles' => $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
| 90 | - 'numberOfMissingFiles' => $thumbnailGenerator->getNumberOfMissingFiles(), |
|
| 91 | - 'totalNumberOfFiles' => $thumbnailGenerator->getTotalNumberOfFiles(), |
|
| 92 | - ); |
|
| 93 | - } else { |
|
| 94 | - $reports[] = array( |
|
| 95 | - 'storage' => $storage, |
|
| 96 | - 'isStorageOnline' => false, |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $newOffset = $limit + $offset; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/WorkResult.html'; |
|
| 105 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 106 | - |
|
| 107 | - $view->assign('limit', $limit); |
|
| 108 | - $view->assign('offset', $newOffset); |
|
| 109 | - $view->assign('reports', $reports); |
|
| 110 | - return $view->render(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return ThumbnailGenerator|object |
|
| 115 | - */ |
|
| 116 | - protected function getThumbnailGenerator() |
|
| 117 | - { |
|
| 118 | - return GeneralUtility::makeInstance(ThumbnailGenerator::class); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return StorageRepository|object |
|
| 123 | - */ |
|
| 124 | - protected function getStorageRepository() |
|
| 125 | - { |
|
| 126 | - return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Tell whether the tools should be displayed according to the context. |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function isShown() |
|
| 135 | - { |
|
| 136 | - return $this->getBackendUser()->isAdmin(); |
|
| 137 | - } |
|
| 22 | + /** |
|
| 23 | + * Display the title of the tool on the welcome screen. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function getTitle() |
|
| 28 | + { |
|
| 29 | + return 'Generate thumbnails'; |
|
| 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/ThumbnailGenerator/Launcher.html'; |
|
| 40 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 41 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 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 | + $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 | + $limit = (int)$arguments['limit']; |
|
| 61 | + $offset = (int)$arguments['offset']; |
|
| 62 | + |
|
| 63 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 64 | + if ($storage->isOnline()) { |
|
| 65 | + $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
| 66 | + $thumbnailGenerator |
|
| 67 | + ->setStorage($storage) |
|
| 68 | + ->generate($limit, $offset); |
|
| 69 | + |
|
| 70 | + $formattedResultSet = []; |
|
| 71 | + $resultSet = $thumbnailGenerator->getResultSet(); |
|
| 72 | + $processedFileIdentifiers = $thumbnailGenerator->getNewProcessedFileIdentifiers(); |
|
| 73 | + |
|
| 74 | + foreach ($processedFileIdentifiers as $fileIdentifier => $processedFileIdentifier) { |
|
| 75 | + $result = $resultSet[$fileIdentifier]; |
|
| 76 | + $formattedResultSet[] = sprintf( |
|
| 77 | + '* File "%s": %s %s', |
|
| 78 | + $result['fileUid'], |
|
| 79 | + $result['fileIdentifier'], |
|
| 80 | + empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $reports[] = array( |
|
| 85 | + 'storage' => $storage, |
|
| 86 | + 'isStorageOnline' => true, |
|
| 87 | + 'resultSet' => $formattedResultSet, |
|
| 88 | + 'numberOfProcessedFiles' => $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
| 89 | + 'numberOfTraversedFiles' => $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
| 90 | + 'numberOfMissingFiles' => $thumbnailGenerator->getNumberOfMissingFiles(), |
|
| 91 | + 'totalNumberOfFiles' => $thumbnailGenerator->getTotalNumberOfFiles(), |
|
| 92 | + ); |
|
| 93 | + } else { |
|
| 94 | + $reports[] = array( |
|
| 95 | + 'storage' => $storage, |
|
| 96 | + 'isStorageOnline' => false, |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $newOffset = $limit + $offset; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/WorkResult.html'; |
|
| 105 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 106 | + |
|
| 107 | + $view->assign('limit', $limit); |
|
| 108 | + $view->assign('offset', $newOffset); |
|
| 109 | + $view->assign('reports', $reports); |
|
| 110 | + return $view->render(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return ThumbnailGenerator|object |
|
| 115 | + */ |
|
| 116 | + protected function getThumbnailGenerator() |
|
| 117 | + { |
|
| 118 | + return GeneralUtility::makeInstance(ThumbnailGenerator::class); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return StorageRepository|object |
|
| 123 | + */ |
|
| 124 | + protected function getStorageRepository() |
|
| 125 | + { |
|
| 126 | + return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Tell whether the tools should be displayed according to the context. |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function isShown() |
|
| 135 | + { |
|
| 136 | + return $this->getBackendUser()->isAdmin(); |
|
| 137 | + } |
|
| 138 | 138 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/Launcher.html'; |
| 40 | 40 | $view = $this->initializeStandaloneView($templateNameAndPath); |
| 41 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 41 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
| 42 | 42 | return $view->render(); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | '* File "%s": %s %s', |
| 78 | 78 | $result['fileUid'], |
| 79 | 79 | $result['fileIdentifier'], |
| 80 | - empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
| 80 | + empty($result['thumbnailUri']) ? '' : ' -> '.$result['thumbnailUri'] |
|
| 81 | 81 | ); |
| 82 | 82 | } |
| 83 | 83 | |