@@ -38,253 +38,253 @@ |
||
38 | 38 | * Manage trusted certificates for users |
39 | 39 | */ |
40 | 40 | class CertificateManager implements ICertificateManager { |
41 | - /** |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - protected $uid; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var \OC\Files\View |
|
48 | - */ |
|
49 | - protected $view; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var IConfig |
|
53 | - */ |
|
54 | - protected $config; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var ILogger |
|
58 | - */ |
|
59 | - protected $logger; |
|
60 | - |
|
61 | - /** @var ISecureRandom */ |
|
62 | - protected $random; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param string $uid |
|
66 | - * @param \OC\Files\View $view relative to data/ |
|
67 | - * @param IConfig $config |
|
68 | - * @param ILogger $logger |
|
69 | - * @param ISecureRandom $random |
|
70 | - */ |
|
71 | - public function __construct($uid, |
|
72 | - \OC\Files\View $view, |
|
73 | - IConfig $config, |
|
74 | - ILogger $logger, |
|
75 | - ISecureRandom $random) { |
|
76 | - $this->uid = $uid; |
|
77 | - $this->view = $view; |
|
78 | - $this->config = $config; |
|
79 | - $this->logger = $logger; |
|
80 | - $this->random = $random; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns all certificates trusted by the user |
|
85 | - * |
|
86 | - * @return \OCP\ICertificate[] |
|
87 | - */ |
|
88 | - public function listCertificates() { |
|
89 | - |
|
90 | - if (!$this->config->getSystemValue('installed', false)) { |
|
91 | - return array(); |
|
92 | - } |
|
93 | - |
|
94 | - $path = $this->getPathToCertificates() . 'uploads/'; |
|
95 | - if (!$this->view->is_dir($path)) { |
|
96 | - return array(); |
|
97 | - } |
|
98 | - $result = array(); |
|
99 | - $handle = $this->view->opendir($path); |
|
100 | - if (!is_resource($handle)) { |
|
101 | - return array(); |
|
102 | - } |
|
103 | - while (false !== ($file = readdir($handle))) { |
|
104 | - if ($file != '.' && $file != '..') { |
|
105 | - try { |
|
106 | - $result[] = new Certificate($this->view->file_get_contents($path . $file), $file); |
|
107 | - } catch (\Exception $e) { |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - closedir($handle); |
|
112 | - return $result; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * create the certificate bundle of all trusted certificated |
|
117 | - */ |
|
118 | - public function createCertificateBundle() { |
|
119 | - $path = $this->getPathToCertificates(); |
|
120 | - $certs = $this->listCertificates(); |
|
121 | - |
|
122 | - if (!$this->view->file_exists($path)) { |
|
123 | - $this->view->mkdir($path); |
|
124 | - } |
|
125 | - |
|
126 | - $defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); |
|
127 | - if (strlen($defaultCertificates) < 1024) { // sanity check to verify that we have some content for our bundle |
|
128 | - // log as exception so we have a stacktrace |
|
129 | - $this->logger->logException(new \Exception('Shipped ca-bundle is empty, refusing to create certificate bundle')); |
|
130 | - return; |
|
131 | - } |
|
132 | - |
|
133 | - $certPath = $path . 'rootcerts.crt'; |
|
134 | - $tmpPath = $certPath . '.tmp' . $this->random->generate(10, ISecureRandom::CHAR_DIGITS); |
|
135 | - $fhCerts = $this->view->fopen($tmpPath, 'w'); |
|
136 | - |
|
137 | - // Write user certificates |
|
138 | - foreach ($certs as $cert) { |
|
139 | - $file = $path . '/uploads/' . $cert->getName(); |
|
140 | - $data = $this->view->file_get_contents($file); |
|
141 | - if (strpos($data, 'BEGIN CERTIFICATE')) { |
|
142 | - fwrite($fhCerts, $data); |
|
143 | - fwrite($fhCerts, "\r\n"); |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - // Append the default certificates |
|
148 | - fwrite($fhCerts, $defaultCertificates); |
|
149 | - |
|
150 | - // Append the system certificate bundle |
|
151 | - $systemBundle = $this->getCertificateBundle(null); |
|
152 | - if ($systemBundle !== $certPath && $this->view->file_exists($systemBundle)) { |
|
153 | - $systemCertificates = $this->view->file_get_contents($systemBundle); |
|
154 | - fwrite($fhCerts, $systemCertificates); |
|
155 | - } |
|
156 | - |
|
157 | - fclose($fhCerts); |
|
158 | - |
|
159 | - $this->view->rename($tmpPath, $certPath); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Save the certificate and re-generate the certificate bundle |
|
164 | - * |
|
165 | - * @param string $certificate the certificate data |
|
166 | - * @param string $name the filename for the certificate |
|
167 | - * @return \OCP\ICertificate |
|
168 | - * @throws \Exception If the certificate could not get added |
|
169 | - */ |
|
170 | - public function addCertificate($certificate, $name) { |
|
171 | - if (!Filesystem::isValidPath($name) or Filesystem::isFileBlacklisted($name)) { |
|
172 | - throw new \Exception('Filename is not valid'); |
|
173 | - } |
|
174 | - |
|
175 | - $dir = $this->getPathToCertificates() . 'uploads/'; |
|
176 | - if (!$this->view->file_exists($dir)) { |
|
177 | - $this->view->mkdir($dir); |
|
178 | - } |
|
179 | - |
|
180 | - try { |
|
181 | - $file = $dir . $name; |
|
182 | - $certificateObject = new Certificate($certificate, $name); |
|
183 | - $this->view->file_put_contents($file, $certificate); |
|
184 | - $this->createCertificateBundle(); |
|
185 | - return $certificateObject; |
|
186 | - } catch (\Exception $e) { |
|
187 | - throw $e; |
|
188 | - } |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Remove the certificate and re-generate the certificate bundle |
|
194 | - * |
|
195 | - * @param string $name |
|
196 | - * @return bool |
|
197 | - */ |
|
198 | - public function removeCertificate($name) { |
|
199 | - if (!Filesystem::isValidPath($name)) { |
|
200 | - return false; |
|
201 | - } |
|
202 | - $path = $this->getPathToCertificates() . 'uploads/'; |
|
203 | - if ($this->view->file_exists($path . $name)) { |
|
204 | - $this->view->unlink($path . $name); |
|
205 | - $this->createCertificateBundle(); |
|
206 | - } |
|
207 | - return true; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Get the path to the certificate bundle for this user |
|
212 | - * |
|
213 | - * @param string|null $uid (optional) user to get the certificate bundle for, use `null` to get the system bundle |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public function getCertificateBundle($uid = '') { |
|
217 | - if ($uid === '') { |
|
218 | - $uid = $this->uid; |
|
219 | - } |
|
220 | - return $this->getPathToCertificates($uid) . 'rootcerts.crt'; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Get the full local path to the certificate bundle for this user |
|
225 | - * |
|
226 | - * @param string $uid (optional) user to get the certificate bundle for, use `null` to get the system bundle |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function getAbsoluteBundlePath($uid = '') { |
|
230 | - if ($uid === '') { |
|
231 | - $uid = $this->uid; |
|
232 | - } |
|
233 | - if ($this->needsRebundling($uid)) { |
|
234 | - if (is_null($uid)) { |
|
235 | - $manager = new CertificateManager(null, $this->view, $this->config, $this->logger, $this->random); |
|
236 | - $manager->createCertificateBundle(); |
|
237 | - } else { |
|
238 | - $this->createCertificateBundle(); |
|
239 | - } |
|
240 | - } |
|
241 | - return $this->view->getLocalFile($this->getCertificateBundle($uid)); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @param string|null $uid (optional) user to get the certificate path for, use `null` to get the system path |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - private function getPathToCertificates($uid = '') { |
|
249 | - if ($uid === '') { |
|
250 | - $uid = $this->uid; |
|
251 | - } |
|
252 | - return is_null($uid) ? '/files_external/' : '/' . $uid . '/files_external/'; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Check if we need to re-bundle the certificates because one of the sources has updated |
|
257 | - * |
|
258 | - * @param string $uid (optional) user to get the certificate path for, use `null` to get the system path |
|
259 | - * @return bool |
|
260 | - */ |
|
261 | - private function needsRebundling($uid = '') { |
|
262 | - if ($uid === '') { |
|
263 | - $uid = $this->uid; |
|
264 | - } |
|
265 | - $sourceMTimes = [$this->getFilemtimeOfCaBundle()]; |
|
266 | - $targetBundle = $this->getCertificateBundle($uid); |
|
267 | - if (!$this->view->file_exists($targetBundle)) { |
|
268 | - return true; |
|
269 | - } |
|
270 | - |
|
271 | - if (!is_null($uid)) { // also depend on the system bundle |
|
272 | - $sourceMTimes[] = $this->view->filemtime($this->getCertificateBundle(null)); |
|
273 | - } |
|
274 | - |
|
275 | - $sourceMTime = array_reduce($sourceMTimes, function ($max, $mtime) { |
|
276 | - return max($max, $mtime); |
|
277 | - }, 0); |
|
278 | - return $sourceMTime > $this->view->filemtime($targetBundle); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * get mtime of ca-bundle shipped by Nextcloud |
|
283 | - * |
|
284 | - * @return int |
|
285 | - */ |
|
286 | - protected function getFilemtimeOfCaBundle() { |
|
287 | - return filemtime(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); |
|
288 | - } |
|
41 | + /** |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + protected $uid; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var \OC\Files\View |
|
48 | + */ |
|
49 | + protected $view; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var IConfig |
|
53 | + */ |
|
54 | + protected $config; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var ILogger |
|
58 | + */ |
|
59 | + protected $logger; |
|
60 | + |
|
61 | + /** @var ISecureRandom */ |
|
62 | + protected $random; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param string $uid |
|
66 | + * @param \OC\Files\View $view relative to data/ |
|
67 | + * @param IConfig $config |
|
68 | + * @param ILogger $logger |
|
69 | + * @param ISecureRandom $random |
|
70 | + */ |
|
71 | + public function __construct($uid, |
|
72 | + \OC\Files\View $view, |
|
73 | + IConfig $config, |
|
74 | + ILogger $logger, |
|
75 | + ISecureRandom $random) { |
|
76 | + $this->uid = $uid; |
|
77 | + $this->view = $view; |
|
78 | + $this->config = $config; |
|
79 | + $this->logger = $logger; |
|
80 | + $this->random = $random; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns all certificates trusted by the user |
|
85 | + * |
|
86 | + * @return \OCP\ICertificate[] |
|
87 | + */ |
|
88 | + public function listCertificates() { |
|
89 | + |
|
90 | + if (!$this->config->getSystemValue('installed', false)) { |
|
91 | + return array(); |
|
92 | + } |
|
93 | + |
|
94 | + $path = $this->getPathToCertificates() . 'uploads/'; |
|
95 | + if (!$this->view->is_dir($path)) { |
|
96 | + return array(); |
|
97 | + } |
|
98 | + $result = array(); |
|
99 | + $handle = $this->view->opendir($path); |
|
100 | + if (!is_resource($handle)) { |
|
101 | + return array(); |
|
102 | + } |
|
103 | + while (false !== ($file = readdir($handle))) { |
|
104 | + if ($file != '.' && $file != '..') { |
|
105 | + try { |
|
106 | + $result[] = new Certificate($this->view->file_get_contents($path . $file), $file); |
|
107 | + } catch (\Exception $e) { |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + closedir($handle); |
|
112 | + return $result; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * create the certificate bundle of all trusted certificated |
|
117 | + */ |
|
118 | + public function createCertificateBundle() { |
|
119 | + $path = $this->getPathToCertificates(); |
|
120 | + $certs = $this->listCertificates(); |
|
121 | + |
|
122 | + if (!$this->view->file_exists($path)) { |
|
123 | + $this->view->mkdir($path); |
|
124 | + } |
|
125 | + |
|
126 | + $defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); |
|
127 | + if (strlen($defaultCertificates) < 1024) { // sanity check to verify that we have some content for our bundle |
|
128 | + // log as exception so we have a stacktrace |
|
129 | + $this->logger->logException(new \Exception('Shipped ca-bundle is empty, refusing to create certificate bundle')); |
|
130 | + return; |
|
131 | + } |
|
132 | + |
|
133 | + $certPath = $path . 'rootcerts.crt'; |
|
134 | + $tmpPath = $certPath . '.tmp' . $this->random->generate(10, ISecureRandom::CHAR_DIGITS); |
|
135 | + $fhCerts = $this->view->fopen($tmpPath, 'w'); |
|
136 | + |
|
137 | + // Write user certificates |
|
138 | + foreach ($certs as $cert) { |
|
139 | + $file = $path . '/uploads/' . $cert->getName(); |
|
140 | + $data = $this->view->file_get_contents($file); |
|
141 | + if (strpos($data, 'BEGIN CERTIFICATE')) { |
|
142 | + fwrite($fhCerts, $data); |
|
143 | + fwrite($fhCerts, "\r\n"); |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + // Append the default certificates |
|
148 | + fwrite($fhCerts, $defaultCertificates); |
|
149 | + |
|
150 | + // Append the system certificate bundle |
|
151 | + $systemBundle = $this->getCertificateBundle(null); |
|
152 | + if ($systemBundle !== $certPath && $this->view->file_exists($systemBundle)) { |
|
153 | + $systemCertificates = $this->view->file_get_contents($systemBundle); |
|
154 | + fwrite($fhCerts, $systemCertificates); |
|
155 | + } |
|
156 | + |
|
157 | + fclose($fhCerts); |
|
158 | + |
|
159 | + $this->view->rename($tmpPath, $certPath); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Save the certificate and re-generate the certificate bundle |
|
164 | + * |
|
165 | + * @param string $certificate the certificate data |
|
166 | + * @param string $name the filename for the certificate |
|
167 | + * @return \OCP\ICertificate |
|
168 | + * @throws \Exception If the certificate could not get added |
|
169 | + */ |
|
170 | + public function addCertificate($certificate, $name) { |
|
171 | + if (!Filesystem::isValidPath($name) or Filesystem::isFileBlacklisted($name)) { |
|
172 | + throw new \Exception('Filename is not valid'); |
|
173 | + } |
|
174 | + |
|
175 | + $dir = $this->getPathToCertificates() . 'uploads/'; |
|
176 | + if (!$this->view->file_exists($dir)) { |
|
177 | + $this->view->mkdir($dir); |
|
178 | + } |
|
179 | + |
|
180 | + try { |
|
181 | + $file = $dir . $name; |
|
182 | + $certificateObject = new Certificate($certificate, $name); |
|
183 | + $this->view->file_put_contents($file, $certificate); |
|
184 | + $this->createCertificateBundle(); |
|
185 | + return $certificateObject; |
|
186 | + } catch (\Exception $e) { |
|
187 | + throw $e; |
|
188 | + } |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Remove the certificate and re-generate the certificate bundle |
|
194 | + * |
|
195 | + * @param string $name |
|
196 | + * @return bool |
|
197 | + */ |
|
198 | + public function removeCertificate($name) { |
|
199 | + if (!Filesystem::isValidPath($name)) { |
|
200 | + return false; |
|
201 | + } |
|
202 | + $path = $this->getPathToCertificates() . 'uploads/'; |
|
203 | + if ($this->view->file_exists($path . $name)) { |
|
204 | + $this->view->unlink($path . $name); |
|
205 | + $this->createCertificateBundle(); |
|
206 | + } |
|
207 | + return true; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Get the path to the certificate bundle for this user |
|
212 | + * |
|
213 | + * @param string|null $uid (optional) user to get the certificate bundle for, use `null` to get the system bundle |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public function getCertificateBundle($uid = '') { |
|
217 | + if ($uid === '') { |
|
218 | + $uid = $this->uid; |
|
219 | + } |
|
220 | + return $this->getPathToCertificates($uid) . 'rootcerts.crt'; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get the full local path to the certificate bundle for this user |
|
225 | + * |
|
226 | + * @param string $uid (optional) user to get the certificate bundle for, use `null` to get the system bundle |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function getAbsoluteBundlePath($uid = '') { |
|
230 | + if ($uid === '') { |
|
231 | + $uid = $this->uid; |
|
232 | + } |
|
233 | + if ($this->needsRebundling($uid)) { |
|
234 | + if (is_null($uid)) { |
|
235 | + $manager = new CertificateManager(null, $this->view, $this->config, $this->logger, $this->random); |
|
236 | + $manager->createCertificateBundle(); |
|
237 | + } else { |
|
238 | + $this->createCertificateBundle(); |
|
239 | + } |
|
240 | + } |
|
241 | + return $this->view->getLocalFile($this->getCertificateBundle($uid)); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @param string|null $uid (optional) user to get the certificate path for, use `null` to get the system path |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + private function getPathToCertificates($uid = '') { |
|
249 | + if ($uid === '') { |
|
250 | + $uid = $this->uid; |
|
251 | + } |
|
252 | + return is_null($uid) ? '/files_external/' : '/' . $uid . '/files_external/'; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Check if we need to re-bundle the certificates because one of the sources has updated |
|
257 | + * |
|
258 | + * @param string $uid (optional) user to get the certificate path for, use `null` to get the system path |
|
259 | + * @return bool |
|
260 | + */ |
|
261 | + private function needsRebundling($uid = '') { |
|
262 | + if ($uid === '') { |
|
263 | + $uid = $this->uid; |
|
264 | + } |
|
265 | + $sourceMTimes = [$this->getFilemtimeOfCaBundle()]; |
|
266 | + $targetBundle = $this->getCertificateBundle($uid); |
|
267 | + if (!$this->view->file_exists($targetBundle)) { |
|
268 | + return true; |
|
269 | + } |
|
270 | + |
|
271 | + if (!is_null($uid)) { // also depend on the system bundle |
|
272 | + $sourceMTimes[] = $this->view->filemtime($this->getCertificateBundle(null)); |
|
273 | + } |
|
274 | + |
|
275 | + $sourceMTime = array_reduce($sourceMTimes, function ($max, $mtime) { |
|
276 | + return max($max, $mtime); |
|
277 | + }, 0); |
|
278 | + return $sourceMTime > $this->view->filemtime($targetBundle); |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * get mtime of ca-bundle shipped by Nextcloud |
|
283 | + * |
|
284 | + * @return int |
|
285 | + */ |
|
286 | + protected function getFilemtimeOfCaBundle() { |
|
287 | + return filemtime(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); |
|
288 | + } |
|
289 | 289 | |
290 | 290 | } |
@@ -37,83 +37,83 @@ |
||
37 | 37 | * @method array fetchAll(integer $fetchMode = null); |
38 | 38 | */ |
39 | 39 | class OC_DB_StatementWrapper { |
40 | - /** |
|
41 | - * @var \Doctrine\DBAL\Driver\Statement |
|
42 | - */ |
|
43 | - private $statement = null; |
|
44 | - private $isManipulation = false; |
|
45 | - private $lastArguments = array(); |
|
40 | + /** |
|
41 | + * @var \Doctrine\DBAL\Driver\Statement |
|
42 | + */ |
|
43 | + private $statement = null; |
|
44 | + private $isManipulation = false; |
|
45 | + private $lastArguments = array(); |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param boolean $isManipulation |
|
49 | - */ |
|
50 | - public function __construct($statement, $isManipulation) { |
|
51 | - $this->statement = $statement; |
|
52 | - $this->isManipulation = $isManipulation; |
|
53 | - } |
|
47 | + /** |
|
48 | + * @param boolean $isManipulation |
|
49 | + */ |
|
50 | + public function __construct($statement, $isManipulation) { |
|
51 | + $this->statement = $statement; |
|
52 | + $this->isManipulation = $isManipulation; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
|
57 | - */ |
|
58 | - public function __call($name,$arguments) { |
|
59 | - return call_user_func_array(array($this->statement,$name), $arguments); |
|
60 | - } |
|
55 | + /** |
|
56 | + * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
|
57 | + */ |
|
58 | + public function __call($name,$arguments) { |
|
59 | + return call_user_func_array(array($this->statement,$name), $arguments); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * make execute return the result instead of a bool |
|
64 | - * |
|
65 | - * @param array $input |
|
66 | - * @return \OC_DB_StatementWrapper|int|bool |
|
67 | - */ |
|
68 | - public function execute($input= []) { |
|
69 | - $this->lastArguments = $input; |
|
70 | - if (count($input) > 0) { |
|
71 | - $result = $this->statement->execute($input); |
|
72 | - } else { |
|
73 | - $result = $this->statement->execute(); |
|
74 | - } |
|
62 | + /** |
|
63 | + * make execute return the result instead of a bool |
|
64 | + * |
|
65 | + * @param array $input |
|
66 | + * @return \OC_DB_StatementWrapper|int|bool |
|
67 | + */ |
|
68 | + public function execute($input= []) { |
|
69 | + $this->lastArguments = $input; |
|
70 | + if (count($input) > 0) { |
|
71 | + $result = $this->statement->execute($input); |
|
72 | + } else { |
|
73 | + $result = $this->statement->execute(); |
|
74 | + } |
|
75 | 75 | |
76 | - if ($result === false) { |
|
77 | - return false; |
|
78 | - } |
|
79 | - if ($this->isManipulation) { |
|
80 | - return $this->statement->rowCount(); |
|
81 | - } else { |
|
82 | - return $this; |
|
83 | - } |
|
84 | - } |
|
76 | + if ($result === false) { |
|
77 | + return false; |
|
78 | + } |
|
79 | + if ($this->isManipulation) { |
|
80 | + return $this->statement->rowCount(); |
|
81 | + } else { |
|
82 | + return $this; |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * provide an alias for fetch |
|
88 | - * |
|
89 | - * @return mixed |
|
90 | - */ |
|
91 | - public function fetchRow() { |
|
92 | - return $this->statement->fetch(); |
|
93 | - } |
|
86 | + /** |
|
87 | + * provide an alias for fetch |
|
88 | + * |
|
89 | + * @return mixed |
|
90 | + */ |
|
91 | + public function fetchRow() { |
|
92 | + return $this->statement->fetch(); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Provide a simple fetchOne. |
|
97 | - * |
|
98 | - * fetch single column from the next row |
|
99 | - * @param int $column the column number to fetch |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function fetchOne($column = 0) { |
|
103 | - return $this->statement->fetchColumn($column); |
|
104 | - } |
|
95 | + /** |
|
96 | + * Provide a simple fetchOne. |
|
97 | + * |
|
98 | + * fetch single column from the next row |
|
99 | + * @param int $column the column number to fetch |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function fetchOne($column = 0) { |
|
103 | + return $this->statement->fetchColumn($column); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Binds a PHP variable to a corresponding named or question mark placeholder in the |
|
108 | - * SQL statement that was use to prepare the statement. |
|
109 | - * |
|
110 | - * @param mixed $column Either the placeholder name or the 1-indexed placeholder index |
|
111 | - * @param mixed $variable The variable to bind |
|
112 | - * @param integer|null $type one of the PDO::PARAM_* constants |
|
113 | - * @param integer|null $length max length when using an OUT bind |
|
114 | - * @return boolean |
|
115 | - */ |
|
116 | - public function bindParam($column, &$variable, $type = null, $length = null){ |
|
117 | - return $this->statement->bindParam($column, $variable, $type, $length); |
|
118 | - } |
|
106 | + /** |
|
107 | + * Binds a PHP variable to a corresponding named or question mark placeholder in the |
|
108 | + * SQL statement that was use to prepare the statement. |
|
109 | + * |
|
110 | + * @param mixed $column Either the placeholder name or the 1-indexed placeholder index |
|
111 | + * @param mixed $variable The variable to bind |
|
112 | + * @param integer|null $type one of the PDO::PARAM_* constants |
|
113 | + * @param integer|null $length max length when using an OUT bind |
|
114 | + * @return boolean |
|
115 | + */ |
|
116 | + public function bindParam($column, &$variable, $type = null, $length = null){ |
|
117 | + return $this->statement->bindParam($column, $variable, $type, $length); |
|
118 | + } |
|
119 | 119 | } |
@@ -33,193 +33,193 @@ |
||
33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
34 | 34 | |
35 | 35 | class Import extends Command implements CompletionAwareInterface { |
36 | - protected $validRootKeys = ['system', 'apps']; |
|
37 | - |
|
38 | - /** @var IConfig */ |
|
39 | - protected $config; |
|
40 | - |
|
41 | - /** |
|
42 | - * @param IConfig $config |
|
43 | - */ |
|
44 | - public function __construct(IConfig $config) { |
|
45 | - parent::__construct(); |
|
46 | - $this->config = $config; |
|
47 | - } |
|
48 | - |
|
49 | - protected function configure() { |
|
50 | - $this |
|
51 | - ->setName('config:import') |
|
52 | - ->setDescription('Import a list of configs') |
|
53 | - ->addArgument( |
|
54 | - 'file', |
|
55 | - InputArgument::OPTIONAL, |
|
56 | - 'File with the json array to import' |
|
57 | - ) |
|
58 | - ; |
|
59 | - } |
|
60 | - |
|
61 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
62 | - $importFile = $input->getArgument('file'); |
|
63 | - if ($importFile !== null) { |
|
64 | - $content = $this->getArrayFromFile($importFile); |
|
65 | - } else { |
|
66 | - $content = $this->getArrayFromStdin(); |
|
67 | - } |
|
68 | - |
|
69 | - try { |
|
70 | - $configs = $this->validateFileContent($content); |
|
71 | - } catch (\UnexpectedValueException $e) { |
|
72 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if (!empty($configs['system'])) { |
|
77 | - $this->config->setSystemValues($configs['system']); |
|
78 | - } |
|
79 | - |
|
80 | - if (!empty($configs['apps'])) { |
|
81 | - foreach ($configs['apps'] as $app => $appConfigs) { |
|
82 | - foreach ($appConfigs as $key => $value) { |
|
83 | - if ($value === null) { |
|
84 | - $this->config->deleteAppValue($app, $key); |
|
85 | - } else { |
|
86 | - $this->config->setAppValue($app, $key, $value); |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - $output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>'); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the content from stdin ("config:import < file.json") |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - protected function getArrayFromStdin() { |
|
101 | - // Read from stdin. stream_set_blocking is used to prevent blocking |
|
102 | - // when nothing is passed via stdin. |
|
103 | - stream_set_blocking(STDIN, 0); |
|
104 | - $content = file_get_contents('php://stdin'); |
|
105 | - stream_set_blocking(STDIN, 1); |
|
106 | - return $content; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get the content of the specified file ("config:import file.json") |
|
111 | - * |
|
112 | - * @param string $importFile |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - protected function getArrayFromFile($importFile) { |
|
116 | - return file_get_contents($importFile); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param string $content |
|
121 | - * @return array |
|
122 | - * @throws \UnexpectedValueException when the array is invalid |
|
123 | - */ |
|
124 | - protected function validateFileContent($content) { |
|
125 | - $decodedContent = json_decode($content, true); |
|
126 | - if (!is_array($decodedContent) || empty($decodedContent)) { |
|
127 | - throw new \UnexpectedValueException('The file must contain a valid json array'); |
|
128 | - } |
|
129 | - |
|
130 | - $this->validateArray($decodedContent); |
|
131 | - |
|
132 | - return $decodedContent; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Validates that the array only contains `system` and `apps` |
|
137 | - * |
|
138 | - * @param array $array |
|
139 | - */ |
|
140 | - protected function validateArray($array) { |
|
141 | - $arrayKeys = array_keys($array); |
|
142 | - $additionalKeys = array_diff($arrayKeys, $this->validRootKeys); |
|
143 | - $commonKeys = array_intersect($arrayKeys, $this->validRootKeys); |
|
144 | - if (!empty($additionalKeys)) { |
|
145 | - throw new \UnexpectedValueException('Found invalid entries in root: ' . implode(', ', $additionalKeys)); |
|
146 | - } |
|
147 | - if (empty($commonKeys)) { |
|
148 | - throw new \UnexpectedValueException('At least one key of the following is expected: ' . implode(', ', $this->validRootKeys)); |
|
149 | - } |
|
150 | - |
|
151 | - if (isset($array['system'])) { |
|
152 | - if (is_array($array['system'])) { |
|
153 | - foreach ($array['system'] as $name => $value) { |
|
154 | - $this->checkTypeRecursively($value, $name); |
|
155 | - } |
|
156 | - } else { |
|
157 | - throw new \UnexpectedValueException('The system config array is not an array'); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - if (isset($array['apps'])) { |
|
162 | - if (is_array($array['apps'])) { |
|
163 | - $this->validateAppsArray($array['apps']); |
|
164 | - } else { |
|
165 | - throw new \UnexpectedValueException('The apps config array is not an array'); |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param mixed $configValue |
|
172 | - * @param string $configName |
|
173 | - */ |
|
174 | - protected function checkTypeRecursively($configValue, $configName) { |
|
175 | - if (!is_array($configValue) && !is_bool($configValue) && !is_int($configValue) && !is_string($configValue) && !is_null($configValue)) { |
|
176 | - throw new \UnexpectedValueException('Invalid system config value for "' . $configName . '". Only arrays, bools, integers, strings and null (delete) are allowed.'); |
|
177 | - } |
|
178 | - if (is_array($configValue)) { |
|
179 | - foreach ($configValue as $key => $value) { |
|
180 | - $this->checkTypeRecursively($value, $configName); |
|
181 | - } |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Validates that app configs are only integers and strings |
|
187 | - * |
|
188 | - * @param array $array |
|
189 | - */ |
|
190 | - protected function validateAppsArray($array) { |
|
191 | - foreach ($array as $app => $configs) { |
|
192 | - foreach ($configs as $name => $value) { |
|
193 | - if (!is_int($value) && !is_string($value) && !is_null($value)) { |
|
194 | - throw new \UnexpectedValueException('Invalid app config value for "' . $app . '":"' . $name . '". Only integers, strings and null (delete) are allowed.'); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $optionName |
|
202 | - * @param CompletionContext $context |
|
203 | - * @return string[] |
|
204 | - */ |
|
205 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
206 | - return []; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @param string $argumentName |
|
211 | - * @param CompletionContext $context |
|
212 | - * @return string[] |
|
213 | - */ |
|
214 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
215 | - if ($argumentName === 'file') { |
|
216 | - $helper = new ShellPathCompletion( |
|
217 | - $this->getName(), |
|
218 | - 'file', |
|
219 | - Completion::TYPE_ARGUMENT |
|
220 | - ); |
|
221 | - return $helper->run(); |
|
222 | - } |
|
223 | - return []; |
|
224 | - } |
|
36 | + protected $validRootKeys = ['system', 'apps']; |
|
37 | + |
|
38 | + /** @var IConfig */ |
|
39 | + protected $config; |
|
40 | + |
|
41 | + /** |
|
42 | + * @param IConfig $config |
|
43 | + */ |
|
44 | + public function __construct(IConfig $config) { |
|
45 | + parent::__construct(); |
|
46 | + $this->config = $config; |
|
47 | + } |
|
48 | + |
|
49 | + protected function configure() { |
|
50 | + $this |
|
51 | + ->setName('config:import') |
|
52 | + ->setDescription('Import a list of configs') |
|
53 | + ->addArgument( |
|
54 | + 'file', |
|
55 | + InputArgument::OPTIONAL, |
|
56 | + 'File with the json array to import' |
|
57 | + ) |
|
58 | + ; |
|
59 | + } |
|
60 | + |
|
61 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
62 | + $importFile = $input->getArgument('file'); |
|
63 | + if ($importFile !== null) { |
|
64 | + $content = $this->getArrayFromFile($importFile); |
|
65 | + } else { |
|
66 | + $content = $this->getArrayFromStdin(); |
|
67 | + } |
|
68 | + |
|
69 | + try { |
|
70 | + $configs = $this->validateFileContent($content); |
|
71 | + } catch (\UnexpectedValueException $e) { |
|
72 | + $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if (!empty($configs['system'])) { |
|
77 | + $this->config->setSystemValues($configs['system']); |
|
78 | + } |
|
79 | + |
|
80 | + if (!empty($configs['apps'])) { |
|
81 | + foreach ($configs['apps'] as $app => $appConfigs) { |
|
82 | + foreach ($appConfigs as $key => $value) { |
|
83 | + if ($value === null) { |
|
84 | + $this->config->deleteAppValue($app, $key); |
|
85 | + } else { |
|
86 | + $this->config->setAppValue($app, $key, $value); |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + $output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>'); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the content from stdin ("config:import < file.json") |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + protected function getArrayFromStdin() { |
|
101 | + // Read from stdin. stream_set_blocking is used to prevent blocking |
|
102 | + // when nothing is passed via stdin. |
|
103 | + stream_set_blocking(STDIN, 0); |
|
104 | + $content = file_get_contents('php://stdin'); |
|
105 | + stream_set_blocking(STDIN, 1); |
|
106 | + return $content; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get the content of the specified file ("config:import file.json") |
|
111 | + * |
|
112 | + * @param string $importFile |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + protected function getArrayFromFile($importFile) { |
|
116 | + return file_get_contents($importFile); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param string $content |
|
121 | + * @return array |
|
122 | + * @throws \UnexpectedValueException when the array is invalid |
|
123 | + */ |
|
124 | + protected function validateFileContent($content) { |
|
125 | + $decodedContent = json_decode($content, true); |
|
126 | + if (!is_array($decodedContent) || empty($decodedContent)) { |
|
127 | + throw new \UnexpectedValueException('The file must contain a valid json array'); |
|
128 | + } |
|
129 | + |
|
130 | + $this->validateArray($decodedContent); |
|
131 | + |
|
132 | + return $decodedContent; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Validates that the array only contains `system` and `apps` |
|
137 | + * |
|
138 | + * @param array $array |
|
139 | + */ |
|
140 | + protected function validateArray($array) { |
|
141 | + $arrayKeys = array_keys($array); |
|
142 | + $additionalKeys = array_diff($arrayKeys, $this->validRootKeys); |
|
143 | + $commonKeys = array_intersect($arrayKeys, $this->validRootKeys); |
|
144 | + if (!empty($additionalKeys)) { |
|
145 | + throw new \UnexpectedValueException('Found invalid entries in root: ' . implode(', ', $additionalKeys)); |
|
146 | + } |
|
147 | + if (empty($commonKeys)) { |
|
148 | + throw new \UnexpectedValueException('At least one key of the following is expected: ' . implode(', ', $this->validRootKeys)); |
|
149 | + } |
|
150 | + |
|
151 | + if (isset($array['system'])) { |
|
152 | + if (is_array($array['system'])) { |
|
153 | + foreach ($array['system'] as $name => $value) { |
|
154 | + $this->checkTypeRecursively($value, $name); |
|
155 | + } |
|
156 | + } else { |
|
157 | + throw new \UnexpectedValueException('The system config array is not an array'); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + if (isset($array['apps'])) { |
|
162 | + if (is_array($array['apps'])) { |
|
163 | + $this->validateAppsArray($array['apps']); |
|
164 | + } else { |
|
165 | + throw new \UnexpectedValueException('The apps config array is not an array'); |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param mixed $configValue |
|
172 | + * @param string $configName |
|
173 | + */ |
|
174 | + protected function checkTypeRecursively($configValue, $configName) { |
|
175 | + if (!is_array($configValue) && !is_bool($configValue) && !is_int($configValue) && !is_string($configValue) && !is_null($configValue)) { |
|
176 | + throw new \UnexpectedValueException('Invalid system config value for "' . $configName . '". Only arrays, bools, integers, strings and null (delete) are allowed.'); |
|
177 | + } |
|
178 | + if (is_array($configValue)) { |
|
179 | + foreach ($configValue as $key => $value) { |
|
180 | + $this->checkTypeRecursively($value, $configName); |
|
181 | + } |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Validates that app configs are only integers and strings |
|
187 | + * |
|
188 | + * @param array $array |
|
189 | + */ |
|
190 | + protected function validateAppsArray($array) { |
|
191 | + foreach ($array as $app => $configs) { |
|
192 | + foreach ($configs as $name => $value) { |
|
193 | + if (!is_int($value) && !is_string($value) && !is_null($value)) { |
|
194 | + throw new \UnexpectedValueException('Invalid app config value for "' . $app . '":"' . $name . '". Only integers, strings and null (delete) are allowed.'); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $optionName |
|
202 | + * @param CompletionContext $context |
|
203 | + * @return string[] |
|
204 | + */ |
|
205 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
206 | + return []; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @param string $argumentName |
|
211 | + * @param CompletionContext $context |
|
212 | + * @return string[] |
|
213 | + */ |
|
214 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
215 | + if ($argumentName === 'file') { |
|
216 | + $helper = new ShellPathCompletion( |
|
217 | + $this->getName(), |
|
218 | + 'file', |
|
219 | + Completion::TYPE_ARGUMENT |
|
220 | + ); |
|
221 | + return $helper->run(); |
|
222 | + } |
|
223 | + return []; |
|
224 | + } |
|
225 | 225 | } |
@@ -29,56 +29,56 @@ |
||
29 | 29 | * @package OC\App\AppStore |
30 | 30 | */ |
31 | 31 | class VersionParser { |
32 | - /** |
|
33 | - * @param string $versionString |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - private function isValidVersionString($versionString) { |
|
37 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
38 | - } |
|
32 | + /** |
|
33 | + * @param string $versionString |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + private function isValidVersionString($versionString) { |
|
37 | + return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Returns the version for a version string |
|
42 | - * |
|
43 | - * @param string $versionSpec |
|
44 | - * @return Version |
|
45 | - * @throws \Exception If the version cannot be parsed |
|
46 | - */ |
|
47 | - public function getVersion($versionSpec) { |
|
48 | - // * indicates that the version is compatible with all versions |
|
49 | - if($versionSpec === '*') { |
|
50 | - return new Version('', ''); |
|
51 | - } |
|
40 | + /** |
|
41 | + * Returns the version for a version string |
|
42 | + * |
|
43 | + * @param string $versionSpec |
|
44 | + * @return Version |
|
45 | + * @throws \Exception If the version cannot be parsed |
|
46 | + */ |
|
47 | + public function getVersion($versionSpec) { |
|
48 | + // * indicates that the version is compatible with all versions |
|
49 | + if($versionSpec === '*') { |
|
50 | + return new Version('', ''); |
|
51 | + } |
|
52 | 52 | |
53 | - // Count the amount of =, if it is one then it's either maximum or minimum |
|
54 | - // version. If it is two then it is maximum and minimum. |
|
55 | - $versionElements = explode(' ', $versionSpec); |
|
56 | - $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
57 | - $firstVersionNumber = substr($firstVersion, 2); |
|
58 | - $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
59 | - $secondVersionNumber = substr($secondVersion, 2); |
|
53 | + // Count the amount of =, if it is one then it's either maximum or minimum |
|
54 | + // version. If it is two then it is maximum and minimum. |
|
55 | + $versionElements = explode(' ', $versionSpec); |
|
56 | + $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
57 | + $firstVersionNumber = substr($firstVersion, 2); |
|
58 | + $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
59 | + $secondVersionNumber = substr($secondVersion, 2); |
|
60 | 60 | |
61 | - switch(count($versionElements)) { |
|
62 | - case 1: |
|
63 | - if(!$this->isValidVersionString($firstVersionNumber)) { |
|
64 | - break; |
|
65 | - } |
|
66 | - if(strpos($firstVersion, '>') === 0) { |
|
67 | - return new Version($firstVersionNumber, ''); |
|
68 | - } |
|
69 | - return new Version('', $firstVersionNumber); |
|
70 | - case 2: |
|
71 | - if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
72 | - break; |
|
73 | - } |
|
74 | - return new Version($firstVersionNumber, $secondVersionNumber); |
|
75 | - } |
|
61 | + switch(count($versionElements)) { |
|
62 | + case 1: |
|
63 | + if(!$this->isValidVersionString($firstVersionNumber)) { |
|
64 | + break; |
|
65 | + } |
|
66 | + if(strpos($firstVersion, '>') === 0) { |
|
67 | + return new Version($firstVersionNumber, ''); |
|
68 | + } |
|
69 | + return new Version('', $firstVersionNumber); |
|
70 | + case 2: |
|
71 | + if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
72 | + break; |
|
73 | + } |
|
74 | + return new Version($firstVersionNumber, $secondVersionNumber); |
|
75 | + } |
|
76 | 76 | |
77 | - throw new \Exception( |
|
78 | - sprintf( |
|
79 | - 'Version cannot be parsed: %s', |
|
80 | - $versionSpec |
|
81 | - ) |
|
82 | - ); |
|
83 | - } |
|
77 | + throw new \Exception( |
|
78 | + sprintf( |
|
79 | + 'Version cannot be parsed: %s', |
|
80 | + $versionSpec |
|
81 | + ) |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -37,167 +37,167 @@ |
||
37 | 37 | |
38 | 38 | class Plugin extends ServerPlugin { |
39 | 39 | |
40 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
41 | - const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
42 | - |
|
43 | - /** @var Auth */ |
|
44 | - private $auth; |
|
45 | - |
|
46 | - /** @var IRequest */ |
|
47 | - private $request; |
|
48 | - |
|
49 | - /** |
|
50 | - * Plugin constructor. |
|
51 | - * |
|
52 | - * @param Auth $authBackEnd |
|
53 | - * @param IRequest $request |
|
54 | - */ |
|
55 | - public function __construct(Auth $authBackEnd, IRequest $request) { |
|
56 | - $this->auth = $authBackEnd; |
|
57 | - $this->request = $request; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Reference to SabreDAV server object. |
|
62 | - * |
|
63 | - * @var \Sabre\DAV\Server |
|
64 | - */ |
|
65 | - protected $server; |
|
66 | - |
|
67 | - /** |
|
68 | - * This method should return a list of server-features. |
|
69 | - * |
|
70 | - * This is for example 'versioning' and is added to the DAV: header |
|
71 | - * in an OPTIONS response. |
|
72 | - * |
|
73 | - * @return string[] |
|
74 | - */ |
|
75 | - function getFeatures() { |
|
76 | - return ['oc-resource-sharing']; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Returns a plugin name. |
|
81 | - * |
|
82 | - * Using this name other plugins will be able to access other plugins |
|
83 | - * using Sabre\DAV\Server::getPlugin |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - function getPluginName() { |
|
88 | - return 'oc-resource-sharing'; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * This initializes the plugin. |
|
93 | - * |
|
94 | - * This function is called by Sabre\DAV\Server, after |
|
95 | - * addPlugin is called. |
|
96 | - * |
|
97 | - * This method should set up the required event subscriptions. |
|
98 | - * |
|
99 | - * @param Server $server |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - function initialize(Server $server) { |
|
103 | - $this->server = $server; |
|
104 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
105 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
106 | - |
|
107 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
108 | - $this->server->on('propFind', [$this, 'propFind']); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * We intercept this to handle POST requests on a dav resource. |
|
113 | - * |
|
114 | - * @param RequestInterface $request |
|
115 | - * @param ResponseInterface $response |
|
116 | - * @return null|false |
|
117 | - */ |
|
118 | - function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
119 | - |
|
120 | - $path = $request->getPath(); |
|
121 | - |
|
122 | - // Only handling xml |
|
123 | - $contentType = $request->getHeader('Content-Type'); |
|
124 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
125 | - return; |
|
126 | - |
|
127 | - // Making sure the node exists |
|
128 | - try { |
|
129 | - $node = $this->server->tree->getNodeForPath($path); |
|
130 | - } catch (NotFound $e) { |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - $requestBody = $request->getBodyAsString(); |
|
135 | - |
|
136 | - // If this request handler could not deal with this POST request, it |
|
137 | - // will return 'null' and other plugins get a chance to handle the |
|
138 | - // request. |
|
139 | - // |
|
140 | - // However, we already requested the full body. This is a problem, |
|
141 | - // because a body can only be read once. This is why we preemptively |
|
142 | - // re-populated the request body with the existing data. |
|
143 | - $request->setBody($requestBody); |
|
144 | - |
|
145 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
146 | - |
|
147 | - switch ($documentType) { |
|
148 | - |
|
149 | - // Dealing with the 'share' document, which modified invitees on a |
|
150 | - // calendar. |
|
151 | - case '{' . self::NS_OWNCLOUD . '}share' : |
|
152 | - |
|
153 | - // We can only deal with IShareableCalendar objects |
|
154 | - if (!$node instanceof IShareable) { |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - $this->server->transactionType = 'post-oc-resource-share'; |
|
159 | - |
|
160 | - // Getting ACL info |
|
161 | - $acl = $this->server->getPlugin('acl'); |
|
162 | - |
|
163 | - // If there's no ACL support, we allow everything |
|
164 | - if ($acl) { |
|
165 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
166 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
167 | - } |
|
168 | - |
|
169 | - $node->updateShares($message->set, $message->remove); |
|
170 | - |
|
171 | - $response->setStatus(200); |
|
172 | - // Adding this because sending a response body may cause issues, |
|
173 | - // and I wanted some type of indicator the response was handled. |
|
174 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
175 | - |
|
176 | - // Breaking the event chain |
|
177 | - return false; |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * This event is triggered when properties are requested for a certain |
|
183 | - * node. |
|
184 | - * |
|
185 | - * This allows us to inject any properties early. |
|
186 | - * |
|
187 | - * @param PropFind $propFind |
|
188 | - * @param INode $node |
|
189 | - * @return void |
|
190 | - */ |
|
191 | - function propFind(PropFind $propFind, INode $node) { |
|
192 | - if ($node instanceof IShareable) { |
|
193 | - |
|
194 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
195 | - return new Invite( |
|
196 | - $node->getShares() |
|
197 | - ); |
|
198 | - }); |
|
199 | - |
|
200 | - } |
|
201 | - } |
|
40 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
41 | + const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
42 | + |
|
43 | + /** @var Auth */ |
|
44 | + private $auth; |
|
45 | + |
|
46 | + /** @var IRequest */ |
|
47 | + private $request; |
|
48 | + |
|
49 | + /** |
|
50 | + * Plugin constructor. |
|
51 | + * |
|
52 | + * @param Auth $authBackEnd |
|
53 | + * @param IRequest $request |
|
54 | + */ |
|
55 | + public function __construct(Auth $authBackEnd, IRequest $request) { |
|
56 | + $this->auth = $authBackEnd; |
|
57 | + $this->request = $request; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Reference to SabreDAV server object. |
|
62 | + * |
|
63 | + * @var \Sabre\DAV\Server |
|
64 | + */ |
|
65 | + protected $server; |
|
66 | + |
|
67 | + /** |
|
68 | + * This method should return a list of server-features. |
|
69 | + * |
|
70 | + * This is for example 'versioning' and is added to the DAV: header |
|
71 | + * in an OPTIONS response. |
|
72 | + * |
|
73 | + * @return string[] |
|
74 | + */ |
|
75 | + function getFeatures() { |
|
76 | + return ['oc-resource-sharing']; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Returns a plugin name. |
|
81 | + * |
|
82 | + * Using this name other plugins will be able to access other plugins |
|
83 | + * using Sabre\DAV\Server::getPlugin |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + function getPluginName() { |
|
88 | + return 'oc-resource-sharing'; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * This initializes the plugin. |
|
93 | + * |
|
94 | + * This function is called by Sabre\DAV\Server, after |
|
95 | + * addPlugin is called. |
|
96 | + * |
|
97 | + * This method should set up the required event subscriptions. |
|
98 | + * |
|
99 | + * @param Server $server |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + function initialize(Server $server) { |
|
103 | + $this->server = $server; |
|
104 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
105 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
106 | + |
|
107 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
108 | + $this->server->on('propFind', [$this, 'propFind']); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * We intercept this to handle POST requests on a dav resource. |
|
113 | + * |
|
114 | + * @param RequestInterface $request |
|
115 | + * @param ResponseInterface $response |
|
116 | + * @return null|false |
|
117 | + */ |
|
118 | + function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
119 | + |
|
120 | + $path = $request->getPath(); |
|
121 | + |
|
122 | + // Only handling xml |
|
123 | + $contentType = $request->getHeader('Content-Type'); |
|
124 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
125 | + return; |
|
126 | + |
|
127 | + // Making sure the node exists |
|
128 | + try { |
|
129 | + $node = $this->server->tree->getNodeForPath($path); |
|
130 | + } catch (NotFound $e) { |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + $requestBody = $request->getBodyAsString(); |
|
135 | + |
|
136 | + // If this request handler could not deal with this POST request, it |
|
137 | + // will return 'null' and other plugins get a chance to handle the |
|
138 | + // request. |
|
139 | + // |
|
140 | + // However, we already requested the full body. This is a problem, |
|
141 | + // because a body can only be read once. This is why we preemptively |
|
142 | + // re-populated the request body with the existing data. |
|
143 | + $request->setBody($requestBody); |
|
144 | + |
|
145 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
146 | + |
|
147 | + switch ($documentType) { |
|
148 | + |
|
149 | + // Dealing with the 'share' document, which modified invitees on a |
|
150 | + // calendar. |
|
151 | + case '{' . self::NS_OWNCLOUD . '}share' : |
|
152 | + |
|
153 | + // We can only deal with IShareableCalendar objects |
|
154 | + if (!$node instanceof IShareable) { |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + $this->server->transactionType = 'post-oc-resource-share'; |
|
159 | + |
|
160 | + // Getting ACL info |
|
161 | + $acl = $this->server->getPlugin('acl'); |
|
162 | + |
|
163 | + // If there's no ACL support, we allow everything |
|
164 | + if ($acl) { |
|
165 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
166 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
167 | + } |
|
168 | + |
|
169 | + $node->updateShares($message->set, $message->remove); |
|
170 | + |
|
171 | + $response->setStatus(200); |
|
172 | + // Adding this because sending a response body may cause issues, |
|
173 | + // and I wanted some type of indicator the response was handled. |
|
174 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
175 | + |
|
176 | + // Breaking the event chain |
|
177 | + return false; |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * This event is triggered when properties are requested for a certain |
|
183 | + * node. |
|
184 | + * |
|
185 | + * This allows us to inject any properties early. |
|
186 | + * |
|
187 | + * @param PropFind $propFind |
|
188 | + * @param INode $node |
|
189 | + * @return void |
|
190 | + */ |
|
191 | + function propFind(PropFind $propFind, INode $node) { |
|
192 | + if ($node instanceof IShareable) { |
|
193 | + |
|
194 | + $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
195 | + return new Invite( |
|
196 | + $node->getShares() |
|
197 | + ); |
|
198 | + }); |
|
199 | + |
|
200 | + } |
|
201 | + } |
|
202 | 202 | |
203 | 203 | } |
@@ -39,84 +39,84 @@ |
||
39 | 39 | use OCP\IUserSession; |
40 | 40 | |
41 | 41 | class AjaxController extends Controller { |
42 | - /** @var RSA */ |
|
43 | - private $rsaMechanism; |
|
44 | - /** @var GlobalAuth */ |
|
45 | - private $globalAuth; |
|
46 | - /** @var IUserSession */ |
|
47 | - private $userSession; |
|
48 | - /** @var IGroupManager */ |
|
49 | - private $groupManager; |
|
42 | + /** @var RSA */ |
|
43 | + private $rsaMechanism; |
|
44 | + /** @var GlobalAuth */ |
|
45 | + private $globalAuth; |
|
46 | + /** @var IUserSession */ |
|
47 | + private $userSession; |
|
48 | + /** @var IGroupManager */ |
|
49 | + private $groupManager; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $appName |
|
53 | - * @param IRequest $request |
|
54 | - * @param RSA $rsaMechanism |
|
55 | - * @param GlobalAuth $globalAuth |
|
56 | - * @param IUserSession $userSession |
|
57 | - * @param IGroupManager $groupManager |
|
58 | - */ |
|
59 | - public function __construct($appName, |
|
60 | - IRequest $request, |
|
61 | - RSA $rsaMechanism, |
|
62 | - GlobalAuth $globalAuth, |
|
63 | - IUserSession $userSession, |
|
64 | - IGroupManager $groupManager) { |
|
65 | - parent::__construct($appName, $request); |
|
66 | - $this->rsaMechanism = $rsaMechanism; |
|
67 | - $this->globalAuth = $globalAuth; |
|
68 | - $this->userSession = $userSession; |
|
69 | - $this->groupManager = $groupManager; |
|
70 | - } |
|
51 | + /** |
|
52 | + * @param string $appName |
|
53 | + * @param IRequest $request |
|
54 | + * @param RSA $rsaMechanism |
|
55 | + * @param GlobalAuth $globalAuth |
|
56 | + * @param IUserSession $userSession |
|
57 | + * @param IGroupManager $groupManager |
|
58 | + */ |
|
59 | + public function __construct($appName, |
|
60 | + IRequest $request, |
|
61 | + RSA $rsaMechanism, |
|
62 | + GlobalAuth $globalAuth, |
|
63 | + IUserSession $userSession, |
|
64 | + IGroupManager $groupManager) { |
|
65 | + parent::__construct($appName, $request); |
|
66 | + $this->rsaMechanism = $rsaMechanism; |
|
67 | + $this->globalAuth = $globalAuth; |
|
68 | + $this->userSession = $userSession; |
|
69 | + $this->groupManager = $groupManager; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param int $keyLength |
|
74 | - * @return array |
|
75 | - */ |
|
76 | - private function generateSshKeys($keyLength) { |
|
77 | - $key = $this->rsaMechanism->createKey($keyLength); |
|
78 | - // Replace the placeholder label with a more meaningful one |
|
79 | - $key['publickey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']); |
|
72 | + /** |
|
73 | + * @param int $keyLength |
|
74 | + * @return array |
|
75 | + */ |
|
76 | + private function generateSshKeys($keyLength) { |
|
77 | + $key = $this->rsaMechanism->createKey($keyLength); |
|
78 | + // Replace the placeholder label with a more meaningful one |
|
79 | + $key['publickey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']); |
|
80 | 80 | |
81 | - return $key; |
|
82 | - } |
|
81 | + return $key; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Generates an SSH public/private key pair. |
|
86 | - * |
|
87 | - * @NoAdminRequired |
|
88 | - * @param int $keyLength |
|
89 | - */ |
|
90 | - public function getSshKeys($keyLength = 1024) { |
|
91 | - $key = $this->generateSshKeys($keyLength); |
|
92 | - return new JSONResponse( |
|
93 | - array('data' => array( |
|
94 | - 'private_key' => $key['privatekey'], |
|
95 | - 'public_key' => $key['publickey'] |
|
96 | - ), |
|
97 | - 'status' => 'success' |
|
98 | - )); |
|
99 | - } |
|
84 | + /** |
|
85 | + * Generates an SSH public/private key pair. |
|
86 | + * |
|
87 | + * @NoAdminRequired |
|
88 | + * @param int $keyLength |
|
89 | + */ |
|
90 | + public function getSshKeys($keyLength = 1024) { |
|
91 | + $key = $this->generateSshKeys($keyLength); |
|
92 | + return new JSONResponse( |
|
93 | + array('data' => array( |
|
94 | + 'private_key' => $key['privatekey'], |
|
95 | + 'public_key' => $key['publickey'] |
|
96 | + ), |
|
97 | + 'status' => 'success' |
|
98 | + )); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @NoAdminRequired |
|
103 | - * |
|
104 | - * @param string $uid |
|
105 | - * @param string $user |
|
106 | - * @param string $password |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - public function saveGlobalCredentials($uid, $user, $password) { |
|
110 | - $currentUser = $this->userSession->getUser(); |
|
101 | + /** |
|
102 | + * @NoAdminRequired |
|
103 | + * |
|
104 | + * @param string $uid |
|
105 | + * @param string $user |
|
106 | + * @param string $password |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + public function saveGlobalCredentials($uid, $user, $password) { |
|
110 | + $currentUser = $this->userSession->getUser(); |
|
111 | 111 | |
112 | - // Non-admins can only edit their own credentials |
|
113 | - $allowedToEdit = ($this->groupManager->isAdmin($currentUser->getUID()) || $currentUser->getUID() === $uid); |
|
112 | + // Non-admins can only edit their own credentials |
|
113 | + $allowedToEdit = ($this->groupManager->isAdmin($currentUser->getUID()) || $currentUser->getUID() === $uid); |
|
114 | 114 | |
115 | - if ($allowedToEdit) { |
|
116 | - $this->globalAuth->saveAuth($uid, $user, $password); |
|
117 | - return true; |
|
118 | - } else { |
|
119 | - return false; |
|
120 | - } |
|
121 | - } |
|
115 | + if ($allowedToEdit) { |
|
116 | + $this->globalAuth->saveAuth($uid, $user, $password); |
|
117 | + return true; |
|
118 | + } else { |
|
119 | + return false; |
|
120 | + } |
|
121 | + } |
|
122 | 122 | } |
@@ -31,151 +31,151 @@ |
||
31 | 31 | use OCP\IMemcacheTTL; |
32 | 32 | |
33 | 33 | class Redis extends Cache implements IMemcacheTTL { |
34 | - /** |
|
35 | - * @var \Redis $cache |
|
36 | - */ |
|
37 | - private static $cache = null; |
|
38 | - |
|
39 | - public function __construct($prefix = '') { |
|
40 | - parent::__construct($prefix); |
|
41 | - if (is_null(self::$cache)) { |
|
42 | - self::$cache = \OC::$server->getGetRedisFactory()->getInstance(); |
|
43 | - } |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * entries in redis get namespaced to prevent collisions between ownCloud instances and users |
|
48 | - */ |
|
49 | - protected function getNameSpace() { |
|
50 | - return $this->prefix; |
|
51 | - } |
|
52 | - |
|
53 | - public function get($key) { |
|
54 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
55 | - if ($result === false && !self::$cache->exists($this->getNameSpace() . $key)) { |
|
56 | - return null; |
|
57 | - } else { |
|
58 | - return json_decode($result, true); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - public function set($key, $value, $ttl = 0) { |
|
63 | - if ($ttl > 0) { |
|
64 | - return self::$cache->setex($this->getNameSpace() . $key, $ttl, json_encode($value)); |
|
65 | - } else { |
|
66 | - return self::$cache->set($this->getNameSpace() . $key, json_encode($value)); |
|
67 | - } |
|
68 | - } |
|
69 | - |
|
70 | - public function hasKey($key) { |
|
71 | - return self::$cache->exists($this->getNameSpace() . $key); |
|
72 | - } |
|
73 | - |
|
74 | - public function remove($key) { |
|
75 | - if (self::$cache->del($this->getNameSpace() . $key)) { |
|
76 | - return true; |
|
77 | - } else { |
|
78 | - return false; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - public function clear($prefix = '') { |
|
83 | - $prefix = $this->getNameSpace() . $prefix . '*'; |
|
84 | - $keys = self::$cache->keys($prefix); |
|
85 | - $deleted = self::$cache->del($keys); |
|
86 | - |
|
87 | - return count($keys) === $deleted; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Set a value in the cache if it's not already stored |
|
92 | - * |
|
93 | - * @param string $key |
|
94 | - * @param mixed $value |
|
95 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
96 | - * @return bool |
|
97 | - */ |
|
98 | - public function add($key, $value, $ttl = 0) { |
|
99 | - // don't encode ints for inc/dec |
|
100 | - if (!is_int($value)) { |
|
101 | - $value = json_encode($value); |
|
102 | - } |
|
103 | - return self::$cache->setnx($this->getPrefix() . $key, $value); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Increase a stored number |
|
108 | - * |
|
109 | - * @param string $key |
|
110 | - * @param int $step |
|
111 | - * @return int | bool |
|
112 | - */ |
|
113 | - public function inc($key, $step = 1) { |
|
114 | - return self::$cache->incrBy($this->getNameSpace() . $key, $step); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Decrease a stored number |
|
119 | - * |
|
120 | - * @param string $key |
|
121 | - * @param int $step |
|
122 | - * @return int | bool |
|
123 | - */ |
|
124 | - public function dec($key, $step = 1) { |
|
125 | - if (!$this->hasKey($key)) { |
|
126 | - return false; |
|
127 | - } |
|
128 | - return self::$cache->decrBy($this->getNameSpace() . $key, $step); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Compare and set |
|
133 | - * |
|
134 | - * @param string $key |
|
135 | - * @param mixed $old |
|
136 | - * @param mixed $new |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - public function cas($key, $old, $new) { |
|
140 | - if (!is_int($new)) { |
|
141 | - $new = json_encode($new); |
|
142 | - } |
|
143 | - self::$cache->watch($this->getNameSpace() . $key); |
|
144 | - if ($this->get($key) === $old) { |
|
145 | - $result = self::$cache->multi() |
|
146 | - ->set($this->getNameSpace() . $key, $new) |
|
147 | - ->exec(); |
|
148 | - return $result !== false; |
|
149 | - } |
|
150 | - self::$cache->unwatch(); |
|
151 | - return false; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Compare and delete |
|
156 | - * |
|
157 | - * @param string $key |
|
158 | - * @param mixed $old |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - public function cad($key, $old) { |
|
162 | - self::$cache->watch($this->getNameSpace() . $key); |
|
163 | - if ($this->get($key) === $old) { |
|
164 | - $result = self::$cache->multi() |
|
165 | - ->del($this->getNameSpace() . $key) |
|
166 | - ->exec(); |
|
167 | - return $result !== false; |
|
168 | - } |
|
169 | - self::$cache->unwatch(); |
|
170 | - return false; |
|
171 | - } |
|
172 | - |
|
173 | - public function setTTL($key, $ttl) { |
|
174 | - self::$cache->expire($this->getNameSpace() . $key, $ttl); |
|
175 | - } |
|
176 | - |
|
177 | - static public function isAvailable() { |
|
178 | - return \OC::$server->getGetRedisFactory()->isAvailable(); |
|
179 | - } |
|
34 | + /** |
|
35 | + * @var \Redis $cache |
|
36 | + */ |
|
37 | + private static $cache = null; |
|
38 | + |
|
39 | + public function __construct($prefix = '') { |
|
40 | + parent::__construct($prefix); |
|
41 | + if (is_null(self::$cache)) { |
|
42 | + self::$cache = \OC::$server->getGetRedisFactory()->getInstance(); |
|
43 | + } |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * entries in redis get namespaced to prevent collisions between ownCloud instances and users |
|
48 | + */ |
|
49 | + protected function getNameSpace() { |
|
50 | + return $this->prefix; |
|
51 | + } |
|
52 | + |
|
53 | + public function get($key) { |
|
54 | + $result = self::$cache->get($this->getNameSpace() . $key); |
|
55 | + if ($result === false && !self::$cache->exists($this->getNameSpace() . $key)) { |
|
56 | + return null; |
|
57 | + } else { |
|
58 | + return json_decode($result, true); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + public function set($key, $value, $ttl = 0) { |
|
63 | + if ($ttl > 0) { |
|
64 | + return self::$cache->setex($this->getNameSpace() . $key, $ttl, json_encode($value)); |
|
65 | + } else { |
|
66 | + return self::$cache->set($this->getNameSpace() . $key, json_encode($value)); |
|
67 | + } |
|
68 | + } |
|
69 | + |
|
70 | + public function hasKey($key) { |
|
71 | + return self::$cache->exists($this->getNameSpace() . $key); |
|
72 | + } |
|
73 | + |
|
74 | + public function remove($key) { |
|
75 | + if (self::$cache->del($this->getNameSpace() . $key)) { |
|
76 | + return true; |
|
77 | + } else { |
|
78 | + return false; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + public function clear($prefix = '') { |
|
83 | + $prefix = $this->getNameSpace() . $prefix . '*'; |
|
84 | + $keys = self::$cache->keys($prefix); |
|
85 | + $deleted = self::$cache->del($keys); |
|
86 | + |
|
87 | + return count($keys) === $deleted; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Set a value in the cache if it's not already stored |
|
92 | + * |
|
93 | + * @param string $key |
|
94 | + * @param mixed $value |
|
95 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
96 | + * @return bool |
|
97 | + */ |
|
98 | + public function add($key, $value, $ttl = 0) { |
|
99 | + // don't encode ints for inc/dec |
|
100 | + if (!is_int($value)) { |
|
101 | + $value = json_encode($value); |
|
102 | + } |
|
103 | + return self::$cache->setnx($this->getPrefix() . $key, $value); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Increase a stored number |
|
108 | + * |
|
109 | + * @param string $key |
|
110 | + * @param int $step |
|
111 | + * @return int | bool |
|
112 | + */ |
|
113 | + public function inc($key, $step = 1) { |
|
114 | + return self::$cache->incrBy($this->getNameSpace() . $key, $step); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Decrease a stored number |
|
119 | + * |
|
120 | + * @param string $key |
|
121 | + * @param int $step |
|
122 | + * @return int | bool |
|
123 | + */ |
|
124 | + public function dec($key, $step = 1) { |
|
125 | + if (!$this->hasKey($key)) { |
|
126 | + return false; |
|
127 | + } |
|
128 | + return self::$cache->decrBy($this->getNameSpace() . $key, $step); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Compare and set |
|
133 | + * |
|
134 | + * @param string $key |
|
135 | + * @param mixed $old |
|
136 | + * @param mixed $new |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + public function cas($key, $old, $new) { |
|
140 | + if (!is_int($new)) { |
|
141 | + $new = json_encode($new); |
|
142 | + } |
|
143 | + self::$cache->watch($this->getNameSpace() . $key); |
|
144 | + if ($this->get($key) === $old) { |
|
145 | + $result = self::$cache->multi() |
|
146 | + ->set($this->getNameSpace() . $key, $new) |
|
147 | + ->exec(); |
|
148 | + return $result !== false; |
|
149 | + } |
|
150 | + self::$cache->unwatch(); |
|
151 | + return false; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Compare and delete |
|
156 | + * |
|
157 | + * @param string $key |
|
158 | + * @param mixed $old |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + public function cad($key, $old) { |
|
162 | + self::$cache->watch($this->getNameSpace() . $key); |
|
163 | + if ($this->get($key) === $old) { |
|
164 | + $result = self::$cache->multi() |
|
165 | + ->del($this->getNameSpace() . $key) |
|
166 | + ->exec(); |
|
167 | + return $result !== false; |
|
168 | + } |
|
169 | + self::$cache->unwatch(); |
|
170 | + return false; |
|
171 | + } |
|
172 | + |
|
173 | + public function setTTL($key, $ttl) { |
|
174 | + self::$cache->expire($this->getNameSpace() . $key, $ttl); |
|
175 | + } |
|
176 | + |
|
177 | + static public function isAvailable() { |
|
178 | + return \OC::$server->getGetRedisFactory()->isAvailable(); |
|
179 | + } |
|
180 | 180 | } |
181 | 181 |
@@ -51,246 +51,246 @@ |
||
51 | 51 | class TagsPlugin extends \Sabre\DAV\ServerPlugin |
52 | 52 | { |
53 | 53 | |
54 | - // namespace |
|
55 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
56 | - const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags'; |
|
57 | - const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite'; |
|
58 | - const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
54 | + // namespace |
|
55 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
56 | + const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags'; |
|
57 | + const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite'; |
|
58 | + const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
59 | 59 | |
60 | - /** |
|
61 | - * Reference to main server object |
|
62 | - * |
|
63 | - * @var \Sabre\DAV\Server |
|
64 | - */ |
|
65 | - private $server; |
|
60 | + /** |
|
61 | + * Reference to main server object |
|
62 | + * |
|
63 | + * @var \Sabre\DAV\Server |
|
64 | + */ |
|
65 | + private $server; |
|
66 | 66 | |
67 | - /** |
|
68 | - * @var \OCP\ITagManager |
|
69 | - */ |
|
70 | - private $tagManager; |
|
67 | + /** |
|
68 | + * @var \OCP\ITagManager |
|
69 | + */ |
|
70 | + private $tagManager; |
|
71 | 71 | |
72 | - /** |
|
73 | - * @var \OCP\ITags |
|
74 | - */ |
|
75 | - private $tagger; |
|
72 | + /** |
|
73 | + * @var \OCP\ITags |
|
74 | + */ |
|
75 | + private $tagger; |
|
76 | 76 | |
77 | - /** |
|
78 | - * Array of file id to tags array |
|
79 | - * The null value means the cache wasn't initialized. |
|
80 | - * |
|
81 | - * @var array |
|
82 | - */ |
|
83 | - private $cachedTags; |
|
77 | + /** |
|
78 | + * Array of file id to tags array |
|
79 | + * The null value means the cache wasn't initialized. |
|
80 | + * |
|
81 | + * @var array |
|
82 | + */ |
|
83 | + private $cachedTags; |
|
84 | 84 | |
85 | - /** |
|
86 | - * @var \Sabre\DAV\Tree |
|
87 | - */ |
|
88 | - private $tree; |
|
85 | + /** |
|
86 | + * @var \Sabre\DAV\Tree |
|
87 | + */ |
|
88 | + private $tree; |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param \Sabre\DAV\Tree $tree tree |
|
92 | - * @param \OCP\ITagManager $tagManager tag manager |
|
93 | - */ |
|
94 | - public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) { |
|
95 | - $this->tree = $tree; |
|
96 | - $this->tagManager = $tagManager; |
|
97 | - $this->tagger = null; |
|
98 | - $this->cachedTags = array(); |
|
99 | - } |
|
90 | + /** |
|
91 | + * @param \Sabre\DAV\Tree $tree tree |
|
92 | + * @param \OCP\ITagManager $tagManager tag manager |
|
93 | + */ |
|
94 | + public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) { |
|
95 | + $this->tree = $tree; |
|
96 | + $this->tagManager = $tagManager; |
|
97 | + $this->tagger = null; |
|
98 | + $this->cachedTags = array(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * This initializes the plugin. |
|
103 | - * |
|
104 | - * This function is called by \Sabre\DAV\Server, after |
|
105 | - * addPlugin is called. |
|
106 | - * |
|
107 | - * This method should set up the required event subscriptions. |
|
108 | - * |
|
109 | - * @param \Sabre\DAV\Server $server |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - public function initialize(\Sabre\DAV\Server $server) { |
|
101 | + /** |
|
102 | + * This initializes the plugin. |
|
103 | + * |
|
104 | + * This function is called by \Sabre\DAV\Server, after |
|
105 | + * addPlugin is called. |
|
106 | + * |
|
107 | + * This method should set up the required event subscriptions. |
|
108 | + * |
|
109 | + * @param \Sabre\DAV\Server $server |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function initialize(\Sabre\DAV\Server $server) { |
|
113 | 113 | |
114 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
115 | - $server->xml->elementMap[self::TAGS_PROPERTYNAME] = TagList::class; |
|
114 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
115 | + $server->xml->elementMap[self::TAGS_PROPERTYNAME] = TagList::class; |
|
116 | 116 | |
117 | - $this->server = $server; |
|
118 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
119 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
120 | - } |
|
117 | + $this->server = $server; |
|
118 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
119 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Returns the tagger |
|
124 | - * |
|
125 | - * @return \OCP\ITags tagger |
|
126 | - */ |
|
127 | - private function getTagger() { |
|
128 | - if (!$this->tagger) { |
|
129 | - $this->tagger = $this->tagManager->load('files'); |
|
130 | - } |
|
131 | - return $this->tagger; |
|
132 | - } |
|
122 | + /** |
|
123 | + * Returns the tagger |
|
124 | + * |
|
125 | + * @return \OCP\ITags tagger |
|
126 | + */ |
|
127 | + private function getTagger() { |
|
128 | + if (!$this->tagger) { |
|
129 | + $this->tagger = $this->tagManager->load('files'); |
|
130 | + } |
|
131 | + return $this->tagger; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Returns tags and favorites. |
|
136 | - * |
|
137 | - * @param integer $fileId file id |
|
138 | - * @return array list($tags, $favorite) with $tags as tag array |
|
139 | - * and $favorite is a boolean whether the file was favorited |
|
140 | - */ |
|
141 | - private function getTagsAndFav($fileId) { |
|
142 | - $isFav = false; |
|
143 | - $tags = $this->getTags($fileId); |
|
144 | - if ($tags) { |
|
145 | - $favPos = array_search(self::TAG_FAVORITE, $tags); |
|
146 | - if ($favPos !== false) { |
|
147 | - $isFav = true; |
|
148 | - unset($tags[$favPos]); |
|
149 | - } |
|
150 | - } |
|
151 | - return array($tags, $isFav); |
|
152 | - } |
|
134 | + /** |
|
135 | + * Returns tags and favorites. |
|
136 | + * |
|
137 | + * @param integer $fileId file id |
|
138 | + * @return array list($tags, $favorite) with $tags as tag array |
|
139 | + * and $favorite is a boolean whether the file was favorited |
|
140 | + */ |
|
141 | + private function getTagsAndFav($fileId) { |
|
142 | + $isFav = false; |
|
143 | + $tags = $this->getTags($fileId); |
|
144 | + if ($tags) { |
|
145 | + $favPos = array_search(self::TAG_FAVORITE, $tags); |
|
146 | + if ($favPos !== false) { |
|
147 | + $isFav = true; |
|
148 | + unset($tags[$favPos]); |
|
149 | + } |
|
150 | + } |
|
151 | + return array($tags, $isFav); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * Returns tags for the given file id |
|
156 | - * |
|
157 | - * @param integer $fileId file id |
|
158 | - * @return array list of tags for that file |
|
159 | - */ |
|
160 | - private function getTags($fileId) { |
|
161 | - if (isset($this->cachedTags[$fileId])) { |
|
162 | - return $this->cachedTags[$fileId]; |
|
163 | - } else { |
|
164 | - $tags = $this->getTagger()->getTagsForObjects(array($fileId)); |
|
165 | - if ($tags !== false) { |
|
166 | - if (empty($tags)) { |
|
167 | - return array(); |
|
168 | - } |
|
169 | - return current($tags); |
|
170 | - } |
|
171 | - } |
|
172 | - return null; |
|
173 | - } |
|
154 | + /** |
|
155 | + * Returns tags for the given file id |
|
156 | + * |
|
157 | + * @param integer $fileId file id |
|
158 | + * @return array list of tags for that file |
|
159 | + */ |
|
160 | + private function getTags($fileId) { |
|
161 | + if (isset($this->cachedTags[$fileId])) { |
|
162 | + return $this->cachedTags[$fileId]; |
|
163 | + } else { |
|
164 | + $tags = $this->getTagger()->getTagsForObjects(array($fileId)); |
|
165 | + if ($tags !== false) { |
|
166 | + if (empty($tags)) { |
|
167 | + return array(); |
|
168 | + } |
|
169 | + return current($tags); |
|
170 | + } |
|
171 | + } |
|
172 | + return null; |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * Updates the tags of the given file id |
|
177 | - * |
|
178 | - * @param int $fileId |
|
179 | - * @param array $tags array of tag strings |
|
180 | - */ |
|
181 | - private function updateTags($fileId, $tags) { |
|
182 | - $tagger = $this->getTagger(); |
|
183 | - $currentTags = $this->getTags($fileId); |
|
175 | + /** |
|
176 | + * Updates the tags of the given file id |
|
177 | + * |
|
178 | + * @param int $fileId |
|
179 | + * @param array $tags array of tag strings |
|
180 | + */ |
|
181 | + private function updateTags($fileId, $tags) { |
|
182 | + $tagger = $this->getTagger(); |
|
183 | + $currentTags = $this->getTags($fileId); |
|
184 | 184 | |
185 | - $newTags = array_diff($tags, $currentTags); |
|
186 | - foreach ($newTags as $tag) { |
|
187 | - if ($tag === self::TAG_FAVORITE) { |
|
188 | - continue; |
|
189 | - } |
|
190 | - $tagger->tagAs($fileId, $tag); |
|
191 | - } |
|
192 | - $deletedTags = array_diff($currentTags, $tags); |
|
193 | - foreach ($deletedTags as $tag) { |
|
194 | - if ($tag === self::TAG_FAVORITE) { |
|
195 | - continue; |
|
196 | - } |
|
197 | - $tagger->unTag($fileId, $tag); |
|
198 | - } |
|
199 | - } |
|
185 | + $newTags = array_diff($tags, $currentTags); |
|
186 | + foreach ($newTags as $tag) { |
|
187 | + if ($tag === self::TAG_FAVORITE) { |
|
188 | + continue; |
|
189 | + } |
|
190 | + $tagger->tagAs($fileId, $tag); |
|
191 | + } |
|
192 | + $deletedTags = array_diff($currentTags, $tags); |
|
193 | + foreach ($deletedTags as $tag) { |
|
194 | + if ($tag === self::TAG_FAVORITE) { |
|
195 | + continue; |
|
196 | + } |
|
197 | + $tagger->unTag($fileId, $tag); |
|
198 | + } |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * Adds tags and favorites properties to the response, |
|
203 | - * if requested. |
|
204 | - * |
|
205 | - * @param PropFind $propFind |
|
206 | - * @param \Sabre\DAV\INode $node |
|
207 | - * @return void |
|
208 | - */ |
|
209 | - public function handleGetProperties( |
|
210 | - PropFind $propFind, |
|
211 | - \Sabre\DAV\INode $node |
|
212 | - ) { |
|
213 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
214 | - return; |
|
215 | - } |
|
201 | + /** |
|
202 | + * Adds tags and favorites properties to the response, |
|
203 | + * if requested. |
|
204 | + * |
|
205 | + * @param PropFind $propFind |
|
206 | + * @param \Sabre\DAV\INode $node |
|
207 | + * @return void |
|
208 | + */ |
|
209 | + public function handleGetProperties( |
|
210 | + PropFind $propFind, |
|
211 | + \Sabre\DAV\INode $node |
|
212 | + ) { |
|
213 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
214 | + return; |
|
215 | + } |
|
216 | 216 | |
217 | - // need prefetch ? |
|
218 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
219 | - && $propFind->getDepth() !== 0 |
|
220 | - && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME)) |
|
221 | - || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME)) |
|
222 | - )) { |
|
223 | - // note: pre-fetching only supported for depth <= 1 |
|
224 | - $folderContent = $node->getChildren(); |
|
225 | - $fileIds[] = (int)$node->getId(); |
|
226 | - foreach ($folderContent as $info) { |
|
227 | - $fileIds[] = (int)$info->getId(); |
|
228 | - } |
|
229 | - $tags = $this->getTagger()->getTagsForObjects($fileIds); |
|
230 | - if ($tags === false) { |
|
231 | - // the tags API returns false on error... |
|
232 | - $tags = array(); |
|
233 | - } |
|
217 | + // need prefetch ? |
|
218 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
219 | + && $propFind->getDepth() !== 0 |
|
220 | + && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME)) |
|
221 | + || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME)) |
|
222 | + )) { |
|
223 | + // note: pre-fetching only supported for depth <= 1 |
|
224 | + $folderContent = $node->getChildren(); |
|
225 | + $fileIds[] = (int)$node->getId(); |
|
226 | + foreach ($folderContent as $info) { |
|
227 | + $fileIds[] = (int)$info->getId(); |
|
228 | + } |
|
229 | + $tags = $this->getTagger()->getTagsForObjects($fileIds); |
|
230 | + if ($tags === false) { |
|
231 | + // the tags API returns false on error... |
|
232 | + $tags = array(); |
|
233 | + } |
|
234 | 234 | |
235 | - $this->cachedTags = $this->cachedTags + $tags; |
|
236 | - $emptyFileIds = array_diff($fileIds, array_keys($tags)); |
|
237 | - // also cache the ones that were not found |
|
238 | - foreach ($emptyFileIds as $fileId) { |
|
239 | - $this->cachedTags[$fileId] = []; |
|
240 | - } |
|
241 | - } |
|
235 | + $this->cachedTags = $this->cachedTags + $tags; |
|
236 | + $emptyFileIds = array_diff($fileIds, array_keys($tags)); |
|
237 | + // also cache the ones that were not found |
|
238 | + foreach ($emptyFileIds as $fileId) { |
|
239 | + $this->cachedTags[$fileId] = []; |
|
240 | + } |
|
241 | + } |
|
242 | 242 | |
243 | - $isFav = null; |
|
243 | + $isFav = null; |
|
244 | 244 | |
245 | - $propFind->handle(self::TAGS_PROPERTYNAME, function() use (&$isFav, $node) { |
|
246 | - list($tags, $isFav) = $this->getTagsAndFav($node->getId()); |
|
247 | - return new TagList($tags); |
|
248 | - }); |
|
245 | + $propFind->handle(self::TAGS_PROPERTYNAME, function() use (&$isFav, $node) { |
|
246 | + list($tags, $isFav) = $this->getTagsAndFav($node->getId()); |
|
247 | + return new TagList($tags); |
|
248 | + }); |
|
249 | 249 | |
250 | - $propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) { |
|
251 | - if (is_null($isFav)) { |
|
252 | - list(, $isFav) = $this->getTagsAndFav($node->getId()); |
|
253 | - } |
|
254 | - if ($isFav) { |
|
255 | - return 1; |
|
256 | - } else { |
|
257 | - return 0; |
|
258 | - } |
|
259 | - }); |
|
260 | - } |
|
250 | + $propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) { |
|
251 | + if (is_null($isFav)) { |
|
252 | + list(, $isFav) = $this->getTagsAndFav($node->getId()); |
|
253 | + } |
|
254 | + if ($isFav) { |
|
255 | + return 1; |
|
256 | + } else { |
|
257 | + return 0; |
|
258 | + } |
|
259 | + }); |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * Updates tags and favorites properties, if applicable. |
|
264 | - * |
|
265 | - * @param string $path |
|
266 | - * @param PropPatch $propPatch |
|
267 | - * |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
271 | - $node = $this->tree->getNodeForPath($path); |
|
272 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
273 | - return; |
|
274 | - } |
|
262 | + /** |
|
263 | + * Updates tags and favorites properties, if applicable. |
|
264 | + * |
|
265 | + * @param string $path |
|
266 | + * @param PropPatch $propPatch |
|
267 | + * |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
271 | + $node = $this->tree->getNodeForPath($path); |
|
272 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
273 | + return; |
|
274 | + } |
|
275 | 275 | |
276 | - $propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($node) { |
|
277 | - $this->updateTags($node->getId(), $tagList->getTags()); |
|
278 | - return true; |
|
279 | - }); |
|
276 | + $propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($node) { |
|
277 | + $this->updateTags($node->getId(), $tagList->getTags()); |
|
278 | + return true; |
|
279 | + }); |
|
280 | 280 | |
281 | - $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) { |
|
282 | - if ((int)$favState === 1 || $favState === 'true') { |
|
283 | - $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
|
284 | - } else { |
|
285 | - $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
|
286 | - } |
|
281 | + $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) { |
|
282 | + if ((int)$favState === 1 || $favState === 'true') { |
|
283 | + $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
|
284 | + } else { |
|
285 | + $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
|
286 | + } |
|
287 | 287 | |
288 | - if (is_null($favState)) { |
|
289 | - // confirm deletion |
|
290 | - return 204; |
|
291 | - } |
|
288 | + if (is_null($favState)) { |
|
289 | + // confirm deletion |
|
290 | + return 204; |
|
291 | + } |
|
292 | 292 | |
293 | - return 200; |
|
294 | - }); |
|
295 | - } |
|
293 | + return 200; |
|
294 | + }); |
|
295 | + } |
|
296 | 296 | } |
@@ -28,40 +28,40 @@ |
||
28 | 28 | namespace OCA\Files; |
29 | 29 | |
30 | 30 | class App { |
31 | - /** |
|
32 | - * @var \OCP\INavigationManager |
|
33 | - */ |
|
34 | - private static $navigationManager; |
|
31 | + /** |
|
32 | + * @var \OCP\INavigationManager |
|
33 | + */ |
|
34 | + private static $navigationManager; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Returns the app's navigation manager |
|
38 | - * |
|
39 | - * @return \OCP\INavigationManager |
|
40 | - */ |
|
41 | - public static function getNavigationManager() { |
|
42 | - // TODO: move this into a service in the Application class |
|
43 | - if (self::$navigationManager === null) { |
|
44 | - self::$navigationManager = new \OC\NavigationManager( |
|
45 | - \OC::$server->getAppManager(), |
|
46 | - \OC::$server->getURLGenerator(), |
|
47 | - \OC::$server->getL10NFactory(), |
|
48 | - \OC::$server->getUserSession(), |
|
49 | - \OC::$server->getGroupManager(), |
|
50 | - \OC::$server->getConfig() |
|
51 | - ); |
|
52 | - self::$navigationManager->clear(false); |
|
53 | - } |
|
54 | - return self::$navigationManager; |
|
55 | - } |
|
36 | + /** |
|
37 | + * Returns the app's navigation manager |
|
38 | + * |
|
39 | + * @return \OCP\INavigationManager |
|
40 | + */ |
|
41 | + public static function getNavigationManager() { |
|
42 | + // TODO: move this into a service in the Application class |
|
43 | + if (self::$navigationManager === null) { |
|
44 | + self::$navigationManager = new \OC\NavigationManager( |
|
45 | + \OC::$server->getAppManager(), |
|
46 | + \OC::$server->getURLGenerator(), |
|
47 | + \OC::$server->getL10NFactory(), |
|
48 | + \OC::$server->getUserSession(), |
|
49 | + \OC::$server->getGroupManager(), |
|
50 | + \OC::$server->getConfig() |
|
51 | + ); |
|
52 | + self::$navigationManager->clear(false); |
|
53 | + } |
|
54 | + return self::$navigationManager; |
|
55 | + } |
|
56 | 56 | |
57 | - public static function extendJsConfig($settings) { |
|
58 | - $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
57 | + public static function extendJsConfig($settings) { |
|
58 | + $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
59 | 59 | |
60 | - $maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024); |
|
61 | - $appConfig['files'] = [ |
|
62 | - 'max_chunk_size' => $maxChunkSize |
|
63 | - ]; |
|
60 | + $maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024); |
|
61 | + $appConfig['files'] = [ |
|
62 | + 'max_chunk_size' => $maxChunkSize |
|
63 | + ]; |
|
64 | 64 | |
65 | - $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
66 | - } |
|
65 | + $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
66 | + } |
|
67 | 67 | } |