Completed
Push — master ( 02a2d0...8117b3 )
by Fabien
54:58
created
Classes/Tool/MissingFilesFinderTool.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -22,129 +22,129 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Classes/Tool/DuplicateFilesFinderTool.php 2 patches
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -21,206 +21,206 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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.
Please login to merge, or discard this patch.
Classes/Tool/ThumbnailGeneratorTool.php 2 patches
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -20,125 +20,125 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Classes/Tool/CacheWarmUpTool.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,73 +18,73 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Classes/Tool/DuplicateRecordsFinderTool.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -20,86 +20,86 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Classes/FileUpload/UploadManager.php 2 patches
Indentation   +357 added lines, -357 removed lines patch added patch discarded remove patch
@@ -21,362 +21,362 @@
 block discarded – undo
21 21
 class UploadManager
22 22
 {
23 23
 
24
-    const UPLOAD_FOLDER = 'typo3temp/pics';
25
-
26
-    /**
27
-     * @var int|null|string
28
-     */
29
-    protected $sizeLimit;
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $uploadFolder;
35
-
36
-    /**
37
-     * @var FormUtility
38
-     */
39
-    protected $formUtility;
40
-
41
-    /**
42
-     * @var \TYPO3\CMS\Core\Resource\ResourceStorage
43
-     */
44
-    protected $storage;
45
-
46
-    /**
47
-     * Name of the file input in the DOM.
48
-     *
49
-     * @var string
50
-     */
51
-    protected $inputName = 'qqfile';
52
-
53
-    /**
54
-     * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
55
-     * @return UploadManager
56
-     */
57
-    function __construct($storage = null)
58
-    {
59
-
60
-        $this->initializeUploadFolder();
61
-
62
-        // max file size in bytes
63
-        $this->sizeLimit = GeneralUtility::getMaxUploadFileSize() * 1024;
64
-        $this->checkServerSettings();
65
-
66
-        $this->formUtility = FormUtility::getInstance();
67
-        $this->storage = $storage;
68
-    }
69
-
70
-    /**
71
-     * Handle the uploaded file.
72
-     *
73
-     * @return UploadedFileInterface
74
-     */
75
-    public function handleUpload()
76
-    {
77
-
78
-        /** @var $uploadedFile UploadedFileInterface */
79
-        $uploadedFile = false;
80
-        if ($this->formUtility->isMultiparted()) {
81
-
82
-            // Default case
83
-            $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\MultipartedFile::class);
84
-        } elseif ($this->formUtility->isOctetStreamed()) {
85
-
86
-            // Fine Upload plugin would use it if forceEncoded = false and paramsInBody = false
87
-            $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\StreamedFile::class);
88
-        } elseif ($this->formUtility->isUrlEncoded()) {
89
-
90
-            // Used for image resizing in BE
91
-            $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\Base64File::class);
92
-        }
93
-
94
-        if (!$uploadedFile) {
95
-            $this->throwException('Could not instantiate an upload object... No file was uploaded?');
96
-        }
97
-
98
-        $fileName = $this->getFileName($uploadedFile);
99
-
100
-        $this->checkFileSize($uploadedFile->getSize());
101
-        $this->checkFileAllowed($fileName);
102
-
103
-        $saved = $uploadedFile->setInputName($this->inputName)
104
-            ->setUploadFolder($this->uploadFolder)
105
-            ->setName($fileName)
106
-            ->save();
107
-
108
-        if (!$saved) {
109
-            $this->throwException('Could not save uploaded file. The upload was cancelled, or server error encountered');
110
-        }
111
-
112
-        // Optimize file if the uploaded file is an image.
113
-        if ($uploadedFile->getType() == \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE) {
114
-            $uploadedFile = ImageOptimizer::getInstance($this->storage)->optimize($uploadedFile);
115
-        }
116
-        return $uploadedFile;
117
-    }
118
-
119
-    /**
120
-     * Internal function that checks if server's may sizes match the
121
-     * object's maximum size for uploads.
122
-     *
123
-     * @return void
124
-     */
125
-    protected function checkServerSettings()
126
-    {
127
-        $postSize = $this->toBytes(ini_get('post_max_size'));
128
-
129
-        $uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
130
-
131
-        if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) {
132
-            $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
133
-            $this->throwException('increase post_max_size and upload_max_filesize to ' . $size);
134
-        }
135
-    }
136
-
137
-    /**
138
-     * Convert a given size with units to bytes.
139
-     *
140
-     * @param string $str
141
-     * @return int|string
142
-     */
143
-    protected function toBytes($str)
144
-    {
145
-        $val = trim($str);
146
-        $last = strtolower($str[strlen($str) - 1]);
147
-        switch ($last) {
148
-            case 'g':
149
-                $val *= 1024;
150
-            case 'm':
151
-                $val *= 1024;
152
-            case 'k':
153
-                $val *= 1024;
154
-        }
155
-        return $val;
156
-    }
157
-
158
-    /**
159
-     * Return a file name given an uploaded file
160
-     *
161
-     * @param UploadedFileInterface $uploadedFile
162
-     * @return string
163
-     */
164
-    public function getFileName(UploadedFileInterface $uploadedFile)
165
-    {
166
-        $pathInfo = pathinfo($uploadedFile->getOriginalName());
167
-        $fileName = $this->sanitizeFileName($pathInfo['filename']);
168
-        $fileNameWithExtension = $fileName;
169
-        if (!empty($pathInfo['extension'])) {
170
-            $fileNameWithExtension = sprintf('%s.%s', $fileName, $pathInfo['extension']);
171
-        }
172
-        return $fileNameWithExtension;
173
-    }
174
-
175
-    /**
176
-     * Check whether the file size does not exceed the allowed limit
177
-     *
178
-     * @param int $size
179
-     */
180
-    public function checkFileSize($size)
181
-    {
182
-        if ($size == 0) {
183
-            $this->throwException('File is empty');
184
-        }
185
-
186
-        if ($size > $this->sizeLimit) {
187
-            $this->throwException('File is too large');
188
-        }
189
-    }
190
-
191
-    /**
192
-     * Check whether the file is allowed
193
-     *
194
-     * @param string $fileName
195
-     */
196
-    public function checkFileAllowed($fileName)
197
-    {
198
-        $isAllowed = $this->checkFileExtensionPermission($fileName);
199
-        if (!$isAllowed) {
200
-            $these = PermissionUtility::getInstance()->getAllowedExtensionList();
201
-            $this->throwException('File has an invalid extension, it should be one of ' . $these . '.');
202
-        }
203
-    }
204
-
205
-    /**
206
-     * If the fileName is given, check it against the
207
-     * TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed
208
-     *
209
-     * @see \TYPO3\CMS\Core\Resource\ResourceStorage->checkFileExtensionPermission($fileName);
210
-     * @param string $fileName Full filename
211
-     * @return boolean true if extension/filename is allowed
212
-     */
213
-    public function checkFileExtensionPermission($fileName)
214
-    {
215
-        $isAllowed = GeneralUtility::verifyFilenameAgainstDenyPattern($fileName);
216
-        if ($isAllowed) {
217
-            $fileInfo = GeneralUtility::split_fileref($fileName);
218
-            // Set up the permissions for the file extension
219
-            $fileExtensionPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace'];
220
-            $fileExtensionPermissions['allow'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['allow']));
221
-            $fileExtensionPermissions['deny'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['deny']));
222
-            $fileExtension = strtolower($fileInfo['fileext']);
223
-            if ($fileExtension !== '') {
224
-                // If the extension is found amongst the allowed types, we return true immediately
225
-                if ($fileExtensionPermissions['allow'] === '*' || GeneralUtility::inList($fileExtensionPermissions['allow'], $fileExtension)) {
226
-                    return true;
227
-                }
228
-                // If the extension is found amongst the denied types, we return false immediately
229
-                if ($fileExtensionPermissions['deny'] === '*' || GeneralUtility::inList($fileExtensionPermissions['deny'], $fileExtension)) {
230
-                    return false;
231
-                }
232
-                // If no match we return true
233
-                return true;
234
-            } else {
235
-                if ($fileExtensionPermissions['allow'] === '*') {
236
-                    return true;
237
-                }
238
-                if ($fileExtensionPermissions['deny'] === '*') {
239
-                    return false;
240
-                }
241
-                return true;
242
-            }
243
-        }
244
-        return false;
245
-    }
246
-
247
-    /**
248
-     * Sanitize the file name for the web.
249
-     * It has been noticed issues when letting done this work by FAL. Give it a little hand.
250
-     *
251
-     * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L252
252
-     * @param string $fileName
253
-     * @param string $slug
254
-     * @param string $extra
255
-     * @return string
256
-     */
257
-    public function sanitizeFileName($fileName, $slug = '-', $extra = null)
258
-    {
259
-        return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug);
260
-    }
261
-
262
-    /**
263
-     * Remove accent from a string
264
-     *
265
-     * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297
266
-     * @param $string
267
-     * @return string
268
-     */
269
-    protected function unAccent($string)
270
-    {
271
-        $searches = array('ç', 'æ', 'œ', 'á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', 'å', 'e', 'i', 'ø', 'u');
272
-        $replaces = array('c', 'ae', 'oe', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u');
273
-        $sanitizedString = str_replace($searches, $replaces, $string);
274
-
275
-        if (extension_loaded('intl') === true) {
276
-            $sanitizedString = \Normalizer::normalize($sanitizedString, \Normalizer::FORM_KD);
277
-        }
278
-        return $sanitizedString;
279
-    }
280
-
281
-    /**
282
-     * @throws FailedFileUploadException
283
-     * @param string $message
284
-     */
285
-    protected function throwException($message)
286
-    {
287
-        throw new FailedFileUploadException($message, 1357510420);
288
-    }
289
-
290
-    /**
291
-     * Initialize Upload Folder.
292
-     *
293
-     * @return void
294
-     */
295
-    protected function initializeUploadFolder()
296
-    {
297
-        $this->uploadFolder = Environment::getPublicPath() . '/' . self::UPLOAD_FOLDER;
298
-
299
-        // Initialize the upload folder for file transfer and create it if not yet existing
300
-        if (!file_exists($this->uploadFolder)) {
301
-            GeneralUtility::mkdir($this->uploadFolder);
302
-        }
303
-
304
-        // Check whether the upload folder is writable
305
-        if (!is_writable($this->uploadFolder)) {
306
-            $this->throwException("Server error. Upload directory isn't writable.");
307
-        }
308
-    }
309
-
310
-    /**
311
-     * @return int|null|string
312
-     */
313
-    public function getSizeLimit()
314
-    {
315
-        return $this->sizeLimit;
316
-    }
317
-
318
-    /**
319
-     * @param int|null|string $sizeLimit
320
-     * @return $this
321
-     */
322
-    public function setSizeLimit($sizeLimit)
323
-    {
324
-        $this->sizeLimit = $sizeLimit;
325
-        return $this;
326
-    }
327
-
328
-    /**
329
-     * @return string
330
-     */
331
-    public function getUploadFolder()
332
-    {
333
-        return $this->uploadFolder;
334
-    }
335
-
336
-    /**
337
-     * @param string $uploadFolder
338
-     * @return $this
339
-     */
340
-    public function setUploadFolder($uploadFolder)
341
-    {
342
-        $this->uploadFolder = $uploadFolder;
343
-        return $this;
344
-    }
345
-
346
-    /**
347
-     * @return string
348
-     */
349
-    public function getInputName()
350
-    {
351
-        return $this->inputName;
352
-    }
353
-
354
-    /**
355
-     * @param string $inputName
356
-     * @return $this
357
-     */
358
-    public function setInputName($inputName)
359
-    {
360
-        $this->inputName = $inputName;
361
-        return $this;
362
-    }
363
-
364
-    /**
365
-     * @return \TYPO3\CMS\Core\Resource\ResourceStorage
366
-     */
367
-    public function getStorage()
368
-    {
369
-        return $this->storage;
370
-    }
371
-
372
-    /**
373
-     * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
374
-     * @return $this
375
-     */
376
-    public function setStorage($storage)
377
-    {
378
-        $this->storage = $storage;
379
-        return $this;
380
-    }
24
+	const UPLOAD_FOLDER = 'typo3temp/pics';
25
+
26
+	/**
27
+	 * @var int|null|string
28
+	 */
29
+	protected $sizeLimit;
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $uploadFolder;
35
+
36
+	/**
37
+	 * @var FormUtility
38
+	 */
39
+	protected $formUtility;
40
+
41
+	/**
42
+	 * @var \TYPO3\CMS\Core\Resource\ResourceStorage
43
+	 */
44
+	protected $storage;
45
+
46
+	/**
47
+	 * Name of the file input in the DOM.
48
+	 *
49
+	 * @var string
50
+	 */
51
+	protected $inputName = 'qqfile';
52
+
53
+	/**
54
+	 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
55
+	 * @return UploadManager
56
+	 */
57
+	function __construct($storage = null)
58
+	{
59
+
60
+		$this->initializeUploadFolder();
61
+
62
+		// max file size in bytes
63
+		$this->sizeLimit = GeneralUtility::getMaxUploadFileSize() * 1024;
64
+		$this->checkServerSettings();
65
+
66
+		$this->formUtility = FormUtility::getInstance();
67
+		$this->storage = $storage;
68
+	}
69
+
70
+	/**
71
+	 * Handle the uploaded file.
72
+	 *
73
+	 * @return UploadedFileInterface
74
+	 */
75
+	public function handleUpload()
76
+	{
77
+
78
+		/** @var $uploadedFile UploadedFileInterface */
79
+		$uploadedFile = false;
80
+		if ($this->formUtility->isMultiparted()) {
81
+
82
+			// Default case
83
+			$uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\MultipartedFile::class);
84
+		} elseif ($this->formUtility->isOctetStreamed()) {
85
+
86
+			// Fine Upload plugin would use it if forceEncoded = false and paramsInBody = false
87
+			$uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\StreamedFile::class);
88
+		} elseif ($this->formUtility->isUrlEncoded()) {
89
+
90
+			// Used for image resizing in BE
91
+			$uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\Base64File::class);
92
+		}
93
+
94
+		if (!$uploadedFile) {
95
+			$this->throwException('Could not instantiate an upload object... No file was uploaded?');
96
+		}
97
+
98
+		$fileName = $this->getFileName($uploadedFile);
99
+
100
+		$this->checkFileSize($uploadedFile->getSize());
101
+		$this->checkFileAllowed($fileName);
102
+
103
+		$saved = $uploadedFile->setInputName($this->inputName)
104
+			->setUploadFolder($this->uploadFolder)
105
+			->setName($fileName)
106
+			->save();
107
+
108
+		if (!$saved) {
109
+			$this->throwException('Could not save uploaded file. The upload was cancelled, or server error encountered');
110
+		}
111
+
112
+		// Optimize file if the uploaded file is an image.
113
+		if ($uploadedFile->getType() == \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE) {
114
+			$uploadedFile = ImageOptimizer::getInstance($this->storage)->optimize($uploadedFile);
115
+		}
116
+		return $uploadedFile;
117
+	}
118
+
119
+	/**
120
+	 * Internal function that checks if server's may sizes match the
121
+	 * object's maximum size for uploads.
122
+	 *
123
+	 * @return void
124
+	 */
125
+	protected function checkServerSettings()
126
+	{
127
+		$postSize = $this->toBytes(ini_get('post_max_size'));
128
+
129
+		$uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
130
+
131
+		if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) {
132
+			$size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
133
+			$this->throwException('increase post_max_size and upload_max_filesize to ' . $size);
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * Convert a given size with units to bytes.
139
+	 *
140
+	 * @param string $str
141
+	 * @return int|string
142
+	 */
143
+	protected function toBytes($str)
144
+	{
145
+		$val = trim($str);
146
+		$last = strtolower($str[strlen($str) - 1]);
147
+		switch ($last) {
148
+			case 'g':
149
+				$val *= 1024;
150
+			case 'm':
151
+				$val *= 1024;
152
+			case 'k':
153
+				$val *= 1024;
154
+		}
155
+		return $val;
156
+	}
157
+
158
+	/**
159
+	 * Return a file name given an uploaded file
160
+	 *
161
+	 * @param UploadedFileInterface $uploadedFile
162
+	 * @return string
163
+	 */
164
+	public function getFileName(UploadedFileInterface $uploadedFile)
165
+	{
166
+		$pathInfo = pathinfo($uploadedFile->getOriginalName());
167
+		$fileName = $this->sanitizeFileName($pathInfo['filename']);
168
+		$fileNameWithExtension = $fileName;
169
+		if (!empty($pathInfo['extension'])) {
170
+			$fileNameWithExtension = sprintf('%s.%s', $fileName, $pathInfo['extension']);
171
+		}
172
+		return $fileNameWithExtension;
173
+	}
174
+
175
+	/**
176
+	 * Check whether the file size does not exceed the allowed limit
177
+	 *
178
+	 * @param int $size
179
+	 */
180
+	public function checkFileSize($size)
181
+	{
182
+		if ($size == 0) {
183
+			$this->throwException('File is empty');
184
+		}
185
+
186
+		if ($size > $this->sizeLimit) {
187
+			$this->throwException('File is too large');
188
+		}
189
+	}
190
+
191
+	/**
192
+	 * Check whether the file is allowed
193
+	 *
194
+	 * @param string $fileName
195
+	 */
196
+	public function checkFileAllowed($fileName)
197
+	{
198
+		$isAllowed = $this->checkFileExtensionPermission($fileName);
199
+		if (!$isAllowed) {
200
+			$these = PermissionUtility::getInstance()->getAllowedExtensionList();
201
+			$this->throwException('File has an invalid extension, it should be one of ' . $these . '.');
202
+		}
203
+	}
204
+
205
+	/**
206
+	 * If the fileName is given, check it against the
207
+	 * TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed
208
+	 *
209
+	 * @see \TYPO3\CMS\Core\Resource\ResourceStorage->checkFileExtensionPermission($fileName);
210
+	 * @param string $fileName Full filename
211
+	 * @return boolean true if extension/filename is allowed
212
+	 */
213
+	public function checkFileExtensionPermission($fileName)
214
+	{
215
+		$isAllowed = GeneralUtility::verifyFilenameAgainstDenyPattern($fileName);
216
+		if ($isAllowed) {
217
+			$fileInfo = GeneralUtility::split_fileref($fileName);
218
+			// Set up the permissions for the file extension
219
+			$fileExtensionPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace'];
220
+			$fileExtensionPermissions['allow'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['allow']));
221
+			$fileExtensionPermissions['deny'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['deny']));
222
+			$fileExtension = strtolower($fileInfo['fileext']);
223
+			if ($fileExtension !== '') {
224
+				// If the extension is found amongst the allowed types, we return true immediately
225
+				if ($fileExtensionPermissions['allow'] === '*' || GeneralUtility::inList($fileExtensionPermissions['allow'], $fileExtension)) {
226
+					return true;
227
+				}
228
+				// If the extension is found amongst the denied types, we return false immediately
229
+				if ($fileExtensionPermissions['deny'] === '*' || GeneralUtility::inList($fileExtensionPermissions['deny'], $fileExtension)) {
230
+					return false;
231
+				}
232
+				// If no match we return true
233
+				return true;
234
+			} else {
235
+				if ($fileExtensionPermissions['allow'] === '*') {
236
+					return true;
237
+				}
238
+				if ($fileExtensionPermissions['deny'] === '*') {
239
+					return false;
240
+				}
241
+				return true;
242
+			}
243
+		}
244
+		return false;
245
+	}
246
+
247
+	/**
248
+	 * Sanitize the file name for the web.
249
+	 * It has been noticed issues when letting done this work by FAL. Give it a little hand.
250
+	 *
251
+	 * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L252
252
+	 * @param string $fileName
253
+	 * @param string $slug
254
+	 * @param string $extra
255
+	 * @return string
256
+	 */
257
+	public function sanitizeFileName($fileName, $slug = '-', $extra = null)
258
+	{
259
+		return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug);
260
+	}
261
+
262
+	/**
263
+	 * Remove accent from a string
264
+	 *
265
+	 * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297
266
+	 * @param $string
267
+	 * @return string
268
+	 */
269
+	protected function unAccent($string)
270
+	{
271
+		$searches = array('ç', 'æ', 'œ', 'á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', 'å', 'e', 'i', 'ø', 'u');
272
+		$replaces = array('c', 'ae', 'oe', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u');
273
+		$sanitizedString = str_replace($searches, $replaces, $string);
274
+
275
+		if (extension_loaded('intl') === true) {
276
+			$sanitizedString = \Normalizer::normalize($sanitizedString, \Normalizer::FORM_KD);
277
+		}
278
+		return $sanitizedString;
279
+	}
280
+
281
+	/**
282
+	 * @throws FailedFileUploadException
283
+	 * @param string $message
284
+	 */
285
+	protected function throwException($message)
286
+	{
287
+		throw new FailedFileUploadException($message, 1357510420);
288
+	}
289
+
290
+	/**
291
+	 * Initialize Upload Folder.
292
+	 *
293
+	 * @return void
294
+	 */
295
+	protected function initializeUploadFolder()
296
+	{
297
+		$this->uploadFolder = Environment::getPublicPath() . '/' . self::UPLOAD_FOLDER;
298
+
299
+		// Initialize the upload folder for file transfer and create it if not yet existing
300
+		if (!file_exists($this->uploadFolder)) {
301
+			GeneralUtility::mkdir($this->uploadFolder);
302
+		}
303
+
304
+		// Check whether the upload folder is writable
305
+		if (!is_writable($this->uploadFolder)) {
306
+			$this->throwException("Server error. Upload directory isn't writable.");
307
+		}
308
+	}
309
+
310
+	/**
311
+	 * @return int|null|string
312
+	 */
313
+	public function getSizeLimit()
314
+	{
315
+		return $this->sizeLimit;
316
+	}
317
+
318
+	/**
319
+	 * @param int|null|string $sizeLimit
320
+	 * @return $this
321
+	 */
322
+	public function setSizeLimit($sizeLimit)
323
+	{
324
+		$this->sizeLimit = $sizeLimit;
325
+		return $this;
326
+	}
327
+
328
+	/**
329
+	 * @return string
330
+	 */
331
+	public function getUploadFolder()
332
+	{
333
+		return $this->uploadFolder;
334
+	}
335
+
336
+	/**
337
+	 * @param string $uploadFolder
338
+	 * @return $this
339
+	 */
340
+	public function setUploadFolder($uploadFolder)
341
+	{
342
+		$this->uploadFolder = $uploadFolder;
343
+		return $this;
344
+	}
345
+
346
+	/**
347
+	 * @return string
348
+	 */
349
+	public function getInputName()
350
+	{
351
+		return $this->inputName;
352
+	}
353
+
354
+	/**
355
+	 * @param string $inputName
356
+	 * @return $this
357
+	 */
358
+	public function setInputName($inputName)
359
+	{
360
+		$this->inputName = $inputName;
361
+		return $this;
362
+	}
363
+
364
+	/**
365
+	 * @return \TYPO3\CMS\Core\Resource\ResourceStorage
366
+	 */
367
+	public function getStorage()
368
+	{
369
+		return $this->storage;
370
+	}
371
+
372
+	/**
373
+	 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
374
+	 * @return $this
375
+	 */
376
+	public function setStorage($storage)
377
+	{
378
+		$this->storage = $storage;
379
+		return $this;
380
+	}
381 381
 
382 382
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
         $uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
130 130
 
131 131
         if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) {
132
-            $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
133
-            $this->throwException('increase post_max_size and upload_max_filesize to ' . $size);
132
+            $size = max(1, $this->sizeLimit / 1024 / 1024).'M';
133
+            $this->throwException('increase post_max_size and upload_max_filesize to '.$size);
134 134
         }
