@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function canResolvesAPath() { |
34 | 34 | $resourceName = uniqid('resource'); |
35 | - $expected = 'media/Resources/Public/' . $resourceName; |
|
35 | + $expected = 'media/Resources/Public/'.$resourceName; |
|
36 | 36 | $actual = \Fab\Media\Utility\Path::resolvePath($resourceName); |
37 | 37 | |
38 | 38 | $this->assertTrue(strpos($actual, $expected) > 0); |
39 | - $this->assertEquals(0, strpos(Environment::getPublicPath() . '/', $expected)); |
|
39 | + $this->assertEquals(0, strpos(Environment::getPublicPath().'/', $expected)); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | public function canReturnsAPublicPath() { |
46 | 46 | |
47 | 47 | $resourceName = uniqid('resource'); |
48 | - $expected = 'media/Resources/Public/' . $resourceName; |
|
48 | + $expected = 'media/Resources/Public/'.$resourceName; |
|
49 | 49 | $actual = \Fab\Media\Utility\Path::getRelativePath($resourceName); |
50 | 50 | |
51 | 51 | $this->assertTrue(strpos($actual, $expected) > 0); |
52 | - $this->assertFalse(strpos(Environment::getPublicPath() . '/', $expected)); |
|
52 | + $this->assertFalse(strpos(Environment::getPublicPath().'/', $expected)); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -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 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $connection->update( |
99 | 99 | $tableName, |
100 | 100 | $values, |
101 | - [ 'uid' => $storage->getUid() ] |
|
101 | + ['uid' => $storage->getUid()] |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | protected function getWarmUpSemaphoreFile() |
117 | 117 | { |
118 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
118 | + return Environment::getPublicPath().'/typo3temp/.media_cache_warmed_up'; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | return $queryBuilder |
259 | 259 | ->select('*') |
260 | 260 | ->from('sys_filemounts') |
261 | - ->where('uid = ' . $identifier) |
|
261 | + ->where('uid = '.$identifier) |
|
262 | 262 | ->execute() |
263 | 263 | ->fetch(); |
264 | 264 | } |
@@ -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 | } |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | { |
34 | 34 | |
35 | 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() . '/')); |
|
36 | + if (!is_file(Environment::getPublicPath().'/'.$resource)) { |
|
37 | + $resource = substr(self::resolvePath($resource), strlen(Environment::getPublicPath().'/')); |
|
38 | 38 | } |
39 | 39 | |
40 | - return PathUtility::getRelativePathTo(PathUtility::dirname(Environment::getPublicPath() . '/' . $resource)) . PathUtility::basename($resource); |
|
40 | + return PathUtility::getRelativePathTo(PathUtility::dirname(Environment::getPublicPath().'/'.$resource)).PathUtility::basename($resource); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | static public function resolvePath($resource) |
50 | 50 | { |
51 | 51 | $resource = self::canonicalPath($resource); |
52 | - if (!is_file(Environment::getPublicPath() . '/' . $resource)) { |
|
53 | - $resource = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored(self::$extensionName) . '/Resources/Public/' . $resource; |
|
52 | + if (!is_file(Environment::getPublicPath().'/'.$resource)) { |
|
53 | + $resource = 'EXT:'.GeneralUtility::camelCaseToLowerCaseUnderscored(self::$extensionName).'/Resources/Public/'.$resource; |
|
54 | 54 | } |
55 | 55 | return GeneralUtility::getFileAbsFileName($resource); |
56 | 56 | } |
@@ -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 |
@@ -41,7 +41,7 @@ |
||
41 | 41 | { |
42 | 42 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
43 | 43 | $view = $this->initializeStandaloneView($templateNameAndPath); |
44 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
44 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
45 | 45 | return $view->render(); |
46 | 46 | } |
47 | 47 |
@@ -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 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateFilesFinder/Launcher.html'; |
42 | 42 | $view = $this->initializeStandaloneView($templateNameAndPath); |
43 | 43 | $view->assign('isAdmin', $this->getBackendUser()->isAdmin()); |
44 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
44 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
45 | 45 | return $view->render(); |
46 | 46 | } |
47 | 47 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | foreach ($allowedMountPoints as $allowedMountPoint) { |
110 | 110 | |
111 | - $pattern = '%^' . $allowedMountPoint . '%isU'; |
|
111 | + $pattern = '%^'.$allowedMountPoint.'%isU'; |
|
112 | 112 | if (preg_match($pattern, $file['identifier'])) { |
113 | 113 | $filteredFiles[] = $file; |
114 | 114 | break; // no need to further loop around, stop the loop. |
@@ -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 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | { |
40 | 40 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/ThumbnailGenerator/Launcher.html'; |
41 | 41 | $view = $this->initializeStandaloneView($templateNameAndPath); |
42 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
42 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
43 | 43 | return $view->render(); |
44 | 44 | } |
45 | 45 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $formattedResultSet[] = sprintf('* File "%s": %s %s', |
82 | 82 | $result['fileUid'], |
83 | 83 | $result['fileIdentifier'], |
84 | - empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
84 | + empty($result['thumbnailUri']) ? '' : ' -> '.$result['thumbnailUri'] |
|
85 | 85 | ); |
86 | 86 | } |
87 | 87 |
@@ -18,73 +18,73 @@ |
||
18 | 18 | class CacheWarmUpTool extends AbstractTool |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Display the title of the tool on the welcome screen. |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getTitle() |
|
27 | - { |
|
28 | - return 'Cache warm up'; |
|
29 | - } |
|
21 | + /** |
|
22 | + * Display the title of the tool on the welcome screen. |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getTitle() |
|
27 | + { |
|
28 | + return 'Cache warm up'; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Display the description of the tool in the welcome screen. |
|
33 | - * |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function getDescription() |
|
37 | - { |
|
38 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/Launcher.html'; |
|
39 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
40 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
41 | - return $view->render(); |
|
42 | - } |
|
31 | + /** |
|
32 | + * Display the description of the tool in the welcome screen. |
|
33 | + * |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function getDescription() |
|
37 | + { |
|
38 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/Launcher.html'; |
|
39 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
40 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
41 | + return $view->render(); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Do the job: warm up the cache. |
|
46 | - * |
|
47 | - * @param array $arguments |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function work(array $arguments = []) |
|
51 | - { |
|
44 | + /** |
|
45 | + * Do the job: warm up the cache. |
|
46 | + * |
|
47 | + * @param array $arguments |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function work(array $arguments = []) |
|
51 | + { |
|
52 | 52 | |
53 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/WorkResult.html'; |
|
54 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
53 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/WorkResult.html'; |
|
54 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
55 | 55 | |
56 | - $numberOfEntries = $this->getCacheService()->warmUp(); |
|
57 | - $view->assign('numberOfEntries', $numberOfEntries); |
|
58 | - touch($this->getWarmUpSemaphorFile()); |
|
56 | + $numberOfEntries = $this->getCacheService()->warmUp(); |
|
57 | + $view->assign('numberOfEntries', $numberOfEntries); |
|
58 | + touch($this->getWarmUpSemaphorFile()); |
|
59 | 59 | |
60 | - return $view->render(); |
|
61 | - } |
|
60 | + return $view->render(); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Tell whether the tools should be displayed according to the context. |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function isShown() |
|
69 | - { |
|
70 | - return $this->getBackendUser()->isAdmin(); |
|
71 | - } |
|
63 | + /** |
|
64 | + * Tell whether the tools should be displayed according to the context. |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function isShown() |
|
69 | + { |
|
70 | + return $this->getBackendUser()->isAdmin(); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - protected function getWarmUpSemaphorFile() |
|
77 | - { |
|
78 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
79 | - } |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + protected function getWarmUpSemaphorFile() |
|
77 | + { |
|
78 | + return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return \Fab\Media\Cache\CacheService|object |
|
83 | - */ |
|
84 | - protected function getCacheService() |
|
85 | - { |
|
86 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
87 | - } |
|
81 | + /** |
|
82 | + * @return \Fab\Media\Cache\CacheService|object |
|
83 | + */ |
|
84 | + protected function getCacheService() |
|
85 | + { |
|
86 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | } |
90 | 90 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/Launcher.html'; |
39 | 39 | $view = $this->initializeStandaloneView($templateNameAndPath); |
40 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
40 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
41 | 41 | return $view->render(); |
42 | 42 | } |
43 | 43 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | protected function getWarmUpSemaphorFile() |
77 | 77 | { |
78 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
78 | + return Environment::getPublicPath().'/typo3temp/.media_cache_warmed_up'; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -20,86 +20,86 @@ |
||
20 | 20 | class DuplicateRecordsFinderTool extends AbstractTool |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Display the title of the tool on the welcome screen. |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function getTitle() |
|
29 | - { |
|
30 | - return 'Find duplicate Records'; |
|
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/DuplicateRecordsFinder/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 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/WorkResult.html'; |
|
56 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
57 | - |
|
58 | - $duplicateRecordsReports = []; |
|
59 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
60 | - |
|
61 | - if ($storage->isOnline()) { |
|
62 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
63 | - $duplicateRecordsReports[] = array( |
|
64 | - 'storage' => $storage, |
|
65 | - 'duplicateFiles' => $duplicateFiles, |
|
66 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
67 | - ); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - $view->assign('duplicateRecordsReports', $duplicateRecordsReports); |
|
72 | - |
|
73 | - return $view->render(); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Return a pointer to the database. |
|
78 | - * |
|
79 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
80 | - */ |
|
81 | - protected function getIndexAnalyser() |
|
82 | - { |
|
83 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @return StorageRepository|object |
|
88 | - */ |
|
89 | - protected function getStorageRepository() |
|
90 | - { |
|
91 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Tell whether the tools should be displayed according to the context. |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function isShown() |
|
100 | - { |
|
101 | - return $this->getBackendUser()->isAdmin(); |
|
102 | - } |
|
23 | + /** |
|
24 | + * Display the title of the tool on the welcome screen. |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function getTitle() |
|
29 | + { |
|
30 | + return 'Find duplicate Records'; |
|
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/DuplicateRecordsFinder/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 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/WorkResult.html'; |
|
56 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
57 | + |
|
58 | + $duplicateRecordsReports = []; |
|
59 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
60 | + |
|
61 | + if ($storage->isOnline()) { |
|
62 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
63 | + $duplicateRecordsReports[] = array( |
|
64 | + 'storage' => $storage, |
|
65 | + 'duplicateFiles' => $duplicateFiles, |
|
66 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
67 | + ); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + $view->assign('duplicateRecordsReports', $duplicateRecordsReports); |
|
72 | + |
|
73 | + return $view->render(); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Return a pointer to the database. |
|
78 | + * |
|
79 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
80 | + */ |
|
81 | + protected function getIndexAnalyser() |
|
82 | + { |
|
83 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @return StorageRepository|object |
|
88 | + */ |
|
89 | + protected function getStorageRepository() |
|
90 | + { |
|
91 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Tell whether the tools should be displayed according to the context. |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function isShown() |
|
100 | + { |
|
101 | + return $this->getBackendUser()->isAdmin(); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } |
105 | 105 |
@@ -39,7 +39,7 @@ |
||
39 | 39 | { |
40 | 40 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/Launcher.html'; |
41 | 41 | $view = $this->initializeStandaloneView($templateNameAndPath); |
42 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
42 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
43 | 43 | return $view->render(); |
44 | 44 | } |
45 | 45 |
@@ -18,154 +18,154 @@ |
||
18 | 18 | class Rotate implements ImageOptimizerInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
23 | - */ |
|
24 | - protected $gifCreator; |
|
25 | - |
|
26 | - /** |
|
27 | - * @return \Fab\Media\FileUpload\Optimizer\Rotate |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
32 | - $this->gifCreator->init(); |
|
33 | - $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Optimize the given uploaded image |
|
38 | - * |
|
39 | - * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
40 | - * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
41 | - */ |
|
42 | - public function optimize($uploadedFile) |
|
43 | - { |
|
44 | - |
|
45 | - $orientation = $this->getOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
46 | - $isRotated = $this->isRotated($orientation); |
|
47 | - |
|
48 | - // Only rotate image if necessary! |
|
49 | - if ($isRotated > 0) { |
|
50 | - $transformation = $this->getTransformation($orientation); |
|
51 | - |
|
52 | - $imParams = '###SkipStripProfile###'; |
|
53 | - if ($transformation !== '') { |
|
54 | - $imParams .= ' ' . $transformation; |
|
55 | - } |
|
56 | - |
|
57 | - $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
|
58 | - if ($tempFileInfo) { |
|
59 | - // Replace original file |
|
60 | - @unlink($uploadedFile->getFileWithAbsolutePath()); |
|
61 | - @rename($tempFileInfo[3], $uploadedFile->getFileWithAbsolutePath()); |
|
62 | - |
|
63 | - if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') { |
|
64 | - $this->resetOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
68 | - return $uploadedFile; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns the EXIF orientation of a given picture. |
|
73 | - * |
|
74 | - * @param string $filename |
|
75 | - * @return integer |
|
76 | - */ |
|
77 | - protected function getOrientation($filename) |
|
78 | - { |
|
79 | - $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); |
|
80 | - $orientation = 1; // Fallback to "straight" |
|
81 | - if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,tif,tiff', $extension) && function_exists('exif_read_data')) { |
|
82 | - try { |
|
83 | - $exif = exif_read_data($filename); |
|
84 | - if ($exif) { |
|
85 | - $orientation = $exif['Orientation']; |
|
86 | - } |
|
87 | - } catch (\Exception $e) {} |
|
88 | - } |
|
89 | - return $orientation; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Returns true if the given picture is rotated. |
|
94 | - * |
|
95 | - * @param integer $orientation EXIF orientation |
|
96 | - * @return integer |
|
97 | - * @see http://www.impulseadventure.com/photo/exif-orientation.html |
|
98 | - */ |
|
99 | - protected function isRotated($orientation) |
|
100 | - { |
|
101 | - $ret = false; |
|
102 | - switch ($orientation) { |
|
103 | - case 2: // horizontal flip |
|
104 | - case 3: // 180° |
|
105 | - case 4: // vertical flip |
|
106 | - case 5: // vertical flip + 90 rotate right |
|
107 | - case 6: // 90° rotate right |
|
108 | - case 7: // horizontal flip + 90 rotate right |
|
109 | - case 8: // 90° rotate left |
|
110 | - $ret = true; |
|
111 | - break; |
|
112 | - } |
|
113 | - return $ret; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Returns a command line parameter to fix the orientation of a rotated picture. |
|
118 | - * |
|
119 | - * @param integer $orientation |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - protected function getTransformation($orientation) |
|
123 | - { |
|
124 | - $transformation = ''; |
|
125 | - if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] !== 'gm') { |
|
126 | - // ImageMagick |
|
127 | - if ($orientation >= 2 && $orientation <= 8) { |
|
128 | - $transformation = '-auto-orient'; |
|
129 | - } |
|
130 | - } else { |
|
131 | - // GraphicsMagick |
|
132 | - switch ($orientation) { |
|
133 | - case 2: // horizontal flip |
|
134 | - $transformation = '-flip horizontal'; |
|
135 | - break; |
|
136 | - case 3: // 180° |
|
137 | - $transformation = '-rotate 180'; |
|
138 | - break; |
|
139 | - case 4: // vertical flip |
|
140 | - $transformation = '-flip vertical'; |
|
141 | - break; |
|
142 | - case 5: // vertical flip + 90 rotate right |
|
143 | - $transformation = '-transpose'; |
|
144 | - break; |
|
145 | - case 6: // 90° rotate right |
|
146 | - $transformation = '-rotate 90'; |
|
147 | - break; |
|
148 | - case 7: // horizontal flip + 90 rotate right |
|
149 | - $transformation = '-transverse'; |
|
150 | - break; |
|
151 | - case 8: // 90° rotate left |
|
152 | - $transformation = '-rotate 270'; |
|
153 | - break; |
|
154 | - } |
|
155 | - } |
|
156 | - return $transformation; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Resets the EXIF orientation flag of a picture. |
|
161 | - * |
|
162 | - * @param string $filename |
|
163 | - * @return void |
|
164 | - * @see http://sylvana.net/jpegcrop/exif_orientation.html |
|
165 | - */ |
|
166 | - protected function resetOrientation($filename) |
|
167 | - { |
|
168 | - JpegExifOrient::setOrientation($filename, 1); |
|
169 | - } |
|
21 | + /** |
|
22 | + * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
23 | + */ |
|
24 | + protected $gifCreator; |
|
25 | + |
|
26 | + /** |
|
27 | + * @return \Fab\Media\FileUpload\Optimizer\Rotate |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
32 | + $this->gifCreator->init(); |
|
33 | + $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Optimize the given uploaded image |
|
38 | + * |
|
39 | + * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
40 | + * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
41 | + */ |
|
42 | + public function optimize($uploadedFile) |
|
43 | + { |
|
44 | + |
|
45 | + $orientation = $this->getOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
46 | + $isRotated = $this->isRotated($orientation); |
|
47 | + |
|
48 | + // Only rotate image if necessary! |
|
49 | + if ($isRotated > 0) { |
|
50 | + $transformation = $this->getTransformation($orientation); |
|
51 | + |
|
52 | + $imParams = '###SkipStripProfile###'; |
|
53 | + if ($transformation !== '') { |
|
54 | + $imParams .= ' ' . $transformation; |
|
55 | + } |
|
56 | + |
|
57 | + $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
|
58 | + if ($tempFileInfo) { |
|
59 | + // Replace original file |
|
60 | + @unlink($uploadedFile->getFileWithAbsolutePath()); |
|
61 | + @rename($tempFileInfo[3], $uploadedFile->getFileWithAbsolutePath()); |
|
62 | + |
|
63 | + if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') { |
|
64 | + $this->resetOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | + return $uploadedFile; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns the EXIF orientation of a given picture. |
|
73 | + * |
|
74 | + * @param string $filename |
|
75 | + * @return integer |
|
76 | + */ |
|
77 | + protected function getOrientation($filename) |
|
78 | + { |
|
79 | + $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); |
|
80 | + $orientation = 1; // Fallback to "straight" |
|
81 | + if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,tif,tiff', $extension) && function_exists('exif_read_data')) { |
|
82 | + try { |
|
83 | + $exif = exif_read_data($filename); |
|
84 | + if ($exif) { |
|
85 | + $orientation = $exif['Orientation']; |
|
86 | + } |
|
87 | + } catch (\Exception $e) {} |
|
88 | + } |
|
89 | + return $orientation; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Returns true if the given picture is rotated. |
|
94 | + * |
|
95 | + * @param integer $orientation EXIF orientation |
|
96 | + * @return integer |
|
97 | + * @see http://www.impulseadventure.com/photo/exif-orientation.html |
|
98 | + */ |
|
99 | + protected function isRotated($orientation) |
|
100 | + { |
|
101 | + $ret = false; |
|
102 | + switch ($orientation) { |
|
103 | + case 2: // horizontal flip |
|
104 | + case 3: // 180° |
|
105 | + case 4: // vertical flip |
|
106 | + case 5: // vertical flip + 90 rotate right |
|
107 | + case 6: // 90° rotate right |
|
108 | + case 7: // horizontal flip + 90 rotate right |
|
109 | + case 8: // 90° rotate left |
|
110 | + $ret = true; |
|
111 | + break; |
|
112 | + } |
|
113 | + return $ret; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Returns a command line parameter to fix the orientation of a rotated picture. |
|
118 | + * |
|
119 | + * @param integer $orientation |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + protected function getTransformation($orientation) |
|
123 | + { |
|
124 | + $transformation = ''; |
|
125 | + if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] !== 'gm') { |
|
126 | + // ImageMagick |
|
127 | + if ($orientation >= 2 && $orientation <= 8) { |
|
128 | + $transformation = '-auto-orient'; |
|
129 | + } |
|
130 | + } else { |
|
131 | + // GraphicsMagick |
|
132 | + switch ($orientation) { |
|
133 | + case 2: // horizontal flip |
|
134 | + $transformation = '-flip horizontal'; |
|
135 | + break; |
|
136 | + case 3: // 180° |
|
137 | + $transformation = '-rotate 180'; |
|
138 | + break; |
|
139 | + case 4: // vertical flip |
|
140 | + $transformation = '-flip vertical'; |
|
141 | + break; |
|
142 | + case 5: // vertical flip + 90 rotate right |
|
143 | + $transformation = '-transpose'; |
|
144 | + break; |
|
145 | + case 6: // 90° rotate right |
|
146 | + $transformation = '-rotate 90'; |
|
147 | + break; |
|
148 | + case 7: // horizontal flip + 90 rotate right |
|
149 | + $transformation = '-transverse'; |
|
150 | + break; |
|
151 | + case 8: // 90° rotate left |
|
152 | + $transformation = '-rotate 270'; |
|
153 | + break; |
|
154 | + } |
|
155 | + } |
|
156 | + return $transformation; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Resets the EXIF orientation flag of a picture. |
|
161 | + * |
|
162 | + * @param string $filename |
|
163 | + * @return void |
|
164 | + * @see http://sylvana.net/jpegcrop/exif_orientation.html |
|
165 | + */ |
|
166 | + protected function resetOrientation($filename) |
|
167 | + { |
|
168 | + JpegExifOrient::setOrientation($filename, 1); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
32 | 32 | $this->gifCreator->init(); |
33 | - $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
33 | + $this->gifCreator->absPrefix = Environment::getPublicPath().'/'; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | $imParams = '###SkipStripProfile###'; |
53 | 53 | if ($transformation !== '') { |
54 | - $imParams .= ' ' . $transformation; |
|
54 | + $imParams .= ' '.$transformation; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |