Completed
Push — master ( 02a2d0...8117b3 )
by Fabien
54:58
created
Classes/Domain/Validator/StorageValidator.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -19,32 +19,32 @@
 block discarded – undo
19 19
 class StorageValidator extends AbstractValidator
20 20
 {
21 21
 
22
-    /**
23
-     * Check if $storageIdentifier is allowed. If it is not valid, throw an exception.
24
-     *
25
-     * @param int $combinedIdentifier
26
-     * @return void
27
-     */
28
-    public function isValid($combinedIdentifier)
29
-    {
22
+	/**
23
+	 * Check if $storageIdentifier is allowed. If it is not valid, throw an exception.
24
+	 *
25
+	 * @param int $combinedIdentifier
26
+	 * @return void
27
+	 */
28
+	public function isValid($combinedIdentifier)
29
+	{
30 30
 
31
-        $allowedStorageIdentifiers = [];
32
-        foreach ($this->getMediaModule()->getAllowedStorages() as $allowedStorage) {
33
-            $allowedStorageIdentifiers[] = $allowedStorage->getUid();
34
-        }
31
+		$allowedStorageIdentifiers = [];
32
+		foreach ($this->getMediaModule()->getAllowedStorages() as $allowedStorage) {
33
+			$allowedStorageIdentifiers[] = $allowedStorage->getUid();
34
+		}
35 35
 
36
-        $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
37
-        if (!in_array($storage->getUid(), $allowedStorageIdentifiers)) {
38
-            $message = sprintf('Storage identifier "%s" is not allowed or is currently off-line.', $combinedIdentifier);
39
-            $this->addError($message, 1380813503);
40
-        }
41
-    }
36
+		$storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
37
+		if (!in_array($storage->getUid(), $allowedStorageIdentifiers)) {
38
+			$message = sprintf('Storage identifier "%s" is not allowed or is currently off-line.', $combinedIdentifier);
39
+			$this->addError($message, 1380813503);
40
+		}
41
+	}
42 42
 
43
-    /**
44
-     * @return MediaModule|object
45
-     */
46
-    protected function getMediaModule()
47
-    {
48
-        return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class);
49
-    }
43
+	/**
44
+	 * @return MediaModule|object
45
+	 */
46
+	protected function getMediaModule()
47
+	{
48
+		return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class);
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Classes/Grid/MetadataRenderer.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,78 +19,78 @@
 block discarded – undo
19 19
 class MetadataRenderer extends ColumnRendererAbstract
20 20
 {
21 21
 
22
-    /**
23
-     * Renders a configurable metadata property of a file in the Grid.
24
-     *
25
-     * @throws \Exception
26
-     * @return string
27
-     */
28
-    public function render()
29
-    {
22
+	/**
23
+	 * Renders a configurable metadata property of a file in the Grid.
24
+	 *
25
+	 * @throws \Exception
26
+	 * @return string
27
+	 */
28
+	public function render()
29
+	{
30 30
 
31
-        if (empty($this->gridRendererConfiguration['property'])) {
32
-            throw new \Exception('Missing property value for Grid Renderer Metadata', 1390391042);
33
-        }
31
+		if (empty($this->gridRendererConfiguration['property'])) {
32
+			throw new \Exception('Missing property value for Grid Renderer Metadata', 1390391042);
33
+		}
34 34
 
35
-        $file = $this->getFileConverter()->convert($this->object);
36
-        $propertyName = $this->gridRendererConfiguration['property'];
35
+		$file = $this->getFileConverter()->convert($this->object);
36
+		$propertyName = $this->gridRendererConfiguration['property'];
37 37
 
38
-        if ($propertyName === 'uid') {
39
-            $metadata = $file->_getMetaData();
40
-            $result = $metadata['uid']; // make an exception here to retrieve the uid of the metadata.
41
-        } else {
42
-            $result = $file->getProperty($propertyName);
43
-        }
38
+		if ($propertyName === 'uid') {
39
+			$metadata = $file->_getMetaData();
40
+			$result = $metadata['uid']; // make an exception here to retrieve the uid of the metadata.
41
+		} else {
42
+			$result = $file->getProperty($propertyName);
43
+		}
44 44
 
45
-        // Avoid bad surprise, converts characters to HTML.
46
-        $fieldType = Tca::table('sys_file_metadata')->field($propertyName)->getType();
47
-        if ($fieldType !== FieldType::TEXTAREA) {
48
-            $result = htmlentities($result);
49
-        } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($result)) {
50
-            $result = htmlentities($result);
51
-        } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($result)) {
52
-            $result = nl2br($result);
53
-        }
45
+		// Avoid bad surprise, converts characters to HTML.
46
+		$fieldType = Tca::table('sys_file_metadata')->field($propertyName)->getType();
47
+		if ($fieldType !== FieldType::TEXTAREA) {
48
+			$result = htmlentities($result);
49
+		} elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($result)) {
50
+			$result = htmlentities($result);
51
+		} elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($result)) {
52
+			$result = nl2br($result);
53
+		}
54 54
 
55
-        return $result;
56
-    }
55
+		return $result;
56
+	}
57 57
 
58
-    /**
59
-     * Check whether a string contains HTML tags.
60
-     *
61
-     * @param string $content the content to be analyzed
62
-     * @return boolean
63
-     */
64
-    protected function hasHtml($content)
65
-    {
66
-        $result = false;
58
+	/**
59
+	 * Check whether a string contains HTML tags.
60
+	 *
61
+	 * @param string $content the content to be analyzed
62
+	 * @return boolean
63
+	 */
64
+	protected function hasHtml($content)
65
+	{
66
+		$result = false;
67 67
 
68
-        // We compare the length of the string with html tags and without html tags.
69
-        if (strlen($content) != strlen(strip_tags($content))) {
70
-            $result = true;
71
-        }
72
-        return $result;
73
-    }
68
+		// We compare the length of the string with html tags and without html tags.
69
+		if (strlen($content) != strlen(strip_tags($content))) {
70
+			$result = true;
71
+		}
72
+		return $result;
73
+	}
74 74
 
75
-    /**
76
-     * Check whether a string contains potential XSS
77
-     *
78
-     * @param string $content the content to be analyzed
79
-     * @return boolean
80
-     */
81
-    protected function isClean($content)
82
-    {
75
+	/**
76
+	 * Check whether a string contains potential XSS
77
+	 *
78
+	 * @param string $content the content to be analyzed
79
+	 * @return boolean
80
+	 */
81
+	protected function isClean($content)
82
+	{
83 83
 
84
-        // @todo implement me!
85
-        $result = true;
86
-        return $result;
87
-    }
84
+		// @todo implement me!
85
+		$result = true;
86
+		return $result;
87
+	}
88 88
 
89
-    /**
90
-     * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
91
-     */
92
-    protected function getFileConverter()
93
-    {
94
-        return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
95
-    }
89
+	/**
90
+	 * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
91
+	 */
92
+	protected function getFileConverter()
93
+	{
94
+		return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Classes/Grid/PreviewRenderer.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -21,82 +21,82 @@
 block discarded – undo
21 21
 class PreviewRenderer extends ColumnRendererAbstract
22 22
 {
23 23
 
24
-    /**
25
-     * Render a preview of a file in the Grid.
26
-     *
27
-     * @return string
28
-     */
29
-    public function render()
30
-    {
24
+	/**
25
+	 * Render a preview of a file in the Grid.
26
+	 *
27
+	 * @return string
28
+	 */
29
+	public function render()
30
+	{
31 31
 
32
-        $file = $this->getFileConverter()->convert($this->object);
32
+		$file = $this->getFileConverter()->convert($this->object);
33 33
 
34
-        $uri = false;
35
-        $appendTime = true;
34
+		$uri = false;
35
+		$appendTime = true;
36 36
 
37
-        // Compute image-editor or link-creator URL.
38
-        if ($this->getModuleLoader()->hasPlugin('imageEditor')) {
39
-            $appendTime = false;
40
-            $uri = $this->getPluginUri('ImageEditor');
41
-        } elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) {
42
-            $appendTime = false;
43
-            $uri = $this->getPluginUri('LinkCreator');
44
-        }
37
+		// Compute image-editor or link-creator URL.
38
+		if ($this->getModuleLoader()->hasPlugin('imageEditor')) {
39
+			$appendTime = false;
40
+			$uri = $this->getPluginUri('ImageEditor');
41
+		} elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) {
42
+			$appendTime = false;
43
+			$uri = $this->getPluginUri('LinkCreator');
44
+		}
45 45
 
46
-        $result = $this->getThumbnailService($file)
47
-            ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
48
-            ->setAppendTimeStamp($appendTime)
49
-            ->setTarget(ThumbnailInterface::TARGET_BLANK)
50
-            ->setAnchorUri($uri)
51
-            ->setAttributes([])
52
-            ->create();
46
+		$result = $this->getThumbnailService($file)
47
+			->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
48
+			->setAppendTimeStamp($appendTime)
49
+			->setTarget(ThumbnailInterface::TARGET_BLANK)
50
+			->setAnchorUri($uri)
51
+			->setAttributes([])
52
+			->create();
53 53
 
54
-        // Add file info
55
-        $result .= sprintf('<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
56
-            $this->getMetadataViewHelper()->render($file)
57
-        );
58
-        return $result;
59
-    }
54
+		// Add file info
55
+		$result .= sprintf('<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
56
+			$this->getMetadataViewHelper()->render($file)
57
+		);
58
+		return $result;
59
+	}
60 60
 
61
-    /**
62
-     * @param File $file
63
-     * @return \Fab\Media\Thumbnail\ThumbnailService|object
64
-     */
65
-    protected function getThumbnailService(File $file)
66
-    {
67
-        return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailService::class, $file);
68
-    }
61
+	/**
62
+	 * @param File $file
63
+	 * @return \Fab\Media\Thumbnail\ThumbnailService|object
64
+	 */
65
+	protected function getThumbnailService(File $file)
66
+	{
67
+		return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailService::class, $file);
68
+	}
69 69
 
70
-    /**
71
-     * @return \Fab\Media\ViewHelpers\MetadataViewHelper|object
72
-     */
73
-    protected function getMetadataViewHelper()
74
-    {
75
-        return GeneralUtility::makeInstance(\Fab\Media\ViewHelpers\MetadataViewHelper::class);
76
-    }
70
+	/**
71
+	 * @return \Fab\Media\ViewHelpers\MetadataViewHelper|object
72
+	 */
73
+	protected function getMetadataViewHelper()
74
+	{
75
+		return GeneralUtility::makeInstance(\Fab\Media\ViewHelpers\MetadataViewHelper::class);
76
+	}
77 77
 