135 135
     }
136 136
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
         $isAllowed = $this->checkFileExtensionPermission($fileName);
199 199
         if (!$isAllowed) {
200 200
             $these = PermissionUtility::getInstance()->getAllowedExtensionList();
201
-            $this->throwException('File has an invalid extension, it should be one of ' . $these . '.');
201
+            $this->throwException('File has an invalid extension, it should be one of '.$these.'.');
202 202
         }
203 203
     }
204 204
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      */
257 257
     public function sanitizeFileName($fileName, $slug = '-', $extra = null)
258 258
     {
259
-        return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug);
259
+        return trim(preg_replace('~[^0-9a-z_'.preg_quote($extra, '~').']+~i', $slug, $this->unAccent($fileName)), $slug);
260 260
     }
261 261
 
262 262
     /**
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      */
295 295
     protected function initializeUploadFolder()
296 296
     {
297
-        $this->uploadFolder = Environment::getPublicPath() . '/' . self::UPLOAD_FOLDER;
297
+        $this->uploadFolder = Environment::getPublicPath().'/'.self::UPLOAD_FOLDER;
298 298
 
299 299
         // Initialize the upload folder for file transfer and create it if not yet existing
300 300
         if (!file_exists($this->uploadFolder)) {
Please login to merge, or discard this patch.
Classes/FileUpload/UploadedFileAbstract.php 2 patches
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -19,142 +19,142 @@
 block discarded – undo
19 19
 abstract class UploadedFileAbstract implements UploadedFileInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $uploadFolder;
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    protected $inputName;
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $name;
36
-
37
-    /**
38
-     * Get the file type.
39
-     *
40
-     * @return int
41
-     */
42
-    public function getType()
43
-    {
44
-        $this->checkFileExistence();
45
-
46
-        // this basically extracts the mimetype and guess the filetype based
47
-        // on the first part of the mimetype works for 99% of all cases, and
48
-        // we don't need to make an SQL statement like EXT:media does currently
49
-        $mimeType = $this->getMimeType();
50
-        list($fileType) = explode('/', $mimeType);
51
-        switch (strtolower($fileType)) {
52
-            case 'text':
53
-                $type = File::FILETYPE_TEXT;
54
-                break;
55
-            case 'image':
56
-                $type = File::FILETYPE_IMAGE;
57
-                break;
58
-            case 'audio':
59
-                $type = File::FILETYPE_AUDIO;
60
-                break;
61
-            case 'video':
62
-                $type = File::FILETYPE_VIDEO;
63
-                break;
64
-            case 'application':
65
-            case 'software':
66
-                $type = File::FILETYPE_APPLICATION;
67
-                break;
68
-            default:
69
-                $type = File::FILETYPE_UNKNOWN;
70
-        }
71
-        return $type;
72
-    }
73
-
74
-    /**
75
-     * Get the file with its absolute path.
76
-     *
77
-     * @return string
78
-     */
79
-    public function getFileWithAbsolutePath()
80
-    {
81
-        return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name;
82
-    }
83
-
84
-    /**
85
-     * Get the file's public URL.
86
-     *
87
-     * @return string
88
-     */
89
-    public function getPublicUrl()
90
-    {
91
-        $fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath());
92
-        return '/' . ltrim($fileNameAndPath, '/');
93
-    }
94
-
95
-    /**
96
-     * @return string
97
-     */
98
-    public function getInputName()
99
-    {
100
-        return $this->inputName;
101
-    }
102
-
103
-    /**
104
-     * @param string $inputName
105
-     * @return UploadedFileInterface
106
-     */
107
-    public function setInputName($inputName)
108
-    {
109
-        $this->inputName = $inputName;
110
-        return $this;
111
-    }
112
-
113
-    /**
114
-     * @return string
115
-     */
116
-    public function getUploadFolder()
117
-    {
118
-        return $this->uploadFolder;
119
-    }
120
-
121
-    /**
122
-     * @param string $uploadFolder
123
-     * @return UploadedFileInterface
124
-     */
125
-    public function setUploadFolder($uploadFolder)
126
-    {
127
-        $this->uploadFolder = $uploadFolder;
128
-        return $this;
129
-    }
130
-
131
-    /**
132
-     * @return string
133
-     */
134
-    public function getName()
135
-    {
136
-        return $this->name;
137
-    }
138
-
139
-    /**
140
-     * @param string $name
141
-     * @return UploadedFileInterface
142
-     */
143
-    public function setName($name)
144
-    {
145
-        $this->name = $name;
146
-        return $this;
147
-    }
148
-
149
-    /**
150
-     * Check whether the file exists.
151
-     */
152
-    protected function checkFileExistence()
153
-    {
154
-        if (!is_file($this->getFileWithAbsolutePath())) {
155
-            $message = sprintf('File not found at "%s". Did you save it?', $this->getFileWithAbsolutePath());
156
-            throw new MissingFileException($message, 1361786958);
157
-        }
158
-    }
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $uploadFolder;
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	protected $inputName;
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $name;
36
+
37
+	/**
38
+	 * Get the file type.
39
+	 *
40
+	 * @return int
41
+	 */
42
+	public function getType()
43
+	{
44
+		$this->checkFileExistence();
45
+
46
+		// this basically extracts the mimetype and guess the filetype based
47
+		// on the first part of the mimetype works for 99% of all cases, and
48
+		// we don't need to make an SQL statement like EXT:media does currently
49
+		$mimeType = $this->getMimeType();
50
+		list($fileType) = explode('/', $mimeType);
51
+		switch (strtolower($fileType)) {
52
+			case 'text':
53
+				$type = File::FILETYPE_TEXT;
54
+				break;
55
+			case 'image':
56
+				$type = File::FILETYPE_IMAGE;
57
+				break;
58
+			case 'audio':
59
+				$type = File::FILETYPE_AUDIO;
60
+				break;
61
+			case 'video':
62
+				$type = File::FILETYPE_VIDEO;
63
+				break;
64
+			case 'application':
65
+			case 'software':
66
+				$type = File::FILETYPE_APPLICATION;
67
+				break;
68
+			default:
69
+				$type = File::FILETYPE_UNKNOWN;
70
+		}
71
+		return $type;
72
+	}
73
+
74
+	/**
75
+	 * Get the file with its absolute path.
76
+	 *
77
+	 * @return string
78
+	 */
79
+	public function getFileWithAbsolutePath()
80
+	{
81
+		return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name;
82
+	}
83
+
84
+	/**
85
+	 * Get the file's public URL.
86
+	 *
87
+	 * @return string
88
+	 */
89
+	public function getPublicUrl()
90
+	{
91
+		$fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath());
92
+		return '/' . ltrim($fileNameAndPath, '/');
93
+	}
94
+
95
+	/**
96
+	 * @return string
97
+	 */
98
+	public function getInputName()
99
+	{
100
+		return $this->inputName;
101
+	}
102
+
103
+	/**
104
+	 * @param string $inputName
105
+	 * @return UploadedFileInterface
106
+	 */
107
+	public function setInputName($inputName)
108
+	{
109
+		$this->inputName = $inputName;
110
+		return $this;
111
+	}
112
+
113
+	/**
114
+	 * @return string
115
+	 */
116
+	public function getUploadFolder()
117
+	{
118
+		return $this->uploadFolder;
119
+	}
120
+
121
+	/**
122
+	 * @param string $uploadFolder
123
+	 * @return UploadedFileInterface
124
+	 */
125
+	public function setUploadFolder($uploadFolder)
126
+	{
127
+		$this->uploadFolder = $uploadFolder;
128
+		return $this;
129
+	}
130
+
131
+	/**
132
+	 * @return string
133
+	 */
134
+	public function getName()
135
+	{
136
+		return $this->name;
137
+	}
138
+
139
+	/**
140
+	 * @param string $name
141
+	 * @return UploadedFileInterface
142
+	 */
143
+	public function setName($name)
144
+	{
145
+		$this->name = $name;
146
+		return $this;
147
+	}
148
+
149
+	/**
150
+	 * Check whether the file exists.
151
+	 */
152
+	protected function checkFileExistence()
153
+	{
154
+		if (!is_file($this->getFileWithAbsolutePath())) {
155
+			$message = sprintf('File not found at "%s". Did you save it?', $this->getFileWithAbsolutePath());
156
+			throw new MissingFileException($message, 1361786958);
157
+		}
158
+	}
159 159
 
