@@ -27,207 +27,207 @@ |
||
27 | 27 | class FilePermissionsAspect |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Post-process the matcher object to respect the file storages. |
|
32 | - * |
|
33 | - * @param Matcher $matcher |
|
34 | - * @param string $dataType |
|
35 | - * @return void |
|
36 | - * @throws \InvalidArgumentException |
|
37 | - */ |
|
38 | - public function addFilePermissionsForFileStorages(Matcher $matcher, $dataType) |
|
39 | - { |
|
40 | - if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
41 | - |
|
42 | - if ($this->isFolderConsidered()) { |
|
43 | - |
|
44 | - $folder = $this->getMediaModule()->getCurrentFolder(); |
|
45 | - |
|
46 | - if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
47 | - |
|
48 | - // Only add like condition if needed. |
|
49 | - if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
50 | - $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
51 | - } |
|
52 | - } else { |
|
53 | - |
|
54 | - // Browse only currently |
|
55 | - $files = $this->getFileUids($folder); |
|
56 | - $matcher->in('uid', $files); |
|
57 | - } |
|
58 | - |
|
59 | - $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
60 | - } else { |
|
61 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
62 | - |
|
63 | - // Set the storage identifier only if the storage is on-line. |
|
64 | - $identifier = -1; |
|
65 | - if ($storage->isOnline()) { |
|
66 | - $identifier = $storage->getUid(); |
|
67 | - } |
|
68 | - |
|
69 | - if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
70 | - |
|
71 | - $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
72 | - $collectedFiles = []; |
|
73 | - foreach ($fileMounts as $fileMount) { |
|
74 | - |
|
75 | - $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
76 | - $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
77 | - |
|
78 | - $files = $this->getFileUids($folder); |
|
79 | - $collectedFiles = array_merge($collectedFiles, $files); |
|
80 | - } |
|
81 | - |
|
82 | - $matcher->in('uid', $collectedFiles); |
|
83 | - } |
|
84 | - |
|
85 | - $matcher->equals('storage', $identifier); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - protected function isPermissionNecessary() |
|
94 | - { |
|
95 | - |
|
96 | - $isNecessary = true; |
|
97 | - |
|
98 | - $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
99 | - |
|
100 | - if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
101 | - $isNecessary = false; |
|
102 | - } |
|
103 | - |
|
104 | - if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
105 | - $isNecessary = false; |
|
106 | - } |
|
107 | - |
|
108 | - return $isNecessary; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return bool |
|
113 | - */ |
|
114 | - protected function isFolderConsidered() |
|
115 | - { |
|
116 | - return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param Folder $folder |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - protected function getFileUids(Folder $folder) |
|
124 | - { |
|
125 | - $files = []; |
|
126 | - foreach ($folder->getFiles() as $file) { |
|
127 | - $files[] = $file->getUid(); |
|
128 | - } |
|
129 | - return $files; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Post-process the constraints object to respect the file mounts. |
|
134 | - * |
|
135 | - * @param Query $query |
|
136 | - * @param ConstraintInterface|null $constraints |
|
137 | - * @param ConstraintContainer $constraintContainer |
|
138 | - * @throws \InvalidArgumentException |
|
139 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
140 | - */ |
|
141 | - public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
142 | - { |
|
143 | - if ($query->getType() === 'sys_file') { |
|
144 | - if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
145 | - $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param Query $query |
|
152 | - * @param ConstraintInterface|null $constraints |
|
153 | - * @param ConstraintContainer $constraintContainer |
|
154 | - * @return array |
|
155 | - * @throws \InvalidArgumentException |
|
156 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
157 | - */ |
|
158 | - protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
159 | - { |
|
160 | - $tableName = 'sys_filemounts'; |
|
161 | - |
|
162 | - // Get the file mount identifiers for the current Backend User. |
|
163 | - $fileMounts = GeneralUtility::trimExplode(',', $this->getCurrentBackendUser()->dataLists['filemount_list']); |
|
164 | - $fileMountUids = implode(',', array_filter($fileMounts)); |
|
165 | - |
|
166 | - // Fetch the records. |
|
167 | - $fileMountRecords = $this->getDataService()->getRecords( |
|
168 | - $tableName, |
|
169 | - [ |
|
170 | - 'uid' => $fileMountUids |
|
171 | - ] |
|
172 | - ); |
|
173 | - $constraintsRespectingFileMounts = []; |
|
174 | - foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
175 | - if ($fileMountRecord['path']) { |
|
176 | - $constraintsRespectingFileMounts[] = $query->like( |
|
177 | - 'identifier', |
|
178 | - $fileMountRecord['path'] . '%' |
|
179 | - ); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
184 | - |
|
185 | - if ($constraints) { |
|
186 | - $constraints = $query->logicalAnd( |
|
187 | - $constraints, |
|
188 | - $logicalOrForRespectingFileMounts |
|
189 | - ); |
|
190 | - } else { |
|
191 | - $constraints = $logicalOrForRespectingFileMounts; |
|
192 | - } |
|
193 | - |
|
194 | - $constraintContainer->setConstraint($constraints); |
|
195 | - |
|
196 | - return [$query, $constraints, $constraintContainer]; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
201 | - */ |
|
202 | - protected function getCurrentBackendUser() |
|
203 | - { |
|
204 | - return $GLOBALS['BE_USER']; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @return object|DataService |
|
209 | - */ |
|
210 | - protected function getDataService(): DataService |
|
211 | - { |
|
212 | - return GeneralUtility::makeInstance(DataService::class); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return MediaModule|object |
|
217 | - * @throws \InvalidArgumentException |
|
218 | - */ |
|
219 | - protected function getMediaModule() |
|
220 | - { |
|
221 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Get the Vidi Module Loader. |
|
226 | - * |
|
227 | - * @return object|ModuleLoader |
|
228 | - */ |
|
229 | - protected function getModuleLoader() |
|
230 | - { |
|
231 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
232 | - } |
|
30 | + /** |
|
31 | + * Post-process the matcher object to respect the file storages. |
|
32 | + * |
|
33 | + * @param Matcher $matcher |
|
34 | + * @param string $dataType |
|
35 | + * @return void |
|
36 | + * @throws \InvalidArgumentException |
|
37 | + */ |
|
38 | + public function addFilePermissionsForFileStorages(Matcher $matcher, $dataType) |
|
39 | + { |
|
40 | + if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
41 | + |
|
42 | + if ($this->isFolderConsidered()) { |
|
43 | + |
|
44 | + $folder = $this->getMediaModule()->getCurrentFolder(); |
|
45 | + |
|
46 | + if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
47 | + |
|
48 | + // Only add like condition if needed. |
|
49 | + if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
50 | + $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
51 | + } |
|
52 | + } else { |
|
53 | + |
|
54 | + // Browse only currently |
|
55 | + $files = $this->getFileUids($folder); |
|
56 | + $matcher->in('uid', $files); |
|
57 | + } |
|
58 | + |
|
59 | + $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
60 | + } else { |
|
61 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
62 | + |
|
63 | + // Set the storage identifier only if the storage is on-line. |
|
64 | + $identifier = -1; |
|
65 | + if ($storage->isOnline()) { |
|
66 | + $identifier = $storage->getUid(); |
|
67 | + } |
|
68 | + |
|
69 | + if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
70 | + |
|
71 | + $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
72 | + $collectedFiles = []; |
|
73 | + foreach ($fileMounts as $fileMount) { |
|
74 | + |
|
75 | + $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
76 | + $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
77 | + |
|
78 | + $files = $this->getFileUids($folder); |
|
79 | + $collectedFiles = array_merge($collectedFiles, $files); |
|
80 | + } |
|
81 | + |
|
82 | + $matcher->in('uid', $collectedFiles); |
|
83 | + } |
|
84 | + |
|
85 | + $matcher->equals('storage', $identifier); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + protected function isPermissionNecessary() |
|
94 | + { |
|
95 | + |
|
96 | + $isNecessary = true; |
|
97 | + |
|
98 | + $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
99 | + |
|
100 | + if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
101 | + $isNecessary = false; |
|
102 | + } |
|
103 | + |
|
104 | + if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
105 | + $isNecessary = false; |
|
106 | + } |
|
107 | + |
|
108 | + return $isNecessary; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return bool |
|
113 | + */ |
|
114 | + protected function isFolderConsidered() |
|
115 | + { |
|
116 | + return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param Folder $folder |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + protected function getFileUids(Folder $folder) |
|
124 | + { |
|
125 | + $files = []; |
|
126 | + foreach ($folder->getFiles() as $file) { |
|
127 | + $files[] = $file->getUid(); |
|
128 | + } |
|
129 | + return $files; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Post-process the constraints object to respect the file mounts. |
|
134 | + * |
|
135 | + * @param Query $query |
|
136 | + * @param ConstraintInterface|null $constraints |
|
137 | + * @param ConstraintContainer $constraintContainer |
|
138 | + * @throws \InvalidArgumentException |
|
139 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
140 | + */ |
|
141 | + public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
142 | + { |
|
143 | + if ($query->getType() === 'sys_file') { |
|
144 | + if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
145 | + $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param Query $query |
|
152 | + * @param ConstraintInterface|null $constraints |
|
153 | + * @param ConstraintContainer $constraintContainer |
|
154 | + * @return array |
|
155 | + * @throws \InvalidArgumentException |
|
156 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
157 | + */ |
|
158 | + protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
159 | + { |
|
160 | + $tableName = 'sys_filemounts'; |
|
161 | + |
|
162 | + // Get the file mount identifiers for the current Backend User. |
|
163 | + $fileMounts = GeneralUtility::trimExplode(',', $this->getCurrentBackendUser()->dataLists['filemount_list']); |
|
164 | + $fileMountUids = implode(',', array_filter($fileMounts)); |
|
165 | + |
|
166 | + // Fetch the records. |
|
167 | + $fileMountRecords = $this->getDataService()->getRecords( |
|
168 | + $tableName, |
|
169 | + [ |
|
170 | + 'uid' => $fileMountUids |
|
171 | + ] |
|
172 | + ); |
|
173 | + $constraintsRespectingFileMounts = []; |
|
174 | + foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
175 | + if ($fileMountRecord['path']) { |
|
176 | + $constraintsRespectingFileMounts[] = $query->like( |
|
177 | + 'identifier', |
|
178 | + $fileMountRecord['path'] . '%' |
|
179 | + ); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
184 | + |
|
185 | + if ($constraints) { |
|
186 | + $constraints = $query->logicalAnd( |
|
187 | + $constraints, |
|
188 | + $logicalOrForRespectingFileMounts |
|
189 | + ); |
|
190 | + } else { |
|
191 | + $constraints = $logicalOrForRespectingFileMounts; |
|
192 | + } |
|
193 | + |
|
194 | + $constraintContainer->setConstraint($constraints); |
|
195 | + |
|
196 | + return [$query, $constraints, $constraintContainer]; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
201 | + */ |
|
202 | + protected function getCurrentBackendUser() |
|
203 | + { |
|
204 | + return $GLOBALS['BE_USER']; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @return object|DataService |
|
209 | + */ |
|
210 | + protected function getDataService(): DataService |
|
211 | + { |
|
212 | + return GeneralUtility::makeInstance(DataService::class); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return MediaModule|object |
|
217 | + * @throws \InvalidArgumentException |
|
218 | + */ |
|
219 | + protected function getMediaModule() |
|
220 | + { |
|
221 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Get the Vidi Module Loader. |
|
226 | + * |
|
227 | + * @return object|ModuleLoader |
|
228 | + */ |
|
229 | + protected function getModuleLoader() |
|
230 | + { |
|
231 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
232 | + } |
|
233 | 233 | } |
@@ -22,248 +22,248 @@ |
||
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 | } |
@@ -20,164 +20,164 @@ |
||
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 | } |
@@ -26,340 +26,340 @@ |
||
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 |
@@ -18,191 +18,191 @@ |
||
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 | } |
@@ -18,231 +18,231 @@ |
||
18 | 18 | class MissingFilesCommandController extends CommandController |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $message = []; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $missingFiles = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $deletedFiles = []; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
38 | - */ |
|
39 | - protected $mailMessage; |
|
40 | - |
|
41 | - /** |
|
42 | - * Check whether the Index is Ok. In case not, display a message on the console. |
|
43 | - * |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function analyseCommand() |
|
47 | - { |
|
48 | - |
|
49 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
50 | - |
|
51 | - // For the CLI cause. |
|
52 | - $storage->setEvaluatePermissions(false); |
|
53 | - |
|
54 | - $this->printOut(); |
|
55 | - $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
56 | - $this->printOut('--------------------------------------------'); |
|
57 | - |
|
58 | - if ($storage->isOnline()) { |
|
59 | - |
|
60 | - $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
61 | - if (empty($missingFiles)) { |
|
62 | - $this->printOut(); |
|
63 | - $this->printOut('Looks good, no missing files!'); |
|
64 | - } else { |
|
65 | - // Missing files... |
|
66 | - $this->printOut(); |
|
67 | - $this->printOut('Missing resources:'); |
|
68 | - $this->missingFiles[$storage->getUid()] = $missingFiles; // Store missing files. |
|
69 | - |
|
70 | - /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
71 | - foreach ($missingFiles as $missingFile) { |
|
72 | - $message = sprintf('* Missing file "%s" with identifier "%s".', |
|
73 | - $missingFile->getUid(), |
|
74 | - $missingFile->getIdentifier() |
|
75 | - ); |
|
76 | - $this->printOut($message); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - } else { |
|
81 | - $this->outputLine('Storage is offline!'); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - $to = $this->getTo(); |
|
86 | - if (!empty($to)) { |
|
87 | - $this->sendReport(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Delete the missing files which have no file references |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function deleteCommand() |
|
97 | - { |
|
98 | - |
|
99 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
100 | - |
|
101 | - // For the CLI cause. |
|
102 | - $storage->setEvaluatePermissions(false); |
|
103 | - |
|
104 | - $this->printOut(); |
|
105 | - $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
106 | - $this->printOut('--------------------------------------------'); |
|
107 | - |
|
108 | - if ($storage->isOnline()) { |
|
109 | - |
|
110 | - $deletedFiles = $this->getIndexAnalyser()->deleteMissingFiles($storage); |
|
111 | - if (empty($deletedFiles)) { |
|
112 | - $this->printOut(); |
|
113 | - $this->printOut('No files deleted!'); |
|
114 | - } else { |
|
115 | - // Missing files... |
|
116 | - $this->printOut(); |
|
117 | - $this->printOut('Deleted Files:'); |
|
118 | - /** @var \TYPO3\CMS\Core\Resource\File $deletedFile */ |
|
119 | - foreach ($deletedFiles as $deletedFileUid => $deletedFileIdentifier) { |
|
120 | - $message = sprintf('* Deleted file "%s" with identifier "%s".', |
|
121 | - $deletedFileUid, |
|
122 | - $deletedFileIdentifier |
|
123 | - ); |
|
124 | - $this->printOut($message); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - } else { |
|
129 | - $this->outputLine('Storage is offline!'); |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Print a message and store its content in a variable for the email report. |
|
136 | - * |
|
137 | - * @param string $message |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - protected function printOut($message = '') |
|
141 | - { |
|
142 | - $this->message[] = $message; |
|
143 | - $this->outputLine($message); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Send a possible report to an admin. |
|
148 | - * |
|
149 | - * @throws \Exception |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - protected function sendReport() |
|
153 | - { |
|
154 | - if ($this->hasReport()) { |
|
155 | - |
|
156 | - // Prepare email. |
|
157 | - $this->getMailMessage()->setTo($this->getTo()) |
|
158 | - ->setFrom($this->getFrom()) |
|
159 | - ->setSubject('Missing files detected!') |
|
160 | - ->setBody(implode("\n", $this->message)); |
|
161 | - |
|
162 | - $isSent = $this->getMailMessage()->send(); |
|
163 | - |
|
164 | - if (!$isSent) { |
|
165 | - throw new \Exception('I could not send a message', 1408343882); |
|
166 | - } |
|
167 | - |
|
168 | - $to = $this->getTo(); |
|
169 | - $this->outputLine(); |
|
170 | - $message = sprintf('Report was sent to %s', key($to)); |
|
171 | - $this->outputLine($message); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Send a report |
|
177 | - * |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - protected function hasReport() |
|
181 | - { |
|
182 | - return !empty($this->missingFiles); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - protected function getTo() |
|
189 | - { |
|
190 | - |
|
191 | - $to = []; |
|
192 | - |
|
193 | - // @todo make me more flexible! |
|
194 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
195 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
196 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
197 | - $to[$emailAddress] = $name; |
|
198 | - |
|
199 | - } |
|
200 | - return $to; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @return array |
|
205 | - */ |
|
206 | - protected function getFrom() |
|
207 | - { |
|
208 | - $from = []; |
|
209 | - |
|
210 | - // @todo make me more flexible! |
|
211 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
212 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
213 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
214 | - $from[$emailAddress] = $name; |
|
215 | - } |
|
216 | - return $from; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return StorageRepository|object |
|
221 | - */ |
|
222 | - protected function getStorageRepository() |
|
223 | - { |
|
224 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return \TYPO3\CMS\Core\Mail\MailMessage |
|
229 | - */ |
|
230 | - public function getMailMessage() |
|
231 | - { |
|
232 | - if (is_null($this->mailMessage)) { |
|
233 | - $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
234 | - } |
|
235 | - return $this->mailMessage; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Return a pointer to the database. |
|
240 | - * |
|
241 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
242 | - */ |
|
243 | - protected function getIndexAnalyser() |
|
244 | - { |
|
245 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
246 | - } |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $message = []; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $missingFiles = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $deletedFiles = []; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
38 | + */ |
|
39 | + protected $mailMessage; |
|
40 | + |
|
41 | + /** |
|
42 | + * Check whether the Index is Ok. In case not, display a message on the console. |
|
43 | + * |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function analyseCommand() |
|
47 | + { |
|
48 | + |
|
49 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
50 | + |
|
51 | + // For the CLI cause. |
|
52 | + $storage->setEvaluatePermissions(false); |
|
53 | + |
|
54 | + $this->printOut(); |
|
55 | + $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
56 | + $this->printOut('--------------------------------------------'); |
|
57 | + |
|
58 | + if ($storage->isOnline()) { |
|
59 | + |
|
60 | + $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
61 | + if (empty($missingFiles)) { |
|
62 | + $this->printOut(); |
|
63 | + $this->printOut('Looks good, no missing files!'); |
|
64 | + } else { |
|
65 | + // Missing files... |
|
66 | + $this->printOut(); |
|
67 | + $this->printOut('Missing resources:'); |
|
68 | + $this->missingFiles[$storage->getUid()] = $missingFiles; // Store missing files. |
|
69 | + |
|
70 | + /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
71 | + foreach ($missingFiles as $missingFile) { |
|
72 | + $message = sprintf('* Missing file "%s" with identifier "%s".', |
|
73 | + $missingFile->getUid(), |
|
74 | + $missingFile->getIdentifier() |
|
75 | + ); |
|
76 | + $this->printOut($message); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + } else { |
|
81 | + $this->outputLine('Storage is offline!'); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + $to = $this->getTo(); |
|
86 | + if (!empty($to)) { |
|
87 | + $this->sendReport(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Delete the missing files which have no file references |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function deleteCommand() |
|
97 | + { |
|
98 | + |
|
99 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
100 | + |
|
101 | + // For the CLI cause. |
|
102 | + $storage->setEvaluatePermissions(false); |
|
103 | + |
|
104 | + $this->printOut(); |
|
105 | + $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
106 | + $this->printOut('--------------------------------------------'); |
|
107 | + |
|
108 | + if ($storage->isOnline()) { |
|
109 | + |
|
110 | + $deletedFiles = $this->getIndexAnalyser()->deleteMissingFiles($storage); |
|
111 | + if (empty($deletedFiles)) { |
|
112 | + $this->printOut(); |
|
113 | + $this->printOut('No files deleted!'); |
|
114 | + } else { |
|
115 | + // Missing files... |
|
116 | + $this->printOut(); |
|
117 | + $this->printOut('Deleted Files:'); |
|
118 | + /** @var \TYPO3\CMS\Core\Resource\File $deletedFile */ |
|
119 | + foreach ($deletedFiles as $deletedFileUid => $deletedFileIdentifier) { |
|
120 | + $message = sprintf('* Deleted file "%s" with identifier "%s".', |
|
121 | + $deletedFileUid, |
|
122 | + $deletedFileIdentifier |
|
123 | + ); |
|
124 | + $this->printOut($message); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + } else { |
|
129 | + $this->outputLine('Storage is offline!'); |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Print a message and store its content in a variable for the email report. |
|
136 | + * |
|
137 | + * @param string $message |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + protected function printOut($message = '') |
|
141 | + { |
|
142 | + $this->message[] = $message; |
|
143 | + $this->outputLine($message); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Send a possible report to an admin. |
|
148 | + * |
|
149 | + * @throws \Exception |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + protected function sendReport() |
|
153 | + { |
|
154 | + if ($this->hasReport()) { |
|
155 | + |
|
156 | + // Prepare email. |
|
157 | + $this->getMailMessage()->setTo($this->getTo()) |
|
158 | + ->setFrom($this->getFrom()) |
|
159 | + ->setSubject('Missing files detected!') |
|
160 | + ->setBody(implode("\n", $this->message)); |
|
161 | + |
|
162 | + $isSent = $this->getMailMessage()->send(); |
|
163 | + |
|
164 | + if (!$isSent) { |
|
165 | + throw new \Exception('I could not send a message', 1408343882); |
|
166 | + } |
|
167 | + |
|
168 | + $to = $this->getTo(); |
|
169 | + $this->outputLine(); |
|
170 | + $message = sprintf('Report was sent to %s', key($to)); |
|
171 | + $this->outputLine($message); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Send a report |
|
177 | + * |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + protected function hasReport() |
|
181 | + { |
|
182 | + return !empty($this->missingFiles); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + protected function getTo() |
|
189 | + { |
|
190 | + |
|
191 | + $to = []; |
|
192 | + |
|
193 | + // @todo make me more flexible! |
|
194 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
195 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
196 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
197 | + $to[$emailAddress] = $name; |
|
198 | + |
|
199 | + } |
|
200 | + return $to; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @return array |
|
205 | + */ |
|
206 | + protected function getFrom() |
|
207 | + { |
|
208 | + $from = []; |
|
209 | + |
|
210 | + // @todo make me more flexible! |
|
211 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
212 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
213 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
214 | + $from[$emailAddress] = $name; |
|
215 | + } |
|
216 | + return $from; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return StorageRepository|object |
|
221 | + */ |
|
222 | + protected function getStorageRepository() |
|
223 | + { |
|
224 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return \TYPO3\CMS\Core\Mail\MailMessage |
|
229 | + */ |
|
230 | + public function getMailMessage() |
|
231 | + { |
|
232 | + if (is_null($this->mailMessage)) { |
|
233 | + $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
234 | + } |
|
235 | + return $this->mailMessage; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Return a pointer to the database. |
|
240 | + * |
|
241 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
242 | + */ |
|
243 | + protected function getIndexAnalyser() |
|
244 | + { |
|
245 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | } |
@@ -18,191 +18,191 @@ |
||
18 | 18 | class DuplicateRecordsCommandController extends CommandController |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $message = []; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $duplicateRecords = []; |
|
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 | - $duplicateRecords = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
56 | - |
|
57 | - // Duplicate file object |
|
58 | - if (empty($duplicateRecords)) { |
|
59 | - $this->printOut(); |
|
60 | - $this->printOut('Looks good, no duplicate records!'); |
|
61 | - } else { |
|
62 | - $this->printOut(); |
|
63 | - $this->printOut('Duplicated identifiers detected:'); |
|
64 | - $this->duplicateRecords[$storage->getUid()] = $duplicateRecords; // Store duplicate files. |
|
65 | - |
|
66 | - foreach ($duplicateRecords 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 identifier %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->duplicateRecords); |
|
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 $duplicateRecords = []; |
|
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 | + $duplicateRecords = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
56 | + |
|
57 | + // Duplicate file object |
|
58 | + if (empty($duplicateRecords)) { |
|
59 | + $this->printOut(); |
|
60 | + $this->printOut('Looks good, no duplicate records!'); |
|
61 | + } else { |
|
62 | + $this->printOut(); |
|
63 | + $this->printOut('Duplicated identifiers detected:'); |
|
64 | + $this->duplicateRecords[$storage->getUid()] = $duplicateRecords; // Store duplicate files. |
|
65 | + |
|
66 | + foreach ($duplicateRecords 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 identifier %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->duplicateRecords); |
|
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 | } |
@@ -21,137 +21,137 @@ |
||
21 | 21 | class ThumbnailCommandController extends CommandController |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException |
|
26 | - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
27 | - */ |
|
28 | - protected function initializeCommandMethodArguments() |
|
29 | - { |
|
30 | - parent::initializeCommandMethodArguments(); |
|
31 | - if ($this->arguments->hasArgument('configuration')) { |
|
32 | - $propertyMappingConfiguration = $this->arguments->getArgument('configuration')->getPropertyMappingConfiguration(); |
|
33 | - $propertyMappingConfiguration->setTypeConverter( |
|
34 | - $this->objectManager->get(ConfigurationArrayConverter::class) |
|
35 | - ); |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Generate a bunch of thumbnails in advance to speed up the output of the Media BE module. |
|
42 | - * |
|
43 | - * @param int $limit where to stop in the batch processing. |
|
44 | - * @param int $offset where to start in the batch processing. |
|
45 | - * @param array $configuration override the default thumbnail configuration. |
|
46 | - * @param bool $verbose will output a detail result of the thumbnail generation. |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - public function generateCommand($limit = 0, $offset = 0, $configuration = [], $verbose = false) |
|
50 | - { |
|
51 | - |
|
52 | - $this->checkEnvironment(); |
|
53 | - |
|
54 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
55 | - |
|
56 | - // TODO: Make me more flexible by passing thumbnail configuration. For now it will only generate thumbnails for the BE module. |
|
57 | - |
|
58 | - $this->outputLine(); |
|
59 | - $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
60 | - $this->outputLine('--------------------------------------------'); |
|
61 | - $this->outputLine(); |
|
62 | - |
|
63 | - if ($storage->isOnline()) { |
|
64 | - |
|
65 | - // For the CLI cause. |
|
66 | - $storage->setEvaluatePermissions(false); |
|
67 | - |
|
68 | - $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
69 | - $thumbnailGenerator |
|
70 | - ->setStorage($storage) |
|
71 | - ->setConfiguration($configuration) |
|
72 | - ->generate($limit, $offset); |
|
73 | - |
|
74 | - if ($verbose) { |
|
75 | - $resultSet = $thumbnailGenerator->getResultSet(); |
|
76 | - foreach ($resultSet as $result) { |
|
77 | - $message = sprintf('* File "%s": %s %s', |
|
78 | - $result['fileUid'], |
|
79 | - $result['fileIdentifier'], |
|
80 | - empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
81 | - ); |
|
82 | - $this->outputLine($message); |
|
83 | - } |
|
84 | - $this->outputLine(); |
|
85 | - } |
|
86 | - |
|
87 | - $message = sprintf('Done! New generated %s thumbnail(s) from %s traversed file(s) of a total of %s files.', |
|
88 | - $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
89 | - $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
90 | - $thumbnailGenerator->getTotalNumberOfFiles() |
|
91 | - ); |
|
92 | - $this->outputLine($message); |
|
93 | - |
|
94 | - // Add warning message if missing files were found along the way. |
|
95 | - if ($thumbnailGenerator->getNumberOfMissingFiles() > 0) { |
|
96 | - |
|
97 | - $message = sprintf('ATTENTION! %s missing file(s) detected.', |
|
98 | - $thumbnailGenerator->getNumberOfMissingFiles() |
|
99 | - ); |
|
100 | - $this->outputLine($message); |
|
101 | - } |
|
102 | - } else { |
|
103 | - $this->outputLine('Storage is offline!'); |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - protected function checkEnvironment() |
|
112 | - { |
|
113 | - $user = $this->getDataService()->getRecord( |
|
114 | - 'be_users', [ |
|
115 | - 'username' => '_cli_lowlevel' |
|
116 | - ]); |
|
117 | - |
|
118 | - if (empty($user)) { |
|
119 | - $this->outputLine('Missing User "_cli_lowlevel" and / or its password.'); |
|
120 | - $this->sendAndExit(1); |
|
121 | - } |
|
122 | - |
|
123 | - $user = $this->getDataService()->getRecord( |
|
124 | - 'be_users', [ |
|
125 | - 'username' => '_cli_scheduler' |
|
126 | - ]); |
|
127 | - |
|
128 | - if (empty($user)) { |
|
129 | - $this->outputLine('Missing User "_cli_scheduler" and / or its password.'); |
|
130 | - $this->sendAndExit(1); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @return object|DataService |
|
136 | - */ |
|
137 | - protected function getDataService(): DataService |
|
138 | - { |
|
139 | - return GeneralUtility::makeInstance(DataService::class); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
144 | - */ |
|
145 | - protected function getThumbnailGenerator() |
|
146 | - { |
|
147 | - return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return StorageRepository|object |
|
152 | - */ |
|
153 | - protected function getStorageRepository() |
|
154 | - { |
|
155 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
156 | - } |
|
24 | + /** |
|
25 | + * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException |
|
26 | + * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
27 | + */ |
|
28 | + protected function initializeCommandMethodArguments() |
|
29 | + { |
|
30 | + parent::initializeCommandMethodArguments(); |
|
31 | + if ($this->arguments->hasArgument('configuration')) { |
|
32 | + $propertyMappingConfiguration = $this->arguments->getArgument('configuration')->getPropertyMappingConfiguration(); |
|
33 | + $propertyMappingConfiguration->setTypeConverter( |
|
34 | + $this->objectManager->get(ConfigurationArrayConverter::class) |
|
35 | + ); |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Generate a bunch of thumbnails in advance to speed up the output of the Media BE module. |
|
42 | + * |
|
43 | + * @param int $limit where to stop in the batch processing. |
|
44 | + * @param int $offset where to start in the batch processing. |
|
45 | + * @param array $configuration override the default thumbnail configuration. |
|
46 | + * @param bool $verbose will output a detail result of the thumbnail generation. |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + public function generateCommand($limit = 0, $offset = 0, $configuration = [], $verbose = false) |
|
50 | + { |
|
51 | + |
|
52 | + $this->checkEnvironment(); |
|
53 | + |
|
54 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
55 | + |
|
56 | + // TODO: Make me more flexible by passing thumbnail configuration. For now it will only generate thumbnails for the BE module. |
|
57 | + |
|
58 | + $this->outputLine(); |
|
59 | + $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
60 | + $this->outputLine('--------------------------------------------'); |
|
61 | + $this->outputLine(); |
|
62 | + |
|
63 | + if ($storage->isOnline()) { |
|
64 | + |
|
65 | + // For the CLI cause. |
|
66 | + $storage->setEvaluatePermissions(false); |
|
67 | + |
|
68 | + $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
69 | + $thumbnailGenerator |
|
70 | + ->setStorage($storage) |
|
71 | + ->setConfiguration($configuration) |
|
72 | + ->generate($limit, $offset); |
|
73 | + |
|
74 | + if ($verbose) { |
|
75 | + $resultSet = $thumbnailGenerator->getResultSet(); |
|
76 | + foreach ($resultSet as $result) { |
|
77 | + $message = sprintf('* File "%s": %s %s', |
|
78 | + $result['fileUid'], |
|
79 | + $result['fileIdentifier'], |
|
80 | + empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
81 | + ); |
|
82 | + $this->outputLine($message); |
|
83 | + } |
|
84 | + $this->outputLine(); |
|
85 | + } |
|
86 | + |
|
87 | + $message = sprintf('Done! New generated %s thumbnail(s) from %s traversed file(s) of a total of %s files.', |
|
88 | + $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
89 | + $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
90 | + $thumbnailGenerator->getTotalNumberOfFiles() |
|
91 | + ); |
|
92 | + $this->outputLine($message); |
|
93 | + |
|
94 | + // Add warning message if missing files were found along the way. |
|
95 | + if ($thumbnailGenerator->getNumberOfMissingFiles() > 0) { |
|
96 | + |
|
97 | + $message = sprintf('ATTENTION! %s missing file(s) detected.', |
|
98 | + $thumbnailGenerator->getNumberOfMissingFiles() |
|
99 | + ); |
|
100 | + $this->outputLine($message); |
|
101 | + } |
|
102 | + } else { |
|
103 | + $this->outputLine('Storage is offline!'); |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + protected function checkEnvironment() |
|
112 | + { |
|
113 | + $user = $this->getDataService()->getRecord( |
|
114 | + 'be_users', [ |
|
115 | + 'username' => '_cli_lowlevel' |
|
116 | + ]); |
|
117 | + |
|
118 | + if (empty($user)) { |
|
119 | + $this->outputLine('Missing User "_cli_lowlevel" and / or its password.'); |
|
120 | + $this->sendAndExit(1); |
|
121 | + } |
|
122 | + |
|
123 | + $user = $this->getDataService()->getRecord( |
|
124 | + 'be_users', [ |
|
125 | + 'username' => '_cli_scheduler' |
|
126 | + ]); |
|
127 | + |
|
128 | + if (empty($user)) { |
|
129 | + $this->outputLine('Missing User "_cli_scheduler" and / or its password.'); |
|
130 | + $this->sendAndExit(1); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @return object|DataService |
|
136 | + */ |
|
137 | + protected function getDataService(): DataService |
|
138 | + { |
|
139 | + return GeneralUtility::makeInstance(DataService::class); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
144 | + */ |
|
145 | + protected function getThumbnailGenerator() |
|
146 | + { |
|
147 | + return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return StorageRepository|object |
|
152 | + */ |
|
153 | + protected function getStorageRepository() |
|
154 | + { |
|
155 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
156 | + } |
|
157 | 157 | } |
@@ -22,213 +22,213 @@ |
||
22 | 22 | class UsageRenderer extends ColumnRendererAbstract |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Render usage of an asset in the grid. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function render() |
|
31 | - { |
|
32 | - $file = $this->getFileConverter()->convert($this->object); |
|
33 | - |
|
34 | - $result = ''; |
|
35 | - |
|
36 | - // Add number of references on the top! |
|
37 | - if ($this->object['number_of_references'] > 1) { |
|
38 | - $result .= sprintf( |
|
39 | - '<div><strong>%s (%s)</strong></div>', |
|
40 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'), |
|
41 | - $this->object['number_of_references'] |
|
42 | - ); |
|
43 | - } |
|
44 | - |
|
45 | - // Render File usage |
|
46 | - $fileReferences = $this->getFileReferenceService()->findFileReferences($file); |
|
47 | - if (!empty($fileReferences)) { |
|
48 | - |
|
49 | - // Finalize file references assembling. |
|
50 | - $result .= sprintf( |
|
51 | - $this->getWrappingTemplate(), |
|
52 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'), |
|
53 | - $this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames')) |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - // Render link usage in RTE |
|
58 | - $linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file); |
|
59 | - if (!empty($linkSoftReferences)) { |
|
60 | - |
|
61 | - // Finalize link references assembling. |
|
62 | - $result .= sprintf( |
|
63 | - $this->getWrappingTemplate(), |
|
64 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'), |
|
65 | - $this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - // Render image usage in RTE |
|
70 | - $imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file); |
|
71 | - if (!empty($imageSoftReferences)) { |
|
72 | - |
|
73 | - // Finalize image references assembling. |
|
74 | - $result .= sprintf( |
|
75 | - $this->getWrappingTemplate(), |
|
76 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'), |
|
77 | - $this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - return $result; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Assemble output reference. |
|
86 | - * |
|
87 | - * @param array $references |
|
88 | - * @param array $mapping |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - protected function assembleOutput(array $references, array $mapping) |
|
92 | - { |
|
93 | - |
|
94 | - $result = ''; |
|
95 | - foreach ($references as $reference) { |
|
96 | - $button = $this->makeLinkButton() |
|
97 | - ->setHref($this->getEditUri($reference, $mapping)) |
|
98 | - ->setClasses('btn-edit-reference') |
|
99 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
100 | - ->render(); |
|
101 | - |
|
102 | - $tableName = $reference[$mapping['tableName']]; |
|
103 | - $identifier = (int)$reference[$mapping['referenceIdentifier']]; |
|
104 | - |
|
105 | - $result .= sprintf( |
|
106 | - '<li title="">%s %s</li>', |
|
107 | - $button, |
|
108 | - $this->computeTitle($tableName, $identifier) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $result; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $tableName |
|
117 | - * @param int $identifier |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - protected function computeTitle($tableName, $identifier) |
|
121 | - { |
|
122 | - $title = ''; |
|
123 | - if (!empty($GLOBALS['TCA'][$tableName])) { |
|
124 | - $title = $this->getRecordTitle($tableName, $identifier); |
|
125 | - if (!$title) { |
|
126 | - $title = Tca::table($tableName)->getTitle(); |
|
127 | - } |
|
128 | - } |
|
129 | - return $title; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return object|LinkButton |
|
134 | - */ |
|
135 | - protected function makeLinkButton() |
|
136 | - { |
|
137 | - return GeneralUtility::makeInstance(LinkButton::class); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param array $reference |
|
142 | - * @param array $mapping |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - protected function getEditUri(array $reference, array $mapping) |
|
146 | - { |
|
147 | - |
|
148 | - $parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]); |
|
149 | - $uri = BackendUtility::getModuleUrl( |
|
150 | - 'record_edit', |
|
151 | - array( |
|
152 | - $parameterName => 'edit', |
|
153 | - 'returnUrl' => $this->getModuleUrl() |
|
154 | - ) |
|
155 | - ); |
|
156 | - return $uri; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - protected function getModuleUrl() |
|
163 | - { |
|
164 | - |
|
165 | - $additionalParameters = []; |
|
166 | - if (GeneralUtility::_GP('id')) { |
|
167 | - $additionalParameters = array( |
|
168 | - 'id' => urldecode(GeneralUtility::_GP('id')), |
|
169 | - ); |
|
170 | - } |
|
171 | - return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Return the title given a table name and an identifier. |
|
176 | - * |
|
177 | - * @param string $tableName |
|
178 | - * @param string $identifier |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - protected function getRecordTitle($tableName, $identifier) |
|
182 | - { |
|
183 | - |
|
184 | - $result = ''; |
|
185 | - if ($tableName && (int)$identifier > 0) { |
|
186 | - |
|
187 | - $labelField = Tca::table($tableName)->getLabelField(); |
|
188 | - |
|
189 | - // Get the title of the record. |
|
190 | - $record = $this->getDataService() |
|
191 | - ->getRecord($tableName, ['uid' => $identifier,]); |
|
192 | - |
|
193 | - if (!empty($record[$labelField])) { |
|
194 | - $result = $record[$labelField]; |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - return $result; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @return object|DataService |
|
203 | - */ |
|
204 | - protected function getDataService(): DataService |
|
205 | - { |
|
206 | - return GeneralUtility::makeInstance(DataService::class); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Return the wrapping HTML template. |
|
211 | - * |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - protected function getWrappingTemplate() |
|
215 | - { |
|
216 | - return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
221 | - */ |
|
222 | - protected function getFileReferenceService() |
|
223 | - { |
|
224 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
229 | - */ |
|
230 | - protected function getFileConverter() |
|
231 | - { |
|
232 | - return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
233 | - } |
|
25 | + /** |
|
26 | + * Render usage of an asset in the grid. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function render() |
|
31 | + { |
|
32 | + $file = $this->getFileConverter()->convert($this->object); |
|
33 | + |
|
34 | + $result = ''; |
|
35 | + |
|
36 | + // Add number of references on the top! |
|
37 | + if ($this->object['number_of_references'] > 1) { |
|
38 | + $result .= sprintf( |
|
39 | + '<div><strong>%s (%s)</strong></div>', |
|
40 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'), |
|
41 | + $this->object['number_of_references'] |
|
42 | + ); |
|
43 | + } |
|
44 | + |
|
45 | + // Render File usage |
|
46 | + $fileReferences = $this->getFileReferenceService()->findFileReferences($file); |
|
47 | + if (!empty($fileReferences)) { |
|
48 | + |
|
49 | + // Finalize file references assembling. |
|
50 | + $result .= sprintf( |
|
51 | + $this->getWrappingTemplate(), |
|
52 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'), |
|
53 | + $this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames')) |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + // Render link usage in RTE |
|
58 | + $linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file); |
|
59 | + if (!empty($linkSoftReferences)) { |
|
60 | + |
|
61 | + // Finalize link references assembling. |
|
62 | + $result .= sprintf( |
|
63 | + $this->getWrappingTemplate(), |
|
64 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'), |
|
65 | + $this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + // Render image usage in RTE |
|
70 | + $imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file); |
|
71 | + if (!empty($imageSoftReferences)) { |
|
72 | + |
|
73 | + // Finalize image references assembling. |
|
74 | + $result .= sprintf( |
|
75 | + $this->getWrappingTemplate(), |
|
76 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'), |
|
77 | + $this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + return $result; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Assemble output reference. |
|
86 | + * |
|
87 | + * @param array $references |
|
88 | + * @param array $mapping |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + protected function assembleOutput(array $references, array $mapping) |
|
92 | + { |
|
93 | + |
|
94 | + $result = ''; |
|
95 | + foreach ($references as $reference) { |
|
96 | + $button = $this->makeLinkButton() |
|
97 | + ->setHref($this->getEditUri($reference, $mapping)) |
|
98 | + ->setClasses('btn-edit-reference') |
|
99 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
100 | + ->render(); |
|
101 | + |
|
102 | + $tableName = $reference[$mapping['tableName']]; |
|
103 | + $identifier = (int)$reference[$mapping['referenceIdentifier']]; |
|
104 | + |
|
105 | + $result .= sprintf( |
|
106 | + '<li title="">%s %s</li>', |
|
107 | + $button, |
|
108 | + $this->computeTitle($tableName, $identifier) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $result; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $tableName |
|
117 | + * @param int $identifier |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + protected function computeTitle($tableName, $identifier) |
|
121 | + { |
|
122 | + $title = ''; |
|
123 | + if (!empty($GLOBALS['TCA'][$tableName])) { |
|
124 | + $title = $this->getRecordTitle($tableName, $identifier); |
|
125 | + if (!$title) { |
|
126 | + $title = Tca::table($tableName)->getTitle(); |
|
127 | + } |
|
128 | + } |
|
129 | + return $title; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return object|LinkButton |
|
134 | + */ |
|
135 | + protected function makeLinkButton() |
|
136 | + { |
|
137 | + return GeneralUtility::makeInstance(LinkButton::class); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param array $reference |
|
142 | + * @param array $mapping |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + protected function getEditUri(array $reference, array $mapping) |
|
146 | + { |
|
147 | + |
|
148 | + $parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]); |
|
149 | + $uri = BackendUtility::getModuleUrl( |
|
150 | + 'record_edit', |
|
151 | + array( |
|
152 | + $parameterName => 'edit', |
|
153 | + 'returnUrl' => $this->getModuleUrl() |
|
154 | + ) |
|
155 | + ); |
|
156 | + return $uri; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + protected function getModuleUrl() |
|
163 | + { |
|
164 | + |
|
165 | + $additionalParameters = []; |
|
166 | + if (GeneralUtility::_GP('id')) { |
|
167 | + $additionalParameters = array( |
|
168 | + 'id' => urldecode(GeneralUtility::_GP('id')), |
|
169 | + ); |
|
170 | + } |
|
171 | + return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Return the title given a table name and an identifier. |
|
176 | + * |
|
177 | + * @param string $tableName |
|
178 | + * @param string $identifier |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + protected function getRecordTitle($tableName, $identifier) |
|
182 | + { |
|
183 | + |
|
184 | + $result = ''; |
|
185 | + if ($tableName && (int)$identifier > 0) { |
|
186 | + |
|
187 | + $labelField = Tca::table($tableName)->getLabelField(); |
|
188 | + |
|
189 | + // Get the title of the record. |
|
190 | + $record = $this->getDataService() |
|
191 | + ->getRecord($tableName, ['uid' => $identifier,]); |
|
192 | + |
|
193 | + if (!empty($record[$labelField])) { |
|
194 | + $result = $record[$labelField]; |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + return $result; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @return object|DataService |
|
203 | + */ |
|
204 | + protected function getDataService(): DataService |
|
205 | + { |
|
206 | + return GeneralUtility::makeInstance(DataService::class); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Return the wrapping HTML template. |
|
211 | + * |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + protected function getWrappingTemplate() |
|
215 | + { |
|
216 | + return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
221 | + */ |
|
222 | + protected function getFileReferenceService() |
|
223 | + { |
|
224 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
229 | + */ |
|
230 | + protected function getFileConverter() |
|
231 | + { |
|
232 | + return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
233 | + } |
|
234 | 234 | } |