78
-    /**
79
-     * @param string $controllerName
80
-     * @return string
81
-     */
82
-    protected function getPluginUri($controllerName)
83
-    {
84
-        $urlParameters = array(
85
-            MediaModule::getParameterPrefix() => array(
86
-                'controller' => $controllerName,
87
-                'action' => 'show',
88
-                'file' => $this->object->getUid(),
89
-            ),
90
-        );
91
-        return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters);
92
-    }
78
+	/**
79
+	 * @param string $controllerName
80
+	 * @return string
81
+	 */
82
+	protected function getPluginUri($controllerName)
83
+	{
84
+		$urlParameters = array(
85
+			MediaModule::getParameterPrefix() => array(
86
+				'controller' => $controllerName,
87
+				'action' => 'show',
88
+				'file' => $this->object->getUid(),
89
+			),
90
+		);
91
+		return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters);
92
+	}
93 93
 
94
-    /**
95
-     * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
96
-     */
97
-    protected function getFileConverter()
98
-    {
99
-        return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
100
-    }
94
+	/**
95
+	 * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
96
+	 */
97
+	protected function getFileConverter()
98
+	{
99
+		return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
100
+	}
101 101
 
102 102
 }
Please login to merge, or discard this patch.
Classes/Hook/FileUploadHook.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,40 +19,40 @@
 block discarded – undo
19 19
 class FileUploadHook implements ExtendedFileUtilityProcessDataHookInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @param string $action The action
24
-     * @param array $cmdArr The parameter sent to the action handler
25
-     * @param array $result The results of all calls to the action handler
26
-     * @param ExtendedFileUtility $pObj The parent object
27
-     * @return void
28
-     */
29
-    public function processData_postProcessAction($action, array $cmdArr, array $result, ExtendedFileUtility $pObj)
30
-    {
31
-        if ($action === 'upload') {
32
-            /** @var \TYPO3\CMS\Core\Resource\File[] $files */
33
-            $files = array_pop($result);
34
-            if (!is_array($files)) {
35
-                return;
36
-            }
22
+	/**
23
+	 * @param string $action The action
24
+	 * @param array $cmdArr The parameter sent to the action handler
25
+	 * @param array $result The results of all calls to the action handler
26
+	 * @param ExtendedFileUtility $pObj The parent object
27
+	 * @return void
28
+	 */
29
+	public function processData_postProcessAction($action, array $cmdArr, array $result, ExtendedFileUtility $pObj)
30
+	{
31
+		if ($action === 'upload') {
32
+			/** @var \TYPO3\CMS\Core\Resource\File[] $files */
33
+			$files = array_pop($result);
34
+			if (!is_array($files)) {
35
+				return;
36
+			}
37 37
 
38
-            foreach ($files as $file) {
39
-                // Run the indexer for extracting metadata.
40
-                $this->getMediaIndexer($file->getStorage())
41
-                    ->extractMetadata($file)
42
-                    ->applyDefaultCategories($file);
43
-            }
44
-        }
45
-    }
38
+			foreach ($files as $file) {
39
+				// Run the indexer for extracting metadata.
40
+				$this->getMediaIndexer($file->getStorage())
41
+					->extractMetadata($file)
42
+					->applyDefaultCategories($file);
43
+			}
44
+		}
45
+	}
46 46
 
47
-    /**
48
-     * Get the instance of the Indexer service to update the metadata of the file.
49
-     *
50
-     * @param ResourceStorage $storage
51
-     * @return \Fab\Media\Index\MediaIndexer|object
52
-     */
53
-    protected function getMediaIndexer($storage)
54
-    {
55
-        return GeneralUtility::makeInstance(\Fab\Media\Index\MediaIndexer::class, $storage);
56
-    }
47
+	/**
48
+	 * Get the instance of the Indexer service to update the metadata of the file.
49
+	 *
50
+	 * @param ResourceStorage $storage
51
+	 * @return \Fab\Media\Index\MediaIndexer|object
52
+	 */
53
+	protected function getMediaIndexer($storage)
54
+	{
55
+		return GeneralUtility::makeInstance(\Fab\Media\Index\MediaIndexer::class, $storage);
56
+	}
57 57
 
58 58
 }
Please login to merge, or discard this patch.
Classes/Hook/DataHandlerHook.php 1 patch
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -23,311 +23,311 @@
 block discarded – undo
23 23
 class DataHandlerHook
