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