@@ -20,43 +20,43 @@ |
||
20 | 20 | class ImageEditorButton extends AbstractComponentView |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Renders a "image-editor" button to be placed in the grid. |
|
25 | - * |
|
26 | - * @param Content $object |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function render(Content $object = null) |
|
30 | - { |
|
31 | - $button = ''; |
|
32 | - if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
33 | - $button = $this->makeLinkButton() |
|
34 | - ->setHref($this->getImageEditorUri($object)) |
|
35 | - ->setDataAttributes([ |
|
36 | - 'uid' => $object->getUid(), |
|
37 | - 'toggle' => 'tooltip', |
|
38 | - ]) |
|
39 | - ->setClasses('btn-imageEditor') |
|
40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
41 | - ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-edit', Icon::SIZE_SMALL)) |
|
42 | - ->render(); |
|
43 | - } |
|
44 | - return $button; |
|
45 | - } |
|
23 | + /** |
|
24 | + * Renders a "image-editor" button to be placed in the grid. |
|
25 | + * |
|
26 | + * @param Content $object |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function render(Content $object = null) |
|
30 | + { |
|
31 | + $button = ''; |
|
32 | + if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
33 | + $button = $this->makeLinkButton() |
|
34 | + ->setHref($this->getImageEditorUri($object)) |
|
35 | + ->setDataAttributes([ |
|
36 | + 'uid' => $object->getUid(), |
|
37 | + 'toggle' => 'tooltip', |
|
38 | + ]) |
|
39 | + ->setClasses('btn-imageEditor') |
|
40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
41 | + ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-edit', Icon::SIZE_SMALL)) |
|
42 | + ->render(); |
|
43 | + } |
|
44 | + return $button; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param Content $object |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - protected function getImageEditorUri(Content $object) |
|
52 | - { |
|
53 | - $urlParameters = array( |
|
54 | - MediaModule::getParameterPrefix() => array( |
|
55 | - 'controller' => 'ImageEditor', |
|
56 | - 'action' => 'show', |
|
57 | - 'file' => $object->getUid(), |
|
58 | - ), |
|
59 | - ); |
|
60 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
61 | - } |
|
47 | + /** |
|
48 | + * @param Content $object |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + protected function getImageEditorUri(Content $object) |
|
52 | + { |
|
53 | + $urlParameters = array( |
|
54 | + MediaModule::getParameterPrefix() => array( |
|
55 | + 'controller' => 'ImageEditor', |
|
56 | + 'action' => 'show', |
|
57 | + 'file' => $object->getUid(), |
|
58 | + ), |
|
59 | + ); |
|
60 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
61 | + } |
|
62 | 62 | } |
@@ -20,44 +20,44 @@ |
||
20 | 20 | class FilePickerButton extends AbstractComponentView |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Renders a "file-picker" button to be placed in the grid. |
|
25 | - * |
|
26 | - * @param Content $object |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function render(Content $object = null) |
|
30 | - { |
|
31 | - $button = ''; |
|
32 | - if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
33 | - $button = $this->makeLinkButton() |
|
34 | - ->setHref($this->getFilePickerUri($object)) |
|
35 | - ->setDataAttributes([ |
|
36 | - 'uid' => $object->getUid(), |
|
37 | - 'toggle' => 'tooltip', |
|
38 | - ]) |
|
39 | - ->setClasses('btn-filePicker') |
|
40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
41 | - ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-export', Icon::SIZE_SMALL)) |
|
42 | - ->render(); |
|
23 | + /** |
|
24 | + * Renders a "file-picker" button to be placed in the grid. |
|
25 | + * |
|
26 | + * @param Content $object |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function render(Content $object = null) |
|
30 | + { |
|
31 | + $button = ''; |
|
32 | + if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
33 | + $button = $this->makeLinkButton() |
|
34 | + ->setHref($this->getFilePickerUri($object)) |
|
35 | + ->setDataAttributes([ |
|
36 | + 'uid' => $object->getUid(), |
|
37 | + 'toggle' => 'tooltip', |
|
38 | + ]) |
|
39 | + ->setClasses('btn-filePicker') |
|
40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
41 | + ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-export', Icon::SIZE_SMALL)) |
|
42 | + ->render(); |
|
43 | 43 | |
44 | - } |
|
45 | - return $button; |
|
46 | - } |
|
44 | + } |
|
45 | + return $button; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param Content $object |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - protected function getFilePickerUri(Content $object) |
|
53 | - { |
|
54 | - $urlParameters = array( |
|
55 | - MediaModule::getParameterPrefix() => array( |
|
56 | - 'controller' => 'Asset', |
|
57 | - 'action' => 'download', |
|
58 | - 'file' => $object->getUid(), |
|
59 | - ), |
|
60 | - ); |
|
61 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
62 | - } |
|
48 | + /** |
|
49 | + * @param Content $object |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + protected function getFilePickerUri(Content $object) |
|
53 | + { |
|
54 | + $urlParameters = array( |
|
55 | + MediaModule::getParameterPrefix() => array( |
|
56 | + 'controller' => 'Asset', |
|
57 | + 'action' => 'download', |
|
58 | + 'file' => $object->getUid(), |
|
59 | + ), |
|
60 | + ); |
|
61 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
62 | + } |
|
63 | 63 | } |
@@ -23,248 +23,248 @@ |
||
23 | 23 | class ActionPermissionFacet implements FacetInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $name = '__action_permission'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $suggestions = array( |
|
40 | - 'r' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.read_only', |
|
41 | - 'w' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.write', |
|
42 | - ); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $fieldNameAndPath = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $dataType; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var bool |
|
56 | - */ |
|
57 | - protected $canModifyMatcher = false; |
|
58 | - |
|
59 | - /** |
|
60 | - * Constructor of a Generic Facet in Vidi. |
|
61 | - * |
|
62 | - * @param string $name |
|
63 | - * @param string $label |
|
64 | - * @param array $suggestions |
|
65 | - * @param string $fieldNameAndPath |
|
66 | - */ |
|
67 | - public function __construct($name = '', $label = '', array $suggestions = [], $fieldNameAndPath = '') |
|
68 | - { |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function getName() |
|
75 | - { |
|
76 | - return $this->name; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function getLabel() |
|
83 | - { |
|
84 | - return $this->getLanguageService()->sL($this->label); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public function getSuggestions() |
|
91 | - { |
|
92 | - $suggestions = []; |
|
93 | - foreach ($this->suggestions as $key => $label) { |
|
94 | - $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
95 | - } |
|
96 | - |
|
97 | - return $suggestions; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function hasSuggestions() |
|
104 | - { |
|
105 | - return true; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $dataType |
|
110 | - * @return $this |
|
111 | - */ |
|
112 | - public function setDataType($dataType) |
|
113 | - { |
|
114 | - $this->dataType = $dataType; |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public function canModifyMatcher() |
|
122 | - { |
|
123 | - return $this->canModifyMatcher; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param Matcher $matcher |
|
128 | - * @param $value |
|
129 | - * @return Matcher |
|
130 | - */ |
|
131 | - public function modifyMatcher(Matcher $matcher, $value) |
|
132 | - { |
|
133 | - return $matcher; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param AfterFindContentObjectsSignalArguments $signalArguments |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - public function modifyResultSet(AfterFindContentObjectsSignalArguments $signalArguments) |
|
141 | - { |
|
142 | - |
|
143 | - if ($signalArguments->getDataType() === 'sys_file') { |
|
144 | - |
|
145 | - $queryParts = $this->getQueryParts(); |
|
146 | - |
|
147 | - if (!empty($queryParts)) { |
|
148 | - $permission = $this->getPermissionValue($queryParts); |
|
149 | - |
|
150 | - if ($permission) { |
|
151 | - |
|
152 | - // We are force to query the content repository again here without limit |
|
153 | - $matcher = $signalArguments->getMatcher(); |
|
154 | - $order = $signalArguments->getOrder(); |
|
155 | - $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order); |
|
156 | - |
|
157 | - $filteredObjects = []; |
|
158 | - foreach ($objects as $object) { |
|
159 | - |
|
160 | - $file = $this->getFileConverter()->convert($object->getUid()); |
|
161 | - if ($permission === 'read' && !$file->checkActionPermission('write')) { |
|
162 | - $filteredObjects[] = $object; |
|
163 | - } elseif ($permission === 'write' && $file->checkActionPermission('write')) { |
|
164 | - $filteredObjects[] = $object; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // Only take part of the array according to offset and limit. |
|
169 | - $offset = $signalArguments->getOffset(); |
|
170 | - $limit = $signalArguments->getLimit(); |
|
171 | - $signalArguments->setContentObjects(array_slice($filteredObjects, $offset, $limit)); |
|
172 | - |
|
173 | - // Count number of records |
|
174 | - $signalArguments->setNumberOfObjects(count($filteredObjects)); |
|
175 | - $signalArguments->setHasBeenProcessed(true); |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - return array($signalArguments); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - protected function getQueryParts() |
|
187 | - { |
|
188 | - |
|
189 | - // Transmit recursive selection parameter. |
|
190 | - $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
191 | - $parameters = GeneralUtility::_GP($parameterPrefix); |
|
192 | - |
|
193 | - $queryParts = []; |
|
194 | - if (!empty($parameters['searchTerm'])) { |
|
195 | - $query = rawurldecode($parameters['searchTerm']); |
|
196 | - $queryParts = json_decode($query, true); |
|
197 | - } |
|
198 | - |
|
199 | - return $queryParts; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Retrieve the search permission value. |
|
204 | - * |
|
205 | - * @param array $queryParts |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - protected function getPermissionValue(array $queryParts) |
|
209 | - { |
|
210 | - $permission = ''; |
|
211 | - |
|
212 | - // Check also amongst labels. |
|
213 | - $labelReadOnly = $this->getLanguageService()->sL($this->suggestions['r']); |
|
214 | - $labelWrite = $this->getLanguageService()->sL($this->suggestions['w']); |
|
215 | - |
|
216 | - foreach ($queryParts as $queryPart) { |
|
217 | - $facetName = key($queryPart); |
|
218 | - $value = $queryPart[$facetName]; |
|
219 | - if ($facetName === $this->name) { |
|
220 | - |
|
221 | - if ($value === 'r' || $value === $labelReadOnly) { |
|
222 | - $permission = 'read'; |
|
223 | - } elseif ($value === 'w' || $value === $labelWrite) { |
|
224 | - $permission = 'write'; |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - return $permission; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Magic method implementation for retrieving state. |
|
233 | - * |
|
234 | - * @param array $states |
|
235 | - * @return $this |
|
236 | - */ |
|
237 | - static public function __set_state($states) |
|
238 | - { |
|
239 | - return new ActionPermissionFacet($states['name'], $states['label'], $states['suggestions'], $states['fieldNameAndPath']); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @return \TYPO3\CMS\Lang\LanguageService |
|
244 | - */ |
|
245 | - protected function getLanguageService() |
|
246 | - { |
|
247 | - return $GLOBALS['LANG']; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @return ContentToFileConverter |
|
252 | - * @throws \InvalidArgumentException |
|
253 | - */ |
|
254 | - protected function getFileConverter() |
|
255 | - { |
|
256 | - return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the Vidi Module Loader. |
|
261 | - * |
|
262 | - * @return ModuleLoader |
|
263 | - * @throws \InvalidArgumentException |
|
264 | - */ |
|
265 | - protected function getModuleLoader() |
|
266 | - { |
|
267 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
268 | - } |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $name = '__action_permission'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $suggestions = array( |
|
40 | + 'r' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.read_only', |
|
41 | + 'w' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.write', |
|
42 | + ); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $fieldNameAndPath = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $dataType; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var bool |
|
56 | + */ |
|
57 | + protected $canModifyMatcher = false; |
|
58 | + |
|
59 | + /** |
|
60 | + * Constructor of a Generic Facet in Vidi. |
|
61 | + * |
|
62 | + * @param string $name |
|
63 | + * @param string $label |
|
64 | + * @param array $suggestions |
|
65 | + * @param string $fieldNameAndPath |
|
66 | + */ |
|
67 | + public function __construct($name = '', $label = '', array $suggestions = [], $fieldNameAndPath = '') |
|
68 | + { |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function getName() |
|
75 | + { |
|
76 | + return $this->name; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function getLabel() |
|
83 | + { |
|
84 | + return $this->getLanguageService()->sL($this->label); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public function getSuggestions() |
|
91 | + { |
|
92 | + $suggestions = []; |
|
93 | + foreach ($this->suggestions as $key => $label) { |
|
94 | + $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
95 | + } |
|
96 | + |
|
97 | + return $suggestions; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function hasSuggestions() |
|
104 | + { |
|
105 | + return true; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $dataType |
|
110 | + * @return $this |
|
111 | + */ |
|
112 | + public function setDataType($dataType) |
|
113 | + { |
|
114 | + $this->dataType = $dataType; |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public function canModifyMatcher() |
|
122 | + { |
|
123 | + return $this->canModifyMatcher; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param Matcher $matcher |
|
128 | + * @param $value |
|
129 | + * @return Matcher |
|
130 | + */ |
|
131 | + public function modifyMatcher(Matcher $matcher, $value) |
|
132 | + { |
|
133 | + return $matcher; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param AfterFindContentObjectsSignalArguments $signalArguments |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + public function modifyResultSet(AfterFindContentObjectsSignalArguments $signalArguments) |
|
141 | + { |
|
142 | + |
|
143 | + if ($signalArguments->getDataType() === 'sys_file') { |
|
144 | + |
|
145 | + $queryParts = $this->getQueryParts(); |
|
146 | + |
|
147 | + if (!empty($queryParts)) { |
|
148 | + $permission = $this->getPermissionValue($queryParts); |
|
149 | + |
|
150 | + if ($permission) { |
|
151 | + |
|
152 | + // We are force to query the content repository again here without limit |
|
153 | + $matcher = $signalArguments->getMatcher(); |
|
154 | + $order = $signalArguments->getOrder(); |
|
155 | + $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order); |
|
156 | + |
|
157 | + $filteredObjects = []; |
|
158 | + foreach ($objects as $object) { |
|
159 | + |
|
160 | + $file = $this->getFileConverter()->convert($object->getUid()); |
|
161 | + if ($permission === 'read' && !$file->checkActionPermission('write')) { |
|
162 | + $filteredObjects[] = $object; |
|
163 | + } elseif ($permission === 'write' && $file->checkActionPermission('write')) { |
|
164 | + $filteredObjects[] = $object; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // Only take part of the array according to offset and limit. |
|
169 | + $offset = $signalArguments->getOffset(); |
|
170 | + $limit = $signalArguments->getLimit(); |
|
171 | + $signalArguments->setContentObjects(array_slice($filteredObjects, $offset, $limit)); |
|
172 | + |
|
173 | + // Count number of records |
|
174 | + $signalArguments->setNumberOfObjects(count($filteredObjects)); |
|
175 | + $signalArguments->setHasBeenProcessed(true); |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + return array($signalArguments); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + protected function getQueryParts() |
|
187 | + { |
|
188 | + |
|
189 | + // Transmit recursive selection parameter. |
|
190 | + $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
191 | + $parameters = GeneralUtility::_GP($parameterPrefix); |
|
192 | + |
|
193 | + $queryParts = []; |
|
194 | + if (!empty($parameters['searchTerm'])) { |
|
195 | + $query = rawurldecode($parameters['searchTerm']); |
|
196 | + $queryParts = json_decode($query, true); |
|
197 | + } |
|
198 | + |
|
199 | + return $queryParts; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Retrieve the search permission value. |
|
204 | + * |
|
205 | + * @param array $queryParts |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + protected function getPermissionValue(array $queryParts) |
|
209 | + { |
|
210 | + $permission = ''; |
|
211 | + |
|
212 | + // Check also amongst labels. |
|
213 | + $labelReadOnly = $this->getLanguageService()->sL($this->suggestions['r']); |
|
214 | + $labelWrite = $this->getLanguageService()->sL($this->suggestions['w']); |
|
215 | + |
|
216 | + foreach ($queryParts as $queryPart) { |
|
217 | + $facetName = key($queryPart); |
|
218 | + $value = $queryPart[$facetName]; |
|
219 | + if ($facetName === $this->name) { |
|
220 | + |
|
221 | + if ($value === 'r' || $value === $labelReadOnly) { |
|
222 | + $permission = 'read'; |
|
223 | + } elseif ($value === 'w' || $value === $labelWrite) { |
|
224 | + $permission = 'write'; |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + return $permission; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Magic method implementation for retrieving state. |
|
233 | + * |
|
234 | + * @param array $states |
|
235 | + * @return $this |
|
236 | + */ |
|
237 | + static public function __set_state($states) |
|
238 | + { |
|
239 | + return new ActionPermissionFacet($states['name'], $states['label'], $states['suggestions'], $states['fieldNameAndPath']); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @return \TYPO3\CMS\Lang\LanguageService |
|
244 | + */ |
|
245 | + protected function getLanguageService() |
|
246 | + { |
|
247 | + return $GLOBALS['LANG']; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @return ContentToFileConverter |
|
252 | + * @throws \InvalidArgumentException |
|
253 | + */ |
|
254 | + protected function getFileConverter() |
|
255 | + { |
|
256 | + return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the Vidi Module Loader. |
|
261 | + * |
|
262 | + * @return ModuleLoader |
|
263 | + * @throws \InvalidArgumentException |
|
264 | + */ |
|
265 | + protected function getModuleLoader() |
|
266 | + { |
|
267 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
268 | + } |
|
269 | 269 | |
270 | 270 | } |
@@ -19,45 +19,45 @@ |
||
19 | 19 | class ProcessedFileController extends ActionController |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Initializes the controller before invoking an action method. |
|
24 | - */ |
|
25 | - public function initializeAction() |
|
26 | - { |
|
27 | - |
|
28 | - // Configure property mapping to retrieve the file object. |
|
29 | - if ($this->arguments->hasArgument('file')) { |
|
30 | - |
|
31 | - /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
32 | - $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
33 | - |
|
34 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
35 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Create a processed file according to some configuration. |
|
41 | - * |
|
42 | - * @param File $file |
|
43 | - * @param array $processingConfiguration |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function createAction(File $file, array $processingConfiguration = []) |
|
47 | - { |
|
48 | - $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); |
|
49 | - |
|
50 | - $response = array( |
|
51 | - 'success' => true, |
|
52 | - 'original' => $file->getUid(), |
|
53 | - 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), |
|
54 | - 'publicUrl' => $processedFile->getPublicUrl(), |
|
55 | - 'width' => $processedFile->getProperty('width'), |
|
56 | - 'height' => $processedFile->getProperty('height'), |
|
57 | - ); |
|
58 | - |
|
59 | - header("Content-Type: text/json"); |
|
60 | - return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
61 | - } |
|
22 | + /** |
|
23 | + * Initializes the controller before invoking an action method. |
|
24 | + */ |
|
25 | + public function initializeAction() |
|
26 | + { |
|
27 | + |
|
28 | + // Configure property mapping to retrieve the file object. |
|
29 | + if ($this->arguments->hasArgument('file')) { |
|
30 | + |
|
31 | + /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
32 | + $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
33 | + |
|
34 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
35 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Create a processed file according to some configuration. |
|
41 | + * |
|
42 | + * @param File $file |
|
43 | + * @param array $processingConfiguration |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function createAction(File $file, array $processingConfiguration = []) |
|
47 | + { |
|
48 | + $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); |
|
49 | + |
|
50 | + $response = array( |
|
51 | + 'success' => true, |
|
52 | + 'original' => $file->getUid(), |
|
53 | + 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), |
|
54 | + 'publicUrl' => $processedFile->getPublicUrl(), |
|
55 | + 'width' => $processedFile->getProperty('width'), |
|
56 | + 'height' => $processedFile->getProperty('height'), |
|
57 | + ); |
|
58 | + |
|
59 | + header("Content-Type: text/json"); |
|
60 | + return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $values = array( |
120 | 120 | 'number_of_references' => $numberOfReferences |
121 | 121 | ); |
122 | - $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = ' . $file->getUid(), $values); |
|
122 | + $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = '.$file->getUid(), $values); |
|
123 | 123 | } catch (FileDoesNotExistException $fileDoesNotExistException) { |
124 | 124 | // Do nothing here. A file that does not exist needs no update. |
125 | 125 | // See https://github.com/fabarea/media/issues/159 for more information. |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | protected function findFileByFileReference($fileReferenceIdentifier) |
274 | 274 | { |
275 | 275 | $tableName = 'sys_file_reference'; |
276 | - $clause = 'uid = ' . $fileReferenceIdentifier; |
|
276 | + $clause = 'uid = '.$fileReferenceIdentifier; |
|
277 | 277 | #$clause .= BackendUtility::BEenableFields($tableName); // was removed following https://forge.typo3.org/issues/62370 |
278 | 278 | $clause .= BackendUtility::deleteClause($tableName); |
279 | 279 | $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_file_reference', $clause); |
@@ -20,311 +20,311 @@ |
||
20 | 20 | class DataHandlerHook |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Store indexed file before the Data Handler start "working". |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $beforeDataHandlerProcessFileIdentifiers = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * Store indexed file after the Data Handler has done its job. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $afterDataHandlerProcessFileIdentifiers = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * Internal key for the Cache Manager. |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $registerKey = 'media-hook-elementsToKeepTrack'; |
|
43 | - |
|
44 | - /** |
|
45 | - * First procedures to launch before all operations in DataHandler. |
|
46 | - * |
|
47 | - * Feed variable $this->beforeDataHandlerProcessFileIdentifiers |
|
48 | - * |
|
49 | - * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function processDatamap_beforeStart(DataHandler $caller) |
|
53 | - { |
|
54 | - |
|
55 | - // Use a register to keep track of files. |
|
56 | - // It is required according to TCEMain behaviour which register "elements to be deleted". |
|
57 | - // Those element must not be forgotten. |
|
58 | - $this->initializeFileRegister(); |
|
59 | - $this->registerFilesToKeepTrack(); |
|
60 | - |
|
61 | - foreach ($caller->datamap as $tableName => $configuration) { |
|
62 | - |
|
63 | - $id = key($configuration); |
|
64 | - if (!MathUtility::canBeInterpretedAsInteger($id)) { |
|
65 | - continue; |
|
66 | - } |
|
67 | - |
|
68 | - /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
69 | - $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
70 | - if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
71 | - $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
72 | - } |
|
73 | - $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
74 | - |
|
75 | - // Make sure $index is an array. |
|
76 | - if (!is_array($indexes)) { |
|
77 | - $indexes = []; |
|
78 | - } |
|
79 | - |
|
80 | - $fileIdentifiers = $this->lookForFiles($indexes); |
|
81 | - $this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Last procedures to launch after all operations in DataHandler. |
|
87 | - * |
|
88 | - * Process field "number_of_references" which may require updates. |
|
89 | - * |
|
90 | - * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public function processDatamap_afterAllOperations(DataHandler $caller) |
|
94 | - { |
|
95 | - |
|
96 | - // First collect files which have been involved. |
|
97 | - foreach ($caller->datamap as $tableName => $configuration) { |
|
98 | - |
|
99 | - $id = key($configuration); |
|
100 | - |
|
101 | - /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
102 | - $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
103 | - if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
104 | - $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
105 | - } |
|
106 | - $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
107 | - |
|
108 | - // Make sure $index is an array. |
|
109 | - if (!is_array($indexes)) { |
|
110 | - $indexes = []; |
|
111 | - } |
|
112 | - |
|
113 | - $fileIdentifiers = $this->lookForFiles($indexes); |
|
114 | - $this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
115 | - } |
|
116 | - |
|
117 | - // After collecting files, update the column "number_of_references". |
|
118 | - foreach ($this->getFileToProcess() as $fileIdentifier) { |
|
119 | - try { |
|
120 | - $file = ResourceFactory::getInstance()->getFileObject($fileIdentifier); |
|
121 | - $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
122 | - |
|
123 | - $values = array( |
|
124 | - 'number_of_references' => $numberOfReferences |
|
125 | - ); |
|
126 | - $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = ' . $file->getUid(), $values); |
|
127 | - } catch (FileDoesNotExistException $fileDoesNotExistException) { |
|
128 | - // Do nothing here. A file that does not exist needs no update. |
|
129 | - // See https://github.com/fabarea/media/issues/159 for more information. |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - protected function initializeFileRegister() |
|
138 | - { |
|
139 | - |
|
140 | - $items = $this->getMemoryCache()->get($this->registerKey); |
|
141 | - if (!is_array($items)) { |
|
142 | - $this->getMemoryCache()->set($this->registerKey, []); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return void |
|
148 | - */ |
|
149 | - protected function registerFilesToKeepTrack() |
|
150 | - { |
|
151 | - $fileIdentifiers = []; |
|
152 | - $elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted'); |
|
153 | - if (is_array($elementsToBeDeleted)) { |
|
154 | - foreach ($elementsToBeDeleted as $tableName => $element) { |
|
155 | - |
|
156 | - if ($tableName === 'sys_file_reference') { |
|
157 | - |
|
158 | - $fileReferenceIdentifier = key($element); |
|
159 | - if ($element[$fileReferenceIdentifier] === true) { |
|
160 | - $fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier); |
|
161 | - $fileIdentifiers[] = $fileIdentifier; |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - // Put back in the memory cache the value. |
|
168 | - $items = $this->getMemoryCache()->get($this->registerKey); |
|
169 | - $mergedItems = array_merge($items, $fileIdentifiers); |
|
170 | - $this->getMemoryCache()->set($this->registerKey, $mergedItems); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - protected function getRegisteredFiles() |
|
177 | - { |
|
178 | - $files = $this->getMemoryCache()->get($this->registerKey); |
|
179 | - return $files; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Look for file which are within the reference index. |
|
184 | - * |
|
185 | - * @return array |
|
186 | - */ |
|
187 | - protected function getFileToProcess() |
|
188 | - { |
|
189 | - $fileIdentifiers = array_merge( |
|
190 | - $this->beforeDataHandlerProcessFileIdentifiers, |
|
191 | - $this->afterDataHandlerProcessFileIdentifiers, |
|
192 | - $this->getRegisteredFiles() |
|
193 | - ); |
|
194 | - return array_unique($fileIdentifiers); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param array $fileIdentifiers |
|
199 | - * @return void |
|
200 | - */ |
|
201 | - protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
202 | - { |
|
203 | - $this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param array $fileIdentifiers |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
211 | - { |
|
212 | - $this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Look for file which are within the reference index. |
|
217 | - * |
|
218 | - * @param array $indexes |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - protected function lookForFiles(array $indexes) |
|
222 | - { |
|
223 | - |
|
224 | - $fileIdentifiers = []; |
|
225 | - if (isset($indexes['relations'])) { |
|
226 | - |
|
227 | - foreach ($indexes['relations'] as $index) { |
|
228 | - if (is_array($index)) { |
|
229 | - if ($this->isSoftReferenceImage($index)) { |
|
230 | - $fileIdentifiers[] = $index['ref_uid']; |
|
231 | - } elseif ($this->isSoftReferenceLink($index)) { |
|
232 | - $fileIdentifiers[] = $index['ref_uid']; |
|
233 | - } elseif ($this->isFileReference($index)) { |
|
234 | - $fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']); |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - return $fileIdentifiers; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @param array $index |
|
245 | - * @return bool |
|
246 | - */ |
|
247 | - public function isFileReference(array $index) |
|
248 | - { |
|
249 | - return $index['ref_table'] === 'sys_file_reference'; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * @param array $index |
|
254 | - * @return bool |
|
255 | - */ |
|
256 | - public function isSoftReferenceLink(array $index) |
|
257 | - { |
|
258 | - return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file'; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * @param array $index |
|
263 | - * @return bool |
|
264 | - */ |
|
265 | - public function isSoftReferenceImage(array $index) |
|
266 | - { |
|
267 | - return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file'; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Retrieve the File identifier. |
|
272 | - * |
|
273 | - * @param $fileReferenceIdentifier |
|
274 | - * @throws \Exception |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - protected function findFileByFileReference($fileReferenceIdentifier) |
|
278 | - { |
|
279 | - $tableName = 'sys_file_reference'; |
|
280 | - $clause = 'uid = ' . $fileReferenceIdentifier; |
|
281 | - #$clause .= BackendUtility::BEenableFields($tableName); // was removed following https://forge.typo3.org/issues/62370 |
|
282 | - $clause .= BackendUtility::deleteClause($tableName); |
|
283 | - $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_file_reference', $clause); |
|
284 | - |
|
285 | - if (empty($record)) { |
|
286 | - throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796); |
|
287 | - } |
|
288 | - |
|
289 | - $fileIdentifier = $record['uid_local']; |
|
290 | - return $fileIdentifier; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
295 | - */ |
|
296 | - protected function getFileReferenceService() |
|
297 | - { |
|
298 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Gets an instance of the memory cache. |
|
303 | - * |
|
304 | - * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend |
|
305 | - */ |
|
306 | - protected function getMemoryCache() |
|
307 | - { |
|
308 | - return $this->getCacheManager()->getCache('cache_runtime'); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Create and returns an instance of the CacheManager |
|
313 | - * |
|
314 | - * @return \TYPO3\CMS\Core\Cache\CacheManager|object |
|
315 | - */ |
|
316 | - protected function getCacheManager() |
|
317 | - { |
|
318 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Wrapper around the global database connection object. |
|
323 | - * |
|
324 | - * @return \Fab\Vidi\Database\DatabaseConnection |
|
325 | - */ |
|
326 | - protected function getDatabaseConnection() |
|
327 | - { |
|
328 | - return $GLOBALS['TYPO3_DB']; |
|
329 | - } |
|
23 | + /** |
|
24 | + * Store indexed file before the Data Handler start "working". |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $beforeDataHandlerProcessFileIdentifiers = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * Store indexed file after the Data Handler has done its job. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $afterDataHandlerProcessFileIdentifiers = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * Internal key for the Cache Manager. |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $registerKey = 'media-hook-elementsToKeepTrack'; |
|
43 | + |
|
44 | + /** |
|
45 | + * First procedures to launch before all operations in DataHandler. |
|
46 | + * |
|
47 | + * Feed variable $this->beforeDataHandlerProcessFileIdentifiers |
|
48 | + * |
|
49 | + * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function processDatamap_beforeStart(DataHandler $caller) |
|
53 | + { |
|
54 | + |
|
55 | + // Use a register to keep track of files. |
|
56 | + // It is required according to TCEMain behaviour which register "elements to be deleted". |
|
57 | + // Those element must not be forgotten. |
|
58 | + $this->initializeFileRegister(); |
|
59 | + $this->registerFilesToKeepTrack(); |
|
60 | + |
|
61 | + foreach ($caller->datamap as $tableName => $configuration) { |
|
62 | + |
|
63 | + $id = key($configuration); |
|
64 | + if (!MathUtility::canBeInterpretedAsInteger($id)) { |
|
65 | + continue; |
|
66 | + } |
|
67 | + |
|
68 | + /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
69 | + $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
70 | + if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
71 | + $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
72 | + } |
|
73 | + $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
74 | + |
|
75 | + // Make sure $index is an array. |
|
76 | + if (!is_array($indexes)) { |
|
77 | + $indexes = []; |
|
78 | + } |
|
79 | + |
|
80 | + $fileIdentifiers = $this->lookForFiles($indexes); |
|
81 | + $this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Last procedures to launch after all operations in DataHandler. |
|
87 | + * |
|
88 | + * Process field "number_of_references" which may require updates. |
|
89 | + * |
|
90 | + * @param \TYPO3\CMS\Core\DataHandling\DataHandler $caller TCEMain Object |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public function processDatamap_afterAllOperations(DataHandler $caller) |
|
94 | + { |
|
95 | + |
|
96 | + // First collect files which have been involved. |
|
97 | + foreach ($caller->datamap as $tableName => $configuration) { |
|
98 | + |
|
99 | + $id = key($configuration); |
|
100 | + |
|
101 | + /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
102 | + $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class); |
|
103 | + if (\TYPO3\CMS\Backend\Utility\BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
104 | + $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
105 | + } |
|
106 | + $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
107 | + |
|
108 | + // Make sure $index is an array. |
|
109 | + if (!is_array($indexes)) { |
|
110 | + $indexes = []; |
|
111 | + } |
|
112 | + |
|
113 | + $fileIdentifiers = $this->lookForFiles($indexes); |
|
114 | + $this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
115 | + } |
|
116 | + |
|
117 | + // After collecting files, update the column "number_of_references". |
|
118 | + foreach ($this->getFileToProcess() as $fileIdentifier) { |
|
119 | + try { |
|
120 | + $file = ResourceFactory::getInstance()->getFileObject($fileIdentifier); |
|
121 | + $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
122 | + |
|
123 | + $values = array( |
|
124 | + 'number_of_references' => $numberOfReferences |
|
125 | + ); |
|
126 | + $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = ' . $file->getUid(), $values); |
|
127 | + } catch (FileDoesNotExistException $fileDoesNotExistException) { |
|
128 | + // Do nothing here. A file that does not exist needs no update. |
|
129 | + // See https://github.com/fabarea/media/issues/159 for more information. |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + protected function initializeFileRegister() |
|
138 | + { |
|
139 | + |
|
140 | + $items = $this->getMemoryCache()->get($this->registerKey); |
|
141 | + if (!is_array($items)) { |
|
142 | + $this->getMemoryCache()->set($this->registerKey, []); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return void |
|
148 | + */ |
|
149 | + protected function registerFilesToKeepTrack() |
|
150 | + { |
|
151 | + $fileIdentifiers = []; |
|
152 | + $elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted'); |
|
153 | + if (is_array($elementsToBeDeleted)) { |
|
154 | + foreach ($elementsToBeDeleted as $tableName => $element) { |
|
155 | + |
|
156 | + if ($tableName === 'sys_file_reference') { |
|
157 | + |
|
158 | + $fileReferenceIdentifier = key($element); |
|
159 | + if ($element[$fileReferenceIdentifier] === true) { |
|
160 | + $fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier); |
|
161 | + $fileIdentifiers[] = $fileIdentifier; |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + // Put back in the memory cache the value. |
|
168 | + $items = $this->getMemoryCache()->get($this->registerKey); |
|
169 | + $mergedItems = array_merge($items, $fileIdentifiers); |
|
170 | + $this->getMemoryCache()->set($this->registerKey, $mergedItems); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + protected function getRegisteredFiles() |
|
177 | + { |
|
178 | + $files = $this->getMemoryCache()->get($this->registerKey); |
|
179 | + return $files; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Look for file which are within the reference index. |
|
184 | + * |
|
185 | + * @return array |
|
186 | + */ |
|
187 | + protected function getFileToProcess() |
|
188 | + { |
|
189 | + $fileIdentifiers = array_merge( |
|
190 | + $this->beforeDataHandlerProcessFileIdentifiers, |
|
191 | + $this->afterDataHandlerProcessFileIdentifiers, |
|
192 | + $this->getRegisteredFiles() |
|
193 | + ); |
|
194 | + return array_unique($fileIdentifiers); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param array $fileIdentifiers |
|
199 | + * @return void |
|
200 | + */ |
|
201 | + protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
202 | + { |
|
203 | + $this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param array $fileIdentifiers |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
211 | + { |
|
212 | + $this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Look for file which are within the reference index. |
|
217 | + * |
|
218 | + * @param array $indexes |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + protected function lookForFiles(array $indexes) |
|
222 | + { |
|
223 | + |
|
224 | + $fileIdentifiers = []; |
|
225 | + if (isset($indexes['relations'])) { |
|
226 | + |
|
227 | + foreach ($indexes['relations'] as $index) { |
|
228 | + if (is_array($index)) { |
|
229 | + if ($this->isSoftReferenceImage($index)) { |
|
230 | + $fileIdentifiers[] = $index['ref_uid']; |
|
231 | + } elseif ($this->isSoftReferenceLink($index)) { |
|
232 | + $fileIdentifiers[] = $index['ref_uid']; |
|
233 | + } elseif ($this->isFileReference($index)) { |
|
234 | + $fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']); |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + return $fileIdentifiers; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @param array $index |
|
245 | + * @return bool |
|
246 | + */ |
|
247 | + public function isFileReference(array $index) |
|
248 | + { |
|
249 | + return $index['ref_table'] === 'sys_file_reference'; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * @param array $index |
|
254 | + * @return bool |
|
255 | + */ |
|
256 | + public function isSoftReferenceLink(array $index) |
|
257 | + { |
|
258 | + return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file'; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * @param array $index |
|
263 | + * @return bool |
|
264 | + */ |
|
265 | + public function isSoftReferenceImage(array $index) |
|
266 | + { |
|
267 | + return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file'; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Retrieve the File identifier. |
|
272 | + * |
|
273 | + * @param $fileReferenceIdentifier |
|
274 | + * @throws \Exception |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + protected function findFileByFileReference($fileReferenceIdentifier) |
|
278 | + { |
|
279 | + $tableName = 'sys_file_reference'; |
|
280 | + $clause = 'uid = ' . $fileReferenceIdentifier; |
|
281 | + #$clause .= BackendUtility::BEenableFields($tableName); // was removed following https://forge.typo3.org/issues/62370 |
|
282 | + $clause .= BackendUtility::deleteClause($tableName); |
|
283 | + $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_file_reference', $clause); |
|
284 | + |
|
285 | + if (empty($record)) { |
|
286 | + throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796); |
|
287 | + } |
|
288 | + |
|
289 | + $fileIdentifier = $record['uid_local']; |
|
290 | + return $fileIdentifier; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
295 | + */ |
|
296 | + protected function getFileReferenceService() |
|
297 | + { |
|
298 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Gets an instance of the memory cache. |
|
303 | + * |
|
304 | + * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend |
|
305 | + */ |
|
306 | + protected function getMemoryCache() |
|
307 | + { |
|
308 | + return $this->getCacheManager()->getCache('cache_runtime'); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Create and returns an instance of the CacheManager |
|
313 | + * |
|
314 | + * @return \TYPO3\CMS\Core\Cache\CacheManager|object |
|
315 | + */ |
|
316 | + protected function getCacheManager() |
|
317 | + { |
|
318 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Wrapper around the global database connection object. |
|
323 | + * |
|
324 | + * @return \Fab\Vidi\Database\DatabaseConnection |
|
325 | + */ |
|
326 | + protected function getDatabaseConnection() |
|
327 | + { |
|
328 | + return $GLOBALS['TYPO3_DB']; |
|
329 | + } |
|
330 | 330 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | * Returns true if the given picture is rotated. |
90 | 90 | * |
91 | 91 | * @param integer $orientation EXIF orientation |
92 | - * @return integer |
|
92 | + * @return boolean |
|
93 | 93 | * @see http://www.impulseadventure.com/photo/exif-orientation.html |
94 | 94 | */ |
95 | 95 | protected function isRotated($orientation) |
@@ -49,7 +49,7 @@ |
||
49 | 49 | |
50 | 50 | $imParams = '###SkipStripProfile###'; |
51 | 51 | if ($transformation !== '') { |
52 | - $imParams .= ' ' . $transformation; |
|
52 | + $imParams .= ' '.$transformation; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
@@ -17,154 +17,154 @@ |
||
17 | 17 | class Rotate implements ImageOptimizerInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
22 | - */ |
|
23 | - protected $gifCreator; |
|
24 | - |
|
25 | - /** |
|
26 | - * @return \Fab\Media\FileUpload\Optimizer\Rotate |
|
27 | - */ |
|
28 | - public function __construct() |
|
29 | - { |
|
30 | - $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
31 | - $this->gifCreator->init(); |
|
32 | - $this->gifCreator->absPrefix = PATH_site; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Optimize the given uploaded image |
|
37 | - * |
|
38 | - * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
39 | - * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
40 | - */ |
|
41 | - public function optimize($uploadedFile) |
|
42 | - { |
|
43 | - |
|
44 | - $orientation = $this->getOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
45 | - $isRotated = $this->isRotated($orientation); |
|
46 | - |
|
47 | - // Only rotate image if necessary! |
|
48 | - if ($isRotated > 0) { |
|
49 | - $transformation = $this->getTransformation($orientation); |
|
50 | - |
|
51 | - $imParams = '###SkipStripProfile###'; |
|
52 | - if ($transformation !== '') { |
|
53 | - $imParams .= ' ' . $transformation; |
|
54 | - } |
|
55 | - |
|
56 | - $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
|
57 | - if ($tempFileInfo) { |
|
58 | - // Replace original file |
|
59 | - @unlink($uploadedFile->getFileWithAbsolutePath()); |
|
60 | - @rename($tempFileInfo[3], $uploadedFile->getFileWithAbsolutePath()); |
|
61 | - |
|
62 | - if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') { |
|
63 | - $this->resetOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
67 | - return $uploadedFile; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns the EXIF orientation of a given picture. |
|
72 | - * |
|
73 | - * @param string $filename |
|
74 | - * @return integer |
|
75 | - */ |
|
76 | - protected function getOrientation($filename) |
|
77 | - { |
|
78 | - $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); |
|
79 | - $orientation = 1; // Fallback to "straight" |
|
80 | - if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,tif,tiff', $extension) && function_exists('exif_read_data')) { |
|
81 | - try { |
|
82 | - $exif = exif_read_data($filename); |
|
83 | - if ($exif) { |
|
84 | - $orientation = $exif['Orientation']; |
|
85 | - } |
|
86 | - } catch (\Exception $e) {} |
|
87 | - } |
|
88 | - return $orientation; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns true if the given picture is rotated. |
|
93 | - * |
|
94 | - * @param integer $orientation EXIF orientation |
|
95 | - * @return integer |
|
96 | - * @see http://www.impulseadventure.com/photo/exif-orientation.html |
|
97 | - */ |
|
98 | - protected function isRotated($orientation) |
|
99 | - { |
|
100 | - $ret = false; |
|
101 | - switch ($orientation) { |
|
102 | - case 2: // horizontal flip |
|
103 | - case 3: // 180° |
|
104 | - case 4: // vertical flip |
|
105 | - case 5: // vertical flip + 90 rotate right |
|
106 | - case 6: // 90° rotate right |
|
107 | - case 7: // horizontal flip + 90 rotate right |
|
108 | - case 8: // 90° rotate left |
|
109 | - $ret = true; |
|
110 | - break; |
|
111 | - } |
|
112 | - return $ret; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Returns a command line parameter to fix the orientation of a rotated picture. |
|
117 | - * |
|
118 | - * @param integer $orientation |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - protected function getTransformation($orientation) |
|
122 | - { |
|
123 | - $transformation = ''; |
|
124 | - if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] !== 'gm') { |
|
125 | - // ImageMagick |
|
126 | - if ($orientation >= 2 && $orientation <= 8) { |
|
127 | - $transformation = '-auto-orient'; |
|
128 | - } |
|
129 | - } else { |
|
130 | - // GraphicsMagick |
|
131 | - switch ($orientation) { |
|
132 | - case 2: // horizontal flip |
|
133 | - $transformation = '-flip horizontal'; |
|
134 | - break; |
|
135 | - case 3: // 180° |
|
136 | - $transformation = '-rotate 180'; |
|
137 | - break; |
|
138 | - case 4: // vertical flip |
|
139 | - $transformation = '-flip vertical'; |
|
140 | - break; |
|
141 | - case 5: // vertical flip + 90 rotate right |
|
142 | - $transformation = '-transpose'; |
|
143 | - break; |
|
144 | - case 6: // 90° rotate right |
|
145 | - $transformation = '-rotate 90'; |
|
146 | - break; |
|
147 | - case 7: // horizontal flip + 90 rotate right |
|
148 | - $transformation = '-transverse'; |
|
149 | - break; |
|
150 | - case 8: // 90° rotate left |
|
151 | - $transformation = '-rotate 270'; |
|
152 | - break; |
|
153 | - } |
|
154 | - } |
|
155 | - return $transformation; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Resets the EXIF orientation flag of a picture. |
|
160 | - * |
|
161 | - * @param string $filename |
|
162 | - * @return void |
|
163 | - * @see http://sylvana.net/jpegcrop/exif_orientation.html |
|
164 | - */ |
|
165 | - protected function resetOrientation($filename) |
|
166 | - { |
|
167 | - JpegExifOrient::setOrientation($filename, 1); |
|
168 | - } |
|
20 | + /** |
|
21 | + * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
22 | + */ |
|
23 | + protected $gifCreator; |
|
24 | + |
|
25 | + /** |
|
26 | + * @return \Fab\Media\FileUpload\Optimizer\Rotate |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
31 | + $this->gifCreator->init(); |
|
32 | + $this->gifCreator->absPrefix = PATH_site; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Optimize the given uploaded image |
|
37 | + * |
|
38 | + * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
39 | + * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
40 | + */ |
|
41 | + public function optimize($uploadedFile) |
|
42 | + { |
|
43 | + |
|
44 | + $orientation = $this->getOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
45 | + $isRotated = $this->isRotated($orientation); |
|
46 | + |
|
47 | + // Only rotate image if necessary! |
|
48 | + if ($isRotated > 0) { |
|
49 | + $transformation = $this->getTransformation($orientation); |
|
50 | + |
|
51 | + $imParams = '###SkipStripProfile###'; |
|
52 | + if ($transformation !== '') { |
|
53 | + $imParams .= ' ' . $transformation; |
|
54 | + } |
|
55 | + |
|
56 | + $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
|
57 | + if ($tempFileInfo) { |
|
58 | + // Replace original file |
|
59 | + @unlink($uploadedFile->getFileWithAbsolutePath()); |
|
60 | + @rename($tempFileInfo[3], $uploadedFile->getFileWithAbsolutePath()); |
|
61 | + |
|
62 | + if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') { |
|
63 | + $this->resetOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | + return $uploadedFile; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns the EXIF orientation of a given picture. |
|
72 | + * |
|
73 | + * @param string $filename |
|
74 | + * @return integer |
|
75 | + */ |
|
76 | + protected function getOrientation($filename) |
|
77 | + { |
|
78 | + $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); |
|
79 | + $orientation = 1; // Fallback to "straight" |
|
80 | + if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,tif,tiff', $extension) && function_exists('exif_read_data')) { |
|
81 | + try { |
|
82 | + $exif = exif_read_data($filename); |
|
83 | + if ($exif) { |
|
84 | + $orientation = $exif['Orientation']; |
|
85 | + } |
|
86 | + } catch (\Exception $e) {} |
|
87 | + } |
|
88 | + return $orientation; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns true if the given picture is rotated. |
|
93 | + * |
|
94 | + * @param integer $orientation EXIF orientation |
|
95 | + * @return integer |
|
96 | + * @see http://www.impulseadventure.com/photo/exif-orientation.html |
|
97 | + */ |
|
98 | + protected function isRotated($orientation) |
|
99 | + { |
|
100 | + $ret = false; |
|
101 | + switch ($orientation) { |
|
102 | + case 2: // horizontal flip |
|
103 | + case 3: // 180° |
|
104 | + case 4: // vertical flip |
|
105 | + case 5: // vertical flip + 90 rotate right |
|
106 | + case 6: // 90° rotate right |
|
107 | + case 7: // horizontal flip + 90 rotate right |
|
108 | + case 8: // 90° rotate left |
|
109 | + $ret = true; |
|
110 | + break; |
|
111 | + } |
|
112 | + return $ret; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Returns a command line parameter to fix the orientation of a rotated picture. |
|
117 | + * |
|
118 | + * @param integer $orientation |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + protected function getTransformation($orientation) |
|
122 | + { |
|
123 | + $transformation = ''; |
|
124 | + if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] !== 'gm') { |
|
125 | + // ImageMagick |
|
126 | + if ($orientation >= 2 && $orientation <= 8) { |
|
127 | + $transformation = '-auto-orient'; |
|
128 | + } |
|
129 | + } else { |
|
130 | + // GraphicsMagick |
|
131 | + switch ($orientation) { |
|
132 | + case 2: // horizontal flip |
|
133 | + $transformation = '-flip horizontal'; |
|
134 | + break; |
|
135 | + case 3: // 180° |
|
136 | + $transformation = '-rotate 180'; |
|
137 | + break; |
|
138 | + case 4: // vertical flip |
|
139 | + $transformation = '-flip vertical'; |
|
140 | + break; |
|
141 | + case 5: // vertical flip + 90 rotate right |
|
142 | + $transformation = '-transpose'; |
|
143 | + break; |
|
144 | + case 6: // 90° rotate right |
|
145 | + $transformation = '-rotate 90'; |
|
146 | + break; |
|
147 | + case 7: // horizontal flip + 90 rotate right |
|
148 | + $transformation = '-transverse'; |
|
149 | + break; |
|
150 | + case 8: // 90° rotate left |
|
151 | + $transformation = '-rotate 270'; |
|
152 | + break; |
|
153 | + } |
|
154 | + } |
|
155 | + return $transformation; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Resets the EXIF orientation flag of a picture. |
|
160 | + * |
|
161 | + * @param string $filename |
|
162 | + * @return void |
|
163 | + * @see http://sylvana.net/jpegcrop/exif_orientation.html |
|
164 | + */ |
|
165 | + protected function resetOrientation($filename) |
|
166 | + { |
|
167 | + JpegExifOrient::setOrientation($filename, 1); |
|
168 | + } |
|
169 | 169 | |
170 | 170 | } |
@@ -193,7 +193,7 @@ |
||
193 | 193 | $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow( |
194 | 194 | $labelField, |
195 | 195 | $tableName, |
196 | - 'uid = ' . $identifier |
|
196 | + 'uid = '.$identifier |
|
197 | 197 | ); |
198 | 198 | |
199 | 199 | if (!empty($record[$labelField])) { |
@@ -21,221 +21,221 @@ |
||
21 | 21 | class UsageRenderer extends ColumnRendererAbstract |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Render usage of an asset in the grid. |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
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 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 | - |
|
191 | - /** @var array $record */ |
|
192 | - $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow( |
|
193 | - $labelField, |
|
194 | - $tableName, |
|
195 | - 'uid = ' . $identifier |
|
196 | - ); |
|
197 | - |
|
198 | - if (!empty($record[$labelField])) { |
|
199 | - $result = $record[$labelField]; |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - return $result; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Return a pointer to the database. |
|
208 | - * |
|
209 | - * @return \Fab\Vidi\Database\DatabaseConnection |
|
210 | - */ |
|
211 | - protected function getDatabaseConnection() |
|
212 | - { |
|
213 | - return $GLOBALS['TYPO3_DB']; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Return the wrapping HTML template. |
|
218 | - * |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - protected function getWrappingTemplate() |
|
222 | - { |
|
223 | - return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
228 | - */ |
|
229 | - protected function getFileReferenceService() |
|
230 | - { |
|
231 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
236 | - */ |
|
237 | - protected function getFileConverter() |
|
238 | - { |
|
239 | - return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
240 | - } |
|
24 | + /** |
|
25 | + * Render usage of an asset in the grid. |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
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 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 | + |
|
191 | + /** @var array $record */ |
|
192 | + $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow( |
|
193 | + $labelField, |
|
194 | + $tableName, |
|
195 | + 'uid = ' . $identifier |
|
196 | + ); |
|
197 | + |
|
198 | + if (!empty($record[$labelField])) { |
|
199 | + $result = $record[$labelField]; |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + return $result; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Return a pointer to the database. |
|
208 | + * |
|
209 | + * @return \Fab\Vidi\Database\DatabaseConnection |
|
210 | + */ |
|
211 | + protected function getDatabaseConnection() |
|
212 | + { |
|
213 | + return $GLOBALS['TYPO3_DB']; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Return the wrapping HTML template. |
|
218 | + * |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + protected function getWrappingTemplate() |
|
222 | + { |
|
223 | + return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
228 | + */ |
|
229 | + protected function getFileReferenceService() |
|
230 | + { |
|
231 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
236 | + */ |
|
237 | + protected function getFileConverter() |
|
238 | + { |
|
239 | + return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
240 | + } |
|
241 | 241 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | // Only add like condition if needed. |
48 | 48 | if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
49 | - $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
49 | + $matcher->like('identifier', $folder->getIdentifier().'%', $automaticallyAddWildCard = false); |
|
50 | 50 | } |
51 | 51 | } else { |
52 | 52 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $collectedFiles = []; |
72 | 72 | foreach ($fileMounts as $fileMount) { |
73 | 73 | |
74 | - $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
74 | + $combinedIdentifier = $fileMount['base'].':'.$fileMount['path']; |
|
75 | 75 | $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
76 | 76 | |
77 | 77 | $files = $this->getFileUids($folder); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | if ($fileMountRecord['path']) { |
184 | 184 | $constraintsRespectingFileMounts[] = $query->like( |
185 | 185 | 'identifier', |
186 | - $fileMountRecord['path'] . '%' |
|
186 | + $fileMountRecord['path'].'%' |
|
187 | 187 | ); |
188 | 188 | } |
189 | 189 | } |
@@ -26,217 +26,217 @@ |
||
26 | 26 | class FilePermissionsAspect |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Post-process the matcher object to respect the file storages. |
|
31 | - * |
|
32 | - * @param Matcher $matcher |
|
33 | - * @param string $dataType |
|
34 | - * @return void |
|
35 | - * @throws \InvalidArgumentException |
|
36 | - */ |
|
37 | - public function addFilePermissionsForFileStorages(Matcher $matcher, $dataType) |
|
38 | - { |
|
39 | - if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
40 | - |
|
41 | - if ($this->isFolderConsidered()) { |
|
42 | - |
|
43 | - $folder = $this->getMediaModule()->getCurrentFolder(); |
|
44 | - |
|
45 | - if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
46 | - |
|
47 | - // Only add like condition if needed. |
|
48 | - if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
49 | - $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
50 | - } |
|
51 | - } else { |
|
52 | - |
|
53 | - // Browse only currently |
|
54 | - $files = $this->getFileUids($folder); |
|
55 | - $matcher->in('uid', $files); |
|
56 | - } |
|
57 | - |
|
58 | - $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
59 | - } else { |
|
60 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
61 | - |
|
62 | - // Set the storage identifier only if the storage is on-line. |
|
63 | - $identifier = -1; |
|
64 | - if ($storage->isOnline()) { |
|
65 | - $identifier = $storage->getUid(); |
|
66 | - } |
|
67 | - |
|
68 | - if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
69 | - |
|
70 | - $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
71 | - $collectedFiles = []; |
|
72 | - foreach ($fileMounts as $fileMount) { |
|
73 | - |
|
74 | - $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
75 | - $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
76 | - |
|
77 | - $files = $this->getFileUids($folder); |
|
78 | - $collectedFiles = array_merge($collectedFiles, $files); |
|
79 | - } |
|
80 | - |
|
81 | - $matcher->in('uid', $collectedFiles); |
|
82 | - } |
|
83 | - |
|
84 | - $matcher->equals('storage', $identifier); |
|
85 | - } |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - protected function isPermissionNecessary() |
|
93 | - { |
|
94 | - |
|
95 | - $isNecessary = true; |
|
96 | - |
|
97 | - $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
98 | - |
|
99 | - if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
100 | - $isNecessary = false; |
|
101 | - } |
|
102 | - |
|
103 | - if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
104 | - $isNecessary = false; |
|
105 | - } |
|
106 | - |
|
107 | - return $isNecessary; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - protected function isFolderConsidered() |
|
114 | - { |
|
115 | - return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param Folder $folder |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - protected function getFileUids(Folder $folder) |
|
123 | - { |
|
124 | - $files = []; |
|
125 | - foreach ($folder->getFiles() as $file) { |
|
126 | - $files[] = $file->getUid(); |
|
127 | - } |
|
128 | - return $files; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Post-process the constraints object to respect the file mounts. |
|
133 | - * |
|
134 | - * @param Query $query |
|
135 | - * @param ConstraintInterface|null $constraints |
|
136 | - * @param ConstraintContainer $constraintContainer |
|
137 | - * @throws \InvalidArgumentException |
|
138 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
139 | - */ |
|
140 | - public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
141 | - { |
|
142 | - if ($query->getType() === 'sys_file') { |
|
143 | - if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
144 | - $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @param Query $query |
|
151 | - * @param ConstraintInterface|null $constraints |
|
152 | - * @param ConstraintContainer $constraintContainer |
|
153 | - * @return array |
|
154 | - * @throws \InvalidArgumentException |
|
155 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
156 | - */ |
|
157 | - protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
158 | - { |
|
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 | - // Compute the clause. |
|
167 | - $clause = sprintf('uid IN (%s) %s %s', |
|
168 | - $fileMountUids, |
|
169 | - BackendUtility::BEenableFields($tableName), |
|
170 | - BackendUtility::deleteClause($tableName) |
|
171 | - ); |
|
172 | - |
|
173 | - // Fetch the records. |
|
174 | - /** @var array $fileMountRecords */ |
|
175 | - $fileMountRecords = $this->getDatabaseConnection()->exec_SELECTgetRows( |
|
176 | - 'path', |
|
177 | - $tableName, |
|
178 | - $clause |
|
179 | - ); |
|
180 | - |
|
181 | - $constraintsRespectingFileMounts = []; |
|
182 | - foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
183 | - if ($fileMountRecord['path']) { |
|
184 | - $constraintsRespectingFileMounts[] = $query->like( |
|
185 | - 'identifier', |
|
186 | - $fileMountRecord['path'] . '%' |
|
187 | - ); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
192 | - |
|
193 | - if ($constraints) { |
|
194 | - $constraints = $query->logicalAnd( |
|
195 | - $constraints, |
|
196 | - $logicalOrForRespectingFileMounts |
|
197 | - ); |
|
198 | - } else { |
|
199 | - $constraints = $logicalOrForRespectingFileMounts; |
|
200 | - } |
|
201 | - |
|
202 | - $constraintContainer->setConstraint($constraints); |
|
203 | - |
|
204 | - return [$query, $constraints, $constraintContainer]; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
209 | - */ |
|
210 | - protected function getCurrentBackendUser() |
|
211 | - { |
|
212 | - return $GLOBALS['BE_USER']; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return \Fab\Vidi\Database\DatabaseConnection |
|
217 | - */ |
|
218 | - protected function getDatabaseConnection() |
|
219 | - { |
|
220 | - return $GLOBALS['TYPO3_DB']; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @return MediaModule|object |
|
225 | - * @throws \InvalidArgumentException |
|
226 | - */ |
|
227 | - protected function getMediaModule() |
|
228 | - { |
|
229 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Get the Vidi Module Loader. |
|
234 | - * |
|
235 | - * @return ModuleLoader |
|
236 | - * @throws \InvalidArgumentException |
|
237 | - */ |
|
238 | - protected function getModuleLoader() |
|
239 | - { |
|
240 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
241 | - } |
|
29 | + /** |
|
30 | + * Post-process the matcher object to respect the file storages. |
|
31 | + * |
|
32 | + * @param Matcher $matcher |
|
33 | + * @param string $dataType |
|
34 | + * @return void |
|
35 | + * @throws \InvalidArgumentException |
|
36 | + */ |
|
37 | + public function addFilePermissionsForFileStorages(Matcher $matcher, $dataType) |
|
38 | + { |
|
39 | + if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
40 | + |
|
41 | + if ($this->isFolderConsidered()) { |
|
42 | + |
|
43 | + $folder = $this->getMediaModule()->getCurrentFolder(); |
|
44 | + |
|
45 | + if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
46 | + |
|
47 | + // Only add like condition if needed. |
|
48 | + if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
49 | + $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
50 | + } |
|
51 | + } else { |
|
52 | + |
|
53 | + // Browse only currently |
|
54 | + $files = $this->getFileUids($folder); |
|
55 | + $matcher->in('uid', $files); |
|
56 | + } |
|
57 | + |
|
58 | + $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
59 | + } else { |
|
60 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
61 | + |
|
62 | + // Set the storage identifier only if the storage is on-line. |
|
63 | + $identifier = -1; |
|
64 | + if ($storage->isOnline()) { |
|
65 | + $identifier = $storage->getUid(); |
|
66 | + } |
|
67 | + |
|
68 | + if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
69 | + |
|
70 | + $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
71 | + $collectedFiles = []; |
|
72 | + foreach ($fileMounts as $fileMount) { |
|
73 | + |
|
74 | + $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
75 | + $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
76 | + |
|
77 | + $files = $this->getFileUids($folder); |
|
78 | + $collectedFiles = array_merge($collectedFiles, $files); |
|
79 | + } |
|
80 | + |
|
81 | + $matcher->in('uid', $collectedFiles); |
|
82 | + } |
|
83 | + |
|
84 | + $matcher->equals('storage', $identifier); |
|
85 | + } |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + protected function isPermissionNecessary() |
|
93 | + { |
|
94 | + |
|
95 | + $isNecessary = true; |
|
96 | + |
|
97 | + $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
98 | + |
|
99 | + if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
100 | + $isNecessary = false; |
|
101 | + } |
|
102 | + |
|
103 | + if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
104 | + $isNecessary = false; |
|
105 | + } |
|
106 | + |
|
107 | + return $isNecessary; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + protected function isFolderConsidered() |
|
114 | + { |
|
115 | + return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param Folder $folder |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + protected function getFileUids(Folder $folder) |
|
123 | + { |
|
124 | + $files = []; |
|
125 | + foreach ($folder->getFiles() as $file) { |
|
126 | + $files[] = $file->getUid(); |
|
127 | + } |
|
128 | + return $files; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Post-process the constraints object to respect the file mounts. |
|
133 | + * |
|
134 | + * @param Query $query |
|
135 | + * @param ConstraintInterface|null $constraints |
|
136 | + * @param ConstraintContainer $constraintContainer |
|
137 | + * @throws \InvalidArgumentException |
|
138 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
139 | + */ |
|
140 | + public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
141 | + { |
|
142 | + if ($query->getType() === 'sys_file') { |
|
143 | + if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
144 | + $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @param Query $query |
|
151 | + * @param ConstraintInterface|null $constraints |
|
152 | + * @param ConstraintContainer $constraintContainer |
|
153 | + * @return array |
|
154 | + * @throws \InvalidArgumentException |
|
155 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException |
|
156 | + */ |
|
157 | + protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer) |
|
158 | + { |
|
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 | + // Compute the clause. |
|
167 | + $clause = sprintf('uid IN (%s) %s %s', |
|
168 | + $fileMountUids, |
|
169 | + BackendUtility::BEenableFields($tableName), |
|
170 | + BackendUtility::deleteClause($tableName) |
|
171 | + ); |
|
172 | + |
|
173 | + // Fetch the records. |
|
174 | + /** @var array $fileMountRecords */ |
|
175 | + $fileMountRecords = $this->getDatabaseConnection()->exec_SELECTgetRows( |
|
176 | + 'path', |
|
177 | + $tableName, |
|
178 | + $clause |
|
179 | + ); |
|
180 | + |
|
181 | + $constraintsRespectingFileMounts = []; |
|
182 | + foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
183 | + if ($fileMountRecord['path']) { |
|
184 | + $constraintsRespectingFileMounts[] = $query->like( |
|
185 | + 'identifier', |
|
186 | + $fileMountRecord['path'] . '%' |
|
187 | + ); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
192 | + |
|
193 | + if ($constraints) { |
|
194 | + $constraints = $query->logicalAnd( |
|
195 | + $constraints, |
|
196 | + $logicalOrForRespectingFileMounts |
|
197 | + ); |
|
198 | + } else { |
|
199 | + $constraints = $logicalOrForRespectingFileMounts; |
|
200 | + } |
|
201 | + |
|
202 | + $constraintContainer->setConstraint($constraints); |
|
203 | + |
|
204 | + return [$query, $constraints, $constraintContainer]; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
209 | + */ |
|
210 | + protected function getCurrentBackendUser() |
|
211 | + { |
|
212 | + return $GLOBALS['BE_USER']; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return \Fab\Vidi\Database\DatabaseConnection |
|
217 | + */ |
|
218 | + protected function getDatabaseConnection() |
|
219 | + { |
|
220 | + return $GLOBALS['TYPO3_DB']; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @return MediaModule|object |
|
225 | + * @throws \InvalidArgumentException |
|
226 | + */ |
|
227 | + protected function getMediaModule() |
|
228 | + { |
|
229 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Get the Vidi Module Loader. |
|
234 | + * |
|
235 | + * @return ModuleLoader |
|
236 | + * @throws \InvalidArgumentException |
|
237 | + */ |
|
238 | + protected function getModuleLoader() |
|
239 | + { |
|
240 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
241 | + } |
|
242 | 242 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function searchForMissingFiles(ResourceStorage $storage) |
30 | 30 | { |
31 | 31 | |
32 | - $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', 'storage = ' . $storage->getUid()); |
|
32 | + $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', 'storage = '.$storage->getUid()); |
|
33 | 33 | $resource = $this->getDatabaseConnection()->sql_query($query); |
34 | 34 | |
35 | 35 | $missingFiles = []; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | // The case is special as we have a missing file in the file system |
68 | 68 | // As a result, we can't use $fileObject->delete(); which will |
69 | 69 | // raise exception "Error while fetching permissions" |
70 | - $this->getDatabaseConnection()->exec_DELETEquery('sys_file', 'uid = ' . $missingFile->getUid()); |
|
70 | + $this->getDatabaseConnection()->exec_DELETEquery('sys_file', 'uid = '.$missingFile->getUid()); |
|
71 | 71 | $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
72 | 72 | } |
73 | 73 | } catch (\Exception $e) { |
@@ -20,112 +20,112 @@ |
||
20 | 20 | class IndexAnalyser implements SingletonInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Return missing file for a given storage. |
|
25 | - * |
|
26 | - * @param ResourceStorage $storage |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function searchForMissingFiles(ResourceStorage $storage) |
|
30 | - { |
|
23 | + /** |
|
24 | + * Return missing file for a given storage. |
|
25 | + * |
|
26 | + * @param ResourceStorage $storage |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function searchForMissingFiles(ResourceStorage $storage) |
|
30 | + { |
|
31 | 31 | |
32 | - $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', 'storage = ' . $storage->getUid()); |
|
33 | - $resource = $this->getDatabaseConnection()->sql_query($query); |
|
32 | + $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', 'storage = ' . $storage->getUid()); |
|
33 | + $resource = $this->getDatabaseConnection()->sql_query($query); |
|
34 | 34 | |
35 | - $missingFiles = []; |
|
36 | - while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
35 | + $missingFiles = []; |
|
36 | + while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
37 | 37 | |
38 | - // This task is very memory consuming on large data set e.g > 20'000 records. |
|
39 | - // We must think of having a pagination if there is the need for such thing. |
|
40 | - $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row); |
|
41 | - if (!$file->exists()) { |
|
42 | - $missingFiles[] = $file; |
|
43 | - } |
|
44 | - } |
|
45 | - return $missingFiles; |
|
46 | - } |
|
38 | + // This task is very memory consuming on large data set e.g > 20'000 records. |
|
39 | + // We must think of having a pagination if there is the need for such thing. |
|
40 | + $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row); |
|
41 | + if (!$file->exists()) { |
|
42 | + $missingFiles[] = $file; |
|
43 | + } |
|
44 | + } |
|
45 | + return $missingFiles; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Deletes all missing files for a given storage. |
|
50 | - * |
|
51 | - * @param ResourceStorage $storage |
|
52 | - * @return array |
|
53 | - * @throws \InvalidArgumentException |
|
54 | - */ |
|
55 | - public function deleteMissingFiles(ResourceStorage $storage) |
|
56 | - { |
|
57 | - /** @var FileReferenceService $fileReferenceService */ |
|
58 | - $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
59 | - $missingFiles = $this->searchForMissingFiles($storage); |
|
60 | - $deletedFiles = []; |
|
48 | + /** |
|
49 | + * Deletes all missing files for a given storage. |
|
50 | + * |
|
51 | + * @param ResourceStorage $storage |
|
52 | + * @return array |
|
53 | + * @throws \InvalidArgumentException |
|
54 | + */ |
|
55 | + public function deleteMissingFiles(ResourceStorage $storage) |
|
56 | + { |
|
57 | + /** @var FileReferenceService $fileReferenceService */ |
|
58 | + $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
59 | + $missingFiles = $this->searchForMissingFiles($storage); |
|
60 | + $deletedFiles = []; |
|
61 | 61 | |
62 | - /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
63 | - foreach ($missingFiles as $missingFile) { |
|
64 | - try { |
|
65 | - // if missingFile has no file references |
|
66 | - if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
67 | - // The case is special as we have a missing file in the file system |
|
68 | - // As a result, we can't use $fileObject->delete(); which will |
|
69 | - // raise exception "Error while fetching permissions" |
|
70 | - $this->getDatabaseConnection()->exec_DELETEquery('sys_file', 'uid = ' . $missingFile->getUid()); |
|
71 | - $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
72 | - } |
|
73 | - } catch (\Exception $e) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - } |
|
77 | - return $deletedFiles; |
|
78 | - } |
|
62 | + /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
63 | + foreach ($missingFiles as $missingFile) { |
|
64 | + try { |
|
65 | + // if missingFile has no file references |
|
66 | + if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
67 | + // The case is special as we have a missing file in the file system |
|
68 | + // As a result, we can't use $fileObject->delete(); which will |
|
69 | + // raise exception "Error while fetching permissions" |
|
70 | + $this->getDatabaseConnection()->exec_DELETEquery('sys_file', 'uid = ' . $missingFile->getUid()); |
|
71 | + $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
72 | + } |
|
73 | + } catch (\Exception $e) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + } |
|
77 | + return $deletedFiles; |
|
78 | + } |
|
79 | 79 | |
80 | - /* |
|
80 | + /* |
|
81 | 81 | * Return duplicates file records |
82 | 82 | * |
83 | 83 | * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
84 | 84 | * @return array |
85 | 85 | */ |
86 | - public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
87 | - { |
|
86 | + public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
87 | + { |
|
88 | 88 | |
89 | - // Detect duplicate records. |
|
90 | - $query = "SELECT identifier FROM sys_file WHERE storage = {$storage->getUid()} GROUP BY identifier, storage Having COUNT(*) > 1"; |
|
91 | - $resource = $this->getDatabaseConnection()->sql_query($query); |
|
92 | - $duplicates = []; |
|
93 | - while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
94 | - $clause = sprintf('identifier = "%s" AND storage = %s', $row['identifier'], $storage->getUid()); |
|
95 | - $records = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file', $clause); |
|
96 | - $duplicates[$row['identifier']] = $records; |
|
97 | - } |
|
98 | - return $duplicates; |
|
99 | - } |
|
89 | + // Detect duplicate records. |
|
90 | + $query = "SELECT identifier FROM sys_file WHERE storage = {$storage->getUid()} GROUP BY identifier, storage Having COUNT(*) > 1"; |
|
91 | + $resource = $this->getDatabaseConnection()->sql_query($query); |
|
92 | + $duplicates = []; |
|
93 | + while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
94 | + $clause = sprintf('identifier = "%s" AND storage = %s', $row['identifier'], $storage->getUid()); |
|
95 | + $records = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file', $clause); |
|
96 | + $duplicates[$row['identifier']] = $records; |
|
97 | + } |
|
98 | + return $duplicates; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Return duplicates file records |
|
103 | - * |
|
104 | - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - public function searchForDuplicateSha1(ResourceStorage $storage) |
|
108 | - { |
|
101 | + /** |
|
102 | + * Return duplicates file records |
|
103 | + * |
|
104 | + * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + public function searchForDuplicateSha1(ResourceStorage $storage) |
|
108 | + { |
|
109 | 109 | |
110 | - // Detect duplicate records. |
|
111 | - $query = "SELECT sha1 FROM sys_file WHERE storage = {$storage->getUid()} GROUP BY sha1, storage Having COUNT(*) > 1"; |
|
112 | - $resource = $this->getDatabaseConnection()->sql_query($query); |
|
113 | - $duplicates = []; |
|
114 | - while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
115 | - $clause = sprintf('sha1 = "%s" AND storage = %s', $row['sha1'], $storage->getUid()); |
|
116 | - $records = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file', $clause); |
|
117 | - $duplicates[$row['sha1']] = $records; |
|
118 | - } |
|
119 | - return $duplicates; |
|
120 | - } |
|
110 | + // Detect duplicate records. |
|
111 | + $query = "SELECT sha1 FROM sys_file WHERE storage = {$storage->getUid()} GROUP BY sha1, storage Having COUNT(*) > 1"; |
|
112 | + $resource = $this->getDatabaseConnection()->sql_query($query); |
|
113 | + $duplicates = []; |
|
114 | + while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
115 | + $clause = sprintf('sha1 = "%s" AND storage = %s', $row['sha1'], $storage->getUid()); |
|
116 | + $records = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file', $clause); |
|
117 | + $duplicates[$row['sha1']] = $records; |
|
118 | + } |
|
119 | + return $duplicates; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Return a pointer to the database. |
|
124 | - * |
|
125 | - * @return \Fab\Vidi\Database\DatabaseConnection |
|
126 | - */ |
|
127 | - protected function getDatabaseConnection() |
|
128 | - { |
|
129 | - return $GLOBALS['TYPO3_DB']; |
|
130 | - } |
|
122 | + /** |
|
123 | + * Return a pointer to the database. |
|
124 | + * |
|
125 | + * @return \Fab\Vidi\Database\DatabaseConnection |
|
126 | + */ |
|
127 | + protected function getDatabaseConnection() |
|
128 | + { |
|
129 | + return $GLOBALS['TYPO3_DB']; |
|
130 | + } |
|
131 | 131 | } |