24 24
 {
25 25
 
26
-    /**
27
-     * Store indexed file before the Data Handler start "working".
28
-     *
29
-     * @var array
30
-     */
31
-    protected $beforeDataHandlerProcessFileIdentifiers = [];
32
-
33
-    /**
34
-     * Store indexed file after the Data Handler has done its job.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $afterDataHandlerProcessFileIdentifiers = [];
39
-
40
-    /**
41
-     * Internal key for the Cache Manager.
42
-     *
43
-     * @var string
44
-     */
45
-    protected $registerKey = 'media-hook-elementsToKeepTrack';
46
-
47
-    /**
48
-     * First procedures to launch before all operations in DataHandler.
49
-     *
50
-     * Feed variable $this->beforeDataHandlerProcessFileIdentifiers
51
-     *
52
-     * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object
53
-     * @return void
54
-     */
55
-    public function processDatamap_beforeStart(DataHandler $caller)
56
-    {
57
-
58
-        // Use a register to keep track of files.
59
-        // It is required according to TCEMain behaviour which register "elements to be deleted".
60
-        // Those element must not be forgotten.
61
-        $this->initializeFileRegister();
62
-        $this->registerFilesToKeepTrack();
63
-
64
-        foreach ($caller->datamap as $tableName => $configuration) {
65
-
66
-            $id = key($configuration);
67
-            if (!MathUtility::canBeInterpretedAsInteger($id)) {
68
-                continue;
69
-            }
70
-
71
-            /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
72
-            $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
73
-            if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) {
74
-                $refIndexObj->setWorkspaceId($caller->BE_USER->workspace);
75
-            }
76
-            $indexes = $refIndexObj->updateRefIndexTable($tableName, $id);
77
-
78
-            // Make sure $index is an array.
79
-            if (!is_array($indexes)) {
80
-                $indexes = [];
81
-            }
82
-
83
-            $fileIdentifiers = $this->lookForFiles($indexes);
84
-            $this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers);
85
-        }
86
-    }
87
-
88
-    /**
89
-     * Last procedures to launch after all operations in DataHandler.
90
-     *
91
-     * Process field "number_of_references" which may require updates.
92
-     *
93
-     * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object
94
-     * @return void
95
-     */
96
-    public function processDatamap_afterAllOperations(DataHandler $caller)
97
-    {
98
-
99
-        // First collect files which have been involved.
100
-        foreach ($caller->datamap as $tableName => $configuration) {
101
-
102
-            $id = key($configuration);
103
-
104
-            /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
105
-            $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
106
-            if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) {
107
-                $refIndexObj->setWorkspaceId($caller->BE_USER->workspace);
108
-            }
109
-            $indexes = $refIndexObj->updateRefIndexTable($tableName, $id);
110
-
111
-            // Make sure $index is an array.
112
-            if (!is_array($indexes)) {
113
-                $indexes = [];
114
-            }
115
-
116
-            $fileIdentifiers = $this->lookForFiles($indexes);
117
-            $this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers);
118
-        }
119
-
120
-        // After collecting files, update the column "number_of_references".
121
-        foreach ($this->getFileToProcess() as $fileIdentifier) {
122
-            try {
123
-                $file = ResourceFactory::getInstance()->getFileObject($fileIdentifier);
124
-                $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file);
125
-
126
-                $values = array(
127
-                    'number_of_references' => $numberOfReferences
128
-                );
129
-                $this->getDataService()->update('sys_file', $values, ['uid' => $file->getUid()]);
130
-            } catch (FileDoesNotExistException $fileDoesNotExistException) {
131
-                // Do nothing here. A file that does not exist needs no update.
132
-                // See https://github.com/fabarea/media/issues/159 for more information.
133
-            }
134
-        }
135
-    }
136
-
137
-    /**
138
-     * @return void
139
-     */
140
-    protected function initializeFileRegister()
141
-    {
142
-
143
-        $items = $this->getMemoryCache()->get($this->registerKey);
144
-        if (!is_array($items)) {
145
-            $this->getMemoryCache()->set($this->registerKey, []);
146
-        }
147
-    }
148
-
149
-    /**
150
-     * @return void
151
-     */
152
-    protected function registerFilesToKeepTrack()
153
-    {
154
-        $fileIdentifiers = [];
155
-        $elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted');
156
-        if (is_array($elementsToBeDeleted)) {
157
-            foreach ($elementsToBeDeleted as $tableName => $element) {
158
-
159
-                if ($tableName === 'sys_file_reference') {
160
-
161
-                    $fileReferenceIdentifier = key($element);
162
-                    if ($element[$fileReferenceIdentifier] === true) {
163
-                        $fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier);
164
-                        $fileIdentifiers[] = $fileIdentifier;
165
-                    }
166
-                }
167
-            }
168
-        }
169
-
170
-        // Put back in the memory cache the value.
171
-        $items = $this->getMemoryCache()->get($this->registerKey);
172
-        $mergedItems = array_merge($items, $fileIdentifiers);
173
-        $this->getMemoryCache()->set($this->registerKey, $mergedItems);
174
-    }
175
-
176
-    /**
177
-     * @return array
178
-     */
179
-    protected function getRegisteredFiles()
180
-    {
181
-        $files = $this->getMemoryCache()->get($this->registerKey);
182
-        return $files;
183
-    }
184
-
185
-    /**
186
-     * Look for file which are within the reference index.
187
-     *
188
-     * @return array
189
-     */
190
-    protected function getFileToProcess()
191
-    {
192
-        $fileIdentifiers = array_merge(
193
-            $this->beforeDataHandlerProcessFileIdentifiers,
194
-            $this->afterDataHandlerProcessFileIdentifiers,
195
-            $this->getRegisteredFiles()
196
-        );
197
-        return array_unique($fileIdentifiers);
198
-    }
199
-
200
-    /**
201
-     * @param array $fileIdentifiers
202
-     * @return void
203
-     */
204
-    protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers)
205
-    {
206
-        $this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers);
207
-    }
208
-
209
-    /**
210
-     * @param array $fileIdentifiers
211
-     * @return void
212
-     */
213
-    protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers)
214
-    {
215
-        $this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers);
216
-    }
217
-
218
-    /**
219
-     * Look for file which are within the reference index.
220
-     *
221
-     * @param array $indexes
222
-     * @return array
223
-     */
224
-    protected function lookForFiles(array $indexes)
225
-    {
226
-
227
-        $fileIdentifiers = [];
228
-        if (isset($indexes['relations'])) {
229
-
230
-            foreach ($indexes['relations'] as $index) {
231
-                if (is_array($index)) {
232
-                    if ($this->isSoftReferenceImage($index)) {
233
-                        $fileIdentifiers[] = $index['ref_uid'];
234
-                    } elseif ($this->isSoftReferenceLink($index)) {
235
-                        $fileIdentifiers[] = $index['ref_uid'];
236
-                    } elseif ($this->isFileReference($index)) {
237
-                        $fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']);
238
-                    }
239
-                }
240
-            }
241
-        }
242
-
243
-        return $fileIdentifiers;
244
-    }
245
-
246
-    /**
247
-     * @param array $index
248
-     * @return bool
249
-     */
250
-    public function isFileReference(array $index)
251
-    {
252
-        return $index['ref_table'] === 'sys_file_reference';
253
-    }
254
-
255
-    /**
256
-     * @param array $index
257
-     * @return bool
258
-     */
259
-    public function isSoftReferenceLink(array $index)
260
-    {
261
-        return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file';
262
-    }
263
-
264
-    /**
265
-     * @param array $index
266
-     * @return bool
267
-     */
268
-    public function isSoftReferenceImage(array $index)
269
-    {
270
-        return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file';
271
-    }
272
-
273
-    /**
274
-     * Retrieve the File identifier.
275
-     *
276
-     * @param $fileReferenceIdentifier
277
-     * @return int
278
-     * @throws \Exception
279
-     */
280
-    protected function findFileByFileReference($fileReferenceIdentifier)
281
-    {
282
-        $record = $this->getDataService()->getRecord(
283
-            'sys_file_reference',
284
-            [
285
-                'uid' => $fileReferenceIdentifier
286
-            ]
287
-        );
288
-
289
-        if (empty($record)) {
290
-            throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796);
291
-        }
292
-
293
-        $fileIdentifier = $record['uid_local'];
294
-        return $fileIdentifier;
295
-    }
296
-
297
-    /**
298
-     * @return \Fab\Media\Resource\FileReferenceService|object
299
-     */
300
-    protected function getFileReferenceService()
301
-    {
302
-        return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class);
303
-    }
304
-
305
-    /**
306
-     * Gets an instance of the memory cache.
307
-     *
308
-     * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
309
-     */
310
-    protected function getMemoryCache()
311
-    {
312
-        return $this->getCacheManager()->getCache('cache_runtime');
313
-    }
314
-
315
-    /**
316
-     * Create and returns an instance of the CacheManager
317
-     *
318
-     * @return \TYPO3\CMS\Core\Cache\CacheManager|object
319
-     */
320
-    protected function getCacheManager()
321
-    {
322
-        return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
323
-    }
324
-
325
-    /**
326
-     * @return object|DataService
327
-     */
328
-    protected function getDataService(): DataService
329
-    {
330
-        return GeneralUtility::makeInstance(DataService::class);
331
-    }
26
+	/**
27
+	 * Store indexed file before the Data Handler start "working".
28
+	 *
29
+	 * @var array
30
+	 */
31
+	protected $beforeDataHandlerProcessFileIdentifiers = [];
32
+
33
+	/**
34
+	 * Store indexed file after the Data Handler has done its job.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $afterDataHandlerProcessFileIdentifiers = [];
39
+
40
+	/**
41
+	 * Internal key for the Cache Manager.
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $registerKey = 'media-hook-elementsToKeepTrack';
46
+
47
+	/**
48
+	 * First procedures to launch before all operations in DataHandler.
49
+	 *
50
+	 * Feed variable $this->beforeDataHandlerProcessFileIdentifiers
51
+	 *
52
+	 * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object
53
+	 * @return void
54
+	 */
55
+	public function processDatamap_beforeStart(DataHandler $caller)
56
+	{
57
+
58
+		// Use a register to keep track of files.
59
+		// It is required according to TCEMain behaviour which register "elements to be deleted".
60
+		// Those element must not be forgotten.
61
+		$this->initializeFileRegister();
62
+		$this->registerFilesToKeepTrack();
63
+
64
+		foreach ($caller->datamap as $tableName => $configuration) {
65
+
66
+			$id = key($configuration);
67
+			if (!MathUtility::canBeInterpretedAsInteger($id)) {
68
+				continue;
69
+			}
70
+
71
+			/** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
72
+			$refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
73
+			if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) {
74
+				$refIndexObj->setWorkspaceId($caller->BE_USER->workspace);
75
+			}
76
+			$indexes = $refIndexObj->updateRefIndexTable($tableName, $id);
77
+
78
+			// Make sure $index is an array.
79
+			if (!is_array($indexes)) {
80
+				$indexes = [];
81
+			}
82
+
83
+			$fileIdentifiers = $this->lookForFiles($indexes);
84
+			$this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers);
85
+		}
86
+	}
87
+
88
+	/**
89
+	 * Last procedures to launch after all operations in DataHandler.
90
+	 *
91
+	 * Process field "number_of_references" which may require updates.
92
+	 *
93
+	 * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object
94
+	 * @return void
95
+	 */
96
+	public function processDatamap_afterAllOperations(DataHandler $caller)
97
+	{
98
+
99
+		// First collect files which have been involved.
100
+		foreach ($caller->datamap as $tableName => $configuration) {
101
+
102
+			$id = key($configuration);
103
+
104
+			/** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
105
+			$refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
106
+			if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) {
107
+				$refIndexObj->setWorkspaceId($caller->BE_USER->workspace);
108
+			}
109
+			$indexes = $refIndexObj->updateRefIndexTable($tableName, $id);
110
+
111
+			// Make sure $index is an array.
112
+			if (!is_array($indexes)) {
113
+				$indexes = [];
114
+			}
115
+
116
+			$fileIdentifiers = $this->lookForFiles($indexes);
117
+			$this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers);
118
+		}
119
+
120
+		// After collecting files, update the column "number_of_references".
121
+		foreach ($this->getFileToProcess() as $fileIdentifier) {
122
+			try {
123
+				$file = ResourceFactory::getInstance()->getFileObject($fileIdentifier);
124
+				$numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file);
125
+
126
+				$values = array(
127
+					'number_of_references' => $numberOfReferences
128
+				);
129
+				$this->getDataService()->update('sys_file', $values, ['uid' => $file->getUid()]);
130
+			} catch (FileDoesNotExistException $fileDoesNotExistException) {
131
+				// Do nothing here. A file that does not exist needs no update.
132
+				// See https://github.com/fabarea/media/issues/159 for more information.
133
+			}
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * @return void
139
+	 */
140
+	protected function initializeFileRegister()
141
+	{
142
+
143
+		$items = $this->getMemoryCache()->get($this->registerKey);
144
+		if (!is_array($items)) {
145
+			$this->getMemoryCache()->set($this->registerKey, []);
146
+		}
147
+	}
148
+
149
+	/**
150
+	 * @return void
151
+	 */
152
+	protected function registerFilesToKeepTrack()
153
+	{
154
+		$fileIdentifiers = [];
155
+		$elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted');
156
+		if (is_array($elementsToBeDeleted)) {
157
+			foreach ($elementsToBeDeleted as $tableName => $element) {
158
+
159
+				if ($tableName === 'sys_file_reference') {
160
+
161
+					$fileReferenceIdentifier = key($element);
162
+					if ($element[$fileReferenceIdentifier] === true) {
163
+						$fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier);
164
+						$fileIdentifiers[] = $fileIdentifier;
165
+					}
166
+				}
167
+			}
168
+		}
169
+
170
+		// Put back in the memory cache the value.
171
+		$items = $this->getMemoryCache()->get($this->registerKey);
172
+		$mergedItems = array_merge($items, $fileIdentifiers);
173
+		$this->getMemoryCache()->set($this->registerKey, $mergedItems);
174
+	}
175
+
176
+	/**
177
+	 * @return array
178
+	 */
179
+	protected function getRegisteredFiles()
180
+	{
181
+		$files = $this->getMemoryCache()->get($this->registerKey);
182
+		return $files;
183
+	}
184
+
185
+	/**
186
+	 * Look for file which are within the reference index.
187
+	 *
188
+	 * @return array
189
+	 */
190
+	protected function getFileToProcess()
191
+	{
192
+		$fileIdentifiers = array_merge(
193
+			$this->beforeDataHandlerProcessFileIdentifiers,
194
+			$this->afterDataHandlerProcessFileIdentifiers,
195
+			$this->getRegisteredFiles()
196
+		);
197
+		return array_unique($fileIdentifiers);
198
+	}
199
+
200
+	/**
201
+	 * @param array $fileIdentifiers
202
+	 * @return void
203
+	 */
204
+	protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers)
205
+	{
206
+		$this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers);
207
+	}
208
+
209
+	/**
210
+	 * @param array $fileIdentifiers
211
+	 * @return void
212
+	 */
213
+	protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers)
214
+	{
215
+		$this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers);
216
+	}
217
+
218
+	/**
219
+	 * Look for file which are within the reference index.
220
+	 *
221
+	 * @param array $indexes
222
+	 * @return array
223
+	 */
224
+	protected function lookForFiles(array $indexes)
225
+	{
226
+
227
+		$fileIdentifiers = [];
228
+		if (isset($indexes['relations'])) {
229
+
230
+			foreach ($indexes['relations'] as $index) {
231
+				if (is_array($index)) {
232
+					if ($this->isSoftReferenceImage($index)) {
233
+						$fileIdentifiers[] = $index['ref_uid'];
234
+					} elseif ($this->isSoftReferenceLink($index)) {
235
+						$fileIdentifiers[] = $index['ref_uid'];
236
+					} elseif ($this->isFileReference($index)) {
237
+						$fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']);
238
+					}
239
+				}
240
+			}
241
+		}
242
+
243
+		return $fileIdentifiers;
244
+	}
245
+
246
+	/**
247
+	 * @param array $index
248
+	 * @return bool
249
+	 */
250
+	public function isFileReference(array $index)
251
+	{
252
+		return $index['ref_table'] === 'sys_file_reference';
253
+	}
254
+
255
+	/**
256
+	 * @param array $index
257
+	 * @return bool
258
+	 */
259
+	public function isSoftReferenceLink(array $index)
260
+	{
261
+		return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file';
262
+	}
263
+
264
+	/**
265
+	 * @param array $index
266
+	 * @return bool
267
+	 */
268
+	public function isSoftReferenceImage(array $index)
269
+	{
270
+		return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file';
271
+	}
272
+
273
+	/**
274
+	 * Retrieve the File identifier.
275
+	 *
276
+	 * @param $fileReferenceIdentifier
277
+	 * @return int
278
+	 * @throws \Exception
279
+	 */
280
+	protected function findFileByFileReference($fileReferenceIdentifier)
281
+	{
282
+		$record = $this->getDataService()->getRecord(
283
+			'sys_file_reference',
284
+			[
285
+				'uid' => $fileReferenceIdentifier
286
+			]
287
+		);
288
+
289
+		if (empty($record)) {
290
+			throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796);
291
+		}
292
+
293
+		$fileIdentifier = $record['uid_local'];
294
+		return $fileIdentifier;
295
+	}
296
+
297
+	/**
298
+	 * @return \Fab\Media\Resource\FileReferenceService|object
299
+	 */
300
+	protected function getFileReferenceService()
301
+	{
302
+		return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class);
303
+	}
304
+
305
+	/**
306
+	 * Gets an instance of the memory cache.
307
+	 *
308
+	 * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
309
+	 */
310
+	protected function getMemoryCache()
311
+	{
312
+		return $this->getCacheManager()->getCache('cache_runtime');
313
+	}
314
+
315
+	/**
316
+	 * Create and returns an instance of the CacheManager
317
+	 *
318
+	 * @return \TYPO3\CMS\Core\Cache\CacheManager|object
319
+	 */
320
+	protected function getCacheManager()
321
+	{
322
+		return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
323
+	}
324
+
325
+	/**
326
+	 * @return object|DataService
327
+	 */
328
+	protected function getDataService(): DataService
329
+	{
330
+		return GeneralUtility::makeInstance(DataService::class);
331
+	}
332 332
 