160 160
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function getFileWithAbsolutePath()
80 80
     {
81
-        return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name;
81
+        return $this->uploadFolder.DIRECTORY_SEPARATOR.$this->name;
82 82
     }
83 83
 
84 84
     /**
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public function getPublicUrl()
90 90
     {
91
-        $fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath());
92
-        return '/' . ltrim($fileNameAndPath, '/');
91
+        $fileNameAndPath = str_replace(Environment::getPublicPath().'/', '', $this->getFileWithAbsolutePath());
92
+        return '/'.ltrim($fileNameAndPath, '/');
93 93
     }
94 94
 
95 95
     /**
Please login to merge, or discard this patch.
Classes/Command/FileCacheCommandController.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -25,105 +25,105 @@
 block discarded – undo
25 25
 class FileCacheCommandController extends CommandController
26 26
 {
27 27
 
28
-    /**
29
-     * Warm up the cache. Update some caching columns such as "number_of_references" to speed up the search.
30
-     *
31
-     * @return void
32
-     */
33
-    public function warmUpCommand()
34
-    {
35
-        $numberOfEntries = $this->getCacheService()->warmUp();
36
-        $message = sprintf('Done! Processed %s entries', $numberOfEntries);
37
-        $this->outputLine($message);
38
-    }
39
-
40
-    /**
41
-     * Flush all processed files to be used for debugging mainly.
42
-     *
43
-     * @return void
44
-     */
45
-    public function flushProcessedFilesCommand()
46
-    {
47
-
48
-        foreach ($this->getStorageRepository()->findAll() as $storage) {
49
-
50
-            // This only works for local driver
51
-            if ($storage->getDriverType() === 'Local') {
52
-
53
-                $this->outputLine();
54
-                $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid()));
55
-                $this->outputLine('--------------------------------------------');
56
-                $this->outputLine();
57
-
58
-                #$storage->getProcessingFolder()->delete(true); // will not work
59
-
60
-                // Well... not really FAL friendly but straightforward for Local drivers.
61
-                $processedDirectoryPath = Environment::getPublicPath() . '/' . $storage->getProcessingFolder()->getPublicUrl();
62
-                $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS);
63
-                $numberOfProcessedFiles = iterator_count($fileIterator);
64
-
65
-                GeneralUtility::rmdir($processedDirectoryPath, true);
66
-                GeneralUtility::mkdir($processedDirectoryPath); // recreate the directory.
67
-
68
-                $message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles);
69
-                $this->outputLine($message);
70
-
71
-                $count = $this->getDataService()
72
-                    ->count(
73
-                        'sys_file_processedfile',
74
-                        [
75
-                            'storage' => $storage->getUid()
76
-                        ]
77
-                    );
78
-
79
-                // Remove the record as well.
80
-                $this->getDataService()->delete('sys_file_processedfile', ['storage' => $storage->getUid()]);
81
-
82
-                $message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $count);
83
-                $this->outputLine($message);
84
-            }
85
-
86
-        }
87
-
88
-        // Remove possible remaining "sys_file_processedfile"
89
-        $this
90
-            ->getConnection('sys_file_processedfile')
91
-            ->query('TRUNCATE sys_file_processedfile');
92
-    }
93
-
94
-    /**
95
-     * @return \Fab\Media\Cache\CacheService|object
96
-     */
97
-    protected function getCacheService()
98
-    {
99
-        return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class);
100
-    }
101
-
102
-    /**
103
-     * @return StorageRepository|object
104
-     */
105
-    protected function getStorageRepository()
106
-    {
107
-        return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
108
-    }
109
-
110
-    /**
111
-     * @return object|DataService
112
-     */
113
-    protected function getDataService(): DataService
114
-    {
115
-        return GeneralUtility::makeInstance(DataService::class);
116
-    }
117
-
118
-    /**
119
-     * @param string $tableName
120
-     * @return object|Connection
121
-     */
122
-    protected function getConnection($tableName): Connection
123
-    {
124
-        /** @var ConnectionPool $connectionPool */
125
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
126
-        return $connectionPool->getConnectionForTable($tableName);
127
-    }
28
+	/**
29
+	 * Warm up the cache. Update some caching columns such as "number_of_references" to speed up the search.
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function warmUpCommand()
34
+	{
35
+		$numberOfEntries = $this->getCacheService()->warmUp();
36
+		$message = sprintf('Done! Processed %s entries', $numberOfEntries);
37
+		$this->outputLine($message);
38
+	}
39
+
40
+	/**
41
+	 * Flush all processed files to be used for debugging mainly.
42
+	 *
43
+	 * @return void
44
+	 */
45
+	public function flushProcessedFilesCommand()
46
+	{
47
+
48
+		foreach ($this->getStorageRepository()->findAll() as $storage) {
49
+
50
+			// This only works for local driver
51
+			if ($storage->getDriverType() === 'Local') {
52
+
53
+				$this->outputLine();
54
+				$this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid()));
55
+				$this->outputLine('--------------------------------------------');
56
+				$this->outputLine();
57
+
58
+				#$storage->getProcessingFolder()->delete(true); // will not work
59
+
60
+				// Well... not really FAL friendly but straightforward for Local drivers.
61
+				$processedDirectoryPath = Environment::getPublicPath() . '/' . $storage->getProcessingFolder()->getPublicUrl();
62
+				$fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS);
63
+				$numberOfProcessedFiles = iterator_count($fileIterator);
64
+
65
+				GeneralUtility::rmdir($processedDirectoryPath, true);
66
+				GeneralUtility::mkdir($processedDirectoryPath); // recreate the directory.
67
+
68
+				$message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles);
69
+				$this->outputLine($message);
70
+
71
+				$count = $this->getDataService()
72
+					->count(
73
+						'sys_file_processedfile',
74
+						[
75
+							'storage' => $storage->getUid()
76
+						]
77
+					);
78
+
79
+				// Remove the record as well.
80
+				$this->getDataService()->delete('sys_file_processedfile', ['storage' => $storage->getUid()]);
81
+
82
+				$message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $count);
83
+				$this->outputLine($message);
84
+			}
85
+
86
+		}
87
+
88
+		// Remove possible remaining "sys_file_processedfile"
89
+		$this
90
+			->getConnection('sys_file_processedfile')
91
+			->query('TRUNCATE sys_file_processedfile');
92
+	}
93
+
94
+	/**
95
+	 * @return \Fab\Media\Cache\CacheService|object
96
+	 */
97
+	protected function getCacheService()
98
+	{
99
+		return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class);
100
+	}
101
+
102
+	/**
103
+	 * @return StorageRepository|object
104
+	 */
105
+	protected function getStorageRepository()
106
+	{
107
+		return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
108
+	}
109
+
110
+	/**
111
+	 * @return object|DataService
112
+	 */
113
+	protected function getDataService(): DataService
114
+	{
115
+		return GeneralUtility::makeInstance(DataService::class);
116
+	}
117
+
118
+	/**
119
+	 * @param string $tableName
120
+	 * @return object|Connection
121
+	 */
122
+	protected function getConnection($tableName): Connection
123
+	{
124
+		/** @var ConnectionPool $connectionPool */
125
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
126
+		return $connectionPool->getConnectionForTable($tableName);
127
+	}
128 128
 
