@@ -22,245 +22,245 @@ |
||
22 | 22 | class CacheService |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Traverse all files and initialize cache values. |
|
27 | - * |
|
28 | - * @return int |
|
29 | - */ |
|
30 | - public function warmUp() |
|
31 | - { |
|
32 | - /** @var QueryBuilder $queryBuilder */ |
|
33 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
34 | - $rows = $queryBuilder |
|
35 | - ->select('*') |
|
36 | - ->from('sys_file') |
|
37 | - ->where('storage > 0') |
|
38 | - ->execute() |
|
39 | - ->fetchAll(); |
|
40 | - |
|
41 | - $counter = 0; |
|
42 | - foreach ($rows as $row) { |
|
43 | - |
|
44 | - $fileIdentifier = $row['uid']; |
|
45 | - $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
46 | - |
|
47 | - $values = array( |
|
48 | - 'number_of_references' => $totalNumberOfReferences |
|
49 | - ); |
|
50 | - |
|
51 | - $this->getDataService()->update( |
|
52 | - 'sys_file', |
|
53 | - $values, |
|
54 | - [ |
|
55 | - 'uid' => $fileIdentifier |
|
56 | - ] |
|
57 | - ); |
|
58 | - $counter++; |
|
59 | - } |
|
60 | - |
|
61 | - return $counter; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Clear all possible cache related to a file. |
|
66 | - * This method is useful when replacing a file for instance. |
|
67 | - * |
|
68 | - * @param File $file |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function clearCache(File $file) |
|
72 | - { |
|
73 | - |
|
74 | - $this->clearCachePages($file); |
|
75 | - $this->flushProcessedFiles($file); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Remove all processed files that belong to the given File object. |
|
80 | - * |
|
81 | - * @param File $file |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - protected function flushProcessedFiles(File $file) |
|
85 | - { |
|
86 | - |
|
87 | - /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
88 | - foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
89 | - if ($processedFile->exists()) { |
|
90 | - $processedFile->delete(true); |
|
91 | - } |
|
92 | - |
|
93 | - $this->getDataService()->delete( |
|
94 | - 'sys_file_processedfile', |
|
95 | - [ |
|
96 | - 'uid' => (int)$processedFile->getUid() |
|
97 | - ] |
|
98 | - ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Return a processed file repository |
|
104 | - * |
|
105 | - * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
106 | - */ |
|
107 | - protected function getProcessedFileRepository() |
|
108 | - { |
|
109 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Returns the file references. |
|
114 | - * |
|
115 | - * @param File $file |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - protected function clearCachePages($file) |
|
119 | - { |
|
120 | - |
|
121 | - /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
122 | - $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
123 | - $tce->start([], []); |
|
124 | - |
|
125 | - #$pages = array_merge( |
|
126 | - # $this->findPagesWithFileReferences($file), |
|
127 | - # $this->findPagesWithSoftReferences($file) |
|
128 | - #); |
|
129 | - |
|
130 | - // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
131 | - // It is adviced to use "registerPageCacheClearing" but how? |
|
132 | - #foreach (array_unique($pages) as $page) { |
|
133 | - # $tce->clear_cache('pages', $page); |
|
134 | - #} |
|
135 | - $tce->clear_cacheCmd('pages'); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Find all pages which contains file references to the given $file. |
|
140 | - * |
|
141 | - * @param File $file |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - protected function findPagesWithFileReferences($file) |
|
145 | - { |
|
146 | - |
|
147 | - /** @var QueryBuilder $queryBuilder */ |
|
148 | - $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
149 | - $rows = $queryBuilder |
|
150 | - ->select('pid') |
|
151 | - ->from('sys_file_reference') |
|
152 | - ->groupBy('pid') // no support for distinct |
|
153 | - ->andWhere( |
|
154 | - 'pid > 0', |
|
155 | - 'uid_local = ' . $file->getUid() |
|
156 | - ) |
|
157 | - ->execute() |
|
158 | - ->fetchAll(); |
|
159 | - |
|
160 | - foreach ($rows as $row) { |
|
161 | - $pages[] = $row['pid']; |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - return $pages; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Find all pages which have soft references to the given $file. |
|
170 | - * |
|
171 | - * @param File $file |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - #protected function findPagesWithSoftReferences(File $file) |
|
175 | - #{ |
|
176 | - # $subClauseParts = array( |
|
177 | - # 'deleted = 0', |
|
178 | - # '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
179 | - # 'ref_table = "sys_file"', |
|
180 | - # 'tablename = "tt_content"', |
|
181 | - # 'ref_uid = ' . $file->getUid(), |
|
182 | - # ); |
|
183 | - # |
|
184 | - # $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
185 | - # 'DISTINCT pid', |
|
186 | - # 'tt_content', |
|
187 | - # sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
188 | - # implode(' AND ', $subClauseParts), |
|
189 | - # $this->getWhereClauseForEnabledFields('tt_content') |
|
190 | - # ) |
|
191 | - # ); |
|
192 | - # |
|
193 | - # // Compute result |
|
194 | - # $pages = []; |
|
195 | - # while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
196 | - # $pages[] = $affectedPage['pid']; |
|
197 | - # } |
|
198 | - # |
|
199 | - # return $pages; |
|
200 | - #} |
|
201 | - |
|
202 | - /** |
|
203 | - * Get the WHERE clause for the enabled fields given a $tableName. |
|
204 | - * |
|
205 | - * @param string $tableName |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - protected function getWhereClauseForEnabledFields($tableName) |
|
209 | - { |
|
210 | - if ($this->isFrontendMode()) { |
|
211 | - // frontend context |
|
212 | - $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
213 | - } else { |
|
214 | - // backend context |
|
215 | - $whereClause = BackendUtility::deleteClause($tableName); |
|
216 | - } |
|
217 | - return $whereClause; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Returns whether the current mode is Frontend |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - protected function isFrontendMode() |
|
226 | - { |
|
227 | - return TYPO3_MODE == 'FE'; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Returns an instance of the page repository. |
|
232 | - * |
|
233 | - * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
234 | - */ |
|
235 | - protected function getPageRepository() |
|
236 | - { |
|
237 | - return $GLOBALS['TSFE']->sys_page; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $tableName |
|
242 | - * @return object|QueryBuilder |
|
243 | - */ |
|
244 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
245 | - { |
|
246 | - /** @var ConnectionPool $connectionPool */ |
|
247 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
248 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return object|DataService |
|
253 | - */ |
|
254 | - protected function getDataService(): DataService |
|
255 | - { |
|
256 | - return GeneralUtility::makeInstance(DataService::class); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
261 | - */ |
|
262 | - protected function getFileReferenceService() |
|
263 | - { |
|
264 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
265 | - } |
|
25 | + /** |
|
26 | + * Traverse all files and initialize cache values. |
|
27 | + * |
|
28 | + * @return int |
|
29 | + */ |
|
30 | + public function warmUp() |
|
31 | + { |
|
32 | + /** @var QueryBuilder $queryBuilder */ |
|
33 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
34 | + $rows = $queryBuilder |
|
35 | + ->select('*') |
|
36 | + ->from('sys_file') |
|
37 | + ->where('storage > 0') |
|
38 | + ->execute() |
|
39 | + ->fetchAll(); |
|
40 | + |
|
41 | + $counter = 0; |
|
42 | + foreach ($rows as $row) { |
|
43 | + |
|
44 | + $fileIdentifier = $row['uid']; |
|
45 | + $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
46 | + |
|
47 | + $values = array( |
|
48 | + 'number_of_references' => $totalNumberOfReferences |
|
49 | + ); |
|
50 | + |
|
51 | + $this->getDataService()->update( |
|
52 | + 'sys_file', |
|
53 | + $values, |
|
54 | + [ |
|
55 | + 'uid' => $fileIdentifier |
|
56 | + ] |
|
57 | + ); |
|
58 | + $counter++; |
|
59 | + } |
|
60 | + |
|
61 | + return $counter; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Clear all possible cache related to a file. |
|
66 | + * This method is useful when replacing a file for instance. |
|
67 | + * |
|
68 | + * @param File $file |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function clearCache(File $file) |
|
72 | + { |
|
73 | + |
|
74 | + $this->clearCachePages($file); |
|
75 | + $this->flushProcessedFiles($file); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Remove all processed files that belong to the given File object. |
|
80 | + * |
|
81 | + * @param File $file |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + protected function flushProcessedFiles(File $file) |
|
85 | + { |
|
86 | + |
|
87 | + /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
88 | + foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
89 | + if ($processedFile->exists()) { |
|
90 | + $processedFile->delete(true); |
|
91 | + } |
|
92 | + |
|
93 | + $this->getDataService()->delete( |
|
94 | + 'sys_file_processedfile', |
|
95 | + [ |
|
96 | + 'uid' => (int)$processedFile->getUid() |
|
97 | + ] |
|
98 | + ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Return a processed file repository |
|
104 | + * |
|
105 | + * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
106 | + */ |
|
107 | + protected function getProcessedFileRepository() |
|
108 | + { |
|
109 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Returns the file references. |
|
114 | + * |
|
115 | + * @param File $file |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + protected function clearCachePages($file) |
|
119 | + { |
|
120 | + |
|
121 | + /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
122 | + $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
123 | + $tce->start([], []); |
|
124 | + |
|
125 | + #$pages = array_merge( |
|
126 | + # $this->findPagesWithFileReferences($file), |
|
127 | + # $this->findPagesWithSoftReferences($file) |
|
128 | + #); |
|
129 | + |
|
130 | + // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
131 | + // It is adviced to use "registerPageCacheClearing" but how? |
|
132 | + #foreach (array_unique($pages) as $page) { |
|
133 | + # $tce->clear_cache('pages', $page); |
|
134 | + #} |
|
135 | + $tce->clear_cacheCmd('pages'); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Find all pages which contains file references to the given $file. |
|
140 | + * |
|
141 | + * @param File $file |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + protected function findPagesWithFileReferences($file) |
|
145 | + { |
|
146 | + |
|
147 | + /** @var QueryBuilder $queryBuilder */ |
|
148 | + $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
149 | + $rows = $queryBuilder |
|
150 | + ->select('pid') |
|
151 | + ->from('sys_file_reference') |
|
152 | + ->groupBy('pid') // no support for distinct |
|
153 | + ->andWhere( |
|
154 | + 'pid > 0', |
|
155 | + 'uid_local = ' . $file->getUid() |
|
156 | + ) |
|
157 | + ->execute() |
|
158 | + ->fetchAll(); |
|
159 | + |
|
160 | + foreach ($rows as $row) { |
|
161 | + $pages[] = $row['pid']; |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + return $pages; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Find all pages which have soft references to the given $file. |
|
170 | + * |
|
171 | + * @param File $file |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + #protected function findPagesWithSoftReferences(File $file) |
|
175 | + #{ |
|
176 | + # $subClauseParts = array( |
|
177 | + # 'deleted = 0', |
|
178 | + # '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
179 | + # 'ref_table = "sys_file"', |
|
180 | + # 'tablename = "tt_content"', |
|
181 | + # 'ref_uid = ' . $file->getUid(), |
|
182 | + # ); |
|
183 | + # |
|
184 | + # $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
185 | + # 'DISTINCT pid', |
|
186 | + # 'tt_content', |
|
187 | + # sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
188 | + # implode(' AND ', $subClauseParts), |
|
189 | + # $this->getWhereClauseForEnabledFields('tt_content') |
|
190 | + # ) |
|
191 | + # ); |
|
192 | + # |
|
193 | + # // Compute result |
|
194 | + # $pages = []; |
|
195 | + # while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
196 | + # $pages[] = $affectedPage['pid']; |
|
197 | + # } |
|
198 | + # |
|
199 | + # return $pages; |
|
200 | + #} |
|
201 | + |
|
202 | + /** |
|
203 | + * Get the WHERE clause for the enabled fields given a $tableName. |
|
204 | + * |
|
205 | + * @param string $tableName |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + protected function getWhereClauseForEnabledFields($tableName) |
|
209 | + { |
|
210 | + if ($this->isFrontendMode()) { |
|
211 | + // frontend context |
|
212 | + $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
213 | + } else { |
|
214 | + // backend context |
|
215 | + $whereClause = BackendUtility::deleteClause($tableName); |
|
216 | + } |
|
217 | + return $whereClause; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Returns whether the current mode is Frontend |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + protected function isFrontendMode() |
|
226 | + { |
|
227 | + return TYPO3_MODE == 'FE'; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Returns an instance of the page repository. |
|
232 | + * |
|
233 | + * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
234 | + */ |
|
235 | + protected function getPageRepository() |
|
236 | + { |
|
237 | + return $GLOBALS['TSFE']->sys_page; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $tableName |
|
242 | + * @return object|QueryBuilder |
|
243 | + */ |
|
244 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
245 | + { |
|
246 | + /** @var ConnectionPool $connectionPool */ |
|
247 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
248 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return object|DataService |
|
253 | + */ |
|
254 | + protected function getDataService(): DataService |
|
255 | + { |
|
256 | + return GeneralUtility::makeInstance(DataService::class); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
261 | + */ |
|
262 | + protected function getFileReferenceService() |
|
263 | + { |
|
264 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
265 | + } |
|
266 | 266 | } |
@@ -21,37 +21,37 @@ |
||
21 | 21 | class ImageEditorController extends ActionController |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Initializes the controller before invoking an action method. |
|
26 | - */ |
|
27 | - public function initializeAction() |
|
28 | - { |
|
29 | - /** @var PageRenderer $pageRenderer */ |
|
30 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
31 | - $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
32 | - |
|
33 | - // Configure property mapping to retrieve the file object. |
|
34 | - if ($this->arguments->hasArgument('file')) { |
|
35 | - |
|
36 | - /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
37 | - $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
38 | - |
|
39 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
40 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Handle GUI for inserting an image in the RTE. |
|
46 | - * |
|
47 | - * @param File $file |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function showAction(File $file) |
|
51 | - { |
|
52 | - $this->view->assign('file', $file); |
|
53 | - $moduleSignature = MediaModule::getSignature(); |
|
54 | - $this->view->assign('moduleUrl', BackendUtility::getModuleUrl($moduleSignature)); |
|
55 | - } |
|
24 | + /** |
|
25 | + * Initializes the controller before invoking an action method. |
|
26 | + */ |
|
27 | + public function initializeAction() |
|
28 | + { |
|
29 | + /** @var PageRenderer $pageRenderer */ |
|
30 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
31 | + $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
32 | + |
|
33 | + // Configure property mapping to retrieve the file object. |
|
34 | + if ($this->arguments->hasArgument('file')) { |
|
35 | + |
|
36 | + /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
37 | + $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
38 | + |
|
39 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
40 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Handle GUI for inserting an image in the RTE. |
|
46 | + * |
|
47 | + * @param File $file |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function showAction(File $file) |
|
51 | + { |
|
52 | + $this->view->assign('file', $file); |
|
53 | + $moduleSignature = MediaModule::getSignature(); |
|
54 | + $this->view->assign('moduleUrl', BackendUtility::getModuleUrl($moduleSignature)); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -19,44 +19,44 @@ discard block |
||
19 | 19 | class RecursiveCheckbox extends AbstractComponentView |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Renders a checkbox for recursive file browsing. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - * @throws \InvalidArgumentException |
|
27 | - */ |
|
28 | - public function render() |
|
29 | - { |
|
22 | + /** |
|
23 | + * Renders a checkbox for recursive file browsing. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + * @throws \InvalidArgumentException |
|
27 | + */ |
|
28 | + public function render() |
|
29 | + { |
|
30 | 30 | |
31 | - $output = ''; |
|
32 | - if ($this->isDisplayed()) { |
|
33 | - $this->loadRequireJsCode(); |
|
34 | - $output = $this->renderRecursiveCheckbox(); |
|
35 | - } |
|
31 | + $output = ''; |
|
32 | + if ($this->isDisplayed()) { |
|
33 | + $this->loadRequireJsCode(); |
|
34 | + $output = $this->renderRecursiveCheckbox(); |
|
35 | + } |
|
36 | 36 | |
37 | - return $output; |
|
38 | - } |
|
37 | + return $output; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - * @throws \InvalidArgumentException |
|
43 | - */ |
|
44 | - protected function isDisplayed() |
|
45 | - { |
|
46 | - $isDisplayed = $this->getMediaModule()->hasFolderTree(); |
|
47 | - if ($this->getModuleLoader()->hasPlugin()) { |
|
48 | - $isDisplayed = false; |
|
49 | - } |
|
50 | - return $isDisplayed; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + * @throws \InvalidArgumentException |
|
43 | + */ |
|
44 | + protected function isDisplayed() |
|
45 | + { |
|
46 | + $isDisplayed = $this->getMediaModule()->hasFolderTree(); |
|
47 | + if ($this->getModuleLoader()->hasPlugin()) { |
|
48 | + $isDisplayed = false; |
|
49 | + } |
|
50 | + return $isDisplayed; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function renderRecursiveCheckbox() |
|
57 | - { |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function renderRecursiveCheckbox() |
|
57 | + { |
|
58 | 58 | |
59 | - $template = '<form action="%s" id="form-checkbox-hasRecursiveSelection" method="get"> |
|
59 | + $template = '<form action="%s" id="form-checkbox-hasRecursiveSelection" method="get"> |
|
60 | 60 | <label> |
61 | 61 | <input type="checkbox" |
62 | 62 | name="%s[hasRecursiveSelection]" |
@@ -67,35 +67,35 @@ discard block |
||
67 | 67 | </label> |
68 | 68 | </form>'; |
69 | 69 | |
70 | - return sprintf( |
|
71 | - $template, |
|
72 | - $this->getModuleLoader()->getModuleUrl(), |
|
73 | - $this->getModuleLoader()->getParameterPrefix(), |
|
74 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:browse_subfolders') |
|
75 | - ); |
|
76 | - } |
|
70 | + return sprintf( |
|
71 | + $template, |
|
72 | + $this->getModuleLoader()->getModuleUrl(), |
|
73 | + $this->getModuleLoader()->getParameterPrefix(), |
|
74 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:browse_subfolders') |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @throws \InvalidArgumentException |
|
81 | - */ |
|
82 | - protected function loadRequireJsCode() |
|
83 | - { |
|
84 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @throws \InvalidArgumentException |
|
81 | + */ |
|
82 | + protected function loadRequireJsCode() |
|
83 | + { |
|
84 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
85 | 85 | |
86 | - $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
87 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
88 | - $pageRenderer->loadRequireJsModule('Fab/Media/BrowseRecursively'); |
|
89 | - } |
|
86 | + $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
87 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
88 | + $pageRenderer->loadRequireJsModule('Fab/Media/BrowseRecursively'); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * @return MediaModule|object |
|
94 | - * @throws \InvalidArgumentException |
|
95 | - */ |
|
96 | - protected function getMediaModule() |
|
97 | - { |
|
98 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
99 | - } |
|
92 | + /** |
|
93 | + * @return MediaModule|object |
|
94 | + * @throws \InvalidArgumentException |
|
95 | + */ |
|
96 | + protected function getMediaModule() |
|
97 | + { |
|
98 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -19,120 +19,120 @@ |
||
19 | 19 | class StorageMenu extends AbstractComponentView |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Renders a dropdown menu for storage. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function render() |
|
28 | - { |
|
29 | - |
|
30 | - $output = ''; |
|
31 | - if ($this->isDisplayed()) { |
|
32 | - $this->loadRequireJsCode(); |
|
33 | - |
|
34 | - $output = $this->renderStorageMenu(); |
|
35 | - } |
|
36 | - |
|
37 | - return $output; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - protected function isDisplayed() |
|
44 | - { |
|
45 | - $isDisplayed = !$this->getMediaModule()->hasFolderTree() || $this->getModuleLoader()->hasPlugin(); |
|
46 | - return $isDisplayed; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - protected function renderStorageMenu() |
|
53 | - { |
|
54 | - |
|
55 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
56 | - |
|
57 | - /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */ |
|
58 | - $options = ''; |
|
59 | - foreach ($this->getMediaModule()->getAllowedStorages() as $storage) { |
|
60 | - $selected = ''; |
|
61 | - if ($currentStorage->getUid() == $storage->getUid()) { |
|
62 | - $selected = 'selected'; |
|
63 | - } |
|
64 | - $options .= sprintf('<option value="%s" %s>%s %s</option>', |
|
65 | - $storage->getUid(), |
|
66 | - $selected, |
|
67 | - $storage->getName(), |
|
68 | - $storage->isOnline() ? |
|
69 | - '' : |
|
70 | - '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
71 | - ); |
|
72 | - } |
|
73 | - |
|
74 | - $parameters = GeneralUtility::_GET(); |
|
75 | - $inputs = ''; |
|
76 | - foreach ($parameters as $parameter => $value) { |
|
77 | - list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
|
78 | - if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
79 | - $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - $template = '<form action="%s" id="form-menu-storage" method="get"> |
|
22 | + /** |
|
23 | + * Renders a dropdown menu for storage. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function render() |
|
28 | + { |
|
29 | + |
|
30 | + $output = ''; |
|
31 | + if ($this->isDisplayed()) { |
|
32 | + $this->loadRequireJsCode(); |
|
33 | + |
|
34 | + $output = $this->renderStorageMenu(); |
|
35 | + } |
|
36 | + |
|
37 | + return $output; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + protected function isDisplayed() |
|
44 | + { |
|
45 | + $isDisplayed = !$this->getMediaModule()->hasFolderTree() || $this->getModuleLoader()->hasPlugin(); |
|
46 | + return $isDisplayed; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + protected function renderStorageMenu() |
|
53 | + { |
|
54 | + |
|
55 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
56 | + |
|
57 | + /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */ |
|
58 | + $options = ''; |
|
59 | + foreach ($this->getMediaModule()->getAllowedStorages() as $storage) { |
|
60 | + $selected = ''; |
|
61 | + if ($currentStorage->getUid() == $storage->getUid()) { |
|
62 | + $selected = 'selected'; |
|
63 | + } |
|
64 | + $options .= sprintf('<option value="%s" %s>%s %s</option>', |
|
65 | + $storage->getUid(), |
|
66 | + $selected, |
|
67 | + $storage->getName(), |
|
68 | + $storage->isOnline() ? |
|
69 | + '' : |
|
70 | + '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
71 | + ); |
|
72 | + } |
|
73 | + |
|
74 | + $parameters = GeneralUtility::_GET(); |
|
75 | + $inputs = ''; |
|
76 | + foreach ($parameters as $parameter => $value) { |
|
77 | + list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
|
78 | + if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
79 | + $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + $template = '<form action="%s" id="form-menu-storage" method="get"> |
|
84 | 84 | %s |
85 | 85 | <select name="%s[storage]" class="form-control" style="padding-right: 20px" id="menu-storage" onchange="$(\'#form-menu-storage\').submit()">%s</select> |
86 | 86 | </form>'; |
87 | 87 | |
88 | - return sprintf( |
|
89 | - $template, |
|
90 | - $this->getModuleLoader()->getModuleUrl(), |
|
91 | - $inputs, |
|
92 | - $this->getModuleLoader()->getParameterPrefix(), |
|
93 | - $options |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - protected function loadRequireJsCode() |
|
101 | - { |
|
102 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
103 | - |
|
104 | - $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
105 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
106 | - $pageRenderer->loadRequireJsModule('Fab/Media/EditStorage'); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Compute parameter and value to be correctly encoded by the browser. |
|
111 | - * |
|
112 | - * @param string $parameter |
|
113 | - * @param mixed $value |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - protected function computeParameterAndValue($parameter, $value) |
|
117 | - { |
|
118 | - |
|
119 | - if (is_string($value)) { |
|
120 | - $result = array($parameter, $value); |
|
121 | - } else { |
|
122 | - $key = key($value); |
|
123 | - $value = current($value); |
|
124 | - $parameter = sprintf('%s[%s]', $parameter, $key); |
|
125 | - $result = $this->computeParameterAndValue($parameter, $value); |
|
126 | - } |
|
127 | - return $result; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return MediaModule|object |
|
132 | - */ |
|
133 | - protected function getMediaModule() |
|
134 | - { |
|
135 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
136 | - } |
|
88 | + return sprintf( |
|
89 | + $template, |
|
90 | + $this->getModuleLoader()->getModuleUrl(), |
|
91 | + $inputs, |
|
92 | + $this->getModuleLoader()->getParameterPrefix(), |
|
93 | + $options |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + protected function loadRequireJsCode() |
|
101 | + { |
|
102 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
103 | + |
|
104 | + $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
105 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
106 | + $pageRenderer->loadRequireJsModule('Fab/Media/EditStorage'); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Compute parameter and value to be correctly encoded by the browser. |
|
111 | + * |
|
112 | + * @param string $parameter |
|
113 | + * @param mixed $value |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + protected function computeParameterAndValue($parameter, $value) |
|
117 | + { |
|
118 | + |
|
119 | + if (is_string($value)) { |
|
120 | + $result = array($parameter, $value); |
|
121 | + } else { |
|
122 | + $key = key($value); |
|
123 | + $value = current($value); |
|
124 | + $parameter = sprintf('%s[%s]', $parameter, $key); |
|
125 | + $result = $this->computeParameterAndValue($parameter, $value); |
|
126 | + } |
|
127 | + return $result; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return MediaModule|object |
|
132 | + */ |
|
133 | + protected function getMediaModule() |
|
134 | + { |
|
135 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | } |
@@ -22,142 +22,142 @@ discard block |
||
22 | 22 | class ConfigurationWarning extends AbstractComponentView |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $notAllowedMountPoints = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * Renders a button for uploading assets. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function render() |
|
36 | - { |
|
37 | - |
|
38 | - $result = ''; |
|
39 | - |
|
40 | - // Check whether storage is configured or not. |
|
41 | - if ($this->checkStorageNotConfigured()) { |
|
42 | - $this->configureStorage(); |
|
43 | - $result .= $this->formatMessageForStorageConfigured(); |
|
44 | - } |
|
45 | - |
|
46 | - // Check whether storage is online or not. |
|
47 | - if ($this->checkStorageOffline()) { |
|
48 | - $result .= $this->formatMessageForStorageOffline(); |
|
49 | - } |
|
50 | - |
|
51 | - // Check all mount points of the storage are available |
|
52 | - if (!$this->checkMountPoints()) { |
|
53 | - $result .= $this->formatMessageForMountPoints(); |
|
54 | - } |
|
55 | - |
|
56 | - // Check all mount points of the storage are available |
|
57 | - if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
58 | - if ($this->canBeInitializedSilently() < 2000) { |
|
59 | - $numberOfFiles = $this->getCacheService()->warmUp(); |
|
60 | - $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
61 | - touch($this->getWarmUpSemaphoreFile()); |
|
62 | - } else { |
|
63 | - $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - return $result; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return \Fab\Media\Cache\CacheService|object |
|
72 | - */ |
|
73 | - protected function getCacheService() |
|
74 | - { |
|
75 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
76 | - } |
|
77 | - |
|
78 | - protected function configureStorage() |
|
79 | - { |
|
80 | - $tableName = 'sys_file_storage'; |
|
81 | - $fields = array( |
|
82 | - 'maximum_dimension_original_image', |
|
83 | - 'extension_allowed_file_type_1', |
|
84 | - 'extension_allowed_file_type_2', |
|
85 | - 'extension_allowed_file_type_3', |
|
86 | - 'extension_allowed_file_type_4', |
|
87 | - 'extension_allowed_file_type_5', |
|
88 | - ); |
|
89 | - |
|
90 | - $values = []; |
|
91 | - foreach ($fields as $field) { |
|
92 | - $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
93 | - } |
|
94 | - |
|
95 | - /** @var ConnectionPool $connectionPool */ |
|
96 | - $connection = GeneralUtility::makeInstance(ConnectionPool::class); |
|
97 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
98 | - $connection->update( |
|
99 | - $tableName, |
|
100 | - $values, |
|
101 | - [ 'uid' => $storage->getUid() ] |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - protected function hasBeenWarmedUp() |
|
109 | - { |
|
110 | - return is_file(($this->getWarmUpSemaphoreFile())); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - protected function getWarmUpSemaphoreFile() |
|
117 | - { |
|
118 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Check whether the storage is correctly configured. |
|
123 | - * |
|
124 | - * @return boolean |
|
125 | - */ |
|
126 | - protected function checkStorageNotConfigured() |
|
127 | - { |
|
128 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
129 | - $storageRecord = $currentStorage->getStorageRecord(); |
|
130 | - |
|
131 | - // Take the storage fields and check whether some data was initialized. |
|
132 | - $fields = array( |
|
133 | - 'extension_allowed_file_type_1', |
|
134 | - 'extension_allowed_file_type_2', |
|
135 | - 'extension_allowed_file_type_3', |
|
136 | - 'extension_allowed_file_type_4', |
|
137 | - 'extension_allowed_file_type_5', |
|
138 | - ); |
|
139 | - |
|
140 | - $result = true; |
|
141 | - foreach ($fields as $fieldName) { |
|
142 | - // true means the storage has data and thus was configured / saved once. |
|
143 | - if (!empty($storageRecord[$fieldName])) { |
|
144 | - $result = false; |
|
145 | - break; |
|
146 | - } |
|
147 | - } |
|
148 | - return $result; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Format a message whenever the storage is offline. |
|
153 | - * |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - protected function formatMessageForStorageConfigured() |
|
157 | - { |
|
158 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
159 | - |
|
160 | - $result = <<< EOF |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $notAllowedMountPoints = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * Renders a button for uploading assets. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function render() |
|
36 | + { |
|
37 | + |
|
38 | + $result = ''; |
|
39 | + |
|
40 | + // Check whether storage is configured or not. |
|
41 | + if ($this->checkStorageNotConfigured()) { |
|
42 | + $this->configureStorage(); |
|
43 | + $result .= $this->formatMessageForStorageConfigured(); |
|
44 | + } |
|
45 | + |
|
46 | + // Check whether storage is online or not. |
|
47 | + if ($this->checkStorageOffline()) { |
|
48 | + $result .= $this->formatMessageForStorageOffline(); |
|
49 | + } |
|
50 | + |
|
51 | + // Check all mount points of the storage are available |
|
52 | + if (!$this->checkMountPoints()) { |
|
53 | + $result .= $this->formatMessageForMountPoints(); |
|
54 | + } |
|
55 | + |
|
56 | + // Check all mount points of the storage are available |
|
57 | + if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
58 | + if ($this->canBeInitializedSilently() < 2000) { |
|
59 | + $numberOfFiles = $this->getCacheService()->warmUp(); |
|
60 | + $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
61 | + touch($this->getWarmUpSemaphoreFile()); |
|
62 | + } else { |
|
63 | + $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + return $result; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return \Fab\Media\Cache\CacheService|object |
|
72 | + */ |
|
73 | + protected function getCacheService() |
|
74 | + { |
|
75 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
76 | + } |
|
77 | + |
|
78 | + protected function configureStorage() |
|
79 | + { |
|
80 | + $tableName = 'sys_file_storage'; |
|
81 | + $fields = array( |
|
82 | + 'maximum_dimension_original_image', |
|
83 | + 'extension_allowed_file_type_1', |
|
84 | + 'extension_allowed_file_type_2', |
|
85 | + 'extension_allowed_file_type_3', |
|
86 | + 'extension_allowed_file_type_4', |
|
87 | + 'extension_allowed_file_type_5', |
|
88 | + ); |
|
89 | + |
|
90 | + $values = []; |
|
91 | + foreach ($fields as $field) { |
|
92 | + $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
93 | + } |
|
94 | + |
|
95 | + /** @var ConnectionPool $connectionPool */ |
|
96 | + $connection = GeneralUtility::makeInstance(ConnectionPool::class); |
|
97 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
98 | + $connection->update( |
|
99 | + $tableName, |
|
100 | + $values, |
|
101 | + [ 'uid' => $storage->getUid() ] |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + protected function hasBeenWarmedUp() |
|
109 | + { |
|
110 | + return is_file(($this->getWarmUpSemaphoreFile())); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + protected function getWarmUpSemaphoreFile() |
|
117 | + { |
|
118 | + return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Check whether the storage is correctly configured. |
|
123 | + * |
|
124 | + * @return boolean |
|
125 | + */ |
|
126 | + protected function checkStorageNotConfigured() |
|
127 | + { |
|
128 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
129 | + $storageRecord = $currentStorage->getStorageRecord(); |
|
130 | + |
|
131 | + // Take the storage fields and check whether some data was initialized. |
|
132 | + $fields = array( |
|
133 | + 'extension_allowed_file_type_1', |
|
134 | + 'extension_allowed_file_type_2', |
|
135 | + 'extension_allowed_file_type_3', |
|
136 | + 'extension_allowed_file_type_4', |
|
137 | + 'extension_allowed_file_type_5', |
|
138 | + ); |
|
139 | + |
|
140 | + $result = true; |
|
141 | + foreach ($fields as $fieldName) { |
|
142 | + // true means the storage has data and thus was configured / saved once. |
|
143 | + if (!empty($storageRecord[$fieldName])) { |
|
144 | + $result = false; |
|
145 | + break; |
|
146 | + } |
|
147 | + } |
|
148 | + return $result; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Format a message whenever the storage is offline. |
|
153 | + * |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + protected function formatMessageForStorageConfigured() |
|
157 | + { |
|
158 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
159 | + |
|
160 | + $result = <<< EOF |
|
161 | 161 | <div class="alert alert-info"> |
162 | 162 | <div class="alert-title"> |
163 | 163 | Storage has been configured. |
@@ -170,29 +170,29 @@ discard block |
||
170 | 170 | </div> |
171 | 171 | EOF; |
172 | 172 | |
173 | - return $result; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Check whether the storage is online or not. |
|
178 | - * |
|
179 | - * @return boolean |
|
180 | - */ |
|
181 | - protected function checkStorageOffline() |
|
182 | - { |
|
183 | - return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Format a message whenever the storage is offline. |
|
188 | - * |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - protected function formatMessageForStorageOffline() |
|
192 | - { |
|
193 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
194 | - |
|
195 | - $result = <<< EOF |
|
173 | + return $result; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Check whether the storage is online or not. |
|
178 | + * |
|
179 | + * @return boolean |
|
180 | + */ |
|
181 | + protected function checkStorageOffline() |
|
182 | + { |
|
183 | + return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Format a message whenever the storage is offline. |
|
188 | + * |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + protected function formatMessageForStorageOffline() |
|
192 | + { |
|
193 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
194 | + |
|
195 | + $result = <<< EOF |
|
196 | 196 | <div class="alert alert-warning"> |
197 | 197 | <div class="alert-title"> |
198 | 198 | Storage is currently offline |
@@ -204,85 +204,85 @@ discard block |
||
204 | 204 | </div> |
205 | 205 | EOF; |
206 | 206 | |
207 | - return $result; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Check whether mount points privilege are ok. |
|
212 | - * |
|
213 | - * @return boolean |
|
214 | - */ |
|
215 | - protected function checkMountPoints() |
|
216 | - { |
|
217 | - if (!$this->getBackendUser()->isAdmin()) { |
|
218 | - |
|
219 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
220 | - |
|
221 | - $fileMountIdentifiers = []; |
|
222 | - foreach ($fileMounts as $fileMount) { |
|
223 | - $fileMountIdentifiers[] = $fileMount['uid']; |
|
224 | - } |
|
225 | - |
|
226 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
227 | - $storageRecord = $storage->getStorageRecord(); |
|
228 | - $fieldNames = array( |
|
229 | - 'mount_point_file_type_1', |
|
230 | - 'mount_point_file_type_2', |
|
231 | - 'mount_point_file_type_3', |
|
232 | - 'mount_point_file_type_4', |
|
233 | - 'mount_point_file_type_5', |
|
234 | - ); |
|
235 | - foreach ($fieldNames as $fileName) { |
|
236 | - $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
237 | - if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
238 | - $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
239 | - } else { |
|
240 | - # $fileMountIdentifier |
|
241 | - $folder = $storage->getRootLevelFolder(); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - return empty($this->notAllowedMountPoints); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Return a mount point according to an file mount identifier. |
|
250 | - * |
|
251 | - * @param string $identifier |
|
252 | - * @return array |
|
253 | - */ |
|
254 | - protected function fetchMountPoint($identifier) |
|
255 | - { |
|
256 | - /** @var QueryBuilder $queryBuilder */ |
|
257 | - $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
258 | - return $queryBuilder |
|
259 | - ->select('*') |
|
260 | - ->from('sys_filemounts') |
|
261 | - ->where('uid = ' . $identifier) |
|
262 | - ->execute() |
|
263 | - ->fetch(); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Format a message whenever mount points privilege are not OK. |
|
268 | - * |
|
269 | - * @return string |
|
270 | - */ |
|
271 | - protected function formatMessageForMountPoints() |
|
272 | - { |
|
273 | - |
|
274 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
275 | - $backendUser = $this->getBackendUser(); |
|
276 | - |
|
277 | - foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
278 | - $list = sprintf('<li>"%s" with path %s</li>', |
|
279 | - $notAllowedMountPoints['title'], |
|
280 | - $notAllowedMountPoints['path'] |
|
281 | - ); |
|
282 | - |
|
283 | - } |
|
284 | - |
|
285 | - $result = <<< EOF |
|
207 | + return $result; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Check whether mount points privilege are ok. |
|
212 | + * |
|
213 | + * @return boolean |
|
214 | + */ |
|
215 | + protected function checkMountPoints() |
|
216 | + { |
|
217 | + if (!$this->getBackendUser()->isAdmin()) { |
|
218 | + |
|
219 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
220 | + |
|
221 | + $fileMountIdentifiers = []; |
|
222 | + foreach ($fileMounts as $fileMount) { |
|
223 | + $fileMountIdentifiers[] = $fileMount['uid']; |
|
224 | + } |
|
225 | + |
|
226 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
227 | + $storageRecord = $storage->getStorageRecord(); |
|
228 | + $fieldNames = array( |
|
229 | + 'mount_point_file_type_1', |
|
230 | + 'mount_point_file_type_2', |
|
231 | + 'mount_point_file_type_3', |
|
232 | + 'mount_point_file_type_4', |
|
233 | + 'mount_point_file_type_5', |
|
234 | + ); |
|
235 | + foreach ($fieldNames as $fileName) { |
|
236 | + $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
237 | + if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
238 | + $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
239 | + } else { |
|
240 | + # $fileMountIdentifier |
|
241 | + $folder = $storage->getRootLevelFolder(); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + return empty($this->notAllowedMountPoints); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Return a mount point according to an file mount identifier. |
|
250 | + * |
|
251 | + * @param string $identifier |
|
252 | + * @return array |
|
253 | + */ |
|
254 | + protected function fetchMountPoint($identifier) |
|
255 | + { |
|
256 | + /** @var QueryBuilder $queryBuilder */ |
|
257 | + $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
258 | + return $queryBuilder |
|
259 | + ->select('*') |
|
260 | + ->from('sys_filemounts') |
|
261 | + ->where('uid = ' . $identifier) |
|
262 | + ->execute() |
|
263 | + ->fetch(); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Format a message whenever mount points privilege are not OK. |
|
268 | + * |
|
269 | + * @return string |
|
270 | + */ |
|
271 | + protected function formatMessageForMountPoints() |
|
272 | + { |
|
273 | + |
|
274 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
275 | + $backendUser = $this->getBackendUser(); |
|
276 | + |
|
277 | + foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
278 | + $list = sprintf('<li>"%s" with path %s</li>', |
|
279 | + $notAllowedMountPoints['title'], |
|
280 | + $notAllowedMountPoints['path'] |
|
281 | + ); |
|
282 | + |
|
283 | + } |
|
284 | + |
|
285 | + $result = <<< EOF |
|
286 | 286 | <div class="alert alert-warning"> |
287 | 287 | <div class="alert-title"> |
288 | 288 | File mount are wrongly configured for user "{$backendUser->user['username']}". |
@@ -297,54 +297,54 @@ discard block |
||
297 | 297 | </div> |
298 | 298 | EOF; |
299 | 299 | |
300 | - return $result; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * @return boolean |
|
305 | - */ |
|
306 | - protected function canBeInitializedSilently() |
|
307 | - { |
|
308 | - /** @var QueryBuilder $queryBuilder */ |
|
309 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
310 | - $count = $queryBuilder |
|
311 | - ->count('*') |
|
312 | - ->from('sys_file') |
|
313 | - ->execute() |
|
314 | - ->fetchColumn(0); |
|
315 | - return (int)$count; |
|
316 | - |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Check whether the column "total_of_references" has been already processed once. |
|
321 | - * |
|
322 | - * @return boolean |
|
323 | - */ |
|
324 | - protected function checkColumnNumberOfReferences() |
|
325 | - { |
|
326 | - /** @var QueryBuilder $queryBuilder */ |
|
327 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
328 | - $file = $queryBuilder |
|
329 | - ->select('*') |
|
330 | - ->from('sys_file') |
|
331 | - ->where('number_of_references > 0') |
|
332 | - ->execute() |
|
333 | - ->fetch(); |
|
334 | - |
|
335 | - return !empty($file); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Format a message if columns "total_of_references" looks wrong. |
|
340 | - * |
|
341 | - * @param int $numberOfFile |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
345 | - { |
|
346 | - |
|
347 | - $result = <<< EOF |
|
300 | + return $result; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * @return boolean |
|
305 | + */ |
|
306 | + protected function canBeInitializedSilently() |
|
307 | + { |
|
308 | + /** @var QueryBuilder $queryBuilder */ |
|
309 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
310 | + $count = $queryBuilder |
|
311 | + ->count('*') |
|
312 | + ->from('sys_file') |
|
313 | + ->execute() |
|
314 | + ->fetchColumn(0); |
|
315 | + return (int)$count; |
|
316 | + |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Check whether the column "total_of_references" has been already processed once. |
|
321 | + * |
|
322 | + * @return boolean |
|
323 | + */ |
|
324 | + protected function checkColumnNumberOfReferences() |
|
325 | + { |
|
326 | + /** @var QueryBuilder $queryBuilder */ |
|
327 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
328 | + $file = $queryBuilder |
|
329 | + ->select('*') |
|
330 | + ->from('sys_file') |
|
331 | + ->where('number_of_references > 0') |
|
332 | + ->execute() |
|
333 | + ->fetch(); |
|
334 | + |
|
335 | + return !empty($file); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Format a message if columns "total_of_references" looks wrong. |
|
340 | + * |
|
341 | + * @param int $numberOfFile |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
345 | + { |
|
346 | + |
|
347 | + $result = <<< EOF |
|
348 | 348 | <div class="alert alert-success"> |
349 | 349 | <div class="alert-title"> |
350 | 350 | Initialized column "number_of_references" for ${numberOfFile} files |
@@ -361,19 +361,19 @@ discard block |
||
361 | 361 | </div> |
362 | 362 | EOF; |
363 | 363 | |
364 | - return $result; |
|
365 | - } |
|
364 | + return $result; |
|
365 | + } |
|
366 | 366 | |
367 | 367 | |
368 | - /** |
|
369 | - * Format a message if columns "total_of_references" looks wrong. |
|
370 | - * |
|
371 | - * @return string |
|
372 | - */ |
|
373 | - protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
374 | - { |
|
368 | + /** |
|
369 | + * Format a message if columns "total_of_references" looks wrong. |
|
370 | + * |
|
371 | + * @return string |
|
372 | + */ |
|
373 | + protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
374 | + { |
|
375 | 375 | |
376 | - $result = <<< EOF |
|
376 | + $result = <<< EOF |
|
377 | 377 | <div class="alert alert-warning"> |
378 | 378 | <div class="alert-title"> |
379 | 379 | Column "number_of_references" requires to be initialized. |
@@ -392,36 +392,36 @@ discard block |
||
392 | 392 | </div> |
393 | 393 | EOF; |
394 | 394 | |
395 | - return $result; |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Returns an instance of the current Backend User. |
|
400 | - * |
|
401 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
402 | - */ |
|
403 | - protected function getBackendUser() |
|
404 | - { |
|
405 | - return $GLOBALS['BE_USER']; |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * @param string $tableName |
|
410 | - * @return object|QueryBuilder |
|
411 | - */ |
|
412 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
413 | - { |
|
414 | - /** @var ConnectionPool $connectionPool */ |
|
415 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
416 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * @return MediaModule|object |
|
421 | - */ |
|
422 | - protected function getMediaModule() |
|
423 | - { |
|
424 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
425 | - } |
|
395 | + return $result; |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Returns an instance of the current Backend User. |
|
400 | + * |
|
401 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
402 | + */ |
|
403 | + protected function getBackendUser() |
|
404 | + { |
|
405 | + return $GLOBALS['BE_USER']; |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * @param string $tableName |
|
410 | + * @return object|QueryBuilder |
|
411 | + */ |
|
412 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
413 | + { |
|
414 | + /** @var ConnectionPool $connectionPool */ |
|
415 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
416 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * @return MediaModule|object |
|
421 | + */ |
|
422 | + protected function getMediaModule() |
|
423 | + { |
|
424 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
425 | + } |
|
426 | 426 | |
427 | 427 | } |
@@ -18,78 +18,78 @@ |
||
18 | 18 | class Path |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - static protected $extensionName = 'media'; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + static protected $extensionName = 'media'; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Return a public path pointing to a resource. |
|
28 | - * |
|
29 | - * @param string $resource |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - static public function getRelativePath($resource) |
|
33 | - { |
|
26 | + /** |
|
27 | + * Return a public path pointing to a resource. |
|
28 | + * |
|
29 | + * @param string $resource |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + static public function getRelativePath($resource) |
|
33 | + { |
|
34 | 34 | |
35 | - // If file is not found, resolve the path |
|
36 | - if (!is_file(Environment::getPublicPath() . '/' . $resource)) { |
|
37 | - $resource = substr(self::resolvePath($resource), strlen(Environment::getPublicPath() . '/')); |
|
38 | - } |
|
35 | + // If file is not found, resolve the path |
|
36 | + if (!is_file(Environment::getPublicPath() . '/' . $resource)) { |
|
37 | + $resource = substr(self::resolvePath($resource), strlen(Environment::getPublicPath() . '/')); |
|
38 | + } |
|
39 | 39 | |
40 | - return PathUtility::getRelativePathTo(PathUtility::dirname(Environment::getPublicPath() . '/' . $resource)) . PathUtility::basename($resource); |
|
41 | - } |
|
40 | + return PathUtility::getRelativePathTo(PathUtility::dirname(Environment::getPublicPath() . '/' . $resource)) . PathUtility::basename($resource); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Resolves path e.g. EXT:media/Resources/Public/foo.png or ../../foo and returns an absolute path to the given resource. |
|
45 | - * |
|
46 | - * @param string $resource |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - static public function resolvePath($resource) |
|
50 | - { |
|
51 | - $resource = self::canonicalPath($resource); |
|
52 | - if (!is_file(Environment::getPublicPath() . '/' . $resource)) { |
|
53 | - $resource = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored(self::$extensionName) . '/Resources/Public/' . $resource; |
|
54 | - } |
|
55 | - return GeneralUtility::getFileAbsFileName($resource); |
|
56 | - } |
|
43 | + /** |
|
44 | + * Resolves path e.g. EXT:media/Resources/Public/foo.png or ../../foo and returns an absolute path to the given resource. |
|
45 | + * |
|
46 | + * @param string $resource |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + static public function resolvePath($resource) |
|
50 | + { |
|
51 | + $resource = self::canonicalPath($resource); |
|
52 | + if (!is_file(Environment::getPublicPath() . '/' . $resource)) { |
|
53 | + $resource = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored(self::$extensionName) . '/Resources/Public/' . $resource; |
|
54 | + } |
|
55 | + return GeneralUtility::getFileAbsFileName($resource); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Tell whether a resource exist. |
|
60 | - * |
|
61 | - * @param string $resource |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - static public function exists($resource) |
|
65 | - { |
|
66 | - return is_file(self::resolvePath($resource)); |
|
67 | - } |
|
58 | + /** |
|
59 | + * Tell whether a resource exist. |
|
60 | + * |
|
61 | + * @param string $resource |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + static public function exists($resource) |
|
65 | + { |
|
66 | + return is_file(self::resolvePath($resource)); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Tell whether a resource does not exist. |
|
71 | - * |
|
72 | - * @param string $resource |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - static public function notExists($resource) |
|
76 | - { |
|
77 | - return !self::exists($resource); |
|
78 | - } |
|
69 | + /** |
|
70 | + * Tell whether a resource does not exist. |
|
71 | + * |
|
72 | + * @param string $resource |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + static public function notExists($resource) |
|
76 | + { |
|
77 | + return !self::exists($resource); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Returns a canonical path by stripping relative segment ../foo/../bar will become foo/bar |
|
82 | - * |
|
83 | - * @param $resource |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - static public function canonicalPath($resource) |
|
87 | - { |
|
88 | - $segments = explode('/', $resource); |
|
89 | - $keys = array_keys($segments, '..'); |
|
90 | - foreach ($keys as $key) { |
|
91 | - unset($segments[$key]); |
|
92 | - } |
|
93 | - return implode('/', $segments); |
|
94 | - } |
|
80 | + /** |
|
81 | + * Returns a canonical path by stripping relative segment ../foo/../bar will become foo/bar |
|
82 | + * |
|
83 | + * @param $resource |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + static public function canonicalPath($resource) |
|
87 | + { |
|
88 | + $segments = explode('/', $resource); |
|
89 | + $keys = array_keys($segments, '..'); |
|
90 | + foreach ($keys as $key) { |
|
91 | + unset($segments[$key]); |
|
92 | + } |
|
93 | + return implode('/', $segments); |
|
94 | + } |
|
95 | 95 | } |
@@ -22,129 +22,129 @@ |
||
22 | 22 | class MissingFilesFinderTool extends AbstractTool |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Display the title of the tool on the welcome screen. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function getTitle() |
|
31 | - { |
|
32 | - return 'Find missing files'; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Display the description of the tool in the welcome screen. |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getDescription() |
|
41 | - { |
|
42 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
|
43 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
44 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
45 | - return $view->render(); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Do the job: analyse Index. |
|
50 | - * |
|
51 | - * @param array $arguments |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function work(array $arguments = []) |
|
55 | - { |
|
56 | - |
|
57 | - // Possible clean up of missing files if the User has clicked so. |
|
58 | - if (!empty($arguments['deleteMissingFiles'])) { |
|
59 | - $this->deleteMissingFilesAction($arguments['files']); |
|
60 | - } |
|
61 | - |
|
62 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/WorkResult.html'; |
|
63 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
64 | - |
|
65 | - $missingReports = []; |
|
66 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
67 | - |
|
68 | - if ($storage->isOnline()) { |
|
69 | - $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
70 | - |
|
71 | - $missingReports[] = array( |
|
72 | - 'storage' => $storage, |
|
73 | - 'missingFiles' => $missingFiles, |
|
74 | - 'numberOfMissingFiles' => count($missingFiles), |
|
75 | - ); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - $view->assign('missingReports', $missingReports); |
|
80 | - |
|
81 | - return $view->render(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Delete files given as parameter. |
|
86 | - * This is a special case as we have a missing file in the file system |
|
87 | - * As a result, we can't use $fileObject->delete(); which will |
|
88 | - * raise exception "Error while fetching permissions". |
|
89 | - * |
|
90 | - * @param array $files |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - protected function deleteMissingFilesAction(array $files = []) |
|
94 | - { |
|
95 | - |
|
96 | - foreach ($files as $fileUid) { |
|
97 | - |
|
98 | - /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
99 | - try { |
|
100 | - $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
101 | - if ($file) { |
|
102 | - // The case is special as we have a missing file in the file system |
|
103 | - // As a result, we can't use $fileObject->delete(); which will |
|
104 | - // raise exception "Error while fetching permissions" |
|
105 | - $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
106 | - } |
|
107 | - } catch (\Exception $e) { |
|
108 | - continue; |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Return a pointer to the database. |
|
115 | - * |
|
116 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
117 | - */ |
|
118 | - protected function getIndexAnalyser() |
|
119 | - { |
|
120 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @return StorageRepository|object |
|
125 | - */ |
|
126 | - protected function getStorageRepository() |
|
127 | - { |
|
128 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Tell whether the tools should be displayed according to the context. |
|
133 | - * |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function isShown() |
|
137 | - { |
|
138 | - return $this->getBackendUser()->isAdmin(); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return object|DataService |
|
143 | - */ |
|
144 | - protected function getDataService(): DataService |
|
145 | - { |
|
146 | - return GeneralUtility::makeInstance(DataService::class); |
|
147 | - } |
|
25 | + /** |
|
26 | + * Display the title of the tool on the welcome screen. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function getTitle() |
|
31 | + { |
|
32 | + return 'Find missing files'; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Display the description of the tool in the welcome screen. |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getDescription() |
|
41 | + { |
|
42 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
|
43 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
44 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
45 | + return $view->render(); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Do the job: analyse Index. |
|
50 | + * |
|
51 | + * @param array $arguments |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function work(array $arguments = []) |
|
55 | + { |
|
56 | + |
|
57 | + // Possible clean up of missing files if the User has clicked so. |
|
58 | + if (!empty($arguments['deleteMissingFiles'])) { |
|
59 | + $this->deleteMissingFilesAction($arguments['files']); |
|
60 | + } |
|
61 | + |
|
62 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/WorkResult.html'; |
|
63 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
64 | + |
|
65 | + $missingReports = []; |
|
66 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
67 | + |
|
68 | + if ($storage->isOnline()) { |
|
69 | + $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
70 | + |
|
71 | + $missingReports[] = array( |
|
72 | + 'storage' => $storage, |
|
73 | + 'missingFiles' => $missingFiles, |
|
74 | + 'numberOfMissingFiles' => count($missingFiles), |
|
75 | + ); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + $view->assign('missingReports', $missingReports); |
|
80 | + |
|
81 | + return $view->render(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Delete files given as parameter. |
|
86 | + * This is a special case as we have a missing file in the file system |
|
87 | + * As a result, we can't use $fileObject->delete(); which will |
|
88 | + * raise exception "Error while fetching permissions". |
|
89 | + * |
|
90 | + * @param array $files |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + protected function deleteMissingFilesAction(array $files = []) |
|
94 | + { |
|
95 | + |
|
96 | + foreach ($files as $fileUid) { |
|
97 | + |
|
98 | + /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
99 | + try { |
|
100 | + $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
101 | + if ($file) { |
|
102 | + // The case is special as we have a missing file in the file system |
|
103 | + // As a result, we can't use $fileObject->delete(); which will |
|
104 | + // raise exception "Error while fetching permissions" |
|
105 | + $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
106 | + } |
|
107 | + } catch (\Exception $e) { |
|
108 | + continue; |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Return a pointer to the database. |
|
115 | + * |
|
116 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
117 | + */ |
|
118 | + protected function getIndexAnalyser() |
|
119 | + { |
|
120 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @return StorageRepository|object |
|
125 | + */ |
|
126 | + protected function getStorageRepository() |
|
127 | + { |
|
128 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Tell whether the tools should be displayed according to the context. |
|
133 | + * |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function isShown() |
|
137 | + { |
|
138 | + return $this->getBackendUser()->isAdmin(); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return object|DataService |
|
143 | + */ |
|
144 | + protected function getDataService(): DataService |
|
145 | + { |
|
146 | + return GeneralUtility::makeInstance(DataService::class); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | } |
150 | 150 |
@@ -21,206 +21,206 @@ |
||
21 | 21 | class DuplicateFilesFinderTool extends AbstractTool |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Display the title of the tool on the welcome screen. |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function getTitle() |
|
30 | - { |
|
31 | - return 'Find duplicate Files'; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Display the description of the tool in the welcome screen. |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function getDescription() |
|
40 | - { |
|
41 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
|
42 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
43 | - $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
|
44 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
45 | - return $view->render(); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Do the job: analyse Index. |
|
50 | - * |
|
51 | - * @param array $arguments |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function work(array $arguments = []) |
|
55 | - { |
|
56 | - |
|
57 | - // Possible clean up of missing files if the User has clicked so. |
|
58 | - if (!empty($arguments['deleteDuplicateFiles'])) { |
|
59 | - $this->deleteMissingFilesAction($arguments['files']); |
|
60 | - } |
|
61 | - |
|
62 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/WorkResult.html'; |
|
63 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
64 | - |
|
65 | - $duplicateFilesReports = []; |
|
66 | - |
|
67 | - if ($this->getBackendUser()->isAdmin()) { |
|
68 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
69 | - if ($storage->isOnline()) { |
|
70 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
71 | - $duplicateFilesReports[] = array( |
|
72 | - 'storage' => $storage, |
|
73 | - 'duplicateFiles' => $duplicateFiles, |
|
74 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
75 | - ); |
|
76 | - } |
|
77 | - } |
|
78 | - } else { |
|
79 | - |
|
80 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
81 | - |
|
82 | - $allowedStorages = []; |
|
83 | - foreach ($fileMounts as $fileMount) { |
|
84 | - if ((bool)$fileMount['read_only']) { |
|
85 | - continue; |
|
86 | - } |
|
87 | - |
|
88 | - if (!isset($allowedStorages[$fileMount['base']])) { |
|
89 | - $allowedStorages[$fileMount['base']] = []; |
|
90 | - } |
|
91 | - if (!in_array($fileMount['base'], $allowedStorages)) { |
|
92 | - $allowedStorages[$fileMount['base']][] = $fileMount['path']; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - foreach ($allowedStorages as $storageIdentifier => $allowedMountPoints) { |
|
97 | - $storage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier); |
|
98 | - |
|
99 | - if ($storage->isOnline()) { |
|
100 | - |
|
101 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
102 | - |
|
103 | - // Filter duplicates files |
|
104 | - foreach ($duplicateFiles as $key => $files) { |
|
105 | - |
|
106 | - $filteredFiles = []; |
|
107 | - foreach ($files as $file) { |
|
108 | - |
|
109 | - foreach ($allowedMountPoints as $allowedMountPoint) { |
|
110 | - |
|
111 | - $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
112 | - if (preg_match($pattern, $file['identifier'])) { |
|
113 | - $filteredFiles[] = $file; |
|
114 | - break; // no need to further loop around, stop the loop. |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - // We need more than 1 files to be shown as duplicate. |
|
120 | - if (count($filteredFiles) > 1) { |
|
121 | - $duplicateFiles[$key] = $filteredFiles; |
|
122 | - } else { |
|
123 | - unset($duplicateFiles[$key]); |
|
124 | - } |
|
125 | - } |
|
126 | - $duplicateFilesReports[] = array( |
|
127 | - 'storage' => $storage, |
|
128 | - 'duplicateFiles' => $duplicateFiles, |
|
129 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
130 | - ); |
|
131 | - |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - $view->assign('duplicateFilesReports', $duplicateFilesReports); |
|
137 | - |
|
138 | - return $view->render(); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Delete files given as parameter. |
|
143 | - * This is a special case as we have a missing file in the file system |
|
144 | - * As a result, we can't use $fileObject->delete(); which will |
|
145 | - * raise exception "Error while fetching permissions". |
|
146 | - * |
|
147 | - * @param array $files |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - protected function deleteMissingFilesAction(array $files = []) |
|
151 | - { |
|
152 | - |
|
153 | - foreach ($files as $fileUid) { |
|
154 | - |
|
155 | - /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
156 | - try { |
|
157 | - $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
158 | - if ($file->exists()) { |
|
159 | - |
|
160 | - $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
161 | - if ($numberOfReferences === 0) { |
|
162 | - $file->delete(); |
|
163 | - } |
|
164 | - } else { |
|
165 | - $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
166 | - } |
|
167 | - } catch (\Exception $e) { |
|
168 | - continue; |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Return a pointer to the database. |
|
175 | - * |
|
176 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
177 | - */ |
|
178 | - protected function getIndexAnalyser() |
|
179 | - { |
|
180 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
185 | - */ |
|
186 | - protected function getThumbnailGenerator() |
|
187 | - { |
|
188 | - return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @return StorageRepository|object |
|
193 | - */ |
|
194 | - protected function getStorageRepository() |
|
195 | - { |
|
196 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Tell whether the tools should be displayed according to the context. |
|
201 | - * |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function isShown() |
|
205 | - { |
|
206 | - return true; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
211 | - */ |
|
212 | - protected function getFileReferenceService() |
|
213 | - { |
|
214 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @return object|DataService |
|
219 | - */ |
|
220 | - protected function getDataService(): DataService |
|
221 | - { |
|
222 | - return GeneralUtility::makeInstance(DataService::class); |
|
223 | - } |
|
24 | + /** |
|
25 | + * Display the title of the tool on the welcome screen. |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function getTitle() |
|
30 | + { |
|
31 | + return 'Find duplicate Files'; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Display the description of the tool in the welcome screen. |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function getDescription() |
|
40 | + { |
|
41 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
|
42 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
43 | + $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
|
44 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
45 | + return $view->render(); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Do the job: analyse Index. |
|
50 | + * |
|
51 | + * @param array $arguments |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function work(array $arguments = []) |
|
55 | + { |
|
56 | + |
|
57 | + // Possible clean up of missing files if the User has clicked so. |
|
58 | + if (!empty($arguments['deleteDuplicateFiles'])) { |
|
59 | + $this->deleteMissingFilesAction($arguments['files']); |
|
60 | + } |
|
61 | + |
|
62 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/WorkResult.html'; |
|
63 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
64 | + |
|
65 | + $duplicateFilesReports = []; |
|
66 | + |
|
67 | + if ($this->getBackendUser()->isAdmin()) { |
|
68 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
69 | + if ($storage->isOnline()) { |
|
70 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
71 | + $duplicateFilesReports[] = array( |
|
72 | + 'storage' => $storage, |
|
73 | + 'duplicateFiles' => $duplicateFiles, |
|
74 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
75 | + ); |
|
76 | + } |
|
77 | + } |
|
78 | + } else { |
|
79 | + |
|
80 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
81 | + |
|
82 | + $allowedStorages = []; |
|
83 | + foreach ($fileMounts as $fileMount) { |
|
84 | + if ((bool)$fileMount['read_only']) { |
|
85 | + continue; |
|
86 | + } |
|
87 | + |
|
88 | + if (!isset($allowedStorages[$fileMount['base']])) { |
|
89 | + $allowedStorages[$fileMount['base']] = []; |
|
90 | + } |
|
91 | + if (!in_array($fileMount['base'], $allowedStorages)) { |
|
92 | + $allowedStorages[$fileMount['base']][] = $fileMount['path']; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + foreach ($allowedStorages as $storageIdentifier => $allowedMountPoints) { |
|
97 | + $storage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier); |
|
98 | + |
|
99 | + if ($storage->isOnline()) { |
|
100 | + |
|
101 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
102 | + |
|
103 | + // Filter duplicates files |
|
104 | + foreach ($duplicateFiles as $key => $files) { |
|
105 | + |
|
106 | + $filteredFiles = []; |
|
107 | + foreach ($files as $file) { |
|
108 | + |
|
109 | + foreach ($allowedMountPoints as $allowedMountPoint) { |
|
110 | + |
|
111 | + $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
112 | + if (preg_match($pattern, $file['identifier'])) { |
|
113 | + $filteredFiles[] = $file; |
|
114 | + break; // no need to further loop around, stop the loop. |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + // We need more than 1 files to be shown as duplicate. |
|
120 | + if (count($filteredFiles) > 1) { |
|
121 | + $duplicateFiles[$key] = $filteredFiles; |
|
122 | + } else { |
|
123 | + unset($duplicateFiles[$key]); |
|
124 | + } |
|
125 | + } |
|
126 | + $duplicateFilesReports[] = array( |
|
127 | + 'storage' => $storage, |
|
128 | + 'duplicateFiles' => $duplicateFiles, |
|
129 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
130 | + ); |
|
131 | + |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + $view->assign('duplicateFilesReports', $duplicateFilesReports); |
|
137 | + |
|
138 | + return $view->render(); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Delete files given as parameter. |
|
143 | + * This is a special case as we have a missing file in the file system |
|
144 | + * As a result, we can't use $fileObject->delete(); which will |
|
145 | + * raise exception "Error while fetching permissions". |
|
146 | + * |
|
147 | + * @param array $files |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + protected function deleteMissingFilesAction(array $files = []) |
|
151 | + { |
|
152 | + |
|
153 | + foreach ($files as $fileUid) { |
|
154 | + |
|
155 | + /** @var \TYPO3\CMS\Core\Resource\File $file */ |
|
156 | + try { |
|
157 | + $file = ResourceFactory::getInstance()->getFileObject($fileUid); |
|
158 | + if ($file->exists()) { |
|
159 | + |
|
160 | + $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
161 | + if ($numberOfReferences === 0) { |
|
162 | + $file->delete(); |
|
163 | + } |
|
164 | + } else { |
|
165 | + $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
166 | + } |
|
167 | + } catch (\Exception $e) { |
|
168 | + continue; |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Return a pointer to the database. |
|
175 | + * |
|
176 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
177 | + */ |
|
178 | + protected function getIndexAnalyser() |
|
179 | + { |
|
180 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
185 | + */ |
|
186 | + protected function getThumbnailGenerator() |
|
187 | + { |
|
188 | + return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @return StorageRepository|object |
|
193 | + */ |
|
194 | + protected function getStorageRepository() |
|
195 | + { |
|
196 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Tell whether the tools should be displayed according to the context. |
|
201 | + * |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function isShown() |
|
205 | + { |
|
206 | + return true; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
211 | + */ |
|
212 | + protected function getFileReferenceService() |
|
213 | + { |
|
214 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @return object|DataService |
|
219 | + */ |
|
220 | + protected function getDataService(): DataService |
|
221 | + { |
|
222 | + return GeneralUtility::makeInstance(DataService::class); |
|
223 | + } |
|
224 | 224 | |
225 | 225 | } |
226 | 226 |
@@ -20,125 +20,125 @@ |
||
20 | 20 | class ThumbnailGeneratorTool extends AbstractTool |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Display the title of the tool on the welcome screen. |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function getTitle() |
|
29 | - { |
|
30 | - return 'Generate thumbnails'; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Display the description of the tool in the welcome screen. |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getDescription() |
|
39 | - { |
|
40 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/Launcher.html'; |
|
41 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
42 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
43 | - return $view->render(); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Do the job: analyse Index. |
|
48 | - * |
|
49 | - * @param array $arguments |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function work(array $arguments = []) |
|
53 | - { |
|
54 | - |
|
55 | - $reports = []; |
|
56 | - |
|
57 | - $limit = 500; // default value |
|
58 | - $newOffset = 0; |
|
59 | - |
|
60 | - // Possible clean up of missing files if the User has clicked so. |
|
61 | - if (isset($arguments['limit']) && isset($arguments['offset'])) { |
|
62 | - |
|
63 | - $limit = (int)$arguments['limit']; |
|
64 | - $offset = (int)$arguments['offset']; |
|
65 | - |
|
66 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
67 | - |
|
68 | - if ($storage->isOnline()) { |
|
69 | - |
|
70 | - $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
71 | - $thumbnailGenerator |
|
72 | - ->setStorage($storage) |
|
73 | - ->generate($limit, $offset); |
|
74 | - |
|
75 | - $formattedResultSet = []; |
|
76 | - $resultSet = $thumbnailGenerator->getResultSet(); |
|
77 | - $processedFileIdentifiers = $thumbnailGenerator->getNewProcessedFileIdentifiers(); |
|
78 | - |
|
79 | - foreach ($processedFileIdentifiers as $fileIdentifier => $processedFileIdentifier) { |
|
80 | - $result = $resultSet[$fileIdentifier]; |
|
81 | - $formattedResultSet[] = sprintf('* File "%s": %s %s', |
|
82 | - $result['fileUid'], |
|
83 | - $result['fileIdentifier'], |
|
84 | - empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - $reports[] = array( |
|
89 | - 'storage' => $storage, |
|
90 | - 'isStorageOnline' => true, |
|
91 | - 'resultSet' => $formattedResultSet, |
|
92 | - 'numberOfProcessedFiles' => $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
93 | - 'numberOfTraversedFiles' => $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
94 | - 'numberOfMissingFiles' => $thumbnailGenerator->getNumberOfMissingFiles(), |
|
95 | - 'totalNumberOfFiles' => $thumbnailGenerator->getTotalNumberOfFiles(), |
|
96 | - ); |
|
97 | - } else { |
|
98 | - $reports[] = array( |
|
99 | - 'storage' => $storage, |
|
100 | - 'isStorageOnline' => false, |
|
101 | - ); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - $newOffset = $limit + $offset; |
|
106 | - } |
|
107 | - |
|
108 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/WorkResult.html'; |
|
109 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
110 | - |
|
111 | - $view->assign('limit', $limit); |
|
112 | - $view->assign('offset', $newOffset); |
|
113 | - $view->assign('reports', $reports); |
|
114 | - return $view->render(); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
119 | - */ |
|
120 | - protected function getThumbnailGenerator() |
|
121 | - { |
|
122 | - return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return StorageRepository|object |
|
127 | - */ |
|
128 | - protected function getStorageRepository() |
|
129 | - { |
|
130 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Tell whether the tools should be displayed according to the context. |
|
135 | - * |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function isShown() |
|
139 | - { |
|
140 | - return $this->getBackendUser()->isAdmin(); |
|
141 | - } |
|
23 | + /** |
|
24 | + * Display the title of the tool on the welcome screen. |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function getTitle() |
|
29 | + { |
|
30 | + return 'Generate thumbnails'; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Display the description of the tool in the welcome screen. |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getDescription() |
|
39 | + { |
|
40 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/Launcher.html'; |
|
41 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
42 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
43 | + return $view->render(); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Do the job: analyse Index. |
|
48 | + * |
|
49 | + * @param array $arguments |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function work(array $arguments = []) |
|
53 | + { |
|
54 | + |
|
55 | + $reports = []; |
|
56 | + |
|
57 | + $limit = 500; // default value |
|
58 | + $newOffset = 0; |
|
59 | + |
|
60 | + // Possible clean up of missing files if the User has clicked so. |
|
61 | + if (isset($arguments['limit']) && isset($arguments['offset'])) { |
|
62 | + |
|
63 | + $limit = (int)$arguments['limit']; |
|
64 | + $offset = (int)$arguments['offset']; |
|
65 | + |
|
66 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
67 | + |
|
68 | + if ($storage->isOnline()) { |
|
69 | + |
|
70 | + $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
71 | + $thumbnailGenerator |
|
72 | + ->setStorage($storage) |
|
73 | + ->generate($limit, $offset); |
|
74 | + |
|
75 | + $formattedResultSet = []; |
|
76 | + $resultSet = $thumbnailGenerator->getResultSet(); |
|
77 | + $processedFileIdentifiers = $thumbnailGenerator->getNewProcessedFileIdentifiers(); |
|
78 | + |
|
79 | + foreach ($processedFileIdentifiers as $fileIdentifier => $processedFileIdentifier) { |
|
80 | + $result = $resultSet[$fileIdentifier]; |
|
81 | + $formattedResultSet[] = sprintf('* File "%s": %s %s', |
|
82 | + $result['fileUid'], |
|
83 | + $result['fileIdentifier'], |
|
84 | + empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + $reports[] = array( |
|
89 | + 'storage' => $storage, |
|
90 | + 'isStorageOnline' => true, |
|
91 | + 'resultSet' => $formattedResultSet, |
|
92 | + 'numberOfProcessedFiles' => $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
93 | + 'numberOfTraversedFiles' => $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
94 | + 'numberOfMissingFiles' => $thumbnailGenerator->getNumberOfMissingFiles(), |
|
95 | + 'totalNumberOfFiles' => $thumbnailGenerator->getTotalNumberOfFiles(), |
|
96 | + ); |
|
97 | + } else { |
|
98 | + $reports[] = array( |
|
99 | + 'storage' => $storage, |
|
100 | + 'isStorageOnline' => false, |
|
101 | + ); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + $newOffset = $limit + $offset; |
|
106 | + } |
|
107 | + |
|
108 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/WorkResult.html'; |
|
109 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
110 | + |
|
111 | + $view->assign('limit', $limit); |
|
112 | + $view->assign('offset', $newOffset); |
|
113 | + $view->assign('reports', $reports); |
|
114 | + return $view->render(); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
119 | + */ |
|
120 | + protected function getThumbnailGenerator() |
|
121 | + { |
|
122 | + return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return StorageRepository|object |
|
127 | + */ |
|
128 | + protected function getStorageRepository() |
|
129 | + { |
|
130 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Tell whether the tools should be displayed according to the context. |
|
135 | + * |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function isShown() |
|
139 | + { |
|
140 | + return $this->getBackendUser()->isAdmin(); |
|
141 | + } |
|
142 | 142 | |
143 | 143 | } |
144 | 144 |