333 333
 }
Please login to merge, or discard this patch.
Classes/Thumbnail/ThumbnailGenerator.php 1 patch
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -22,248 +22,248 @@
 block discarded – undo
22 22
 class ThumbnailGenerator
23 23
 {
24 24
 
25
-    /**
26
-     * @var int
27
-     */
28
-    protected $numberOfTraversedFiles = 0;
29
-
30
-    /**
31
-     * @var int
32
-     */
33
-    protected $numberOfProcessedFiles = 0;
34
-
35
-    /**
36
-     * @var int
37
-     */
38
-    protected $numberOfMissingFiles = 0;
39
-
40
-    /**
41
-     * @var array
42
-     */
43
-    protected $configuration = [];
44
-
45
-    /**
46
-     * @var ResourceStorage
47
-     */
48
-    protected $storage = null;
49
-
50
-    /**
51
-     * @var Selection
52
-     */
53
-    protected $selection = null;
54
-
55
-    /**
56
-     * @var array
57
-     */
58
-    protected $resultSet = [];
59
-
60
-    /**
61
-     * @var array
62
-     */
63
-    protected $newProcessedFileIdentifiers = [];
64
-
65
-    /**
66
-     * Internal variable
67
-     *
68
-     * @var int
69
-     */
70
-    protected $lastInsertedProcessedFile = 0;
71
-
72
-    /**
73
-     * Generate
74
-     *
75
-     * @param int $limit
76
-     * @param int $offset
77
-     * @return void
78
-     * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
79
-     * @throws \InvalidArgumentException
80
-     * @throws \Fab\Media\Exception\InvalidKeyInArrayException
81
-     * @throws \Fab\Media\Exception\MissingTcaConfigurationException
82
-     */
83
-    public function generate($limit = 0, $offset = 0)
84
-    {
85
-
86
-        // Compute a possible limit and offset for the query.
87
-        //$limitAndOffset = '';
88
-        //if ($limit > 0 || $offset > 0) {
89
-        //    $limitAndOffset = $limit . ' OFFSET ' . $offset;
90
-        //}
91
-
92
-        $rows = $this->getDataService()
93
-            ->getRecords(
94
-                'sys_file',
95
-                [
96
-                    'storage' => $this->storage->getUid()
97
-                ] // todo add limit and offset
98
-            );
99
-
100
-        foreach ($rows as $row) {
101
-
102
-
103
-            $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row);
104
-
105
-            if ($file->exists()) {
106
-
107
-                $thumbnailUri = $this->getThumbnailService($file)
108
-                    ->setOutputType(ThumbnailInterface::OUTPUT_URI)
109
-                    ->setConfiguration($this->configuration)
110
-                    ->create();
111
-
112
-                $this->resultSet[$file->getUid()] = array(
113
-                    'fileUid' => $file->getUid(),
114
-                    'fileIdentifier' => $file->getIdentifier(),
115
-                    'thumbnailUri' => strpos($thumbnailUri, '_processed_') > 0 ? $thumbnailUri : '', // only returns the thumbnail uri if a processed file has been created.
116
-                );
117
-
118
-                //if ($this->isNewProcessedFile()) { // todo restore me
119
-                //    $this->incrementNumberOfProcessedFiles();
120
-                //   $this->newProcessedFileIdentifiers[$file->getUid()] = $this->lastInsertedProcessedFile;
121
-                //}
122
-
123
-                $this->incrementNumberOfTraversedFiles();
124
-            } else {
125
-                $this->incrementNumberOfMissingFiles();
126
-            }
127
-        }
128
-
129
-    }
130
-
131
-    /**
132
-     * @return int
133
-     */
134
-    protected function isNewProcessedFile()
135
-    {
136
-        $isNewProcessedFile = false;
137
-        $lastInsertedId = $this->getDatabaseConnection()->sql_insert_id();
138
-        if ($lastInsertedId > 0 && $lastInsertedId !== $this->lastInsertedProcessedFile) {
139
-            $this->lastInsertedProcessedFile = $lastInsertedId;
140
-            $isNewProcessedFile = true;
141
-        }
142
-        return $isNewProcessedFile;
143
-    }
144
-
145
-    /**
146
-     * @return int
147
-     */
148
-    public function getNumberOfTraversedFiles()
149
-    {
150
-        return $this->numberOfTraversedFiles;
151
-    }
152
-
153
-    /**
154
-     * @return int
155
-     */
156
-    public function getNumberOfProcessedFiles()
157
-    {
158
-        return $this->numberOfProcessedFiles;
159
-    }
160
-
161
-    /**
162
-     * @return int
163
-     */
164
-    public function getTotalNumberOfFiles()
165
-    {
166
-        return $this->getDataService()
167
-            ->count(
168
-                'sys_file',
169
-                [
170
-                    'storage' => $this->storage->getUid()
171
-                ]
172
-            );
173
-    }
174
-
175
-    /**
176
-     * @return array
177
-     */
178
-    public function getResultSet()
179
-    {
180
-        return $this->resultSet;
181
-    }
182
-
183
-    /**
184
-     * @return array
185
-     */
186
-    public function getNewProcessedFileIdentifiers()
187
-    {
188
-        return $this->newProcessedFileIdentifiers;
189
-    }
190
-
191
-    /**
192
-     * @return int
193
-     */
194
-    public function getNumberOfMissingFiles()
195
-    {
196
-        return $this->numberOfMissingFiles;
197
-    }
198
-
199
-    /**
200
-     * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
201
-     * @return $this
202
-     */
203
-    public function setStorage($storage)
204
-    {
205
-        $this->storage = $storage;
206
-        return $this;
207
-    }
208
-
209
-    /**
210
-     * @param \Fab\Vidi\Domain\Model\Selection $selection
211
-     * @return $this
212
-     */
213
-    public function setSelection($selection)
214
-    {
215
-        $this->selection = $selection;
216
-        return $this;
217
-    }
218
-
219
-    /**
220
-     * @param array $configuration
221
-     * @return $this
222
-     */
223
-    public function setConfiguration($configuration)
224
-    {
225
-        $this->configuration = $configuration;
226
-        return $this;
227
-    }
228
-
229
-    /**
230
-     * @param File $file
231
-     * @return object|ThumbnailService
232
-     */
233
-    protected function getThumbnailService(File $file)
234
-    {
235
-        return GeneralUtility::makeInstance(ThumbnailService::class, $file);
236
-    }
237
-
238
-    /**
239
-     * @return void
240
-     */
241
-    protected function incrementNumberOfTraversedFiles()
242
-    {
243
-        $this->numberOfTraversedFiles++;
244
-    }
245
-
246
-    /**
247
-     * @return void
248
-     */
249
-    protected function incrementNumberOfMissingFiles()
250
-    {
251
-        $this->numberOfMissingFiles++;
252
-    }
253
-
254
-    /**
255
-     * @return void
256
-     */
257
-    protected function incrementNumberOfProcessedFiles()
258
-    {
259
-        $this->numberOfProcessedFiles++;
260
-    }
261
-
262
-    /**
263
-     * @return object|DataService
264
-     */
265
-    protected function getDataService(): DataService
266
-    {
267
-        return GeneralUtility::makeInstance(DataService::class);
268
-    }
25
+	/**
26
+	 * @var int
27
+	 */
28
+	protected $numberOfTraversedFiles = 0;
29
+
30
+	/**
31
+	 * @var int
32
+	 */
33
+	protected $numberOfProcessedFiles = 0;
34
+
35
+	/**
36
+	 * @var int
37
+	 */
38
+	protected $numberOfMissingFiles = 0;
39
+
40
+	/**
41
+	 * @var array
42
+	 */
43
+	protected $configuration = [];
44
+
45
+	/**
46
+	 * @var ResourceStorage
47
+	 */
48
+	protected $storage = null;
49
+
50
+	/**
51
+	 * @var Selection
52
+	 */
53
+	protected $selection = null;
54
+
55
+	/**
56
+	 * @var array
57
+	 */
58
+	protected $resultSet = [];
59
+
60
+	/**
61
+	 * @var array
62
+	 */
63
+	protected $newProcessedFileIdentifiers = [];
64
+
65
+	/**
66
+	 * Internal variable
67
+	 *
68
+	 * @var int
69
+	 */
70
+	protected $lastInsertedProcessedFile = 0;
71
+
72
+	/**
73
+	 * Generate
74
+	 *
75
+	 * @param int $limit
76
+	 * @param int $offset
77
+	 * @return void
78
+	 * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
79
+	 * @throws \InvalidArgumentException
80
+	 * @throws \Fab\Media\Exception\InvalidKeyInArrayException
81
+	 * @throws \Fab\Media\Exception\MissingTcaConfigurationException
82
+	 */
83
+	public function generate($limit = 0, $offset = 0)
84
+	{
85
+
86
+		// Compute a possible limit and offset for the query.
87
+		//$limitAndOffset = '';
88
+		//if ($limit > 0 || $offset > 0) {
89
+		//    $limitAndOffset = $limit . ' OFFSET ' . $offset;
90
+		//}
91
+
92
+		$rows = $this->getDataService()
93
+			->getRecords(
94
+				'sys_file',
95
+				[
96
+					'storage' => $this->storage->getUid()
97
+				] // todo add limit and offset
98
+			);
99
+
100
+		foreach ($rows as $row) {
101
+
102
+
103
+			$file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row);
104
+
105
+			if ($file->exists()) {
106
+
107
+				$thumbnailUri = $this->getThumbnailService($file)
108
+					->setOutputType(ThumbnailInterface::OUTPUT_URI)
109
+					->setConfiguration($this->configuration)
110
+					->create();
111
+
112
+				$this->resultSet[$file->getUid()] = array(
113
+					'fileUid' => $file->getUid(),
114
+					'fileIdentifier' => $file->getIdentifier(),
115
+					'thumbnailUri' => strpos($thumbnailUri, '_processed_') > 0 ? $thumbnailUri : '', // only returns the thumbnail uri if a processed file has been created.
116
+				);
117
+
118
+				//if ($this->isNewProcessedFile()) { // todo restore me
119
+				//    $this->incrementNumberOfProcessedFiles();
120
+				//   $this->newProcessedFileIdentifiers[$file->getUid()] = $this->lastInsertedProcessedFile;
121
+				//}
122
+
123
+				$this->incrementNumberOfTraversedFiles();
124
+			} else {
125
+				$this->incrementNumberOfMissingFiles();
126
+			}
127
+		}
128
+
129
+	}
130
+
131
+	/**
132
+	 * @return int
133
+	 */
134
+	protected function isNewProcessedFile()
135
+	{
136
+		$isNewProcessedFile = false;
137
+		$lastInsertedId = $this->getDatabaseConnection()->sql_insert_id();
138
+		if ($lastInsertedId > 0 && $lastInsertedId !== $this->lastInsertedProcessedFile) {
139
+			$this->lastInsertedProcessedFile = $lastInsertedId;
140
+			$isNewProcessedFile = true;
141
+		}
142
+		return $isNewProcessedFile;
143
+	}
144
+
145
+	/**
146
+	 * @return int
147
+	 */
148
+	public function getNumberOfTraversedFiles()
149
+	{
150
+		return $this->numberOfTraversedFiles;
151
+	}
152
+
153
+	/**
154
+	 * @return int
155
+	 */
156
+	public function getNumberOfProcessedFiles()
157
+	{
158
+		return $this->numberOfProcessedFiles;
159
+	}
160
+
161
+	/**
162
+	 * @return int
163
+	 */
164
+	public function getTotalNumberOfFiles()
165
+	{
166
+		return $this->getDataService()
167
+			->count(
168
+				'sys_file',
169
+				[
170
+					'storage' => $this->storage->getUid()
171
+				]
172
+			);
173
+	}
174
+
175
+	/**
176
+	 * @return array
177
+	 */
178
+	public function getResultSet()
179
+	{
180
+		return $this->resultSet;
181
+	}
182
+
183
+	/**
184
+	 * @return array
185
+	 */
186
+	public function getNewProcessedFileIdentifiers()
187
+	{
188
+		return $this->newProcessedFileIdentifiers;
189
+	}
190
+
191
+	/**
192
+	 * @return int
193
+	 */
194
+	public function getNumberOfMissingFiles()
195
+	{
196
+		return $this->numberOfMissingFiles;
197
+	}
198
+
199
+	/**
200
+	 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
201
+	 * @return $this
202
+	 */
203
+	public function setStorage($storage)
204
+	{
205
+		$this->storage = $storage;
206
+		return $this;
207
+	}
208
+
209
+	/**
210
+	 * @param \Fab\Vidi\Domain\Model\Selection $selection
211
+	 * @return $this
212
+	 */
213
+	public function setSelection($selection)
214
+	{
215
+		$this->selection = $selection;
216
+		return $this;
217
+	}
218
+
219
+	/**
220
+	 * @param array $configuration
221
+	 * @return $this
222
+	 */
223
+	public function setConfiguration($configuration)
224
+	{
225
+		$this->configuration = $configuration;
226
+		return $this;
227
+	}
228
+
229
+	/**
230
+	 * @param File $file
231
+	 * @return object|ThumbnailService
232
+	 */
233
+	protected function getThumbnailService(File $file)
234
+	{
235
+		return GeneralUtility::makeInstance(ThumbnailService::class, $file);
236
+	}
237
+
238
+	/**
239
+	 * @return void
240
+	 */
241
+	protected function incrementNumberOfTraversedFiles()
242
+	{
243
+		$this->numberOfTraversedFiles++;
244
+	}
245
+
246
+	/**
247
+	 * @return void
248
+	 */
249
+	protected function incrementNumberOfMissingFiles()
250
+	{
251
+		$this->numberOfMissingFiles++;
252
+	}
253
+
254
+	/**
255
+	 * @return void
256
+	 */
257
+	protected function incrementNumberOfProcessedFiles()
258
+	{
259
+		$this->numberOfProcessedFiles++;
260
+	}
261
+
262
+	/**
263
+	 * @return object|DataService
264
+	 */
265
+	protected function getDataService(): DataService
266
+	{
267
+		return GeneralUtility::makeInstance(DataService::class);
268
+	}
269 269
 }