129 129
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
                 #$storage->getProcessingFolder()->delete(true); // will not work
59 59
 
60 60
                 // Well... not really FAL friendly but straightforward for Local drivers.
61
-                $processedDirectoryPath = Environment::getPublicPath() . '/' . $storage->getProcessingFolder()->getPublicUrl();
61
+                $processedDirectoryPath = Environment::getPublicPath().'/'.$storage->getProcessingFolder()->getPublicUrl();
62 62
                 $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS);
63 63
                 $numberOfProcessedFiles = iterator_count($fileIterator);
64 64
 
Please login to merge, or discard this patch.
Classes/Index/IndexAnalyser.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -22,169 +22,169 @@
 block discarded – undo
22 22
 class IndexAnalyser implements SingletonInterface
23 23
 {
24 24
 
25
-    /**
26
-     * Return missing file for a given storage.
27
-     *
28
-     * @param ResourceStorage $storage
29
-     * @return array
30
-     */
31
-    public function searchForMissingFiles(ResourceStorage $storage)
32
-    {
33
-
34
-        /** @var ConnectionPool $connectionPool */
35
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
36
-        $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
37
-
38
-        $missingFiles = [];
39
-        $statement = $queryBuilder
40
-            ->select('*')
41
-            ->from('sys_file')
42
-            ->where(
43
-                $queryBuilder->expr()->eq('storage', $storage->getUid())
44
-            )->execute();
45
-        while ($row = $statement->fetchAssociative()) {
46
-
47
-            // This task is very memory consuming on large data set e.g > 20'000 records.
48
-            // We must think of having a pagination if there is the need for such thing.
49
-            $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row);
50
-            if (!$file->exists()) {
51
-                $missingFiles[] = $file;
52
-            }
53
-        }
54
-        return $missingFiles;
55
-    }
56
-
57
-    /**
58
-     * Deletes all missing files for a given storage.
59
-     *
60
-     * @param ResourceStorage $storage
61
-     * @return array
62
-     * @throws \InvalidArgumentException
63
-     */
64
-    public function deleteMissingFiles(ResourceStorage $storage)
65
-    {
66
-        /** @var FileReferenceService $fileReferenceService */
67
-        $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class);
68
-        $missingFiles = $this->searchForMissingFiles($storage);
69
-        $deletedFiles = [];
70
-
71
-        /** @var ConnectionPool $connectionPool */
72
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
73
-
74
-        /** @var \TYPO3\CMS\Core\Resource\File $missingFile */
75
-        foreach ($missingFiles as $missingFile) {
76
-            try {
77
-                // if missingFile has no file references
78
-                if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) {
79
-                    // The case is special as we have a missing file in the file system
80
-                    // As a result, we can't use $fileObject->delete(); which will
81
-                    // raise exception "Error while fetching permissions"
82
-                    $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
83
-                    $queryBuilder->delete('sys_file')
84
-                        ->where($queryBuilder->expr()->eq('uid', $missingFile->getUid()))
85
-                        ->execute();
86
-
87
-                    $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier();
88
-                }
89
-            } catch (\Exception $e) {
90
-                continue;
91
-            }
92
-        }
93
-        return $deletedFiles;
94
-    }
95
-
96
-    /*
25
+	/**
26
+	 * Return missing file for a given storage.
27
+	 *
28
+	 * @param ResourceStorage $storage
29
+	 * @return array
30
+	 */
31
+	public function searchForMissingFiles(ResourceStorage $storage)
32
+	{
33
+
34
+		/** @var ConnectionPool $connectionPool */
35
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
36
+		$queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
37
+
38
+		$missingFiles = [];
39
+		$statement = $queryBuilder
40
+			->select('*')
41
+			->from('sys_file')
42
+			->where(
43
+				$queryBuilder->expr()->eq('storage', $storage->getUid())
44
+			)->execute();
45
+		while ($row = $statement->fetchAssociative()) {
46
+
47
+			// This task is very memory consuming on large data set e.g > 20'000 records.
48
+			// We must think of having a pagination if there is the need for such thing.
49
+			$file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row);
50
+			if (!$file->exists()) {
51
+				$missingFiles[] = $file;
52
+			}
53
+		}
54
+		return $missingFiles;
55
+	}
56
+
57
+	/**
58
+	 * Deletes all missing files for a given storage.
59
+	 *
60
+	 * @param ResourceStorage $storage
61
+	 * @return array
62
+	 * @throws \InvalidArgumentException
63
+	 */
64
+	public function deleteMissingFiles(ResourceStorage $storage)
65
+	{
66
+		/** @var FileReferenceService $fileReferenceService */
67
+		$fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class);
68
+		$missingFiles = $this->searchForMissingFiles($storage);
69
+		$deletedFiles = [];
70
+
71
+		/** @var ConnectionPool $connectionPool */
72
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
73
+
74
+		/** @var \TYPO3\CMS\Core\Resource\File $missingFile */
75
+		foreach ($missingFiles as $missingFile) {
76
+			try {
77
+				// if missingFile has no file references
78
+				if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) {
79
+					// The case is special as we have a missing file in the file system
80
+					// As a result, we can't use $fileObject->delete(); which will
81
+					// raise exception "Error while fetching permissions"
82
+					$queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
83
+					$queryBuilder->delete('sys_file')
84
+						->where($queryBuilder->expr()->eq('uid', $missingFile->getUid()))
85
+						->execute();
86
+
87
+					$deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier();
88
+				}
89
+			} catch (\Exception $e) {
90
+				continue;
91
+			}
92
+		}
93
+		return $deletedFiles;
94
+	}
95
+
96
+	/*
97 97
      * Return duplicates file records
98 98
      *
99 99
      * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
100 100
      * @return array
101 101
      */
