@@ -18,191 +18,191 @@ |
||
18 | 18 | class DuplicateRecordsCommandController extends CommandController |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $message = []; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $duplicateRecords = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
33 | - */ |
|
34 | - protected $mailMessage; |
|
35 | - |
|
36 | - /** |
|
37 | - * Check whether the Index is Ok. In case not, display a message on the console. |
|
38 | - * |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function analyseCommand() |
|
42 | - { |
|
43 | - |
|
44 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
45 | - |
|
46 | - // For the CLI cause. |
|
47 | - $storage->setEvaluatePermissions(false); |
|
48 | - |
|
49 | - $this->printOut(); |
|
50 | - $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
51 | - $this->printOut('--------------------------------------------'); |
|
52 | - |
|
53 | - if ($storage->isOnline()) { |
|
54 | - |
|
55 | - $duplicateRecords = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
56 | - |
|
57 | - // Duplicate file object |
|
58 | - if (empty($duplicateRecords)) { |
|
59 | - $this->printOut(); |
|
60 | - $this->printOut('Looks good, no duplicate records!'); |
|
61 | - } else { |
|
62 | - $this->printOut(); |
|
63 | - $this->printOut('Duplicated identifiers detected:'); |
|
64 | - $this->duplicateRecords[$storage->getUid()] = $duplicateRecords; // Store duplicate files. |
|
65 | - |
|
66 | - foreach ($duplicateRecords as $identifier => $duplicate) { |
|
67 | - |
|
68 | - // build temporary array |
|
69 | - $uids = []; |
|
70 | - foreach ($duplicate as $value) { |
|
71 | - $uids[] = $value['uid']; |
|
72 | - } |
|
73 | - |
|
74 | - $message = sprintf('* uids "%s" having same identifier %s', |
|
75 | - implode(',', $uids), |
|
76 | - $identifier |
|
77 | - ); |
|
78 | - $this->printOut($message); |
|
79 | - |
|
80 | - } |
|
81 | - } |
|
82 | - } else { |
|
83 | - $this->outputLine('Storage is offline!'); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $to = $this->getTo(); |
|
88 | - if (!empty($to)) { |
|
89 | - $this->sendReport(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Print a message and store its content in a variable for the email report. |
|
95 | - * |
|
96 | - * @param string $message |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - protected function printOut($message = '') |
|
100 | - { |
|
101 | - $this->message[] = $message; |
|
102 | - $this->outputLine($message); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Send a possible report to an admin. |
|
107 | - * |
|
108 | - * @throws \Exception |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - protected function sendReport() |
|
112 | - { |
|
113 | - if ($this->hasReport()) { |
|
114 | - |
|
115 | - // Prepare email. |
|
116 | - $this->getMailMessage()->setTo($this->getTo()) |
|
117 | - ->setFrom($this->getFrom()) |
|
118 | - ->setSubject('Duplicate records detected!') |
|
119 | - ->setBody(implode("\n", $this->message)); |
|
120 | - |
|
121 | - $isSent = $this->getMailMessage()->send(); |
|
122 | - |
|
123 | - if (!$isSent) { |
|
124 | - throw new \Exception('I could not send a message', 1408343882); |
|
125 | - } |
|
126 | - |
|
127 | - $to = $this->getTo(); |
|
128 | - $this->outputLine(); |
|
129 | - $message = sprintf('Report was sent to %s', key($to)); |
|
130 | - $this->outputLine($message); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Send a report |
|
136 | - * |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - protected function hasReport() |
|
140 | - { |
|
141 | - return !empty($this->duplicateRecords); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - protected function getTo() |
|
148 | - { |
|
149 | - |
|
150 | - $to = []; |
|
151 | - |
|
152 | - // @todo make me more flexible! |
|
153 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
154 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
155 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
156 | - $to[$emailAddress] = $name; |
|
157 | - |
|
158 | - } |
|
159 | - return $to; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - protected function getFrom() |
|
166 | - { |
|
167 | - |
|
168 | - $from = []; |
|
169 | - |
|
170 | - // @todo make me more flexible! |
|
171 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
172 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
173 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
174 | - $from[$emailAddress] = $name; |
|
175 | - } |
|
176 | - return $from; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return StorageRepository|object |
|
181 | - */ |
|
182 | - protected function getStorageRepository() |
|
183 | - { |
|
184 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @return \TYPO3\CMS\Core\Mail\MailMessage|object |
|
189 | - */ |
|
190 | - public function getMailMessage() |
|
191 | - { |
|
192 | - if (is_null($this->mailMessage)) { |
|
193 | - $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
194 | - } |
|
195 | - return $this->mailMessage; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Return a pointer to the database. |
|
200 | - * |
|
201 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
202 | - */ |
|
203 | - protected function getIndexAnalyser() |
|
204 | - { |
|
205 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
206 | - } |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $message = []; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $duplicateRecords = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
33 | + */ |
|
34 | + protected $mailMessage; |
|
35 | + |
|
36 | + /** |
|
37 | + * Check whether the Index is Ok. In case not, display a message on the console. |
|
38 | + * |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function analyseCommand() |
|
42 | + { |
|
43 | + |
|
44 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
45 | + |
|
46 | + // For the CLI cause. |
|
47 | + $storage->setEvaluatePermissions(false); |
|
48 | + |
|
49 | + $this->printOut(); |
|
50 | + $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
51 | + $this->printOut('--------------------------------------------'); |
|
52 | + |
|
53 | + if ($storage->isOnline()) { |
|
54 | + |
|
55 | + $duplicateRecords = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
56 | + |
|
57 | + // Duplicate file object |
|
58 | + if (empty($duplicateRecords)) { |
|
59 | + $this->printOut(); |
|
60 | + $this->printOut('Looks good, no duplicate records!'); |
|
61 | + } else { |
|
62 | + $this->printOut(); |
|
63 | + $this->printOut('Duplicated identifiers detected:'); |
|
64 | + $this->duplicateRecords[$storage->getUid()] = $duplicateRecords; // Store duplicate files. |
|
65 | + |
|
66 | + foreach ($duplicateRecords as $identifier => $duplicate) { |
|
67 | + |
|
68 | + // build temporary array |
|
69 | + $uids = []; |
|
70 | + foreach ($duplicate as $value) { |
|
71 | + $uids[] = $value['uid']; |
|
72 | + } |
|
73 | + |
|
74 | + $message = sprintf('* uids "%s" having same identifier %s', |
|
75 | + implode(',', $uids), |
|
76 | + $identifier |
|
77 | + ); |
|
78 | + $this->printOut($message); |
|
79 | + |
|
80 | + } |
|
81 | + } |
|
82 | + } else { |
|
83 | + $this->outputLine('Storage is offline!'); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $to = $this->getTo(); |
|
88 | + if (!empty($to)) { |
|
89 | + $this->sendReport(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Print a message and store its content in a variable for the email report. |
|
95 | + * |
|
96 | + * @param string $message |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + protected function printOut($message = '') |
|
100 | + { |
|
101 | + $this->message[] = $message; |
|
102 | + $this->outputLine($message); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Send a possible report to an admin. |
|
107 | + * |
|
108 | + * @throws \Exception |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + protected function sendReport() |
|
112 | + { |
|
113 | + if ($this->hasReport()) { |
|
114 | + |
|
115 | + // Prepare email. |
|
116 | + $this->getMailMessage()->setTo($this->getTo()) |
|
117 | + ->setFrom($this->getFrom()) |
|
118 | + ->setSubject('Duplicate records detected!') |
|
119 | + ->setBody(implode("\n", $this->message)); |
|
120 | + |
|
121 | + $isSent = $this->getMailMessage()->send(); |
|
122 | + |
|
123 | + if (!$isSent) { |
|
124 | + throw new \Exception('I could not send a message', 1408343882); |
|
125 | + } |
|
126 | + |
|
127 | + $to = $this->getTo(); |
|
128 | + $this->outputLine(); |
|
129 | + $message = sprintf('Report was sent to %s', key($to)); |
|
130 | + $this->outputLine($message); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Send a report |
|
136 | + * |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + protected function hasReport() |
|
140 | + { |
|
141 | + return !empty($this->duplicateRecords); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + protected function getTo() |
|
148 | + { |
|
149 | + |
|
150 | + $to = []; |
|
151 | + |
|
152 | + // @todo make me more flexible! |
|
153 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
154 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
155 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
156 | + $to[$emailAddress] = $name; |
|
157 | + |
|
158 | + } |
|
159 | + return $to; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + protected function getFrom() |
|
166 | + { |
|
167 | + |
|
168 | + $from = []; |
|
169 | + |
|
170 | + // @todo make me more flexible! |
|
171 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
172 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
173 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
174 | + $from[$emailAddress] = $name; |
|
175 | + } |
|
176 | + return $from; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return StorageRepository|object |
|
181 | + */ |
|
182 | + protected function getStorageRepository() |
|
183 | + { |
|
184 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @return \TYPO3\CMS\Core\Mail\MailMessage|object |
|
189 | + */ |
|
190 | + public function getMailMessage() |
|
191 | + { |
|
192 | + if (is_null($this->mailMessage)) { |
|
193 | + $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
194 | + } |
|
195 | + return $this->mailMessage; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Return a pointer to the database. |
|
200 | + * |
|
201 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
202 | + */ |
|
203 | + protected function getIndexAnalyser() |
|
204 | + { |
|
205 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | } |
@@ -22,213 +22,213 @@ |
||
22 | 22 | class UsageRenderer extends ColumnRendererAbstract |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Render usage of an asset in the grid. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function render() |
|
31 | - { |
|
32 | - $file = $this->getFileConverter()->convert($this->object); |
|
33 | - |
|
34 | - $result = ''; |
|
35 | - |
|
36 | - // Add number of references on the top! |
|
37 | - if ($this->object['number_of_references'] > 1) { |
|
38 | - $result .= sprintf( |
|
39 | - '<div><strong>%s (%s)</strong></div>', |
|
40 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'), |
|
41 | - $this->object['number_of_references'] |
|
42 | - ); |
|
43 | - } |
|
44 | - |
|
45 | - // Render File usage |
|
46 | - $fileReferences = $this->getFileReferenceService()->findFileReferences($file); |
|
47 | - if (!empty($fileReferences)) { |
|
48 | - |
|
49 | - // Finalize file references assembling. |
|
50 | - $result .= sprintf( |
|
51 | - $this->getWrappingTemplate(), |
|
52 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'), |
|
53 | - $this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames')) |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - // Render link usage in RTE |
|
58 | - $linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file); |
|
59 | - if (!empty($linkSoftReferences)) { |
|
60 | - |
|
61 | - // Finalize link references assembling. |
|
62 | - $result .= sprintf( |
|
63 | - $this->getWrappingTemplate(), |
|
64 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'), |
|
65 | - $this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - // Render image usage in RTE |
|
70 | - $imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file); |
|
71 | - if (!empty($imageSoftReferences)) { |
|
72 | - |
|
73 | - // Finalize image references assembling. |
|
74 | - $result .= sprintf( |
|
75 | - $this->getWrappingTemplate(), |
|
76 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'), |
|
77 | - $this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - return $result; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Assemble output reference. |
|
86 | - * |
|
87 | - * @param array $references |
|
88 | - * @param array $mapping |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - protected function assembleOutput(array $references, array $mapping) |
|
92 | - { |
|
93 | - |
|
94 | - $result = ''; |
|
95 | - foreach ($references as $reference) { |
|
96 | - $button = $this->makeLinkButton() |
|
97 | - ->setHref($this->getEditUri($reference, $mapping)) |
|
98 | - ->setClasses('btn-edit-reference') |
|
99 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
100 | - ->render(); |
|
101 | - |
|
102 | - $tableName = $reference[$mapping['tableName']]; |
|
103 | - $identifier = (int)$reference[$mapping['referenceIdentifier']]; |
|
104 | - |
|
105 | - $result .= sprintf( |
|
106 | - '<li title="">%s %s</li>', |
|
107 | - $button, |
|
108 | - $this->computeTitle($tableName, $identifier) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $result; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $tableName |
|
117 | - * @param int $identifier |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - protected function computeTitle($tableName, $identifier) |
|
121 | - { |
|
122 | - $title = ''; |
|
123 | - if (!empty($GLOBALS['TCA'][$tableName])) { |
|
124 | - $title = $this->getRecordTitle($tableName, $identifier); |
|
125 | - if (!$title) { |
|
126 | - $title = Tca::table($tableName)->getTitle(); |
|
127 | - } |
|
128 | - } |
|
129 | - return $title; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return object|LinkButton |
|
134 | - */ |
|
135 | - protected function makeLinkButton() |
|
136 | - { |
|
137 | - return GeneralUtility::makeInstance(LinkButton::class); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param array $reference |
|
142 | - * @param array $mapping |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - protected function getEditUri(array $reference, array $mapping) |
|
146 | - { |
|
147 | - |
|
148 | - $parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]); |
|
149 | - $uri = BackendUtility::getModuleUrl( |
|
150 | - 'record_edit', |
|
151 | - array( |
|
152 | - $parameterName => 'edit', |
|
153 | - 'returnUrl' => $this->getModuleUrl() |
|
154 | - ) |
|
155 | - ); |
|
156 | - return $uri; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - protected function getModuleUrl() |
|
163 | - { |
|
164 | - |
|
165 | - $additionalParameters = []; |
|
166 | - if (GeneralUtility::_GP('id')) { |
|
167 | - $additionalParameters = array( |
|
168 | - 'id' => urldecode(GeneralUtility::_GP('id')), |
|
169 | - ); |
|
170 | - } |
|
171 | - return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Return the title given a table name and an identifier. |
|
176 | - * |
|
177 | - * @param string $tableName |
|
178 | - * @param string $identifier |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - protected function getRecordTitle($tableName, $identifier) |
|
182 | - { |
|
183 | - |
|
184 | - $result = ''; |
|
185 | - if ($tableName && (int)$identifier > 0) { |
|
186 | - |
|
187 | - $labelField = Tca::table($tableName)->getLabelField(); |
|
188 | - |
|
189 | - // Get the title of the record. |
|
190 | - $record = $this->getDataService() |
|
191 | - ->getRecord($tableName, ['uid' => $identifier,]); |
|
192 | - |
|
193 | - if (!empty($record[$labelField])) { |
|
194 | - $result = $record[$labelField]; |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - return $result; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @return object|DataService |
|
203 | - */ |
|
204 | - protected function getDataService(): DataService |
|
205 | - { |
|
206 | - return GeneralUtility::makeInstance(DataService::class); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Return the wrapping HTML template. |
|
211 | - * |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - protected function getWrappingTemplate() |
|
215 | - { |
|
216 | - return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
221 | - */ |
|
222 | - protected function getFileReferenceService() |
|
223 | - { |
|
224 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
229 | - */ |
|
230 | - protected function getFileConverter() |
|
231 | - { |
|
232 | - return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
233 | - } |
|
25 | + /** |
|
26 | + * Render usage of an asset in the grid. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function render() |
|
31 | + { |
|
32 | + $file = $this->getFileConverter()->convert($this->object); |
|
33 | + |
|
34 | + $result = ''; |
|
35 | + |
|
36 | + // Add number of references on the top! |
|
37 | + if ($this->object['number_of_references'] > 1) { |
|
38 | + $result .= sprintf( |
|
39 | + '<div><strong>%s (%s)</strong></div>', |
|
40 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'), |
|
41 | + $this->object['number_of_references'] |
|
42 | + ); |
|
43 | + } |
|
44 | + |
|
45 | + // Render File usage |
|
46 | + $fileReferences = $this->getFileReferenceService()->findFileReferences($file); |
|
47 | + if (!empty($fileReferences)) { |
|
48 | + |
|
49 | + // Finalize file references assembling. |
|
50 | + $result .= sprintf( |
|
51 | + $this->getWrappingTemplate(), |
|
52 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'), |
|
53 | + $this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames')) |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + // Render link usage in RTE |
|
58 | + $linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file); |
|
59 | + if (!empty($linkSoftReferences)) { |
|
60 | + |
|
61 | + // Finalize link references assembling. |
|
62 | + $result .= sprintf( |
|
63 | + $this->getWrappingTemplate(), |
|
64 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'), |
|
65 | + $this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + // Render image usage in RTE |
|
70 | + $imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file); |
|
71 | + if (!empty($imageSoftReferences)) { |
|
72 | + |
|
73 | + // Finalize image references assembling. |
|
74 | + $result .= sprintf( |
|
75 | + $this->getWrappingTemplate(), |
|
76 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'), |
|
77 | + $this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + return $result; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Assemble output reference. |
|
86 | + * |
|
87 | + * @param array $references |
|
88 | + * @param array $mapping |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + protected function assembleOutput(array $references, array $mapping) |
|
92 | + { |
|
93 | + |
|
94 | + $result = ''; |
|
95 | + foreach ($references as $reference) { |
|
96 | + $button = $this->makeLinkButton() |
|
97 | + ->setHref($this->getEditUri($reference, $mapping)) |
|
98 | + ->setClasses('btn-edit-reference') |
|
99 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
100 | + ->render(); |
|
101 | + |
|
102 | + $tableName = $reference[$mapping['tableName']]; |
|
103 | + $identifier = (int)$reference[$mapping['referenceIdentifier']]; |
|
104 | + |
|
105 | + $result .= sprintf( |
|
106 | + '<li title="">%s %s</li>', |
|
107 | + $button, |
|
108 | + $this->computeTitle($tableName, $identifier) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $result; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $tableName |
|
117 | + * @param int $identifier |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + protected function computeTitle($tableName, $identifier) |
|
121 | + { |
|
122 | + $title = ''; |
|
123 | + if (!empty($GLOBALS['TCA'][$tableName])) { |
|
124 | + $title = $this->getRecordTitle($tableName, $identifier); |
|
125 | + if (!$title) { |
|
126 | + $title = Tca::table($tableName)->getTitle(); |
|
127 | + } |
|
128 | + } |
|
129 | + return $title; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return object|LinkButton |
|
134 | + */ |
|
135 | + protected function makeLinkButton() |
|
136 | + { |
|
137 | + return GeneralUtility::makeInstance(LinkButton::class); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param array $reference |
|
142 | + * @param array $mapping |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + protected function getEditUri(array $reference, array $mapping) |
|
146 | + { |
|
147 | + |
|
148 | + $parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]); |
|
149 | + $uri = BackendUtility::getModuleUrl( |
|
150 | + 'record_edit', |
|
151 | + array( |
|
152 | + $parameterName => 'edit', |
|
153 | + 'returnUrl' => $this->getModuleUrl() |
|
154 | + ) |
|
155 | + ); |
|
156 | + return $uri; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + protected function getModuleUrl() |
|
163 | + { |
|
164 | + |
|
165 | + $additionalParameters = []; |
|
166 | + if (GeneralUtility::_GP('id')) { |
|
167 | + $additionalParameters = array( |
|
168 | + 'id' => urldecode(GeneralUtility::_GP('id')), |
|
169 | + ); |
|
170 | + } |
|
171 | + return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Return the title given a table name and an identifier. |
|
176 | + * |
|
177 | + * @param string $tableName |
|
178 | + * @param string $identifier |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + protected function getRecordTitle($tableName, $identifier) |
|
182 | + { |
|
183 | + |
|
184 | + $result = ''; |
|
185 | + if ($tableName && (int)$identifier > 0) { |
|
186 | + |
|
187 | + $labelField = Tca::table($tableName)->getLabelField(); |
|
188 | + |
|
189 | + // Get the title of the record. |
|
190 | + $record = $this->getDataService() |
|
191 | + ->getRecord($tableName, ['uid' => $identifier,]); |
|
192 | + |
|
193 | + if (!empty($record[$labelField])) { |
|
194 | + $result = $record[$labelField]; |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + return $result; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @return object|DataService |
|
203 | + */ |
|
204 | + protected function getDataService(): DataService |
|
205 | + { |
|
206 | + return GeneralUtility::makeInstance(DataService::class); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Return the wrapping HTML template. |
|
211 | + * |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + protected function getWrappingTemplate() |
|
215 | + { |
|
216 | + return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
221 | + */ |
|
222 | + protected function getFileReferenceService() |
|
223 | + { |
|
224 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
229 | + */ |
|
230 | + protected function getFileConverter() |
|
231 | + { |
|
232 | + return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
233 | + } |
|
234 | 234 | } |
@@ -188,7 +188,7 @@ |
||
188 | 188 | |
189 | 189 | // Get the title of the record. |
190 | 190 | $record = $this->getDataService() |
191 | - ->getRecord($tableName, ['uid' => $identifier,]); |
|
191 | + ->getRecord($tableName, ['uid' => $identifier, ]); |
|
192 | 192 | |
193 | 193 | if (!empty($record[$labelField])) { |
194 | 194 | $result = $record[$labelField]; |
@@ -23,121 +23,121 @@ |
||
23 | 23 | class FooterViewHelper extends AbstractViewHelper |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * Render a form footer. |
|
28 | - * Example: |
|
29 | - * Created on 30-12-12 by John Updated on 22-05-12 by Jane |
|
30 | - * |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function render() |
|
34 | - { |
|
35 | - |
|
36 | - /** @var File $file */ |
|
37 | - $file = $this->templateVariableContainer->get('file'); |
|
38 | - $template = '<span>%s %s %s</span> <span style="padding-left: 50px">%s %s %s</span>'; |
|
39 | - |
|
40 | - $format = sprintf('%s @ %s', |
|
41 | - $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], |
|
42 | - $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] |
|
43 | - ); |
|
44 | - |
|
45 | - $arguments = array( |
|
46 | - 'date' => null, |
|
47 | - 'format' => $format, |
|
48 | - 'base' => null |
|
49 | - ); |
|
50 | - |
|
51 | - $result = sprintf($template, |
|
52 | - LocalizationUtility::translate('created_on', 'media'), |
|
53 | - $file->getProperty('crdate') ? $this->formatDate($arguments, $file->getProperty('crdate')) : '', |
|
54 | - $this->getUserName($file->getProperty('cruser_id')), |
|
55 | - LocalizationUtility::translate('updated_on', 'media'), |
|
56 | - $file->getProperty('tstamp') ? $this->formatDate($arguments, '@' . $file->getProperty('tstamp')) : '', |
|
57 | - $this->getUserName($file->getProperty('upuser_id')) |
|
58 | - ); |
|
59 | - |
|
60 | - return $result; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Get the User name to be displayed |
|
66 | - * |
|
67 | - * @param int $userIdentifier |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getUserName($userIdentifier) |
|
71 | - { |
|
72 | - |
|
73 | - $username = ''; |
|
74 | - |
|
75 | - if ($userIdentifier > 0) { |
|
76 | - $record = $this->getDataService() |
|
77 | - ->getRecord( |
|
78 | - 'be_users', |
|
79 | - [ |
|
80 | - 'uid' => $userIdentifier |
|
81 | - ] |
|
82 | - ); |
|
83 | - $username = sprintf('%s %s', |
|
84 | - LocalizationUtility::translate('by', 'media'), |
|
85 | - empty($record['realName']) ? $record['username'] : $record['realName'] |
|
86 | - ); |
|
87 | - } |
|
88 | - |
|
89 | - return $username; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return object|DataService |
|
94 | - */ |
|
95 | - protected function getDataService(): DataService |
|
96 | - { |
|
97 | - return GeneralUtility::makeInstance(DataService::class); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param array $arguments |
|
102 | - * @param int|string $date |
|
103 | - * @return string |
|
104 | - * @throws Exception |
|
105 | - */ |
|
106 | - public function formatDate(array $arguments, $date) |
|
107 | - { |
|
108 | - $format = $arguments['format']; |
|
109 | - $base = $date; |
|
110 | - if (is_string($base)) { |
|
111 | - $base = trim($base); |
|
112 | - } |
|
113 | - |
|
114 | - if ($format === '') { |
|
115 | - $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d'; |
|
116 | - } |
|
117 | - |
|
118 | - if (is_string($date)) { |
|
119 | - $date = trim($date); |
|
120 | - } |
|
121 | - |
|
122 | - if ($date === '') { |
|
123 | - $date = 'now'; |
|
124 | - } |
|
125 | - |
|
126 | - if (!$date instanceof \DateTimeInterface) { |
|
127 | - try { |
|
128 | - $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base); |
|
129 | - $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base); |
|
130 | - $date = new \DateTime('@' . $dateTimestamp); |
|
131 | - $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
|
132 | - } catch (\Exception $exception) { |
|
133 | - throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - if (strpos($format, '%') !== false) { |
|
138 | - return strftime($format, $date->format('U')); |
|
139 | - } else { |
|
140 | - return $date->format($format); |
|
141 | - } |
|
142 | - } |
|
26 | + /** |
|
27 | + * Render a form footer. |
|
28 | + * Example: |
|
29 | + * Created on 30-12-12 by John Updated on 22-05-12 by Jane |
|
30 | + * |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function render() |
|
34 | + { |
|
35 | + |
|
36 | + /** @var File $file */ |
|
37 | + $file = $this->templateVariableContainer->get('file'); |
|
38 | + $template = '<span>%s %s %s</span> <span style="padding-left: 50px">%s %s %s</span>'; |
|
39 | + |
|
40 | + $format = sprintf('%s @ %s', |
|
41 | + $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], |
|
42 | + $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] |
|
43 | + ); |
|
44 | + |
|
45 | + $arguments = array( |
|
46 | + 'date' => null, |
|
47 | + 'format' => $format, |
|
48 | + 'base' => null |
|
49 | + ); |
|
50 | + |
|
51 | + $result = sprintf($template, |
|
52 | + LocalizationUtility::translate('created_on', 'media'), |
|
53 | + $file->getProperty('crdate') ? $this->formatDate($arguments, $file->getProperty('crdate')) : '', |
|
54 | + $this->getUserName($file->getProperty('cruser_id')), |
|
55 | + LocalizationUtility::translate('updated_on', 'media'), |
|
56 | + $file->getProperty('tstamp') ? $this->formatDate($arguments, '@' . $file->getProperty('tstamp')) : '', |
|
57 | + $this->getUserName($file->getProperty('upuser_id')) |
|
58 | + ); |
|
59 | + |
|
60 | + return $result; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Get the User name to be displayed |
|
66 | + * |
|
67 | + * @param int $userIdentifier |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getUserName($userIdentifier) |
|
71 | + { |
|
72 | + |
|
73 | + $username = ''; |
|
74 | + |
|
75 | + if ($userIdentifier > 0) { |
|
76 | + $record = $this->getDataService() |
|
77 | + ->getRecord( |
|
78 | + 'be_users', |
|
79 | + [ |
|
80 | + 'uid' => $userIdentifier |
|
81 | + ] |
|
82 | + ); |
|
83 | + $username = sprintf('%s %s', |
|
84 | + LocalizationUtility::translate('by', 'media'), |
|
85 | + empty($record['realName']) ? $record['username'] : $record['realName'] |
|
86 | + ); |
|
87 | + } |
|
88 | + |
|
89 | + return $username; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return object|DataService |
|
94 | + */ |
|
95 | + protected function getDataService(): DataService |
|
96 | + { |
|
97 | + return GeneralUtility::makeInstance(DataService::class); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param array $arguments |
|
102 | + * @param int|string $date |
|
103 | + * @return string |
|
104 | + * @throws Exception |
|
105 | + */ |
|
106 | + public function formatDate(array $arguments, $date) |
|
107 | + { |
|
108 | + $format = $arguments['format']; |
|
109 | + $base = $date; |
|
110 | + if (is_string($base)) { |
|
111 | + $base = trim($base); |
|
112 | + } |
|
113 | + |
|
114 | + if ($format === '') { |
|
115 | + $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d'; |
|
116 | + } |
|
117 | + |
|
118 | + if (is_string($date)) { |
|
119 | + $date = trim($date); |
|
120 | + } |
|
121 | + |
|
122 | + if ($date === '') { |
|
123 | + $date = 'now'; |
|
124 | + } |
|
125 | + |
|
126 | + if (!$date instanceof \DateTimeInterface) { |
|
127 | + try { |
|
128 | + $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base); |
|
129 | + $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base); |
|
130 | + $date = new \DateTime('@' . $dateTimestamp); |
|
131 | + $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
|
132 | + } catch (\Exception $exception) { |
|
133 | + throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + if (strpos($format, '%') !== false) { |
|
138 | + return strftime($format, $date->format('U')); |
|
139 | + } else { |
|
140 | + return $date->format($format); |
|
141 | + } |
|
142 | + } |
|
143 | 143 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $file->getProperty('crdate') ? $this->formatDate($arguments, $file->getProperty('crdate')) : '', |
54 | 54 | $this->getUserName($file->getProperty('cruser_id')), |
55 | 55 | LocalizationUtility::translate('updated_on', 'media'), |
56 | - $file->getProperty('tstamp') ? $this->formatDate($arguments, '@' . $file->getProperty('tstamp')) : '', |
|
56 | + $file->getProperty('tstamp') ? $this->formatDate($arguments, '@'.$file->getProperty('tstamp')) : '', |
|
57 | 57 | $this->getUserName($file->getProperty('upuser_id')) |
58 | 58 | ); |
59 | 59 | |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | |
126 | 126 | if (!$date instanceof \DateTimeInterface) { |
127 | 127 | try { |
128 | - $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base); |
|
129 | - $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base); |
|
130 | - $date = new \DateTime('@' . $dateTimestamp); |
|
128 | + $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '').$base); |
|
129 | + $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '').$date, $base); |
|
130 | + $date = new \DateTime('@'.$dateTimestamp); |
|
131 | 131 | $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
132 | 132 | } catch (\Exception $exception) { |
133 | - throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579); |
|
133 | + throw new Exception('"'.$date.'" could not be parsed by \DateTime constructor: '.$exception->getMessage(), 1241722579); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 |
@@ -22,245 +22,245 @@ |
||
22 | 22 | class CacheService |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Traverse all files and initialize cache values. |
|
27 | - * |
|
28 | - * @return int |
|
29 | - */ |
|
30 | - public function warmUp() |
|
31 | - { |
|
32 | - /** @var QueryBuilder $queryBuilder */ |
|
33 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
34 | - $rows = $queryBuilder |
|
35 | - ->select('*') |
|
36 | - ->from('sys_file') |
|
37 | - ->where('storage > 0') |
|
38 | - ->execute() |
|
39 | - ->fetchAll(); |
|
40 | - |
|
41 | - $counter = 0; |
|
42 | - foreach ($rows as $row) { |
|
43 | - |
|
44 | - $fileIdentifier = $row['uid']; |
|
45 | - $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
46 | - |
|
47 | - $values = array( |
|
48 | - 'number_of_references' => $totalNumberOfReferences |
|
49 | - ); |
|
50 | - |
|
51 | - $this->getDataService()->update( |
|
52 | - 'sys_file', |
|
53 | - $values, |
|
54 | - [ |
|
55 | - 'uid' => $fileIdentifier |
|
56 | - ] |
|
57 | - ); |
|
58 | - $counter++; |
|
59 | - } |
|
60 | - |
|
61 | - return $counter; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Clear all possible cache related to a file. |
|
66 | - * This method is useful when replacing a file for instance. |
|
67 | - * |
|
68 | - * @param File $file |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function clearCache(File $file) |
|
72 | - { |
|
73 | - |
|
74 | - $this->clearCachePages($file); |
|
75 | - $this->flushProcessedFiles($file); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Remove all processed files that belong to the given File object. |
|
80 | - * |
|
81 | - * @param File $file |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - protected function flushProcessedFiles(File $file) |
|
85 | - { |
|
86 | - |
|
87 | - /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
88 | - foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
89 | - if ($processedFile->exists()) { |
|
90 | - $processedFile->delete(true); |
|
91 | - } |
|
92 | - |
|
93 | - $this->getDataService()->delete( |
|
94 | - 'sys_file_processedfile', |
|
95 | - [ |
|
96 | - 'uid' => (int)$processedFile->getUid() |
|
97 | - ] |
|
98 | - ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Return a processed file repository |
|
104 | - * |
|
105 | - * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
106 | - */ |
|
107 | - protected function getProcessedFileRepository() |
|
108 | - { |
|
109 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Returns the file references. |
|
114 | - * |
|
115 | - * @param File $file |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - protected function clearCachePages($file) |
|
119 | - { |
|
120 | - |
|
121 | - /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
122 | - $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
123 | - $tce->start([], []); |
|
124 | - |
|
125 | - #$pages = array_merge( |
|
126 | - # $this->findPagesWithFileReferences($file), |
|
127 | - # $this->findPagesWithSoftReferences($file) |
|
128 | - #); |
|
129 | - |
|
130 | - // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
131 | - // It is adviced to use "registerPageCacheClearing" but how? |
|
132 | - #foreach (array_unique($pages) as $page) { |
|
133 | - # $tce->clear_cache('pages', $page); |
|
134 | - #} |
|
135 | - $tce->clear_cacheCmd('pages'); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Find all pages which contains file references to the given $file. |
|
140 | - * |
|
141 | - * @param File $file |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - protected function findPagesWithFileReferences($file) |
|
145 | - { |
|
146 | - |
|
147 | - /** @var QueryBuilder $queryBuilder */ |
|
148 | - $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
149 | - $rows = $queryBuilder |
|
150 | - ->select('pid') |
|
151 | - ->from('sys_file_reference') |
|
152 | - ->groupBy('pid') // no support for distinct |
|
153 | - ->andWhere( |
|
154 | - 'pid > 0', |
|
155 | - 'uid_local = ' . $file->getUid() |
|
156 | - ) |
|
157 | - ->execute() |
|
158 | - ->fetchAll(); |
|
159 | - |
|
160 | - foreach ($rows as $row) { |
|
161 | - $pages[] = $row['pid']; |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - return $pages; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Find all pages which have soft references to the given $file. |
|
170 | - * |
|
171 | - * @param File $file |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - #protected function findPagesWithSoftReferences(File $file) |
|
175 | - #{ |
|
176 | - # $subClauseParts = array( |
|
177 | - # 'deleted = 0', |
|
178 | - # '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
179 | - # 'ref_table = "sys_file"', |
|
180 | - # 'tablename = "tt_content"', |
|
181 | - # 'ref_uid = ' . $file->getUid(), |
|
182 | - # ); |
|
183 | - # |
|
184 | - # $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
185 | - # 'DISTINCT pid', |
|
186 | - # 'tt_content', |
|
187 | - # sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
188 | - # implode(' AND ', $subClauseParts), |
|
189 | - # $this->getWhereClauseForEnabledFields('tt_content') |
|
190 | - # ) |
|
191 | - # ); |
|
192 | - # |
|
193 | - # // Compute result |
|
194 | - # $pages = []; |
|
195 | - # while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
196 | - # $pages[] = $affectedPage['pid']; |
|
197 | - # } |
|
198 | - # |
|
199 | - # return $pages; |
|
200 | - #} |
|
201 | - |
|
202 | - /** |
|
203 | - * Get the WHERE clause for the enabled fields given a $tableName. |
|
204 | - * |
|
205 | - * @param string $tableName |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - protected function getWhereClauseForEnabledFields($tableName) |
|
209 | - { |
|
210 | - if ($this->isFrontendMode()) { |
|
211 | - // frontend context |
|
212 | - $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
213 | - } else { |
|
214 | - // backend context |
|
215 | - $whereClause = BackendUtility::deleteClause($tableName); |
|
216 | - } |
|
217 | - return $whereClause; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Returns whether the current mode is Frontend |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - protected function isFrontendMode() |
|
226 | - { |
|
227 | - return TYPO3_MODE == 'FE'; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Returns an instance of the page repository. |
|
232 | - * |
|
233 | - * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
234 | - */ |
|
235 | - protected function getPageRepository() |
|
236 | - { |
|
237 | - return $GLOBALS['TSFE']->sys_page; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $tableName |
|
242 | - * @return object|QueryBuilder |
|
243 | - */ |
|
244 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
245 | - { |
|
246 | - /** @var ConnectionPool $connectionPool */ |
|
247 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
248 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return object|DataService |
|
253 | - */ |
|
254 | - protected function getDataService(): DataService |
|
255 | - { |
|
256 | - return GeneralUtility::makeInstance(DataService::class); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
261 | - */ |
|
262 | - protected function getFileReferenceService() |
|
263 | - { |
|
264 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
265 | - } |
|
25 | + /** |
|
26 | + * Traverse all files and initialize cache values. |
|
27 | + * |
|
28 | + * @return int |
|
29 | + */ |
|
30 | + public function warmUp() |
|
31 | + { |
|
32 | + /** @var QueryBuilder $queryBuilder */ |
|
33 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
34 | + $rows = $queryBuilder |
|
35 | + ->select('*') |
|
36 | + ->from('sys_file') |
|
37 | + ->where('storage > 0') |
|
38 | + ->execute() |
|
39 | + ->fetchAll(); |
|
40 | + |
|
41 | + $counter = 0; |
|
42 | + foreach ($rows as $row) { |
|
43 | + |
|
44 | + $fileIdentifier = $row['uid']; |
|
45 | + $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
46 | + |
|
47 | + $values = array( |
|
48 | + 'number_of_references' => $totalNumberOfReferences |
|
49 | + ); |
|
50 | + |
|
51 | + $this->getDataService()->update( |
|
52 | + 'sys_file', |
|
53 | + $values, |
|
54 | + [ |
|
55 | + 'uid' => $fileIdentifier |
|
56 | + ] |
|
57 | + ); |
|
58 | + $counter++; |
|
59 | + } |
|
60 | + |
|
61 | + return $counter; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Clear all possible cache related to a file. |
|
66 | + * This method is useful when replacing a file for instance. |
|
67 | + * |
|
68 | + * @param File $file |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function clearCache(File $file) |
|
72 | + { |
|
73 | + |
|
74 | + $this->clearCachePages($file); |
|
75 | + $this->flushProcessedFiles($file); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Remove all processed files that belong to the given File object. |
|
80 | + * |
|
81 | + * @param File $file |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + protected function flushProcessedFiles(File $file) |
|
85 | + { |
|
86 | + |
|
87 | + /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
88 | + foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
89 | + if ($processedFile->exists()) { |
|
90 | + $processedFile->delete(true); |
|
91 | + } |
|
92 | + |
|
93 | + $this->getDataService()->delete( |
|
94 | + 'sys_file_processedfile', |
|
95 | + [ |
|
96 | + 'uid' => (int)$processedFile->getUid() |
|
97 | + ] |
|
98 | + ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Return a processed file repository |
|
104 | + * |
|
105 | + * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
106 | + */ |
|
107 | + protected function getProcessedFileRepository() |
|
108 | + { |
|
109 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Returns the file references. |
|
114 | + * |
|
115 | + * @param File $file |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + protected function clearCachePages($file) |
|
119 | + { |
|
120 | + |
|
121 | + /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
122 | + $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
123 | + $tce->start([], []); |
|
124 | + |
|
125 | + #$pages = array_merge( |
|
126 | + # $this->findPagesWithFileReferences($file), |
|
127 | + # $this->findPagesWithSoftReferences($file) |
|
128 | + #); |
|
129 | + |
|
130 | + // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
131 | + // It is adviced to use "registerPageCacheClearing" but how? |
|
132 | + #foreach (array_unique($pages) as $page) { |
|
133 | + # $tce->clear_cache('pages', $page); |
|
134 | + #} |
|
135 | + $tce->clear_cacheCmd('pages'); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Find all pages which contains file references to the given $file. |
|
140 | + * |
|
141 | + * @param File $file |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + protected function findPagesWithFileReferences($file) |
|
145 | + { |
|
146 | + |
|
147 | + /** @var QueryBuilder $queryBuilder */ |
|
148 | + $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
149 | + $rows = $queryBuilder |
|
150 | + ->select('pid') |
|
151 | + ->from('sys_file_reference') |
|
152 | + ->groupBy('pid') // no support for distinct |
|
153 | + ->andWhere( |
|
154 | + 'pid > 0', |
|
155 | + 'uid_local = ' . $file->getUid() |
|
156 | + ) |
|
157 | + ->execute() |
|
158 | + ->fetchAll(); |
|
159 | + |
|
160 | + foreach ($rows as $row) { |
|
161 | + $pages[] = $row['pid']; |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + return $pages; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Find all pages which have soft references to the given $file. |
|
170 | + * |
|
171 | + * @param File $file |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + #protected function findPagesWithSoftReferences(File $file) |
|
175 | + #{ |
|
176 | + # $subClauseParts = array( |
|
177 | + # 'deleted = 0', |
|
178 | + # '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
179 | + # 'ref_table = "sys_file"', |
|
180 | + # 'tablename = "tt_content"', |
|
181 | + # 'ref_uid = ' . $file->getUid(), |
|
182 | + # ); |
|
183 | + # |
|
184 | + # $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
185 | + # 'DISTINCT pid', |
|
186 | + # 'tt_content', |
|
187 | + # sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
188 | + # implode(' AND ', $subClauseParts), |
|
189 | + # $this->getWhereClauseForEnabledFields('tt_content') |
|
190 | + # ) |
|
191 | + # ); |
|
192 | + # |
|
193 | + # // Compute result |
|
194 | + # $pages = []; |
|
195 | + # while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
196 | + # $pages[] = $affectedPage['pid']; |
|
197 | + # } |
|
198 | + # |
|
199 | + # return $pages; |
|
200 | + #} |
|
201 | + |
|
202 | + /** |
|
203 | + * Get the WHERE clause for the enabled fields given a $tableName. |
|
204 | + * |
|
205 | + * @param string $tableName |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + protected function getWhereClauseForEnabledFields($tableName) |
|
209 | + { |
|
210 | + if ($this->isFrontendMode()) { |
|
211 | + // frontend context |
|
212 | + $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
213 | + } else { |
|
214 | + // backend context |
|
215 | + $whereClause = BackendUtility::deleteClause($tableName); |
|
216 | + } |
|
217 | + return $whereClause; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Returns whether the current mode is Frontend |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + protected function isFrontendMode() |
|
226 | + { |
|
227 | + return TYPO3_MODE == 'FE'; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Returns an instance of the page repository. |
|
232 | + * |
|
233 | + * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
234 | + */ |
|
235 | + protected function getPageRepository() |
|
236 | + { |
|
237 | + return $GLOBALS['TSFE']->sys_page; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $tableName |
|
242 | + * @return object|QueryBuilder |
|
243 | + */ |
|
244 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
245 | + { |
|
246 | + /** @var ConnectionPool $connectionPool */ |
|
247 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
248 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return object|DataService |
|
253 | + */ |
|
254 | + protected function getDataService(): DataService |
|
255 | + { |
|
256 | + return GeneralUtility::makeInstance(DataService::class); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
261 | + */ |
|
262 | + protected function getFileReferenceService() |
|
263 | + { |
|
264 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
265 | + } |
|
266 | 266 | } |
@@ -152,7 +152,7 @@ |
||
152 | 152 | ->groupBy('pid') // no support for distinct |
153 | 153 | ->andWhere( |
154 | 154 | 'pid > 0', |
155 | - 'uid_local = ' . $file->getUid() |
|
155 | + 'uid_local = '.$file->getUid() |
|
156 | 156 | ) |
157 | 157 | ->execute() |
158 | 158 | ->fetchAll(); |
@@ -21,37 +21,37 @@ |
||
21 | 21 | class ImageEditorController extends ActionController |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Initializes the controller before invoking an action method. |
|
26 | - */ |
|
27 | - public function initializeAction() |
|
28 | - { |
|
29 | - /** @var PageRenderer $pageRenderer */ |
|
30 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
31 | - $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
32 | - |
|
33 | - // Configure property mapping to retrieve the file object. |
|
34 | - if ($this->arguments->hasArgument('file')) { |
|
35 | - |
|
36 | - /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
37 | - $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
38 | - |
|
39 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
40 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Handle GUI for inserting an image in the RTE. |
|
46 | - * |
|
47 | - * @param File $file |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function showAction(File $file) |
|
51 | - { |
|
52 | - $this->view->assign('file', $file); |
|
53 | - $moduleSignature = MediaModule::getSignature(); |
|
54 | - $this->view->assign('moduleUrl', BackendUtility::getModuleUrl($moduleSignature)); |
|
55 | - } |
|
24 | + /** |
|
25 | + * Initializes the controller before invoking an action method. |
|
26 | + */ |
|
27 | + public function initializeAction() |
|
28 | + { |
|
29 | + /** @var PageRenderer $pageRenderer */ |
|
30 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
31 | + $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
32 | + |
|
33 | + // Configure property mapping to retrieve the file object. |
|
34 | + if ($this->arguments->hasArgument('file')) { |
|
35 | + |
|
36 | + /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
37 | + $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
38 | + |
|
39 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
40 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Handle GUI for inserting an image in the RTE. |
|
46 | + * |
|
47 | + * @param File $file |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function showAction(File $file) |
|
51 | + { |
|
52 | + $this->view->assign('file', $file); |
|
53 | + $moduleSignature = MediaModule::getSignature(); |
|
54 | + $this->view->assign('moduleUrl', BackendUtility::getModuleUrl($moduleSignature)); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -19,44 +19,44 @@ discard block |
||
19 | 19 | class RecursiveCheckbox extends AbstractComponentView |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Renders a checkbox for recursive file browsing. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - * @throws \InvalidArgumentException |
|
27 | - */ |
|
28 | - public function render() |
|
29 | - { |
|
22 | + /** |
|
23 | + * Renders a checkbox for recursive file browsing. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + * @throws \InvalidArgumentException |
|
27 | + */ |
|
28 | + public function render() |
|
29 | + { |
|
30 | 30 | |
31 | - $output = ''; |
|
32 | - if ($this->isDisplayed()) { |
|
33 | - $this->loadRequireJsCode(); |
|
34 | - $output = $this->renderRecursiveCheckbox(); |
|
35 | - } |
|
31 | + $output = ''; |
|
32 | + if ($this->isDisplayed()) { |
|
33 | + $this->loadRequireJsCode(); |
|
34 | + $output = $this->renderRecursiveCheckbox(); |
|
35 | + } |
|
36 | 36 | |
37 | - return $output; |
|
38 | - } |
|
37 | + return $output; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - * @throws \InvalidArgumentException |
|
43 | - */ |
|
44 | - protected function isDisplayed() |
|
45 | - { |
|
46 | - $isDisplayed = $this->getMediaModule()->hasFolderTree(); |
|
47 | - if ($this->getModuleLoader()->hasPlugin()) { |
|
48 | - $isDisplayed = false; |
|
49 | - } |
|
50 | - return $isDisplayed; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + * @throws \InvalidArgumentException |
|
43 | + */ |
|
44 | + protected function isDisplayed() |
|
45 | + { |
|
46 | + $isDisplayed = $this->getMediaModule()->hasFolderTree(); |
|
47 | + if ($this->getModuleLoader()->hasPlugin()) { |
|
48 | + $isDisplayed = false; |
|
49 | + } |
|
50 | + return $isDisplayed; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function renderRecursiveCheckbox() |
|
57 | - { |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function renderRecursiveCheckbox() |
|
57 | + { |
|
58 | 58 | |
59 | - $template = '<form action="%s" id="form-checkbox-hasRecursiveSelection" method="get"> |
|
59 | + $template = '<form action="%s" id="form-checkbox-hasRecursiveSelection" method="get"> |
|
60 | 60 | <label> |
61 | 61 | <input type="checkbox" |
62 | 62 | name="%s[hasRecursiveSelection]" |
@@ -67,35 +67,35 @@ discard block |
||
67 | 67 | </label> |
68 | 68 | </form>'; |
69 | 69 | |
70 | - return sprintf( |
|
71 | - $template, |
|
72 | - $this->getModuleLoader()->getModuleUrl(), |
|
73 | - $this->getModuleLoader()->getParameterPrefix(), |
|
74 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:browse_subfolders') |
|
75 | - ); |
|
76 | - } |
|
70 | + return sprintf( |
|
71 | + $template, |
|
72 | + $this->getModuleLoader()->getModuleUrl(), |
|
73 | + $this->getModuleLoader()->getParameterPrefix(), |
|
74 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:browse_subfolders') |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @throws \InvalidArgumentException |
|
81 | - */ |
|
82 | - protected function loadRequireJsCode() |
|
83 | - { |
|
84 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @throws \InvalidArgumentException |
|
81 | + */ |
|
82 | + protected function loadRequireJsCode() |
|
83 | + { |
|
84 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
85 | 85 | |
86 | - $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
87 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
88 | - $pageRenderer->loadRequireJsModule('Fab/Media/BrowseRecursively'); |
|
89 | - } |
|
86 | + $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
87 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
88 | + $pageRenderer->loadRequireJsModule('Fab/Media/BrowseRecursively'); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * @return MediaModule|object |
|
94 | - * @throws \InvalidArgumentException |
|
95 | - */ |
|
96 | - protected function getMediaModule() |
|
97 | - { |
|
98 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
99 | - } |
|
92 | + /** |
|
93 | + * @return MediaModule|object |
|
94 | + * @throws \InvalidArgumentException |
|
95 | + */ |
|
96 | + protected function getMediaModule() |
|
97 | + { |
|
98 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -19,120 +19,120 @@ |
||
19 | 19 | class StorageMenu extends AbstractComponentView |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Renders a dropdown menu for storage. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function render() |
|
28 | - { |
|
29 | - |
|
30 | - $output = ''; |
|
31 | - if ($this->isDisplayed()) { |
|
32 | - $this->loadRequireJsCode(); |
|
33 | - |
|
34 | - $output = $this->renderStorageMenu(); |
|
35 | - } |
|
36 | - |
|
37 | - return $output; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - protected function isDisplayed() |
|
44 | - { |
|
45 | - $isDisplayed = !$this->getMediaModule()->hasFolderTree() || $this->getModuleLoader()->hasPlugin(); |
|
46 | - return $isDisplayed; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - protected function renderStorageMenu() |
|
53 | - { |
|
54 | - |
|
55 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
56 | - |
|
57 | - /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */ |
|
58 | - $options = ''; |
|
59 | - foreach ($this->getMediaModule()->getAllowedStorages() as $storage) { |
|
60 | - $selected = ''; |
|
61 | - if ($currentStorage->getUid() == $storage->getUid()) { |
|
62 | - $selected = 'selected'; |
|
63 | - } |
|
64 | - $options .= sprintf('<option value="%s" %s>%s %s</option>', |
|
65 | - $storage->getUid(), |
|
66 | - $selected, |
|
67 | - $storage->getName(), |
|
68 | - $storage->isOnline() ? |
|
69 | - '' : |
|
70 | - '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
71 | - ); |
|
72 | - } |
|
73 | - |
|
74 | - $parameters = GeneralUtility::_GET(); |
|
75 | - $inputs = ''; |
|
76 | - foreach ($parameters as $parameter => $value) { |
|
77 | - list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
|
78 | - if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
79 | - $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - $template = '<form action="%s" id="form-menu-storage" method="get"> |
|
22 | + /** |
|
23 | + * Renders a dropdown menu for storage. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function render() |
|
28 | + { |
|
29 | + |
|
30 | + $output = ''; |
|
31 | + if ($this->isDisplayed()) { |
|
32 | + $this->loadRequireJsCode(); |
|
33 | + |
|
34 | + $output = $this->renderStorageMenu(); |
|
35 | + } |
|
36 | + |
|
37 | + return $output; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + protected function isDisplayed() |
|
44 | + { |
|
45 | + $isDisplayed = !$this->getMediaModule()->hasFolderTree() || $this->getModuleLoader()->hasPlugin(); |
|
46 | + return $isDisplayed; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + protected function renderStorageMenu() |
|
53 | + { |
|
54 | + |
|
55 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
56 | + |
|
57 | + /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */ |
|
58 | + $options = ''; |
|
59 | + foreach ($this->getMediaModule()->getAllowedStorages() as $storage) { |
|
60 | + $selected = ''; |
|
61 | + if ($currentStorage->getUid() == $storage->getUid()) { |
|
62 | + $selected = 'selected'; |
|
63 | + } |
|
64 | + $options .= sprintf('<option value="%s" %s>%s %s</option>', |
|
65 | + $storage->getUid(), |
|
66 | + $selected, |
|
67 | + $storage->getName(), |
|
68 | + $storage->isOnline() ? |
|
69 | + '' : |
|
70 | + '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
71 | + ); |
|
72 | + } |
|
73 | + |
|
74 | + $parameters = GeneralUtility::_GET(); |
|
75 | + $inputs = ''; |
|
76 | + foreach ($parameters as $parameter => $value) { |
|
77 | + list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
|
78 | + if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
79 | + $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + $template = '<form action="%s" id="form-menu-storage" method="get"> |
|
84 | 84 | %s |
85 | 85 | <select name="%s[storage]" class="form-control" style="padding-right: 20px" id="menu-storage" onchange="$(\'#form-menu-storage\').submit()">%s</select> |
86 | 86 | </form>'; |
87 | 87 | |
88 | - return sprintf( |
|
89 | - $template, |
|
90 | - $this->getModuleLoader()->getModuleUrl(), |
|
91 | - $inputs, |
|
92 | - $this->getModuleLoader()->getParameterPrefix(), |
|
93 | - $options |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - protected function loadRequireJsCode() |
|
101 | - { |
|
102 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
103 | - |
|
104 | - $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
105 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
106 | - $pageRenderer->loadRequireJsModule('Fab/Media/EditStorage'); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Compute parameter and value to be correctly encoded by the browser. |
|
111 | - * |
|
112 | - * @param string $parameter |
|
113 | - * @param mixed $value |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - protected function computeParameterAndValue($parameter, $value) |
|
117 | - { |
|
118 | - |
|
119 | - if (is_string($value)) { |
|
120 | - $result = array($parameter, $value); |
|
121 | - } else { |
|
122 | - $key = key($value); |
|
123 | - $value = current($value); |
|
124 | - $parameter = sprintf('%s[%s]', $parameter, $key); |
|
125 | - $result = $this->computeParameterAndValue($parameter, $value); |
|
126 | - } |
|
127 | - return $result; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return MediaModule|object |
|
132 | - */ |
|
133 | - protected function getMediaModule() |
|
134 | - { |
|
135 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
136 | - } |
|
88 | + return sprintf( |
|
89 | + $template, |
|
90 | + $this->getModuleLoader()->getModuleUrl(), |
|
91 | + $inputs, |
|
92 | + $this->getModuleLoader()->getParameterPrefix(), |
|
93 | + $options |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + protected function loadRequireJsCode() |
|
101 | + { |
|
102 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
103 | + |
|
104 | + $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
105 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
106 | + $pageRenderer->loadRequireJsModule('Fab/Media/EditStorage'); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Compute parameter and value to be correctly encoded by the browser. |
|
111 | + * |
|
112 | + * @param string $parameter |
|
113 | + * @param mixed $value |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + protected function computeParameterAndValue($parameter, $value) |
|
117 | + { |
|
118 | + |
|
119 | + if (is_string($value)) { |
|
120 | + $result = array($parameter, $value); |
|
121 | + } else { |
|
122 | + $key = key($value); |
|
123 | + $value = current($value); |
|
124 | + $parameter = sprintf('%s[%s]', $parameter, $key); |
|
125 | + $result = $this->computeParameterAndValue($parameter, $value); |
|
126 | + } |
|
127 | + return $result; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return MediaModule|object |
|
132 | + */ |
|
133 | + protected function getMediaModule() |
|
134 | + { |
|
135 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | } |
@@ -66,8 +66,7 @@ discard block |
||
66 | 66 | $selected, |
67 | 67 | $storage->getName(), |
68 | 68 | $storage->isOnline() ? |
69 | - '' : |
|
70 | - '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
69 | + '' : '('.$this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline').')' |
|
71 | 70 | ); |
72 | 71 | } |
73 | 72 | |
@@ -75,7 +74,7 @@ discard block |
||
75 | 74 | $inputs = ''; |
76 | 75 | foreach ($parameters as $parameter => $value) { |
77 | 76 | list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
78 | - if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
77 | + if ($parameter !== $this->getModuleLoader()->getParameterPrefix().'[storage]') { |
|
79 | 78 | $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
80 | 79 | } |
81 | 80 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function canResolvesAPath() { |
34 | 34 | $resourceName = uniqid('resource'); |
35 | - $expected = 'media/Resources/Public/' . $resourceName; |
|
35 | + $expected = 'media/Resources/Public/'.$resourceName; |
|
36 | 36 | $actual = \Fab\Media\Utility\Path::resolvePath($resourceName); |
37 | 37 | |
38 | 38 | $this->assertTrue(strpos($actual, $expected) > 0); |
39 | - $this->assertEquals(0, strpos(Environment::getPublicPath() . '/', $expected)); |
|
39 | + $this->assertEquals(0, strpos(Environment::getPublicPath().'/', $expected)); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | public function canReturnsAPublicPath() { |
46 | 46 | |
47 | 47 | $resourceName = uniqid('resource'); |
48 | - $expected = 'media/Resources/Public/' . $resourceName; |
|
48 | + $expected = 'media/Resources/Public/'.$resourceName; |
|
49 | 49 | $actual = \Fab\Media\Utility\Path::getRelativePath($resourceName); |
50 | 50 | |
51 | 51 | $this->assertTrue(strpos($actual, $expected) > 0); |
52 | - $this->assertFalse(strpos(Environment::getPublicPath() . '/', $expected)); |
|
52 | + $this->assertFalse(strpos(Environment::getPublicPath().'/', $expected)); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -22,142 +22,142 @@ discard block |
||
22 | 22 | class ConfigurationWarning extends AbstractComponentView |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $notAllowedMountPoints = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * Renders a button for uploading assets. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function render() |
|
36 | - { |
|
37 | - |
|
38 | - $result = ''; |
|
39 | - |
|
40 | - // Check whether storage is configured or not. |
|
41 | - if ($this->checkStorageNotConfigured()) { |
|
42 | - $this->configureStorage(); |
|
43 | - $result .= $this->formatMessageForStorageConfigured(); |
|
44 | - } |
|
45 | - |
|
46 | - // Check whether storage is online or not. |
|
47 | - if ($this->checkStorageOffline()) { |
|
48 | - $result .= $this->formatMessageForStorageOffline(); |
|
49 | - } |
|
50 | - |
|
51 | - // Check all mount points of the storage are available |
|
52 | - if (!$this->checkMountPoints()) { |
|
53 | - $result .= $this->formatMessageForMountPoints(); |
|
54 | - } |
|
55 | - |
|
56 | - // Check all mount points of the storage are available |
|
57 | - if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
58 | - if ($this->canBeInitializedSilently() < 2000) { |
|
59 | - $numberOfFiles = $this->getCacheService()->warmUp(); |
|
60 | - $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
61 | - touch($this->getWarmUpSemaphoreFile()); |
|
62 | - } else { |
|
63 | - $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - return $result; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return \Fab\Media\Cache\CacheService|object |
|
72 | - */ |
|
73 | - protected function getCacheService() |
|
74 | - { |
|
75 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
76 | - } |
|
77 | - |
|
78 | - protected function configureStorage() |
|
79 | - { |
|
80 | - $tableName = 'sys_file_storage'; |
|
81 | - $fields = array( |
|
82 | - 'maximum_dimension_original_image', |
|
83 | - 'extension_allowed_file_type_1', |
|
84 | - 'extension_allowed_file_type_2', |
|
85 | - 'extension_allowed_file_type_3', |
|
86 | - 'extension_allowed_file_type_4', |
|
87 | - 'extension_allowed_file_type_5', |
|
88 | - ); |
|
89 | - |
|
90 | - $values = []; |
|
91 | - foreach ($fields as $field) { |
|
92 | - $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
93 | - } |
|
94 | - |
|
95 | - /** @var ConnectionPool $connectionPool */ |
|
96 | - $connection = GeneralUtility::makeInstance(ConnectionPool::class); |
|
97 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
98 | - $connection->update( |
|
99 | - $tableName, |
|
100 | - $values, |
|
101 | - [ 'uid' => $storage->getUid() ] |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - protected function hasBeenWarmedUp() |
|
109 | - { |
|
110 | - return is_file(($this->getWarmUpSemaphoreFile())); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - protected function getWarmUpSemaphoreFile() |
|
117 | - { |
|
118 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Check whether the storage is correctly configured. |
|
123 | - * |
|
124 | - * @return boolean |
|
125 | - */ |
|
126 | - protected function checkStorageNotConfigured() |
|
127 | - { |
|
128 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
129 | - $storageRecord = $currentStorage->getStorageRecord(); |
|
130 | - |
|
131 | - // Take the storage fields and check whether some data was initialized. |
|
132 | - $fields = array( |
|
133 | - 'extension_allowed_file_type_1', |
|
134 | - 'extension_allowed_file_type_2', |
|
135 | - 'extension_allowed_file_type_3', |
|
136 | - 'extension_allowed_file_type_4', |
|
137 | - 'extension_allowed_file_type_5', |
|
138 | - ); |
|
139 | - |
|
140 | - $result = true; |
|
141 | - foreach ($fields as $fieldName) { |
|
142 | - // true means the storage has data and thus was configured / saved once. |
|
143 | - if (!empty($storageRecord[$fieldName])) { |
|
144 | - $result = false; |
|
145 | - break; |
|
146 | - } |
|
147 | - } |
|
148 | - return $result; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Format a message whenever the storage is offline. |
|
153 | - * |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - protected function formatMessageForStorageConfigured() |
|
157 | - { |
|
158 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
159 | - |
|
160 | - $result = <<< EOF |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $notAllowedMountPoints = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * Renders a button for uploading assets. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function render() |
|
36 | + { |
|
37 | + |
|
38 | + $result = ''; |
|
39 | + |
|
40 | + // Check whether storage is configured or not. |
|
41 | + if ($this->checkStorageNotConfigured()) { |
|
42 | + $this->configureStorage(); |
|
43 | + $result .= $this->formatMessageForStorageConfigured(); |
|
44 | + } |
|
45 | + |
|
46 | + // Check whether storage is online or not. |
|
47 | + if ($this->checkStorageOffline()) { |
|
48 | + $result .= $this->formatMessageForStorageOffline(); |
|
49 | + } |
|
50 | + |
|
51 | + // Check all mount points of the storage are available |
|
52 | + if (!$this->checkMountPoints()) { |
|
53 | + $result .= $this->formatMessageForMountPoints(); |
|
54 | + } |
|
55 | + |
|
56 | + // Check all mount points of the storage are available |
|
57 | + if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
58 | + if ($this->canBeInitializedSilently() < 2000) { |
|
59 | + $numberOfFiles = $this->getCacheService()->warmUp(); |
|
60 | + $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
61 | + touch($this->getWarmUpSemaphoreFile()); |
|
62 | + } else { |
|
63 | + $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + return $result; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return \Fab\Media\Cache\CacheService|object |
|
72 | + */ |
|
73 | + protected function getCacheService() |
|
74 | + { |
|
75 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
76 | + } |
|
77 | + |
|
78 | + protected function configureStorage() |
|
79 | + { |
|
80 | + $tableName = 'sys_file_storage'; |
|
81 | + $fields = array( |
|
82 | + 'maximum_dimension_original_image', |
|
83 | + 'extension_allowed_file_type_1', |
|
84 | + 'extension_allowed_file_type_2', |
|
85 | + 'extension_allowed_file_type_3', |
|
86 | + 'extension_allowed_file_type_4', |
|
87 | + 'extension_allowed_file_type_5', |
|
88 | + ); |
|
89 | + |
|
90 | + $values = []; |
|
91 | + foreach ($fields as $field) { |
|
92 | + $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
93 | + } |
|
94 | + |
|
95 | + /** @var ConnectionPool $connectionPool */ |
|
96 | + $connection = GeneralUtility::makeInstance(ConnectionPool::class); |
|
97 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
98 | + $connection->update( |
|
99 | + $tableName, |
|
100 | + $values, |
|
101 | + [ 'uid' => $storage->getUid() ] |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + protected function hasBeenWarmedUp() |
|
109 | + { |
|
110 | + return is_file(($this->getWarmUpSemaphoreFile())); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + protected function getWarmUpSemaphoreFile() |
|
117 | + { |
|
118 | + return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Check whether the storage is correctly configured. |
|
123 | + * |
|
124 | + * @return boolean |
|
125 | + */ |
|
126 | + protected function checkStorageNotConfigured() |
|
127 | + { |
|
128 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
129 | + $storageRecord = $currentStorage->getStorageRecord(); |
|
130 | + |
|
131 | + // Take the storage fields and check whether some data was initialized. |
|
132 | + $fields = array( |
|
133 | + 'extension_allowed_file_type_1', |
|
134 | + 'extension_allowed_file_type_2', |
|
135 | + 'extension_allowed_file_type_3', |
|
136 | + 'extension_allowed_file_type_4', |
|
137 | + 'extension_allowed_file_type_5', |
|
138 | + ); |
|
139 | + |
|
140 | + $result = true; |
|
141 | + foreach ($fields as $fieldName) { |
|
142 | + // true means the storage has data and thus was configured / saved once. |
|
143 | + if (!empty($storageRecord[$fieldName])) { |
|
144 | + $result = false; |
|
145 | + break; |
|
146 | + } |
|
147 | + } |
|
148 | + return $result; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Format a message whenever the storage is offline. |
|
153 | + * |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + protected function formatMessageForStorageConfigured() |
|
157 | + { |
|
158 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
159 | + |
|
160 | + $result = <<< EOF |
|
161 | 161 | <div class="alert alert-info"> |
162 | 162 | <div class="alert-title"> |
163 | 163 | Storage has been configured. |
@@ -170,29 +170,29 @@ discard block |
||
170 | 170 | </div> |
171 | 171 | EOF; |
172 | 172 | |
173 | - return $result; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Check whether the storage is online or not. |
|
178 | - * |
|
179 | - * @return boolean |
|
180 | - */ |
|
181 | - protected function checkStorageOffline() |
|
182 | - { |
|
183 | - return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Format a message whenever the storage is offline. |
|
188 | - * |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - protected function formatMessageForStorageOffline() |
|
192 | - { |
|
193 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
194 | - |
|
195 | - $result = <<< EOF |
|
173 | + return $result; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Check whether the storage is online or not. |
|
178 | + * |
|
179 | + * @return boolean |
|
180 | + */ |
|
181 | + protected function checkStorageOffline() |
|
182 | + { |
|
183 | + return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Format a message whenever the storage is offline. |
|
188 | + * |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + protected function formatMessageForStorageOffline() |
|
192 | + { |
|
193 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
194 | + |
|
195 | + $result = <<< EOF |
|
196 | 196 | <div class="alert alert-warning"> |
197 | 197 | <div class="alert-title"> |
198 | 198 | Storage is currently offline |
@@ -204,85 +204,85 @@ discard block |
||
204 | 204 | </div> |
205 | 205 | EOF; |
206 | 206 | |
207 | - return $result; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Check whether mount points privilege are ok. |
|
212 | - * |
|
213 | - * @return boolean |
|
214 | - */ |
|
215 | - protected function checkMountPoints() |
|
216 | - { |
|
217 | - if (!$this->getBackendUser()->isAdmin()) { |
|
218 | - |
|
219 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
220 | - |
|
221 | - $fileMountIdentifiers = []; |
|
222 | - foreach ($fileMounts as $fileMount) { |
|
223 | - $fileMountIdentifiers[] = $fileMount['uid']; |
|
224 | - } |
|
225 | - |
|
226 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
227 | - $storageRecord = $storage->getStorageRecord(); |
|
228 | - $fieldNames = array( |
|
229 | - 'mount_point_file_type_1', |
|
230 | - 'mount_point_file_type_2', |
|
231 | - 'mount_point_file_type_3', |
|
232 | - 'mount_point_file_type_4', |
|
233 | - 'mount_point_file_type_5', |
|
234 | - ); |
|
235 | - foreach ($fieldNames as $fileName) { |
|
236 | - $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
237 | - if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
238 | - $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
239 | - } else { |
|
240 | - # $fileMountIdentifier |
|
241 | - $folder = $storage->getRootLevelFolder(); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - return empty($this->notAllowedMountPoints); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Return a mount point according to an file mount identifier. |
|
250 | - * |
|
251 | - * @param string $identifier |
|
252 | - * @return array |
|
253 | - */ |
|
254 | - protected function fetchMountPoint($identifier) |
|
255 | - { |
|
256 | - /** @var QueryBuilder $queryBuilder */ |
|
257 | - $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
258 | - return $queryBuilder |
|
259 | - ->select('*') |
|
260 | - ->from('sys_filemounts') |
|
261 | - ->where('uid = ' . $identifier) |
|
262 | - ->execute() |
|
263 | - ->fetch(); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Format a message whenever mount points privilege are not OK. |
|
268 | - * |
|
269 | - * @return string |
|
270 | - */ |
|
271 | - protected function formatMessageForMountPoints() |
|
272 | - { |
|
273 | - |
|
274 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
275 | - $backendUser = $this->getBackendUser(); |
|
276 | - |
|
277 | - foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
278 | - $list = sprintf('<li>"%s" with path %s</li>', |
|
279 | - $notAllowedMountPoints['title'], |
|
280 | - $notAllowedMountPoints['path'] |
|
281 | - ); |
|
282 | - |
|
283 | - } |
|
284 | - |
|
285 | - $result = <<< EOF |
|
207 | + return $result; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Check whether mount points privilege are ok. |
|
212 | + * |
|
213 | + * @return boolean |
|
214 | + */ |
|
215 | + protected function checkMountPoints() |
|
216 | + { |
|
217 | + if (!$this->getBackendUser()->isAdmin()) { |
|
218 | + |
|
219 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
220 | + |
|
221 | + $fileMountIdentifiers = []; |
|
222 | + foreach ($fileMounts as $fileMount) { |
|
223 | + $fileMountIdentifiers[] = $fileMount['uid']; |
|
224 | + } |
|
225 | + |
|
226 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
227 | + $storageRecord = $storage->getStorageRecord(); |
|
228 | + $fieldNames = array( |
|
229 | + 'mount_point_file_type_1', |
|
230 | + 'mount_point_file_type_2', |
|
231 | + 'mount_point_file_type_3', |
|
232 | + 'mount_point_file_type_4', |
|
233 | + 'mount_point_file_type_5', |
|
234 | + ); |
|
235 | + foreach ($fieldNames as $fileName) { |
|
236 | + $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
237 | + if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
238 | + $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
239 | + } else { |
|
240 | + # $fileMountIdentifier |
|
241 | + $folder = $storage->getRootLevelFolder(); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + return empty($this->notAllowedMountPoints); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Return a mount point according to an file mount identifier. |
|
250 | + * |
|
251 | + * @param string $identifier |
|
252 | + * @return array |
|
253 | + */ |
|
254 | + protected function fetchMountPoint($identifier) |
|
255 | + { |
|
256 | + /** @var QueryBuilder $queryBuilder */ |
|
257 | + $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
258 | + return $queryBuilder |
|
259 | + ->select('*') |
|
260 | + ->from('sys_filemounts') |
|
261 | + ->where('uid = ' . $identifier) |
|
262 | + ->execute() |
|
263 | + ->fetch(); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Format a message whenever mount points privilege are not OK. |
|
268 | + * |
|
269 | + * @return string |
|
270 | + */ |
|
271 | + protected function formatMessageForMountPoints() |
|
272 | + { |
|
273 | + |
|
274 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
275 | + $backendUser = $this->getBackendUser(); |
|
276 | + |
|
277 | + foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
278 | + $list = sprintf('<li>"%s" with path %s</li>', |
|
279 | + $notAllowedMountPoints['title'], |
|
280 | + $notAllowedMountPoints['path'] |
|
281 | + ); |
|
282 | + |
|
283 | + } |
|
284 | + |
|
285 | + $result = <<< EOF |
|
286 | 286 | <div class="alert alert-warning"> |
287 | 287 | <div class="alert-title"> |
288 | 288 | File mount are wrongly configured for user "{$backendUser->user['username']}". |
@@ -297,54 +297,54 @@ discard block |
||
297 | 297 | </div> |
298 | 298 | EOF; |
299 | 299 | |
300 | - return $result; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * @return boolean |
|
305 | - */ |
|
306 | - protected function canBeInitializedSilently() |
|
307 | - { |
|
308 | - /** @var QueryBuilder $queryBuilder */ |
|
309 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
310 | - $count = $queryBuilder |
|
311 | - ->count('*') |
|
312 | - ->from('sys_file') |
|
313 | - ->execute() |
|
314 | - ->fetchColumn(0); |
|
315 | - return (int)$count; |
|
316 | - |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Check whether the column "total_of_references" has been already processed once. |
|
321 | - * |
|
322 | - * @return boolean |
|
323 | - */ |
|
324 | - protected function checkColumnNumberOfReferences() |
|
325 | - { |
|
326 | - /** @var QueryBuilder $queryBuilder */ |
|
327 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
328 | - $file = $queryBuilder |
|
329 | - ->select('*') |
|
330 | - ->from('sys_file') |
|
331 | - ->where('number_of_references > 0') |
|
332 | - ->execute() |
|
333 | - ->fetch(); |
|
334 | - |
|
335 | - return !empty($file); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Format a message if columns "total_of_references" looks wrong. |
|
340 | - * |
|
341 | - * @param int $numberOfFile |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
345 | - { |
|
346 | - |
|
347 | - $result = <<< EOF |
|
300 | + return $result; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * @return boolean |
|
305 | + */ |
|
306 | + protected function canBeInitializedSilently() |
|
307 | + { |
|
308 | + /** @var QueryBuilder $queryBuilder */ |
|
309 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
310 | + $count = $queryBuilder |
|
311 | + ->count('*') |
|
312 | + ->from('sys_file') |
|
313 | + ->execute() |
|
314 | + ->fetchColumn(0); |
|
315 | + return (int)$count; |
|
316 | + |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Check whether the column "total_of_references" has been already processed once. |
|
321 | + * |
|
322 | + * @return boolean |
|
323 | + */ |
|
324 | + protected function checkColumnNumberOfReferences() |
|
325 | + { |
|
326 | + /** @var QueryBuilder $queryBuilder */ |
|
327 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
328 | + $file = $queryBuilder |
|
329 | + ->select('*') |
|
330 | + ->from('sys_file') |
|
331 | + ->where('number_of_references > 0') |
|
332 | + ->execute() |
|
333 | + ->fetch(); |
|
334 | + |
|
335 | + return !empty($file); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Format a message if columns "total_of_references" looks wrong. |
|
340 | + * |
|
341 | + * @param int $numberOfFile |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
345 | + { |
|
346 | + |
|
347 | + $result = <<< EOF |
|
348 | 348 | <div class="alert alert-success"> |
349 | 349 | <div class="alert-title"> |
350 | 350 | Initialized column "number_of_references" for ${numberOfFile} files |
@@ -361,19 +361,19 @@ discard block |
||
361 | 361 | </div> |
362 | 362 | EOF; |
363 | 363 | |
364 | - return $result; |
|
365 | - } |
|
364 | + return $result; |
|
365 | + } |
|
366 | 366 | |
367 | 367 | |
368 | - /** |
|
369 | - * Format a message if columns "total_of_references" looks wrong. |
|
370 | - * |
|
371 | - * @return string |
|
372 | - */ |
|
373 | - protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
374 | - { |
|
368 | + /** |
|
369 | + * Format a message if columns "total_of_references" looks wrong. |
|
370 | + * |
|
371 | + * @return string |
|
372 | + */ |
|
373 | + protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
374 | + { |
|
375 | 375 | |
376 | - $result = <<< EOF |
|
376 | + $result = <<< EOF |
|
377 | 377 | <div class="alert alert-warning"> |
378 | 378 | <div class="alert-title"> |
379 | 379 | Column "number_of_references" requires to be initialized. |
@@ -392,36 +392,36 @@ discard block |
||
392 | 392 | </div> |
393 | 393 | EOF; |
394 | 394 | |
395 | - return $result; |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Returns an instance of the current Backend User. |
|
400 | - * |
|
401 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
402 | - */ |
|
403 | - protected function getBackendUser() |
|
404 | - { |
|
405 | - return $GLOBALS['BE_USER']; |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * @param string $tableName |
|
410 | - * @return object|QueryBuilder |
|
411 | - */ |
|
412 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
413 | - { |
|
414 | - /** @var ConnectionPool $connectionPool */ |
|
415 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
416 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * @return MediaModule|object |
|
421 | - */ |
|
422 | - protected function getMediaModule() |
|
423 | - { |
|
424 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
425 | - } |
|
395 | + return $result; |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Returns an instance of the current Backend User. |
|
400 | + * |
|
401 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
402 | + */ |
|
403 | + protected function getBackendUser() |
|
404 | + { |
|
405 | + return $GLOBALS['BE_USER']; |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * @param string $tableName |
|
410 | + * @return object|QueryBuilder |
|
411 | + */ |
|
412 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
413 | + { |
|
414 | + /** @var ConnectionPool $connectionPool */ |
|
415 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
416 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * @return MediaModule|object |
|
421 | + */ |
|
422 | + protected function getMediaModule() |
|
423 | + { |
|
424 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
425 | + } |
|
426 | 426 | |
427 | 427 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $connection->update( |
99 | 99 | $tableName, |
100 | 100 | $values, |
101 | - [ 'uid' => $storage->getUid() ] |
|
101 | + ['uid' => $storage->getUid()] |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | protected function getWarmUpSemaphoreFile() |
117 | 117 | { |
118 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
118 | + return Environment::getPublicPath().'/typo3temp/.media_cache_warmed_up'; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | return $queryBuilder |
259 | 259 | ->select('*') |
260 | 260 | ->from('sys_filemounts') |
261 | - ->where('uid = ' . $identifier) |
|
261 | + ->where('uid = '.$identifier) |
|
262 | 262 | ->execute() |
263 | 263 | ->fetch(); |
264 | 264 | } |