Please login to merge, or discard this patch.
Classes/Resource/FileReferenceService.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -20,164 +20,164 @@
 block discarded – undo
20 20
  */
21 21
 class FileReferenceService
22 22
 {
23
-    /**
24
-     * Return all references found in sys_file_reference.
25
-     *
26
-     * @param File|int $file
27
-     * @return array
28
-     */
29
-    public function findFileReferences($file)
30
-    {
31
-
32
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
33
-
34
-        // Get the file references of the file.
35
-        return $this->getDataService()->getRecords(
36
-            'sys_file_reference',
37
-            [
38
-                'uid_local' => $fileIdentifier,
39
-            ]
40
-        );
41
-    }
42
-
43
-    /**
44
-     * Return soft image references.
45
-     *
46
-     * @param File|int $file
47
-     * @return array
48
-     */
49
-    public function findSoftImageReferences($file)
50
-    {
51
-
52
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
53
-
54
-        // Get the file references of the file in the RTE.
55
-        $softReferences = $this->getDataService()->getRecords(
56
-            'sys_refindex',
57
-            [
58
-                'softref_key' => 'rtehtmlarea_images',
59
-                'ref_table' => 'sys_file',
60
-                'ref_uid' => $fileIdentifier,
61
-            ]
62
-        );
63
-        return $softReferences;
64
-    }
65
-
66
-    /**
67
-     * Return link image references.
68
-     *
69
-     * @param File|int $file
70
-     * @return array
71
-     */
72
-    public function findSoftLinkReferences($file)
73
-    {
74
-
75
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
76
-
77
-        // Get the link references of the file.
78
-        $softReferences = $this->getDataService()->getRecords(
79
-            'sys_refindex',
80
-            [
81
-                'softref_key' => 'typolink_tag',
82
-                'ref_table' => 'sys_file',
83
-                'ref_uid' => $fileIdentifier,
84
-            ]
85
-        );
86
-        return $softReferences;
87
-    }
88
-
89
-    /**
90
-     * Count all references found in sys_file_reference.
91
-     *
92
-     * @param File|int $file
93
-     * @return int
94
-     */
95
-    public function countFileReferences($file)
96
-    {
97
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
98
-
99
-        return $this->getDataService()
100
-            ->count(
101
-            'sys_file_reference',
102
-            [
103
-                'uid_local' => $fileIdentifier
104
-            ]
105
-        );
106
-    }
107
-
108
-    /**
109
-     * Count soft image references.
110
-     *
111
-     * @param File|int $file
112
-     * @return int
113
-     */
114
-    public function countSoftImageReferences($file)
115
-    {
116
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
117
-
118
-        return $this->getDataService()
119
-            ->count(
120
-                'sys_refindex',
121
-                [
122
-                    'softref_key' => 'rtehtmlarea_images',
123
-                    'ref_table' => 'sys_file',
124
-                    'ref_uid' => $fileIdentifier
125
-                ]
126
-            );
127
-    }
128
-
129
-    /**
130
-     * Count link image references.
131
-     *
132
-     * @param File|int $file
133
-     * @return int
134
-     */
135
-    public function countSoftLinkReferences($file)
136
-    {
137
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
138
-
139
-        return $this->getDataService()
140
-            ->count(
141
-                'sys_refindex',
142
-                [
143
-                    'softref_key' => 'typolink_tag',
144
-                    'ref_table' => 'sys_file',
145
-                    'ref_uid' => $fileIdentifier
146
-                ]
147
-            );
148
-    }
149
-
150
-    /**
151
-     * Count total reference.
152
-     *
153
-     * @param File|int $file
154
-     * @return int
155
-     */
156
-    public function countTotalReferences($file)
157
-    {
158
-        $numberOfReferences = $this->countFileReferences($file);
159
-        $numberOfReferences += $this->countSoftImageReferences($file);
160
-        $numberOfReferences += $this->countSoftLinkReferences($file);
161
-
162
-        return $numberOfReferences;
163
-    }
164
-
165
-    /**
166
-     * @param string $tableName
167
-     * @return object|QueryBuilder
168
-     */
169
-    protected function getQueryBuilder($tableName): QueryBuilder
170
-    {
171
-        /** @var ConnectionPool $connectionPool */
172
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
173
-        return $connectionPool->getQueryBuilderForTable($tableName);
174
-    }
175
-
176
-    /**
177
-     * @return object|DataService
178
-     */
179
-    protected function getDataService(): DataService
180
-    {
181
-        return GeneralUtility::makeInstance(DataService::class);
182
-    }
23
+	/**
24
+	 * Return all references found in sys_file_reference.
25
+	 *
26
+	 * @param File|int $file
27
+	 * @return array
28
+	 */
29
+	public function findFileReferences($file)
30
+	{
31
+
32
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
33
+
34
+		// Get the file references of the file.
35
+		return $this->getDataService()->getRecords(
36
+			'sys_file_reference',
37
+			[
38
+				'uid_local' => $fileIdentifier,
39
+			]
40
+		);
41
+	}
42
+
43
+	/**
44
+	 * Return soft image references.
45
+	 *
46
+	 * @param File|int $file
47
+	 * @return array
48
+	 */
49
+	public function findSoftImageReferences($file)
50
+	{
51
+
52
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
53
+
54
+		// Get the file references of the file in the RTE.
55
+		$softReferences = $this->getDataService()->getRecords(
56
+			'sys_refindex',
57
+			[
58
+				'softref_key' => 'rtehtmlarea_images',
59
+				'ref_table' => 'sys_file',
60
+				'ref_uid' => $fileIdentifier,
61
+			]
62
+		);
63
+		return $softReferences;
64
+	}
65
+
66
+	/**
67
+	 * Return link image references.
68
+	 *
69
+	 * @param File|int $file
70
+	 * @return array
71
+	 */
72
+	public function findSoftLinkReferences($file)
73
+	{
74
+
75
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
76
+
77
+		// Get the link references of the file.
78
+		$softReferences = $this->getDataService()->getRecords(
79
+			'sys_refindex',
80
+			[
81
+				'softref_key' => 'typolink_tag',
82
+				'ref_table' => 'sys_file',
83
+				'ref_uid' => $fileIdentifier,
84
+			]
85
+		);
86
+		return $softReferences;
87
+	}
88
+
89
+	/**
90
+	 * Count all references found in sys_file_reference.
91
+	 *
92
+	 * @param File|int $file
93
+	 * @return int
94
+	 */
95
+	public function countFileReferences($file)
96
+	{
97
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
98
+
99
+		return $this->getDataService()
100
+			->count(
101
+			'sys_file_reference',
102
+			[
103
+				'uid_local' => $fileIdentifier
104
+			]
105
+		);
106
+	}
107
+
108
+	/**
109
+	 * Count soft image references.
110
+	 *
111
+	 * @param File|int $file
112
+	 * @return int
113
+	 */
114
+	public function countSoftImageReferences($file)
115
+	{
116
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
117
+
118
+		return $this->getDataService()
119
+			->count(
120
+				'sys_refindex',
121
+				[
122
+					'softref_key' => 'rtehtmlarea_images',
123
+					'ref_table' => 'sys_file',
124
+					'ref_uid' => $fileIdentifier
125
+				]
126
+			);
127
+	}
128
+
129
+	/**
130
+	 * Count link image references.
131
+	 *
132
+	 * @param File|int $file
133
+	 * @return int
134
+	 */
135
+	public function countSoftLinkReferences($file)
136
+	{
137
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
138
+
139
+		return $this->getDataService()
140
+			->count(
141
+				'sys_refindex',
142
+				[
143
+					'softref_key' => 'typolink_tag',
144
+					'ref_table' => 'sys_file',
145
+					'ref_uid' => $fileIdentifier
146
+				]
147
+			);
148
+	}
149
+
150
+	/**
151
+	 * Count total reference.
152
+	 *
153
+	 * @param File|int $file
154
+	 * @return int
155
+	 */
156
+	public function countTotalReferences($file)
157
+	{
158
+		$numberOfReferences = $this->countFileReferences($file);
159
+		$numberOfReferences += $this->countSoftImageReferences($file);
160
+		$numberOfReferences += $this->countSoftLinkReferences($file);
161
+
162
+		return $numberOfReferences;
163
+	}
164
+
165
+	/**
166
+	 * @param string $tableName
167
+	 * @return object|QueryBuilder
168
+	 */
169
+	protected function getQueryBuilder($tableName): QueryBuilder
170
+	{
171
+		/** @var ConnectionPool $connectionPool */
172
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
173
+		return $connectionPool->getQueryBuilderForTable($tableName);
174
+	}
175
+
176
+	/**
177
+	 * @return object|DataService
178
+	 */
179
+	protected function getDataService(): DataService
180
+	{
181
+		return GeneralUtility::makeInstance(DataService::class);
182
+	}
183 183
 }
