@@ -19,142 +19,142 @@ |
||
19 | 19 | abstract class UploadedFileAbstract implements UploadedFileInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $uploadFolder; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $inputName; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $name; |
|
36 | - |
|
37 | - /** |
|
38 | - * Get the file type. |
|
39 | - * |
|
40 | - * @return int |
|
41 | - */ |
|
42 | - public function getType() |
|
43 | - { |
|
44 | - $this->checkFileExistence(); |
|
45 | - |
|
46 | - // this basically extracts the mimetype and guess the filetype based |
|
47 | - // on the first part of the mimetype works for 99% of all cases, and |
|
48 | - // we don't need to make an SQL statement like EXT:media does currently |
|
49 | - $mimeType = $this->getMimeType(); |
|
50 | - list($fileType) = explode('/', $mimeType); |
|
51 | - switch (strtolower($fileType)) { |
|
52 | - case 'text': |
|
53 | - $type = File::FILETYPE_TEXT; |
|
54 | - break; |
|
55 | - case 'image': |
|
56 | - $type = File::FILETYPE_IMAGE; |
|
57 | - break; |
|
58 | - case 'audio': |
|
59 | - $type = File::FILETYPE_AUDIO; |
|
60 | - break; |
|
61 | - case 'video': |
|
62 | - $type = File::FILETYPE_VIDEO; |
|
63 | - break; |
|
64 | - case 'application': |
|
65 | - case 'software': |
|
66 | - $type = File::FILETYPE_APPLICATION; |
|
67 | - break; |
|
68 | - default: |
|
69 | - $type = File::FILETYPE_UNKNOWN; |
|
70 | - } |
|
71 | - return $type; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Get the file with its absolute path. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getFileWithAbsolutePath() |
|
80 | - { |
|
81 | - return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get the file's public URL. |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function getPublicUrl() |
|
90 | - { |
|
91 | - $fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath()); |
|
92 | - return '/' . ltrim($fileNameAndPath, '/'); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getInputName() |
|
99 | - { |
|
100 | - return $this->inputName; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $inputName |
|
105 | - * @return UploadedFileInterface |
|
106 | - */ |
|
107 | - public function setInputName($inputName) |
|
108 | - { |
|
109 | - $this->inputName = $inputName; |
|
110 | - return $this; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function getUploadFolder() |
|
117 | - { |
|
118 | - return $this->uploadFolder; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $uploadFolder |
|
123 | - * @return UploadedFileInterface |
|
124 | - */ |
|
125 | - public function setUploadFolder($uploadFolder) |
|
126 | - { |
|
127 | - $this->uploadFolder = $uploadFolder; |
|
128 | - return $this; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function getName() |
|
135 | - { |
|
136 | - return $this->name; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $name |
|
141 | - * @return UploadedFileInterface |
|
142 | - */ |
|
143 | - public function setName($name) |
|
144 | - { |
|
145 | - $this->name = $name; |
|
146 | - return $this; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Check whether the file exists. |
|
151 | - */ |
|
152 | - protected function checkFileExistence() |
|
153 | - { |
|
154 | - if (!is_file($this->getFileWithAbsolutePath())) { |
|
155 | - $message = sprintf('File not found at "%s". Did you save it?', $this->getFileWithAbsolutePath()); |
|
156 | - throw new MissingFileException($message, 1361786958); |
|
157 | - } |
|
158 | - } |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $uploadFolder; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $inputName; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $name; |
|
36 | + |
|
37 | + /** |
|
38 | + * Get the file type. |
|
39 | + * |
|
40 | + * @return int |
|
41 | + */ |
|
42 | + public function getType() |
|
43 | + { |
|
44 | + $this->checkFileExistence(); |
|
45 | + |
|
46 | + // this basically extracts the mimetype and guess the filetype based |
|
47 | + // on the first part of the mimetype works for 99% of all cases, and |
|
48 | + // we don't need to make an SQL statement like EXT:media does currently |
|
49 | + $mimeType = $this->getMimeType(); |
|
50 | + list($fileType) = explode('/', $mimeType); |
|
51 | + switch (strtolower($fileType)) { |
|
52 | + case 'text': |
|
53 | + $type = File::FILETYPE_TEXT; |
|
54 | + break; |
|
55 | + case 'image': |
|
56 | + $type = File::FILETYPE_IMAGE; |
|
57 | + break; |
|
58 | + case 'audio': |
|
59 | + $type = File::FILETYPE_AUDIO; |
|
60 | + break; |
|
61 | + case 'video': |
|
62 | + $type = File::FILETYPE_VIDEO; |
|
63 | + break; |
|
64 | + case 'application': |
|
65 | + case 'software': |
|
66 | + $type = File::FILETYPE_APPLICATION; |
|
67 | + break; |
|
68 | + default: |
|
69 | + $type = File::FILETYPE_UNKNOWN; |
|
70 | + } |
|
71 | + return $type; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Get the file with its absolute path. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getFileWithAbsolutePath() |
|
80 | + { |
|
81 | + return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get the file's public URL. |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function getPublicUrl() |
|
90 | + { |
|
91 | + $fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath()); |
|
92 | + return '/' . ltrim($fileNameAndPath, '/'); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getInputName() |
|
99 | + { |
|
100 | + return $this->inputName; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $inputName |
|
105 | + * @return UploadedFileInterface |
|
106 | + */ |
|
107 | + public function setInputName($inputName) |
|
108 | + { |
|
109 | + $this->inputName = $inputName; |
|
110 | + return $this; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function getUploadFolder() |
|
117 | + { |
|
118 | + return $this->uploadFolder; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $uploadFolder |
|
123 | + * @return UploadedFileInterface |
|
124 | + */ |
|
125 | + public function setUploadFolder($uploadFolder) |
|
126 | + { |
|
127 | + $this->uploadFolder = $uploadFolder; |
|
128 | + return $this; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function getName() |
|
135 | + { |
|
136 | + return $this->name; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $name |
|
141 | + * @return UploadedFileInterface |
|
142 | + */ |
|
143 | + public function setName($name) |
|
144 | + { |
|
145 | + $this->name = $name; |
|
146 | + return $this; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Check whether the file exists. |
|
151 | + */ |
|
152 | + protected function checkFileExistence() |
|
153 | + { |
|
154 | + if (!is_file($this->getFileWithAbsolutePath())) { |
|
155 | + $message = sprintf('File not found at "%s". Did you save it?', $this->getFileWithAbsolutePath()); |
|
156 | + throw new MissingFileException($message, 1361786958); |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | 160 | } |
@@ -25,105 +25,105 @@ |
||
25 | 25 | class FileCacheCommandController extends CommandController |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Warm up the cache. Update some caching columns such as "number_of_references" to speed up the search. |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function warmUpCommand() |
|
34 | - { |
|
35 | - $numberOfEntries = $this->getCacheService()->warmUp(); |
|
36 | - $message = sprintf('Done! Processed %s entries', $numberOfEntries); |
|
37 | - $this->outputLine($message); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Flush all processed files to be used for debugging mainly. |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function flushProcessedFilesCommand() |
|
46 | - { |
|
47 | - |
|
48 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
49 | - |
|
50 | - // This only works for local driver |
|
51 | - if ($storage->getDriverType() === 'Local') { |
|
52 | - |
|
53 | - $this->outputLine(); |
|
54 | - $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
55 | - $this->outputLine('--------------------------------------------'); |
|
56 | - $this->outputLine(); |
|
57 | - |
|
58 | - #$storage->getProcessingFolder()->delete(true); // will not work |
|
59 | - |
|
60 | - // Well... not really FAL friendly but straightforward for Local drivers. |
|
61 | - $processedDirectoryPath = Environment::getPublicPath() . '/' . $storage->getProcessingFolder()->getPublicUrl(); |
|
62 | - $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS); |
|
63 | - $numberOfProcessedFiles = iterator_count($fileIterator); |
|
64 | - |
|
65 | - GeneralUtility::rmdir($processedDirectoryPath, true); |
|
66 | - GeneralUtility::mkdir($processedDirectoryPath); // recreate the directory. |
|
67 | - |
|
68 | - $message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles); |
|
69 | - $this->outputLine($message); |
|
70 | - |
|
71 | - $count = $this->getDataService() |
|
72 | - ->count( |
|
73 | - 'sys_file_processedfile', |
|
74 | - [ |
|
75 | - 'storage' => $storage->getUid() |
|
76 | - ] |
|
77 | - ); |
|
78 | - |
|
79 | - // Remove the record as well. |
|
80 | - $this->getDataService()->delete('sys_file_processedfile', ['storage' => $storage->getUid()]); |
|
81 | - |
|
82 | - $message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $count); |
|
83 | - $this->outputLine($message); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - // Remove possible remaining "sys_file_processedfile" |
|
89 | - $this |
|
90 | - ->getConnection('sys_file_processedfile') |
|
91 | - ->query('TRUNCATE sys_file_processedfile'); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @return \Fab\Media\Cache\CacheService|object |
|
96 | - */ |
|
97 | - protected function getCacheService() |
|
98 | - { |
|
99 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return StorageRepository|object |
|
104 | - */ |
|
105 | - protected function getStorageRepository() |
|
106 | - { |
|
107 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @return object|DataService |
|
112 | - */ |
|
113 | - protected function getDataService(): DataService |
|
114 | - { |
|
115 | - return GeneralUtility::makeInstance(DataService::class); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param string $tableName |
|
120 | - * @return object|Connection |
|
121 | - */ |
|
122 | - protected function getConnection($tableName): Connection |
|
123 | - { |
|
124 | - /** @var ConnectionPool $connectionPool */ |
|
125 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
126 | - return $connectionPool->getConnectionForTable($tableName); |
|
127 | - } |
|
28 | + /** |
|
29 | + * Warm up the cache. Update some caching columns such as "number_of_references" to speed up the search. |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function warmUpCommand() |
|
34 | + { |
|
35 | + $numberOfEntries = $this->getCacheService()->warmUp(); |
|
36 | + $message = sprintf('Done! Processed %s entries', $numberOfEntries); |
|
37 | + $this->outputLine($message); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Flush all processed files to be used for debugging mainly. |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function flushProcessedFilesCommand() |
|
46 | + { |
|
47 | + |
|
48 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
49 | + |
|
50 | + // This only works for local driver |
|
51 | + if ($storage->getDriverType() === 'Local') { |
|
52 | + |
|
53 | + $this->outputLine(); |
|
54 | + $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
55 | + $this->outputLine('--------------------------------------------'); |
|
56 | + $this->outputLine(); |
|
57 | + |
|
58 | + #$storage->getProcessingFolder()->delete(true); // will not work |
|
59 | + |
|
60 | + // Well... not really FAL friendly but straightforward for Local drivers. |
|
61 | + $processedDirectoryPath = Environment::getPublicPath() . '/' . $storage->getProcessingFolder()->getPublicUrl(); |
|
62 | + $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS); |
|
63 | + $numberOfProcessedFiles = iterator_count($fileIterator); |
|
64 | + |
|
65 | + GeneralUtility::rmdir($processedDirectoryPath, true); |
|
66 | + GeneralUtility::mkdir($processedDirectoryPath); // recreate the directory. |
|
67 | + |
|
68 | + $message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles); |
|
69 | + $this->outputLine($message); |
|
70 | + |
|
71 | + $count = $this->getDataService() |
|
72 | + ->count( |
|
73 | + 'sys_file_processedfile', |
|
74 | + [ |
|
75 | + 'storage' => $storage->getUid() |
|
76 | + ] |
|
77 | + ); |
|
78 | + |
|
79 | + // Remove the record as well. |
|
80 | + $this->getDataService()->delete('sys_file_processedfile', ['storage' => $storage->getUid()]); |
|
81 | + |
|
82 | + $message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $count); |
|
83 | + $this->outputLine($message); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + // Remove possible remaining "sys_file_processedfile" |
|
89 | + $this |
|
90 | + ->getConnection('sys_file_processedfile') |
|
91 | + ->query('TRUNCATE sys_file_processedfile'); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @return \Fab\Media\Cache\CacheService|object |
|
96 | + */ |
|
97 | + protected function getCacheService() |
|
98 | + { |
|
99 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return StorageRepository|object |
|
104 | + */ |
|
105 | + protected function getStorageRepository() |
|
106 | + { |
|
107 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @return object|DataService |
|
112 | + */ |
|
113 | + protected function getDataService(): DataService |
|
114 | + { |
|
115 | + return GeneralUtility::makeInstance(DataService::class); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param string $tableName |
|
120 | + * @return object|Connection |
|
121 | + */ |
|
122 | + protected function getConnection($tableName): Connection |
|
123 | + { |
|
124 | + /** @var ConnectionPool $connectionPool */ |
|
125 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
126 | + return $connectionPool->getConnectionForTable($tableName); |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
@@ -22,169 +22,169 @@ |
||
22 | 22 | class IndexAnalyser implements SingletonInterface |
23 | 23 | { |
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 | - |
|
34 | - /** @var ConnectionPool $connectionPool */ |
|
35 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
36 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
37 | - |
|
38 | - $missingFiles = []; |
|
39 | - $statement = $queryBuilder |
|
40 | - ->select('*') |
|
41 | - ->from('sys_file') |
|
42 | - ->where( |
|
43 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
44 | - )->execute(); |
|
45 | - while ($row = $statement->fetchAssociative()) { |
|
46 | - |
|
47 | - // This task is very memory consuming on large data set e.g > 20'000 records. |
|
48 | - // We must think of having a pagination if there is the need for such thing. |
|
49 | - $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row); |
|
50 | - if (!$file->exists()) { |
|
51 | - $missingFiles[] = $file; |
|
52 | - } |
|
53 | - } |
|
54 | - return $missingFiles; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Deletes all missing files for a given storage. |
|
59 | - * |
|
60 | - * @param ResourceStorage $storage |
|
61 | - * @return array |
|
62 | - * @throws \InvalidArgumentException |
|
63 | - */ |
|
64 | - public function deleteMissingFiles(ResourceStorage $storage) |
|
65 | - { |
|
66 | - /** @var FileReferenceService $fileReferenceService */ |
|
67 | - $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
68 | - $missingFiles = $this->searchForMissingFiles($storage); |
|
69 | - $deletedFiles = []; |
|
70 | - |
|
71 | - /** @var ConnectionPool $connectionPool */ |
|
72 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
73 | - |
|
74 | - /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
75 | - foreach ($missingFiles as $missingFile) { |
|
76 | - try { |
|
77 | - // if missingFile has no file references |
|
78 | - if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
79 | - // The case is special as we have a missing file in the file system |
|
80 | - // As a result, we can't use $fileObject->delete(); which will |
|
81 | - // raise exception "Error while fetching permissions" |
|
82 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
83 | - $queryBuilder->delete('sys_file') |
|
84 | - ->where($queryBuilder->expr()->eq('uid', $missingFile->getUid())) |
|
85 | - ->execute(); |
|
86 | - |
|
87 | - $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
88 | - } |
|
89 | - } catch (\Exception $e) { |
|
90 | - continue; |
|
91 | - } |
|
92 | - } |
|
93 | - return $deletedFiles; |
|
94 | - } |
|
95 | - |
|
96 | - /* |
|
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 | + |
|
34 | + /** @var ConnectionPool $connectionPool */ |
|
35 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
36 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
37 | + |
|
38 | + $missingFiles = []; |
|
39 | + $statement = $queryBuilder |
|
40 | + ->select('*') |
|
41 | + ->from('sys_file') |
|
42 | + ->where( |
|
43 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
44 | + )->execute(); |
|
45 | + while ($row = $statement->fetchAssociative()) { |
|
46 | + |
|
47 | + // This task is very memory consuming on large data set e.g > 20'000 records. |
|
48 | + // We must think of having a pagination if there is the need for such thing. |
|
49 | + $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row); |
|
50 | + if (!$file->exists()) { |
|
51 | + $missingFiles[] = $file; |
|
52 | + } |
|
53 | + } |
|
54 | + return $missingFiles; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Deletes all missing files for a given storage. |
|
59 | + * |
|
60 | + * @param ResourceStorage $storage |
|
61 | + * @return array |
|
62 | + * @throws \InvalidArgumentException |
|
63 | + */ |
|
64 | + public function deleteMissingFiles(ResourceStorage $storage) |
|
65 | + { |
|
66 | + /** @var FileReferenceService $fileReferenceService */ |
|
67 | + $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
68 | + $missingFiles = $this->searchForMissingFiles($storage); |
|
69 | + $deletedFiles = []; |
|
70 | + |
|
71 | + /** @var ConnectionPool $connectionPool */ |
|
72 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
73 | + |
|
74 | + /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
75 | + foreach ($missingFiles as $missingFile) { |
|
76 | + try { |
|
77 | + // if missingFile has no file references |
|
78 | + if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
79 | + // The case is special as we have a missing file in the file system |
|
80 | + // As a result, we can't use $fileObject->delete(); which will |
|
81 | + // raise exception "Error while fetching permissions" |
|
82 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
83 | + $queryBuilder->delete('sys_file') |
|
84 | + ->where($queryBuilder->expr()->eq('uid', $missingFile->getUid())) |
|
85 | + ->execute(); |
|
86 | + |
|
87 | + $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
88 | + } |
|
89 | + } catch (\Exception $e) { |
|
90 | + continue; |
|
91 | + } |
|
92 | + } |
|
93 | + return $deletedFiles; |
|
94 | + } |
|
95 | + |
|
96 | + /* |
|
97 | 97 | * Return duplicates file records |
98 | 98 | * |
99 | 99 | * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
100 | 100 | * @return array |
101 | 101 | */ |
102 | - public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
103 | - { |
|
104 | - /** @var ConnectionPool $connectionPool */ |
|
105 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
106 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
107 | - |
|
108 | - $statement = $queryBuilder |
|
109 | - ->select('*') |
|
110 | - ->from('sys_file') |
|
111 | - ->where( |
|
112 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
113 | - ) |
|
114 | - ->groupby('identifier') |
|
115 | - ->having('count(*) > 1') |
|
116 | - ->execute(); |
|
117 | - |
|
118 | - // Detect duplicate records. |
|
119 | - $duplicates = []; |
|
120 | - while ($row = $statement->fetchAssociative()) { |
|
121 | - |
|
122 | - $records = $queryBuilder |
|
123 | - ->select('*') |
|
124 | - ->from('sys_file') |
|
125 | - ->where( |
|
126 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
127 | - ) |
|
128 | - ->andWhere( |
|
129 | - $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier'])) |
|
130 | - ) |
|
131 | - ->execute(); |
|
132 | - $records = $records->fetchAllAssociative(); |
|
133 | - $duplicates[$row['identifier']] = $records; |
|
134 | - } |
|
135 | - return $duplicates; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Return duplicates file records |
|
140 | - * |
|
141 | - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - public function searchForDuplicateSha1(ResourceStorage $storage) |
|
145 | - { |
|
146 | - /** @var ConnectionPool $connectionPool */ |
|
147 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
148 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
149 | - |
|
150 | - $statement = $queryBuilder |
|
151 | - ->select('*') |
|
152 | - ->from('sys_file') |
|
153 | - ->where( |
|
154 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
155 | - ) |
|
156 | - ->groupby('sha1') |
|
157 | - ->having('count(*) > 1') |
|
158 | - ->execute(); |
|
159 | - |
|
160 | - // Detect duplicate records. |
|
161 | - $duplicates = []; |
|
162 | - while ($row = $statement->fetchAssociative()) { |
|
163 | - |
|
164 | - $records = $queryBuilder |
|
165 | - ->select('*') |
|
166 | - ->from('sys_file') |
|
167 | - ->where( |
|
168 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
169 | - ) |
|
170 | - ->andWhere( |
|
171 | - $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1'])) |
|
172 | - ) |
|
173 | - ->execute(); |
|
174 | - $records = $records->fetchAllAssociative(); |
|
175 | - $duplicates[$row['sha1']] = $records; |
|
176 | - } |
|
177 | - return $duplicates; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $tableName |
|
182 | - * @return object|QueryBuilder |
|
183 | - */ |
|
184 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
185 | - { |
|
186 | - /** @var ConnectionPool $connectionPool */ |
|
187 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
188 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
189 | - } |
|
102 | + public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
103 | + { |
|
104 | + /** @var ConnectionPool $connectionPool */ |
|
105 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
106 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
107 | + |
|
108 | + $statement = $queryBuilder |
|
109 | + ->select('*') |
|
110 | + ->from('sys_file') |
|
111 | + ->where( |
|
112 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
113 | + ) |
|
114 | + ->groupby('identifier') |
|
115 | + ->having('count(*) > 1') |
|
116 | + ->execute(); |
|
117 | + |
|
118 | + // Detect duplicate records. |
|
119 | + $duplicates = []; |
|
120 | + while ($row = $statement->fetchAssociative()) { |
|
121 | + |
|
122 | + $records = $queryBuilder |
|
123 | + ->select('*') |
|
124 | + ->from('sys_file') |
|
125 | + ->where( |
|
126 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
127 | + ) |
|
128 | + ->andWhere( |
|
129 | + $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier'])) |
|
130 | + ) |
|
131 | + ->execute(); |
|
132 | + $records = $records->fetchAllAssociative(); |
|
133 | + $duplicates[$row['identifier']] = $records; |
|
134 | + } |
|
135 | + return $duplicates; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Return duplicates file records |
|
140 | + * |
|
141 | + * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + public function searchForDuplicateSha1(ResourceStorage $storage) |
|
145 | + { |
|
146 | + /** @var ConnectionPool $connectionPool */ |
|
147 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
148 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
149 | + |
|
150 | + $statement = $queryBuilder |
|
151 | + ->select('*') |
|
152 | + ->from('sys_file') |
|
153 | + ->where( |
|
154 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
155 | + ) |
|
156 | + ->groupby('sha1') |
|
157 | + ->having('count(*) > 1') |
|
158 | + ->execute(); |
|
159 | + |
|
160 | + // Detect duplicate records. |
|
161 | + $duplicates = []; |
|
162 | + while ($row = $statement->fetchAssociative()) { |
|
163 | + |
|
164 | + $records = $queryBuilder |
|
165 | + ->select('*') |
|
166 | + ->from('sys_file') |
|
167 | + ->where( |
|
168 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
169 | + ) |
|
170 | + ->andWhere( |
|
171 | + $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1'])) |
|
172 | + ) |
|
173 | + ->execute(); |
|
174 | + $records = $records->fetchAllAssociative(); |
|
175 | + $duplicates[$row['sha1']] = $records; |
|
176 | + } |
|
177 | + return $duplicates; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $tableName |
|
182 | + * @return object|QueryBuilder |
|
183 | + */ |
|
184 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
185 | + { |
|
186 | + /** @var ConnectionPool $connectionPool */ |
|
187 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
188 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
189 | + } |
|
190 | 190 | } |