102
-    public function searchForDuplicateIdentifiers(ResourceStorage $storage)
103
-    {
104
-        /** @var ConnectionPool $connectionPool */
105
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
106
-        $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
107
-
108
-        $statement = $queryBuilder
109
-            ->select('*')
110
-            ->from('sys_file')
111
-            ->where(
112
-                $queryBuilder->expr()->eq('storage', $storage->getUid())
113
-            )
114
-            ->groupby('identifier')
115
-            ->having('count(*) > 1')
116
-            ->execute();
117
-
118
-        // Detect duplicate records.
119
-        $duplicates = [];
120
-        while ($row = $statement->fetchAssociative()) {
121
-
122
-            $records = $queryBuilder
123
-                ->select('*')
124
-                ->from('sys_file')
125
-                ->where(
126
-                    $queryBuilder->expr()->eq('storage', $storage->getUid())
127
-                )
128
-                ->andWhere(
129
-                    $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier']))
130
-                )
131
-                ->execute();
132
-            $records = $records->fetchAllAssociative();
133
-            $duplicates[$row['identifier']] = $records;
134
-        }
135
-        return $duplicates;
136
-    }
137
-
138
-    /**
139
-     * Return duplicates file records
140
-     *
141
-     * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
142
-     * @return array
143
-     */
144
-    public function searchForDuplicateSha1(ResourceStorage $storage)
145
-    {
146
-        /** @var ConnectionPool $connectionPool */
147
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
148
-        $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
149
-
150
-        $statement = $queryBuilder
151
-            ->select('*')
152
-            ->from('sys_file')
153
-            ->where(
154
-                $queryBuilder->expr()->eq('storage', $storage->getUid())
155
-            )
156
-            ->groupby('sha1')
157
-            ->having('count(*) > 1')
158
-            ->execute();
159
-
160
-        // Detect duplicate records.
161
-        $duplicates = [];
162
-        while ($row = $statement->fetchAssociative()) {
163
-
164
-            $records = $queryBuilder
165
-                ->select('*')
166
-                ->from('sys_file')
167
-                ->where(
168
-                    $queryBuilder->expr()->eq('storage', $storage->getUid())
169
-                )
170
-                ->andWhere(
171
-                    $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1']))
172
-                )
173
-                ->execute();
174
-            $records = $records->fetchAllAssociative();
175
-            $duplicates[$row['sha1']] = $records;
176
-        }
177
-        return $duplicates;
178
-    }
179
-
180
-    /**
181
-     * @param string $tableName
182
-     * @return object|QueryBuilder
183
-     */
184
-    protected function getQueryBuilder($tableName): QueryBuilder
185
-    {
186
-        /** @var ConnectionPool $connectionPool */
187
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
188
-        return $connectionPool->getQueryBuilderForTable($tableName);
189
-    }
102
+	public function searchForDuplicateIdentifiers(ResourceStorage $storage)
103
+	{
104
+		/** @var ConnectionPool $connectionPool */
105
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
106
+		$queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
107
+
108
+		$statement = $queryBuilder
109
+			->select('*')
110
+			->from('sys_file')
111
+			->where(
112
+				$queryBuilder->expr()->eq('storage', $storage->getUid())
113
+			)
114
+			->groupby('identifier')
115
+			->having('count(*) > 1')
116
+			->execute();
117
+
118
+		// Detect duplicate records.
119
+		$duplicates = [];
120
+		while ($row = $statement->fetchAssociative()) {
121
+
122
+			$records = $queryBuilder
123
+				->select('*')
124
+				->from('sys_file')
125
+				->where(
126
+					$queryBuilder->expr()->eq('storage', $storage->getUid())
127
+				)
128
+				->andWhere(
129
+					$queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier']))
130
+				)
131
+				->execute();
132
+			$records = $records->fetchAllAssociative();
133
+			$duplicates[$row['identifier']] = $records;
134
+		}
135
+		return $duplicates;
136
+	}
137
+
138
+	/**
139
+	 * Return duplicates file records
140
+	 *
141
+	 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
142
+	 * @return array
143
+	 */
144
+	public function searchForDuplicateSha1(ResourceStorage $storage)
145
+	{
146
+		/** @var ConnectionPool $connectionPool */
147
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
148
+		$queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file');
149
+
150
+		$statement = $queryBuilder
151
+			->select('*')
152
+			->from('sys_file')
153
+			->where(
154
+				$queryBuilder->expr()->eq('storage', $storage->getUid())
155
+			)
156
+			->groupby('sha1')
157
+			->having('count(*) > 1')
158
+			->execute();
159
+
160
+		// Detect duplicate records.
161
+		$duplicates = [];
162
+		while ($row = $statement->fetchAssociative()) {
163
+
164
+			$records = $queryBuilder
165
+				->select('*')
166
+				->from('sys_file')
167
+				->where(
168
+					$queryBuilder->expr()->eq('storage', $storage->getUid())
169
+				)
170
+				->andWhere(
171
+					$queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1']))
172
+				)
173
+				->execute();
174
+			$records = $records->fetchAllAssociative();
175
+			$duplicates[$row['sha1']] = $records;
176
+		}
177
+		return $duplicates;
178
+	}
179
+
180
+	/**
181
+	 * @param string $tableName
182
+	 * @return object|QueryBuilder
183
+	 */
184
+	protected function getQueryBuilder($tableName): QueryBuilder
185
+	{
186
+		/** @var ConnectionPool $connectionPool */
187
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
188
+		return $connectionPool->getQueryBuilderForTable($tableName);
189
+	}
190 190
 }
Please login to merge, or discard this patch.