Please login to merge, or discard this patch.
Classes/Module/MediaModule.php 2 patches
Indentation   +335 added lines, -335 removed lines patch added patch discarded remove patch
@@ -26,340 +26,340 @@
 block discarded – undo
26 26
 class MediaModule implements SingletonInterface
27 27
 {
28 28
 
29
-    /**
30
-     * @var string
31
-     */
32
-    const SIGNATURE = 'user_MediaM1';
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    const PARAMETER_PREFIX = 'tx_media_user_mediam1';
38
-
39
-    /**
40
-     * @var ResourceStorage
41
-     */
42
-    protected $currentStorage;
43
-
44
-    /**
45
-     * @return string
46
-     */
47
-    static public function getSignature()
48
-    {
49
-        return self::SIGNATURE;
50
-    }
51
-
52
-    /**
53
-     * @return string
54
-     */
55
-    static public function getParameterPrefix()
56
-    {
57
-        return self::PARAMETER_PREFIX;
58
-    }
59
-
60
-    /**
61
-     * Return all storage allowed for the Backend User.
62
-     *
63
-     * @throws \RuntimeException
64
-     * @return ResourceStorage[]
65
-     */
66
-    public function getAllowedStorages()
67
-    {
68
-
69
-        $storages = $this->getBackendUser()->getFileStorages();
70
-        if (empty($storages)) {
71
-            throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970);
72
-        }
73
-        return $storages;
74
-    }
75
-
76
-    /**
77
-     * Returns the current file storage in use.
78
-     *
79
-     * @return ResourceStorage
80
-     */
81
-    public function getCurrentStorage()
82
-    {
83
-        if (is_null($this->currentStorage)) {
84
-
85
-            $storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments();
86
-
87
-            if ($storageIdentifier > 0) {
88
-                $currentStorage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier);
89
-            } else {
90
-
91
-                // We differentiate the cases whether the User is admin or not.
92
-                if ($this->getBackendUser()->isAdmin()) {
93
-
94
-                    $currentStorage = ResourceFactory::getInstance()->getDefaultStorage();
95
-
96
-                    // Not default storage has been flagged in "sys_file_storage".
97
-                    // Fallback approach: take the first storage as the current.
98
-                    if (!$currentStorage) {
99
-                        /** @var $storageRepository StorageRepository */
100
-                        $storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
101
-
102
-                        $storages = $storageRepository->findAll();
103
-                        $currentStorage = current($storages);
104
-                    }
105
-                } else {
106
-                    $fileMounts = $this->getBackendUser()->getFileMountRecords();
107
-                    $firstFileMount = current($fileMounts);
108
-                    $currentStorage = ResourceFactory::getInstance()->getStorageObject($firstFileMount['base']);
109
-                }
110
-            }
111
-
112
-            $this->currentStorage = $currentStorage;
113
-        }
114
-        return $this->currentStorage;
115
-    }
116
-
117
-    /**
118
-     * Retrieve a possible storage identifier from the session or from the arguments.
119
-     *
120
-     * @return int
121
-     */
122
-    protected function getStorageIdentifierFromSessionOrArguments()
123
-    {
124
-
125
-        // Default value
126
-        $storageIdentifier = 0;
127
-
128
-        // Get last selected storage from User settings
129
-        if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) {
130
-            $storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage');
131
-        }
132
-
133
-        $argumentPrefix = $this->getModuleLoader()->getParameterPrefix();
134
-        $arguments = GeneralUtility::_GET($argumentPrefix);
135
-
136
-        // Override selected storage from the session if GET argument "storage" is detected.
137
-        if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) {
138
-            $storageIdentifier = (int)$arguments['storage'];
139
-
140
-            // Save state
141
-            SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier);
142
-        }
143
-
144
-        return (int)$storageIdentifier;
145
-    }
146
-
147
-    /**
148
-     * Return the combined parameter from the URL.
149
-     *
150
-     * @return string
151
-     */
152
-    public function getCombinedIdentifier()
153
-    {
154
-
155
-        // Fetch possible combined identifier.
156
-        $combinedIdentifier = GeneralUtility::_GET('id');
157
-
158
-        if ($combinedIdentifier) {
159
-
160
-            // Fix a bug at the Core level: the "id" parameter is encoded again when translating file.
161
-            // Add a loop to decode maximum 999 time!
162
-            $semaphore = 0;
163
-            $semaphoreLimit = 999;
164
-            while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) {
165
-                $combinedIdentifier = urldecode($combinedIdentifier);
166
-                $semaphore++;
167
-            }
168
-        }
169
-
170
-        return $combinedIdentifier;
171
-    }
172
-
173
-    /**
174
-     * @param $combinedIdentifier
175
-     * @return bool
176
-     */
177
-    protected function isWellDecoded($combinedIdentifier)
178
-    {
179
-        return preg_match('/.*:.*/', $combinedIdentifier);
180
-    }
181
-
182
-    /**
183
-     * @return Folder
184
-     */
185
-    public function getFirstAvailableFolder()
186
-    {
187
-
188
-        // Take the first object of the first storage.
189
-        $storages = $this->getBackendUser()->getFileStorages();
190
-        $storage = reset($storages);
191
-        if ($storage) {
192
-            $folder = $storage->getRootLevelFolder();
193
-        } else {
194
-            throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954);
195
-        }
196
-        return $folder;
197
-    }
198
-
199
-    /**
200
-     * @return Folder
201
-     */
202
-    public function getCurrentFolder()
203
-    {
204
-
205
-        $combinedIdentifier = $this->getCombinedIdentifier();
206
-
207
-        if ($combinedIdentifier) {
208
-            $folder = $this->getFolderForCombinedIdentifier($combinedIdentifier);
209
-        } else {
210
-            $folder = $this->getFirstAvailableFolder();
211
-        }
212
-
213
-        return $folder;
214
-    }
215
-
216
-    /**
217
-     * @param string $combinedIdentifier
218
-     * @return Folder
219
-     */
220
-    public function getFolderForCombinedIdentifier($combinedIdentifier)
221
-    {
222
-
223
-        // Code taken from FileListController.php
224
-        $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
225
-        $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1);
226
-        if (!$storage->hasFolder($identifier)) {
227
-            $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier);
228
-        }
229
-
230
-        // Retrieve the folder object.
231
-        $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
232
-
233
-        // Disallow the rendering of the processing folder (e.g. could be called manually)
234
-        // and all folders without any defined storage
235
-        if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) {
236
-            $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
237
-            $folder = $storage->getRootLevelFolder();
238
-        }
239
-
240
-        return $folder;
241
-    }
242
-
243
-    /**
244
-     * Tell whether the Folder Tree is display or not.
245
-     *
246
-     * @return bool
247
-     */
248
-    public function hasFolderTree()
249
-    {
250
-        $configuration = $this->getModuleConfiguration();
251
-        return (bool)$configuration['has_folder_tree'];
252
-    }
253
-
254
-    /**
255
-     * Tell whether the sub-folders must be included when browsing.
256
-     *
257
-     * @return bool
258
-     */
259
-    public function hasRecursiveSelection()
260
-    {
261
-
262
-        $parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
263
-        $parameters = GeneralUtility::_GET($parameterPrefix);
264
-
265
-        $hasRecursiveSelection = true;
266
-        if (isset($parameters['hasRecursiveSelection'])) {
267
-            $hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection'];
268
-        }
269
-
270
-        return $hasRecursiveSelection;
271
-    }
272
-
273
-    /**
274
-     * Return the target folder for the uploaded file.
275
-     *
276
-     * @param UploadedFileInterface $uploadedFile
277
-     * @param ResourceStorage $storage
278
-     * @return \TYPO3\CMS\Core\Resource\Folder
279
-     */
280
-    public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage)
281
-    {
282
-
283
-        // default is the root level
284
-        $folder = $storage->getRootLevelFolder(); // get the root folder by default
285
-
286
-        // Get a possible mount point coming from the storage record.
287
-        $storageRecord = $storage->getStorageRecord();
288
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()];
289
-        if ($mountPointIdentifier > 0) {
290
-
291
-            // We don't have a Mount Point repository in FAL, so query the database directly.
292
-            $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]);
293
-
294
-            if (!empty($record['path'])) {
295
-                $folder = $storage->getFolder($record['path']);
296
-            }
297
-        }
298
-        return $folder;
299
-    }
300
-
301
-    /**
302
-     * Return a new target folder when moving file from one storage to another.
303
-     *
304
-     * @param ResourceStorage $storage
305
-     * @param File $file
306
-     * @return \TYPO3\CMS\Core\Resource\Folder
307
-     */
308
-    public function getDefaultFolderInStorage(ResourceStorage $storage, File $file)
309
-    {
310
-
311
-        // default is the root level
312
-        $folder = $storage->getRootLevelFolder();
313
-
314
-        // Retrieve storage record and a possible configured mount point.
315
-        $storageRecord = $storage->getStorageRecord();
316
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()];
317
-
318
-        if ($mountPointIdentifier > 0) {
319
-
320
-            // We don't have a Mount Point repository in FAL, so query the database directly.
321
-            $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]);
322
-            if (!empty($record['path'])) {
323
-                $folder = $storage->getFolder($record['path']);
324
-            }
325
-        }
326
-        return $folder;
327
-    }
328
-
329
-    /**
330
-     * @return array
331
-     */
332
-    protected function getModuleConfiguration()
333
-    {
334
-        return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media');
335
-    }
336
-
337
-    /**
338
-     * @return object|DataService
339
-     */
340
-    protected function getDataService(): DataService
341
-    {
342
-        return GeneralUtility::makeInstance(DataService::class);
343
-    }
344
-
345
-    /**
346
-     * Returns an instance of the current Backend User.
347
-     *
348
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
349
-     */
350
-    protected function getBackendUser()
351
-    {
352
-        return $GLOBALS['BE_USER'];
353
-    }
354
-
355
-    /**
356
-     * Return the module loader.
357
-     *
358
-     * @return \Fab\Vidi\Module\ModuleLoader|object
359
-     */
360
-    protected function getModuleLoader()
361
-    {
362
-        return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
363
-    }
29
+	/**
30
+	 * @var string
31
+	 */
32
+	const SIGNATURE = 'user_MediaM1';
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	const PARAMETER_PREFIX = 'tx_media_user_mediam1';
38
+
39
+	/**
40
+	 * @var ResourceStorage
41
+	 */
42
+	protected $currentStorage;
43
+
44
+	/**
45
+	 * @return string
46
+	 */
47
+	static public function getSignature()
48
+	{
49
+		return self::SIGNATURE;
50
+	}
51
+
52
+	/**
53
+	 * @return string
54
+	 */
55
+	static public function getParameterPrefix()
56
+	{
57
+		return self::PARAMETER_PREFIX;
58
+	}
59
+
60
+	/**
61
+	 * Return all storage allowed for the Backend User.
62
+	 *
63
+	 * @throws \RuntimeException
64
+	 * @return ResourceStorage[]
65
+	 */
66
+	public function getAllowedStorages()
67
+	{
68
+
69
+		$storages = $this->getBackendUser()->getFileStorages();
70
+		if (empty($storages)) {
71
+			throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970);
72
+		}
73
+		return $storages;
74
+	}
75
+
76
+	/**
77
+	 * Returns the current file storage in use.
78
+	 *
79
+	 * @return ResourceStorage
80
+	 */
81
+	public function getCurrentStorage()
82
+	{
83
+		if (is_null($this->currentStorage)) {
84
+
85
+			$storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments();
86
+
87
+			if ($storageIdentifier > 0) {
88
+				$currentStorage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier);
89
+			} else {
90
+
91
+				// We differentiate the cases whether the User is admin or not.
92
+				if ($this->getBackendUser()->isAdmin()) {
93
+
94
+					$currentStorage = ResourceFactory::getInstance()->getDefaultStorage();
95
+
96
+					// Not default storage has been flagged in "sys_file_storage".
97
+					// Fallback approach: take the first storage as the current.
98
+					if (!$currentStorage) {
99
+						/** @var $storageRepository StorageRepository */
100
+						$storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
101
+
102
+						$storages = $storageRepository->findAll();
103
+						$currentStorage = current($storages);
104
+					}
105
+				} else {
106
+					$fileMounts = $this->getBackendUser()->getFileMountRecords();
107
+					$firstFileMount = current($fileMounts);
108
+					$currentStorage = ResourceFactory::getInstance()->getStorageObject($firstFileMount['base']);
109
+				}
110
+			}
111
+
112
+			$this->currentStorage = $currentStorage;
113
+		}
114
+		return $this->currentStorage;
115
+	}
116
+
117
+	/**
118
+	 * Retrieve a possible storage identifier from the session or from the arguments.
119
+	 *
120
+	 * @return int
121
+	 */
122
+	protected function getStorageIdentifierFromSessionOrArguments()
123
+	{
124
+
125
+		// Default value
126
+		$storageIdentifier = 0;
127
+
128
+		// Get last selected storage from User settings
129
+		if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) {
130
+			$storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage');
131
+		}
132
+
133
+		$argumentPrefix = $this->getModuleLoader()->getParameterPrefix();
134
+		$arguments = GeneralUtility::_GET($argumentPrefix);
135
+
136
+		// Override selected storage from the session if GET argument "storage" is detected.
137
+		if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) {
138
+			$storageIdentifier = (int)$arguments['storage'];
139
+
140
+			// Save state
141
+			SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier);
142
+		}
143
+
144
+		return (int)$storageIdentifier;
145
+	}
146
+
147
+	/**
148
+	 * Return the combined parameter from the URL.
149
+	 *
150
+	 * @return string
151
+	 */
152
+	public function getCombinedIdentifier()
153
+	{
154
+
155
+		// Fetch possible combined identifier.
156
+		$combinedIdentifier = GeneralUtility::_GET('id');
157
+
158
+		if ($combinedIdentifier) {
159
+
160
+			// Fix a bug at the Core level: the "id" parameter is encoded again when translating file.
161
+			// Add a loop to decode maximum 999 time!
162
+			$semaphore = 0;
163
+			$semaphoreLimit = 999;
164
+			while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) {
165
+				$combinedIdentifier = urldecode($combinedIdentifier);
166
+				$semaphore++;
167
+			}
168
+		}
169
+
170
+		return $combinedIdentifier;
171
+	}
172
+
173
+	/**
174
+	 * @param $combinedIdentifier
175
+	 * @return bool
176
+	 */
177
+	protected function isWellDecoded($combinedIdentifier)
178
+	{
179
+		return preg_match('/.*:.*/', $combinedIdentifier);
180
+	}
181
+
182
+	/**
183
+	 * @return Folder
184
+	 */
185
+	public function getFirstAvailableFolder()
186
+	{
187
+
188
+		// Take the first object of the first storage.
189
+		$storages = $this->getBackendUser()->getFileStorages();
190
+		$storage = reset($storages);
191
+		if ($storage) {
192
+			$folder = $storage->getRootLevelFolder();
193
+		} else {
194
+			throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954);
195
+		}
196
+		return $folder;
197
+	}
198
+
199
+	/**
200
+	 * @return Folder
201
+	 */
202
+	public function getCurrentFolder()
203
+	{
204
+
205
+		$combinedIdentifier = $this->getCombinedIdentifier();
206
+
207
+		if ($combinedIdentifier) {
208
+			$folder = $this->getFolderForCombinedIdentifier($combinedIdentifier);
209
+		} else {
210
+			$folder = $this->getFirstAvailableFolder();
211
+		}
212
+
213
+		return $folder;
214
+	}
215
+
216
+	/**
217
+	 * @param string $combinedIdentifier
218
+	 * @return Folder
219
+	 */
220
+	public function getFolderForCombinedIdentifier($combinedIdentifier)
221
+	{
222
+
223
+		// Code taken from FileListController.php
224
+		$storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
225
+		$identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1);
226
+		if (!$storage->hasFolder($identifier)) {
227
+			$identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier);
228
+		}
229
+
230
+		// Retrieve the folder object.
231
+		$folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
232
+
233
+		// Disallow the rendering of the processing folder (e.g. could be called manually)
234
+		// and all folders without any defined storage
235
+		if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) {
236
+			$storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
237
+			$folder = $storage->getRootLevelFolder();
238
+		}
239
+
240
+		return $folder;
241
+	}
242
+
243
+	/**
244
+	 * Tell whether the Folder Tree is display or not.
245
+	 *
246
+	 * @return bool
247
+	 */
248
+	public function hasFolderTree()
249
+	{
250
+		$configuration = $this->getModuleConfiguration();
251
+		return (bool)$configuration['has_folder_tree'];
252
+	}
253
+
254
+	/**
255
+	 * Tell whether the sub-folders must be included when browsing.
256
+	 *
257
+	 * @return bool
258
+	 */
259
+	public function hasRecursiveSelection()
260
+	{
261
+
262
+		$parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
263
+		$parameters = GeneralUtility::_GET($parameterPrefix);
264
+
265
+		$hasRecursiveSelection = true;
266
+		if (isset($parameters['hasRecursiveSelection'])) {
267
+			$hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection'];
268
+		}
269
+
270
+		return $hasRecursiveSelection;
271
+	}
272
+
273
+	/**
274
+	 * Return the target folder for the uploaded file.
275
+	 *
276
+	 * @param UploadedFileInterface $uploadedFile
277
+	 * @param ResourceStorage $storage
278
+	 * @return \TYPO3\CMS\Core\Resource\Folder
279
+	 */
280
+	public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage)
281
+	{
282
+
283
+		// default is the root level
284
+		$folder = $storage->getRootLevelFolder(); // get the root folder by default
285
+
286
+		// Get a possible mount point coming from the storage record.
287
+		$storageRecord = $storage->getStorageRecord();
288
+		$mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()];
289
+		if ($mountPointIdentifier > 0) {
290
+
291
+			// We don't have a Mount Point repository in FAL, so query the database directly.
292
+			$record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]);
293
+
294
+			if (!empty($record['path'])) {
295
+				$folder = $storage->getFolder($record['path']);
296
+			}
297
+		}
298
+		return $folder;
299
+	}
300
+
301
+	/**
302
+	 * Return a new target folder when moving file from one storage to another.
303
+	 *
304
+	 * @param ResourceStorage $storage
305
+	 * @param File $file
306
+	 * @return \TYPO3\CMS\Core\Resource\Folder
307
+	 */
308
+	public function getDefaultFolderInStorage(ResourceStorage $storage, File $file)
309
+	{
310
+
311
+		// default is the root level
312
+		$folder = $storage->getRootLevelFolder();
313
+
314
+		// Retrieve storage record and a possible configured mount point.
315
+		$storageRecord = $storage->getStorageRecord();
316
+		$mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()];
317
+
318
+		if ($mountPointIdentifier > 0) {
319
+
320
+			// We don't have a Mount Point repository in FAL, so query the database directly.
321
+			$record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]);
322
+			if (!empty($record['path'])) {
323
+				$folder = $storage->getFolder($record['path']);
324
+			}
325
+		}
326
+		return $folder;
327
+	}
328
+
329
+	/**
330
+	 * @return array
331
+	 */
332
+	protected function getModuleConfiguration()
333
+	{
334
+		return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media');
335
+	}
336
+
337
+	/**
338
+	 * @return object|DataService
339
+	 */
340
+	protected function getDataService(): DataService
341
+	{
342
+		return GeneralUtility::makeInstance(DataService::class);
343
+	}
344
+
345
+	/**
346
+	 * Returns an instance of the current Backend User.
347
+	 *
348
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
349
+	 */
350
+	protected function getBackendUser()
351
+	{
352
+		return $GLOBALS['BE_USER'];
353
+	}
354
+
355
+	/**
356
+	 * Return the module loader.
357
+	 *
358
+	 * @return \Fab\Vidi\Module\ModuleLoader|object
359
+	 */
360
+	protected function getModuleLoader()
361
+	{
362
+		return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
363
+	}
364 364
 
365 365
 }
366 366
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
         }
229 229
 
230 230
         // Retrieve the folder object.
231
-        $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
231
+        $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid().':'.$identifier);
232 232
 
233 233
         // Disallow the rendering of the processing folder (e.g. could be called manually)
234 234
         // and all folders without any defined storage
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 
286 286
         // Get a possible mount point coming from the storage record.
287 287
         $storageRecord = $storage->getStorageRecord();
288
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()];
288
+        $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$uploadedFile->getType()];
289 289
         if ($mountPointIdentifier > 0) {
290 290
 
291 291
             // We don't have a Mount Point repository in FAL, so query the database directly.
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 
314 314
         // Retrieve storage record and a possible configured mount point.
315 315
         $storageRecord = $storage->getStorageRecord();
316
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()];
316
+        $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$file->getType()];
317 317
 
318 318
         if ($mountPointIdentifier > 0) {
319 319
 
Please login to merge, or discard this patch.
Classes/Command/DuplicateFilesCommandController.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -18,191 +18,191 @@
 block discarded – undo
18 18
 class DuplicateFilesCommandController extends CommandController
19 19
 {
20 20
 
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $message = [];
25
-
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $duplicateFiles = [];
30
-
31
-    /**
32
-     * @var \TYPO3\CMS\Core\Mail\MailMessage
33
-     */
34
-    protected $mailMessage;
35
-
36
-    /**
37
-     * Check whether the Index is Ok. In case not, display a message on the console.
38
-     *
39
-     * @return void
40
-     */
41
-    public function analyseCommand()
42
-    {
43
-
44
-        foreach ($this->getStorageRepository()->findAll() as $storage) {
45
-
46
-            // For the CLI cause.
47
-            $storage->setEvaluatePermissions(false);
48
-
49
-            $this->printOut();
50
-            $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid()));
51
-            $this->printOut('--------------------------------------------');
52
-
53
-            if ($storage->isOnline()) {
54
-
55
-                $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage);
56
-
57
-                // Duplicate file object
58
-                if (empty($duplicateFiles)) {
59
-                    $this->printOut();
60
-                    $this->printOut('Looks good, no duplicate files!');
61
-                } else {
62
-                    $this->printOut();
63
-                    $this->printOut('Duplicated identifiers detected:');
64
-                    $this->duplicateFiles[$storage->getUid()] = $duplicateFiles; // Store duplicate files.
65
-
66
-                    foreach ($duplicateFiles as $identifier => $duplicate) {
67
-
68
-                        // build temporary array
69
-                        $uids = [];
70
-                        foreach ($duplicate as $value) {
71
-                            $uids[] = $value['uid'];
72
-                        }
73
-
74
-                        $message = sprintf('* uids "%s" having same sha1 %s',
75
-                            implode(',', $uids),
76
-                            $identifier
77
-                        );
78
-                        $this->printOut($message);
79
-
80
-                    }
81
-                }
82
-            } else {
83
-                $this->outputLine('Storage is offline!');
84
-            }
85
-        }
86
-
87
-        $to = $this->getTo();
88
-        if (!empty($to)) {
89
-            $this->sendReport();
90
-        }
91
-    }
92
-
93
-    /**
94
-     * Print a message and store its content in a variable for the email report.
95
-     *
96
-     * @param string $message
97
-     * @return void
98
-     */
99
-    protected function printOut($message = '')
100
-    {
101
-        $this->message[] = $message;
102
-        $this->outputLine($message);
103
-    }
104
-
105
-    /**
106
-     * Send a possible report to an admin.
107
-     *
108
-     * @throws \Exception
109
-     * @return void
110
-     */
111
-    protected function sendReport()
112
-    {
113
-        if ($this->hasReport()) {
114
-
115
-            // Prepare email.
116
-            $this->getMailMessage()->setTo($this->getTo())
117
-                ->setFrom($this->getFrom())
118
-                ->setSubject('Duplicate records detected!')
119
-                ->setBody(implode("\n", $this->message));
120
-
121
-            $isSent = $this->getMailMessage()->send();
122
-
123
-            if (!$isSent) {
124
-                throw new \Exception('I could not send a message', 1408343882);
125
-            }
126
-
127
-            $to = $this->getTo();
128
-            $this->outputLine();
129
-            $message = sprintf('Report was sent to %s', key($to));
130
-            $this->outputLine($message);
131
-        }
132
-    }
133
-
134
-    /**
135
-     * Send a report
136
-     *
137
-     * @return bool
138
-     */
139
-    protected function hasReport()
140
-    {
141
-        return !empty($this->duplicateFiles);
142
-    }
143
-
144
-    /**
145
-     * @return array
146
-     */
147
-    protected function getTo()
148
-    {
149
-
150
-        $to = [];
151
-
152
-        // @todo make me more flexible!
153
-        if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) {
154
-            $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
155
-            $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
156
-            $to[$emailAddress] = $name;
157
-
158
-        }
159
-        return $to;
160
-    }
161
-
162
-    /**
163
-     * @return array
164
-     */
165
-    protected function getFrom()
166
-    {
167
-
168
-        $from = [];
169
-
170
-        // @todo make me more flexible!
171
-        if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) {
172
-            $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
173
-            $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
174
-            $from[$emailAddress] = $name;
175
-        }
176
-        return $from;
177
-    }
178
-
179
-    /**
180
-     * @return StorageRepository|object
181
-     */
182
-    protected function getStorageRepository()
183
-    {
184
-        return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
185
-    }
186
-
187
-    /**
188
-     * @return \TYPO3\CMS\Core\Mail\MailMessage|object
189
-     */
190
-    public function getMailMessage()
191
-    {
192
-        if (is_null($this->mailMessage)) {
193
-            $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
194
-        }
195
-        return $this->mailMessage;
196
-    }
197
-
198
-    /**
199
-     * Return a pointer to the database.
200
-     *
201
-     * @return \Fab\Media\Index\IndexAnalyser|object
202
-     */
203
-    protected function getIndexAnalyser()
204
-    {
205
-        return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class);
206
-    }
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $message = [];
25
+
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $duplicateFiles = [];
30
+
31
+	/**
32
+	 * @var \TYPO3\CMS\Core\Mail\MailMessage
33
+	 */
34
+	protected $mailMessage;
35
+
36
+	/**
37
+	 * Check whether the Index is Ok. In case not, display a message on the console.
38
+	 *
39
+	 * @return void
40
+	 */
41
+	public function analyseCommand()
42
+	{
43
+
44
+		foreach ($this->getStorageRepository()->findAll() as $storage) {
45
+
46
+			// For the CLI cause.
47
+			$storage->setEvaluatePermissions(false);
48
+
49
+			$this->printOut();
50
+			$this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid()));
51
+			$this->printOut('--------------------------------------------');
52
+
53
+			if ($storage->isOnline()) {
54
+
55
+				$duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage);
56
+
57
+				// Duplicate file object
58
+				if (empty($duplicateFiles)) {
59
+					$this->printOut();
60
+					$this->printOut('Looks good, no duplicate files!');
61
+				} else {
62
+					$this->printOut();
63
+					$this->printOut('Duplicated identifiers detected:');
64
+					$this->duplicateFiles[$storage->getUid()] = $duplicateFiles; // Store duplicate files.
65
+
66
+					foreach ($duplicateFiles as $identifier => $duplicate) {
67
+
68
+						// build temporary array
69
+						$uids = [];
70
+						foreach ($duplicate as $value) {
71
+							$uids[] = $value['uid'];
72
+						}
73
+
74
+						$message = sprintf('* uids "%s" having same sha1 %s',
75
+							implode(',', $uids),
76
+							$identifier
77
+						);
78
+						$this->printOut($message);
79
+
80
+					}
81
+				}
82
+			} else {
83
+				$this->outputLine('Storage is offline!');
84
+			}
85
+		}
86
+
87
+		$to = $this->getTo();
88
+		if (!empty($to)) {
89
+			$this->sendReport();
90
+		}
91
+	}
92
+
93
+	/**
94
+	 * Print a message and store its content in a variable for the email report.
95
+	 *
96
+	 * @param string $message
97
+	 * @return void
98
+	 */
99
+	protected function printOut($message = '')
100
+	{
101
+		$this->message[] = $message;
102
+		$this->outputLine($message);
103
+	}
104
+
105
+	/**
106
+	 * Send a possible report to an admin.
107
+	 *
108
+	 * @throws \Exception
109
+	 * @return void
110
+	 */
111
+	protected function sendReport()
112
+	{
113
+		if ($this->hasReport()) {
114
+
115
+			// Prepare email.
116
+			$this->getMailMessage()->setTo($this->getTo())
117
+				->setFrom($this->getFrom())
118
+				->setSubject('Duplicate records detected!')
119
+				->setBody(implode("\n", $this->message));
120
+
121
+			$isSent = $this->getMailMessage()->send();
122
+
123
+			if (!$isSent) {
124
+				throw new \Exception('I could not send a message', 1408343882);
125
+			}
126
+
127
+			$to = $this->getTo();
128
+			$this->outputLine();
129
+			$message = sprintf('Report was sent to %s', key($to));
130
+			$this->outputLine($message);
131
+		}
132
+	}
133
+
134
+	/**
135
+	 * Send a report
136
+	 *
137
+	 * @return bool
138
+	 */
139
+	protected function hasReport()
140
+	{
141
+		return !empty($this->duplicateFiles);
142
+	}
143
+
144
+	/**
145
+	 * @return array
146
+	 */
147
+	protected function getTo()
148
+	{
149
+
150
+		$to = [];
151
+
152
+		// @todo make me more flexible!
153
+		if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) {
154
+			$emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
155
+			$name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
156
+			$to[$emailAddress] = $name;
157
+
158
+		}
159
+		return $to;
160
+	}
161
+
162
+	/**
163
+	 * @return array
164
+	 */
165
+	protected function getFrom()
166
+	{
167
+
168
+		$from = [];
169
+
170
+		// @todo make me more flexible!
171
+		if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) {
172
+			$emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
173
+			$name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
174
+			$from[$emailAddress] = $name;
175
+		}
176
+		return $from;
177
+	}
178
+
179
+	/**
180
+	 * @return StorageRepository|object
181
+	 */
182
+	protected function getStorageRepository()
183
+	{
184
+		return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
185
+	}
186
+
187
+	/**
188
+	 * @return \TYPO3\CMS\Core\Mail\MailMessage|object
189
+	 */
190
+	public function getMailMessage()
191
+	{
192
+		if (is_null($this->mailMessage)) {
193
+			$this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
194
+		}
195
+		return $this->mailMessage;
196
+	}
197
+
198
+	/**
199
+	 * Return a pointer to the database.
200
+	 *
201
+	 * @return \Fab\Media\Index\IndexAnalyser|object
202
+	 */
203
+	protected function getIndexAnalyser()
204
+	{
205
+		return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class);
206
+	}
207 207
 
208 208
 }
Please login to merge, or discard this patch.