@@ -56,491 +56,491 @@ |
||
56 | 56 | * @package OC\Files\Cache |
57 | 57 | */ |
58 | 58 | class Scanner extends BasicEmitter implements IScanner { |
59 | - /** |
|
60 | - * @var \OC\Files\Storage\Storage $storage |
|
61 | - */ |
|
62 | - protected $storage; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string $storageId |
|
66 | - */ |
|
67 | - protected $storageId; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var \OC\Files\Cache\Cache $cache |
|
71 | - */ |
|
72 | - protected $cache; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var boolean $cacheActive If true, perform cache operations, if false, do not affect cache |
|
76 | - */ |
|
77 | - protected $cacheActive; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var bool $useTransactions whether to use transactions |
|
81 | - */ |
|
82 | - protected $useTransactions = true; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var \OCP\Lock\ILockingProvider |
|
86 | - */ |
|
87 | - protected $lockingProvider; |
|
88 | - |
|
89 | - public function __construct(\OC\Files\Storage\Storage $storage) { |
|
90 | - $this->storage = $storage; |
|
91 | - $this->storageId = $this->storage->getId(); |
|
92 | - $this->cache = $storage->getCache(); |
|
93 | - $this->cacheActive = !\OC::$server->getConfig()->getSystemValue('filesystem_cache_readonly', false); |
|
94 | - $this->lockingProvider = \OC::$server->getLockingProvider(); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Whether to wrap the scanning of a folder in a database transaction |
|
99 | - * On default transactions are used |
|
100 | - * |
|
101 | - * @param bool $useTransactions |
|
102 | - */ |
|
103 | - public function setUseTransactions($useTransactions) { |
|
104 | - $this->useTransactions = $useTransactions; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * get all the metadata of a file or folder |
|
109 | - * * |
|
110 | - * |
|
111 | - * @param string $path |
|
112 | - * @return array an array of metadata of the file |
|
113 | - */ |
|
114 | - protected function getData($path) { |
|
115 | - $data = $this->storage->getMetaData($path); |
|
116 | - if (is_null($data)) { |
|
117 | - \OCP\Util::writeLog(Scanner::class, "!!! Path '$path' is not accessible or present !!!", ILogger::DEBUG); |
|
118 | - } |
|
119 | - return $data; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * scan a single file and store it in the cache |
|
124 | - * |
|
125 | - * @param string $file |
|
126 | - * @param int $reuseExisting |
|
127 | - * @param int $parentId |
|
128 | - * @param array|null|false $cacheData existing data in the cache for the file to be scanned |
|
129 | - * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
130 | - * @param null $data the metadata for the file, as returned by the storage |
|
131 | - * @return array an array of metadata of the scanned file |
|
132 | - * @throws \OCP\Lock\LockedException |
|
133 | - */ |
|
134 | - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) { |
|
135 | - if ($file !== '') { |
|
136 | - try { |
|
137 | - $this->storage->verifyPath(dirname($file), basename($file)); |
|
138 | - } catch (\Exception $e) { |
|
139 | - return null; |
|
140 | - } |
|
141 | - } |
|
142 | - // only proceed if $file is not a partial file nor a blacklisted file |
|
143 | - if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file)) { |
|
144 | - |
|
145 | - //acquire a lock |
|
146 | - if ($lock) { |
|
147 | - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
148 | - $this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - try { |
|
153 | - $data = $data ?? $this->getData($file); |
|
154 | - } catch (ForbiddenException $e) { |
|
155 | - if ($lock) { |
|
156 | - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
157 | - $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - return null; |
|
162 | - } |
|
163 | - |
|
164 | - try { |
|
165 | - if ($data) { |
|
166 | - |
|
167 | - // pre-emit only if it was a file. By that we avoid counting/treating folders as files |
|
168 | - if ($data['mimetype'] !== 'httpd/unix-directory') { |
|
169 | - $this->emit('\OC\Files\Cache\Scanner', 'scanFile', [$file, $this->storageId]); |
|
170 | - \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', ['path' => $file, 'storage' => $this->storageId]); |
|
171 | - } |
|
172 | - |
|
173 | - $parent = dirname($file); |
|
174 | - if ($parent === '.' or $parent === '/') { |
|
175 | - $parent = ''; |
|
176 | - } |
|
177 | - if ($parentId === -1) { |
|
178 | - $parentId = $this->cache->getParentId($file); |
|
179 | - } |
|
180 | - |
|
181 | - // scan the parent if it's not in the cache (id -1) and the current file is not the root folder |
|
182 | - if ($file and $parentId === -1) { |
|
183 | - $parentData = $this->scanFile($parent); |
|
184 | - if (!$parentData) { |
|
185 | - return null; |
|
186 | - } |
|
187 | - $parentId = $parentData['fileid']; |
|
188 | - } |
|
189 | - if ($parent) { |
|
190 | - $data['parent'] = $parentId; |
|
191 | - } |
|
192 | - if (is_null($cacheData)) { |
|
193 | - /** @var CacheEntry $cacheData */ |
|
194 | - $cacheData = $this->cache->get($file); |
|
195 | - } |
|
196 | - if ($cacheData and $reuseExisting and isset($cacheData['fileid'])) { |
|
197 | - // prevent empty etag |
|
198 | - if (empty($cacheData['etag'])) { |
|
199 | - $etag = $data['etag']; |
|
200 | - } else { |
|
201 | - $etag = $cacheData['etag']; |
|
202 | - } |
|
203 | - $fileId = $cacheData['fileid']; |
|
204 | - $data['fileid'] = $fileId; |
|
205 | - // only reuse data if the file hasn't explicitly changed |
|
206 | - if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) { |
|
207 | - $data['mtime'] = $cacheData['mtime']; |
|
208 | - if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) { |
|
209 | - $data['size'] = $cacheData['size']; |
|
210 | - } |
|
211 | - if ($reuseExisting & self::REUSE_ETAG) { |
|
212 | - $data['etag'] = $etag; |
|
213 | - } |
|
214 | - } |
|
215 | - // Only update metadata that has changed |
|
216 | - $newData = array_diff_assoc($data, $cacheData->getData()); |
|
217 | - } else { |
|
218 | - $newData = $data; |
|
219 | - $fileId = -1; |
|
220 | - } |
|
221 | - if (!empty($newData)) { |
|
222 | - // Reset the checksum if the data has changed |
|
223 | - $newData['checksum'] = ''; |
|
224 | - $newData['parent'] = $parentId; |
|
225 | - $data['fileid'] = $this->addToCache($file, $newData, $fileId); |
|
226 | - } |
|
227 | - if ($cacheData && isset($cacheData['size'])) { |
|
228 | - $data['oldSize'] = $cacheData['size']; |
|
229 | - } else { |
|
230 | - $data['oldSize'] = 0; |
|
231 | - } |
|
232 | - |
|
233 | - if ($cacheData && isset($cacheData['encrypted'])) { |
|
234 | - $data['encrypted'] = $cacheData['encrypted']; |
|
235 | - } |
|
236 | - |
|
237 | - // post-emit only if it was a file. By that we avoid counting/treating folders as files |
|
238 | - if ($data['mimetype'] !== 'httpd/unix-directory') { |
|
239 | - $this->emit('\OC\Files\Cache\Scanner', 'postScanFile', [$file, $this->storageId]); |
|
240 | - \OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', ['path' => $file, 'storage' => $this->storageId]); |
|
241 | - } |
|
242 | - } else { |
|
243 | - $this->removeFromCache($file); |
|
244 | - } |
|
245 | - } catch (\Exception $e) { |
|
246 | - if ($lock) { |
|
247 | - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
248 | - $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
249 | - } |
|
250 | - } |
|
251 | - throw $e; |
|
252 | - } |
|
253 | - |
|
254 | - //release the acquired lock |
|
255 | - if ($lock) { |
|
256 | - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
257 | - $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - if ($data && !isset($data['encrypted'])) { |
|
262 | - $data['encrypted'] = false; |
|
263 | - } |
|
264 | - return $data; |
|
265 | - } |
|
266 | - |
|
267 | - return null; |
|
268 | - } |
|
269 | - |
|
270 | - protected function removeFromCache($path) { |
|
271 | - \OC_Hook::emit('Scanner', 'removeFromCache', ['file' => $path]); |
|
272 | - $this->emit('\OC\Files\Cache\Scanner', 'removeFromCache', [$path]); |
|
273 | - if ($this->cacheActive) { |
|
274 | - $this->cache->remove($path); |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @param string $path |
|
280 | - * @param array $data |
|
281 | - * @param int $fileId |
|
282 | - * @return int the id of the added file |
|
283 | - */ |
|
284 | - protected function addToCache($path, $data, $fileId = -1) { |
|
285 | - if (isset($data['scan_permissions'])) { |
|
286 | - $data['permissions'] = $data['scan_permissions']; |
|
287 | - } |
|
288 | - \OC_Hook::emit('Scanner', 'addToCache', ['file' => $path, 'data' => $data]); |
|
289 | - $this->emit('\OC\Files\Cache\Scanner', 'addToCache', [$path, $this->storageId, $data]); |
|
290 | - if ($this->cacheActive) { |
|
291 | - if ($fileId !== -1) { |
|
292 | - $this->cache->update($fileId, $data); |
|
293 | - return $fileId; |
|
294 | - } else { |
|
295 | - return $this->cache->insert($path, $data); |
|
296 | - } |
|
297 | - } else { |
|
298 | - return -1; |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * @param string $path |
|
304 | - * @param array $data |
|
305 | - * @param int $fileId |
|
306 | - */ |
|
307 | - protected function updateCache($path, $data, $fileId = -1) { |
|
308 | - \OC_Hook::emit('Scanner', 'addToCache', ['file' => $path, 'data' => $data]); |
|
309 | - $this->emit('\OC\Files\Cache\Scanner', 'updateCache', [$path, $this->storageId, $data]); |
|
310 | - if ($this->cacheActive) { |
|
311 | - if ($fileId !== -1) { |
|
312 | - $this->cache->update($fileId, $data); |
|
313 | - } else { |
|
314 | - $this->cache->put($path, $data); |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * scan a folder and all it's children |
|
321 | - * |
|
322 | - * @param string $path |
|
323 | - * @param bool $recursive |
|
324 | - * @param int $reuse |
|
325 | - * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
326 | - * @return array an array of the meta data of the scanned file or folder |
|
327 | - */ |
|
328 | - public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
329 | - if ($reuse === -1) { |
|
330 | - $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG; |
|
331 | - } |
|
332 | - if ($lock) { |
|
333 | - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
334 | - $this->storage->acquireLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider); |
|
335 | - $this->storage->acquireLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
336 | - } |
|
337 | - } |
|
338 | - try { |
|
339 | - $data = $this->scanFile($path, $reuse, -1, null, $lock); |
|
340 | - if ($data and $data['mimetype'] === 'httpd/unix-directory') { |
|
341 | - $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock); |
|
342 | - $data['size'] = $size; |
|
343 | - } |
|
344 | - } finally { |
|
345 | - if ($lock) { |
|
346 | - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
347 | - $this->storage->releaseLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
348 | - $this->storage->releaseLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider); |
|
349 | - } |
|
350 | - } |
|
351 | - } |
|
352 | - return $data; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Get the children currently in the cache |
|
357 | - * |
|
358 | - * @param int $folderId |
|
359 | - * @return array[] |
|
360 | - */ |
|
361 | - protected function getExistingChildren($folderId) { |
|
362 | - $existingChildren = []; |
|
363 | - $children = $this->cache->getFolderContentsById($folderId); |
|
364 | - foreach ($children as $child) { |
|
365 | - $existingChildren[$child['name']] = $child; |
|
366 | - } |
|
367 | - return $existingChildren; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * scan all the files and folders in a folder |
|
372 | - * |
|
373 | - * @param string $path |
|
374 | - * @param bool $recursive |
|
375 | - * @param int $reuse |
|
376 | - * @param int $folderId id for the folder to be scanned |
|
377 | - * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
378 | - * @return int the size of the scanned folder or -1 if the size is unknown at this stage |
|
379 | - */ |
|
380 | - protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderId = null, $lock = true) { |
|
381 | - if ($reuse === -1) { |
|
382 | - $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG; |
|
383 | - } |
|
384 | - $this->emit('\OC\Files\Cache\Scanner', 'scanFolder', [$path, $this->storageId]); |
|
385 | - $size = 0; |
|
386 | - if (!is_null($folderId)) { |
|
387 | - $folderId = $this->cache->getId($path); |
|
388 | - } |
|
389 | - $childQueue = $this->handleChildren($path, $recursive, $reuse, $folderId, $lock, $size); |
|
390 | - |
|
391 | - foreach ($childQueue as $child => $childId) { |
|
392 | - $childSize = $this->scanChildren($child, $recursive, $reuse, $childId, $lock); |
|
393 | - if ($childSize === -1) { |
|
394 | - $size = -1; |
|
395 | - } elseif ($size !== -1) { |
|
396 | - $size += $childSize; |
|
397 | - } |
|
398 | - } |
|
399 | - if ($this->cacheActive) { |
|
400 | - $this->cache->update($folderId, ['size' => $size]); |
|
401 | - } |
|
402 | - $this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', [$path, $this->storageId]); |
|
403 | - return $size; |
|
404 | - } |
|
405 | - |
|
406 | - private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$size) { |
|
407 | - // we put this in it's own function so it cleans up the memory before we start recursing |
|
408 | - $existingChildren = $this->getExistingChildren($folderId); |
|
409 | - $newChildren = iterator_to_array($this->storage->getDirectoryContent($path)); |
|
410 | - |
|
411 | - if ($this->useTransactions) { |
|
412 | - \OC::$server->getDatabaseConnection()->beginTransaction(); |
|
413 | - } |
|
414 | - |
|
415 | - $exceptionOccurred = false; |
|
416 | - $childQueue = []; |
|
417 | - $newChildNames = []; |
|
418 | - foreach ($newChildren as $fileMeta) { |
|
419 | - $permissions = isset($fileMeta['scan_permissions']) ? $fileMeta['scan_permissions'] : $fileMeta['permissions']; |
|
420 | - if ($permissions === 0) { |
|
421 | - continue; |
|
422 | - } |
|
423 | - $file = $fileMeta['name']; |
|
424 | - $newChildNames[] = $file; |
|
425 | - $child = $path ? $path . '/' . $file : $file; |
|
426 | - try { |
|
427 | - $existingData = isset($existingChildren[$file]) ? $existingChildren[$file] : false; |
|
428 | - $data = $this->scanFile($child, $reuse, $folderId, $existingData, $lock, $fileMeta); |
|
429 | - if ($data) { |
|
430 | - if ($data['mimetype'] === 'httpd/unix-directory' and $recursive === self::SCAN_RECURSIVE) { |
|
431 | - $childQueue[$child] = $data['fileid']; |
|
432 | - } elseif ($data['mimetype'] === 'httpd/unix-directory' and $recursive === self::SCAN_RECURSIVE_INCOMPLETE and $data['size'] === -1) { |
|
433 | - // only recurse into folders which aren't fully scanned |
|
434 | - $childQueue[$child] = $data['fileid']; |
|
435 | - } elseif ($data['size'] === -1) { |
|
436 | - $size = -1; |
|
437 | - } elseif ($size !== -1) { |
|
438 | - $size += $data['size']; |
|
439 | - } |
|
440 | - } |
|
441 | - } catch (Exception $ex) { |
|
442 | - // might happen if inserting duplicate while a scanning |
|
443 | - // process is running in parallel |
|
444 | - // log and ignore |
|
445 | - if ($this->useTransactions) { |
|
446 | - \OC::$server->getDatabaseConnection()->rollback(); |
|
447 | - \OC::$server->getDatabaseConnection()->beginTransaction(); |
|
448 | - } |
|
449 | - \OC::$server->getLogger()->logException($ex, [ |
|
450 | - 'message' => 'Exception while scanning file "' . $child . '"', |
|
451 | - 'level' => ILogger::DEBUG, |
|
452 | - 'app' => 'core', |
|
453 | - ]); |
|
454 | - $exceptionOccurred = true; |
|
455 | - } catch (\OCP\Lock\LockedException $e) { |
|
456 | - if ($this->useTransactions) { |
|
457 | - \OC::$server->getDatabaseConnection()->rollback(); |
|
458 | - } |
|
459 | - throw $e; |
|
460 | - } |
|
461 | - } |
|
462 | - $removedChildren = \array_diff(array_keys($existingChildren), $newChildNames); |
|
463 | - foreach ($removedChildren as $childName) { |
|
464 | - $child = $path ? $path . '/' . $childName : $childName; |
|
465 | - $this->removeFromCache($child); |
|
466 | - } |
|
467 | - if ($this->useTransactions) { |
|
468 | - \OC::$server->getDatabaseConnection()->commit(); |
|
469 | - } |
|
470 | - if ($exceptionOccurred) { |
|
471 | - // It might happen that the parallel scan process has already |
|
472 | - // inserted mimetypes but those weren't available yet inside the transaction |
|
473 | - // To make sure to have the updated mime types in such cases, |
|
474 | - // we reload them here |
|
475 | - \OC::$server->getMimeTypeLoader()->reset(); |
|
476 | - } |
|
477 | - return $childQueue; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * check if the file should be ignored when scanning |
|
482 | - * NOTE: files with a '.part' extension are ignored as well! |
|
483 | - * prevents unfinished put requests to be scanned |
|
484 | - * |
|
485 | - * @param string $file |
|
486 | - * @return boolean |
|
487 | - */ |
|
488 | - public static function isPartialFile($file) { |
|
489 | - if (pathinfo($file, PATHINFO_EXTENSION) === 'part') { |
|
490 | - return true; |
|
491 | - } |
|
492 | - if (strpos($file, '.part/') !== false) { |
|
493 | - return true; |
|
494 | - } |
|
495 | - |
|
496 | - return false; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * walk over any folders that are not fully scanned yet and scan them |
|
501 | - */ |
|
502 | - public function backgroundScan() { |
|
503 | - if (!$this->cache->inCache('')) { |
|
504 | - $this->runBackgroundScanJob(function () { |
|
505 | - $this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG); |
|
506 | - }, ''); |
|
507 | - } else { |
|
508 | - $lastPath = null; |
|
509 | - while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { |
|
510 | - $this->runBackgroundScanJob(function () use ($path) { |
|
511 | - $this->scan($path, self::SCAN_RECURSIVE_INCOMPLETE, self::REUSE_ETAG | self::REUSE_SIZE); |
|
512 | - }, $path); |
|
513 | - // FIXME: this won't proceed with the next item, needs revamping of getIncomplete() |
|
514 | - // to make this possible |
|
515 | - $lastPath = $path; |
|
516 | - } |
|
517 | - } |
|
518 | - } |
|
519 | - |
|
520 | - private function runBackgroundScanJob(callable $callback, $path) { |
|
521 | - try { |
|
522 | - $callback(); |
|
523 | - \OC_Hook::emit('Scanner', 'correctFolderSize', ['path' => $path]); |
|
524 | - if ($this->cacheActive && $this->cache instanceof Cache) { |
|
525 | - $this->cache->correctFolderSize($path, null, true); |
|
526 | - } |
|
527 | - } catch (\OCP\Files\StorageInvalidException $e) { |
|
528 | - // skip unavailable storages |
|
529 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
530 | - // skip unavailable storages |
|
531 | - } catch (\OCP\Files\ForbiddenException $e) { |
|
532 | - // skip forbidden storages |
|
533 | - } catch (\OCP\Lock\LockedException $e) { |
|
534 | - // skip unavailable storages |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Set whether the cache is affected by scan operations |
|
540 | - * |
|
541 | - * @param boolean $active The active state of the cache |
|
542 | - */ |
|
543 | - public function setCacheActive($active) { |
|
544 | - $this->cacheActive = $active; |
|
545 | - } |
|
59 | + /** |
|
60 | + * @var \OC\Files\Storage\Storage $storage |
|
61 | + */ |
|
62 | + protected $storage; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string $storageId |
|
66 | + */ |
|
67 | + protected $storageId; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var \OC\Files\Cache\Cache $cache |
|
71 | + */ |
|
72 | + protected $cache; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var boolean $cacheActive If true, perform cache operations, if false, do not affect cache |
|
76 | + */ |
|
77 | + protected $cacheActive; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var bool $useTransactions whether to use transactions |
|
81 | + */ |
|
82 | + protected $useTransactions = true; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var \OCP\Lock\ILockingProvider |
|
86 | + */ |
|
87 | + protected $lockingProvider; |
|
88 | + |
|
89 | + public function __construct(\OC\Files\Storage\Storage $storage) { |
|
90 | + $this->storage = $storage; |
|
91 | + $this->storageId = $this->storage->getId(); |
|
92 | + $this->cache = $storage->getCache(); |
|
93 | + $this->cacheActive = !\OC::$server->getConfig()->getSystemValue('filesystem_cache_readonly', false); |
|
94 | + $this->lockingProvider = \OC::$server->getLockingProvider(); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Whether to wrap the scanning of a folder in a database transaction |
|
99 | + * On default transactions are used |
|
100 | + * |
|
101 | + * @param bool $useTransactions |
|
102 | + */ |
|
103 | + public function setUseTransactions($useTransactions) { |
|
104 | + $this->useTransactions = $useTransactions; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * get all the metadata of a file or folder |
|
109 | + * * |
|
110 | + * |
|
111 | + * @param string $path |
|
112 | + * @return array an array of metadata of the file |
|
113 | + */ |
|
114 | + protected function getData($path) { |
|
115 | + $data = $this->storage->getMetaData($path); |
|
116 | + if (is_null($data)) { |
|
117 | + \OCP\Util::writeLog(Scanner::class, "!!! Path '$path' is not accessible or present !!!", ILogger::DEBUG); |
|
118 | + } |
|
119 | + return $data; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * scan a single file and store it in the cache |
|
124 | + * |
|
125 | + * @param string $file |
|
126 | + * @param int $reuseExisting |
|
127 | + * @param int $parentId |
|
128 | + * @param array|null|false $cacheData existing data in the cache for the file to be scanned |
|
129 | + * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
130 | + * @param null $data the metadata for the file, as returned by the storage |
|
131 | + * @return array an array of metadata of the scanned file |
|
132 | + * @throws \OCP\Lock\LockedException |
|
133 | + */ |
|
134 | + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) { |
|
135 | + if ($file !== '') { |
|
136 | + try { |
|
137 | + $this->storage->verifyPath(dirname($file), basename($file)); |
|
138 | + } catch (\Exception $e) { |
|
139 | + return null; |
|
140 | + } |
|
141 | + } |
|
142 | + // only proceed if $file is not a partial file nor a blacklisted file |
|
143 | + if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file)) { |
|
144 | + |
|
145 | + //acquire a lock |
|
146 | + if ($lock) { |
|
147 | + if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
148 | + $this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + try { |
|
153 | + $data = $data ?? $this->getData($file); |
|
154 | + } catch (ForbiddenException $e) { |
|
155 | + if ($lock) { |
|
156 | + if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
157 | + $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + return null; |
|
162 | + } |
|
163 | + |
|
164 | + try { |
|
165 | + if ($data) { |
|
166 | + |
|
167 | + // pre-emit only if it was a file. By that we avoid counting/treating folders as files |
|
168 | + if ($data['mimetype'] !== 'httpd/unix-directory') { |
|
169 | + $this->emit('\OC\Files\Cache\Scanner', 'scanFile', [$file, $this->storageId]); |
|
170 | + \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', ['path' => $file, 'storage' => $this->storageId]); |
|
171 | + } |
|
172 | + |
|
173 | + $parent = dirname($file); |
|
174 | + if ($parent === '.' or $parent === '/') { |
|
175 | + $parent = ''; |
|
176 | + } |
|
177 | + if ($parentId === -1) { |
|
178 | + $parentId = $this->cache->getParentId($file); |
|
179 | + } |
|
180 | + |
|
181 | + // scan the parent if it's not in the cache (id -1) and the current file is not the root folder |
|
182 | + if ($file and $parentId === -1) { |
|
183 | + $parentData = $this->scanFile($parent); |
|
184 | + if (!$parentData) { |
|
185 | + return null; |
|
186 | + } |
|
187 | + $parentId = $parentData['fileid']; |
|
188 | + } |
|
189 | + if ($parent) { |
|
190 | + $data['parent'] = $parentId; |
|
191 | + } |
|
192 | + if (is_null($cacheData)) { |
|
193 | + /** @var CacheEntry $cacheData */ |
|
194 | + $cacheData = $this->cache->get($file); |
|
195 | + } |
|
196 | + if ($cacheData and $reuseExisting and isset($cacheData['fileid'])) { |
|
197 | + // prevent empty etag |
|
198 | + if (empty($cacheData['etag'])) { |
|
199 | + $etag = $data['etag']; |
|
200 | + } else { |
|
201 | + $etag = $cacheData['etag']; |
|
202 | + } |
|
203 | + $fileId = $cacheData['fileid']; |
|
204 | + $data['fileid'] = $fileId; |
|
205 | + // only reuse data if the file hasn't explicitly changed |
|
206 | + if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) { |
|
207 | + $data['mtime'] = $cacheData['mtime']; |
|
208 | + if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) { |
|
209 | + $data['size'] = $cacheData['size']; |
|
210 | + } |
|
211 | + if ($reuseExisting & self::REUSE_ETAG) { |
|
212 | + $data['etag'] = $etag; |
|
213 | + } |
|
214 | + } |
|
215 | + // Only update metadata that has changed |
|
216 | + $newData = array_diff_assoc($data, $cacheData->getData()); |
|
217 | + } else { |
|
218 | + $newData = $data; |
|
219 | + $fileId = -1; |
|
220 | + } |
|
221 | + if (!empty($newData)) { |
|
222 | + // Reset the checksum if the data has changed |
|
223 | + $newData['checksum'] = ''; |
|
224 | + $newData['parent'] = $parentId; |
|
225 | + $data['fileid'] = $this->addToCache($file, $newData, $fileId); |
|
226 | + } |
|
227 | + if ($cacheData && isset($cacheData['size'])) { |
|
228 | + $data['oldSize'] = $cacheData['size']; |
|
229 | + } else { |
|
230 | + $data['oldSize'] = 0; |
|
231 | + } |
|
232 | + |
|
233 | + if ($cacheData && isset($cacheData['encrypted'])) { |
|
234 | + $data['encrypted'] = $cacheData['encrypted']; |
|
235 | + } |
|
236 | + |
|
237 | + // post-emit only if it was a file. By that we avoid counting/treating folders as files |
|
238 | + if ($data['mimetype'] !== 'httpd/unix-directory') { |
|
239 | + $this->emit('\OC\Files\Cache\Scanner', 'postScanFile', [$file, $this->storageId]); |
|
240 | + \OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', ['path' => $file, 'storage' => $this->storageId]); |
|
241 | + } |
|
242 | + } else { |
|
243 | + $this->removeFromCache($file); |
|
244 | + } |
|
245 | + } catch (\Exception $e) { |
|
246 | + if ($lock) { |
|
247 | + if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
248 | + $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
249 | + } |
|
250 | + } |
|
251 | + throw $e; |
|
252 | + } |
|
253 | + |
|
254 | + //release the acquired lock |
|
255 | + if ($lock) { |
|
256 | + if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
257 | + $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + if ($data && !isset($data['encrypted'])) { |
|
262 | + $data['encrypted'] = false; |
|
263 | + } |
|
264 | + return $data; |
|
265 | + } |
|
266 | + |
|
267 | + return null; |
|
268 | + } |
|
269 | + |
|
270 | + protected function removeFromCache($path) { |
|
271 | + \OC_Hook::emit('Scanner', 'removeFromCache', ['file' => $path]); |
|
272 | + $this->emit('\OC\Files\Cache\Scanner', 'removeFromCache', [$path]); |
|
273 | + if ($this->cacheActive) { |
|
274 | + $this->cache->remove($path); |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @param string $path |
|
280 | + * @param array $data |
|
281 | + * @param int $fileId |
|
282 | + * @return int the id of the added file |
|
283 | + */ |
|
284 | + protected function addToCache($path, $data, $fileId = -1) { |
|
285 | + if (isset($data['scan_permissions'])) { |
|
286 | + $data['permissions'] = $data['scan_permissions']; |
|
287 | + } |
|
288 | + \OC_Hook::emit('Scanner', 'addToCache', ['file' => $path, 'data' => $data]); |
|
289 | + $this->emit('\OC\Files\Cache\Scanner', 'addToCache', [$path, $this->storageId, $data]); |
|
290 | + if ($this->cacheActive) { |
|
291 | + if ($fileId !== -1) { |
|
292 | + $this->cache->update($fileId, $data); |
|
293 | + return $fileId; |
|
294 | + } else { |
|
295 | + return $this->cache->insert($path, $data); |
|
296 | + } |
|
297 | + } else { |
|
298 | + return -1; |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * @param string $path |
|
304 | + * @param array $data |
|
305 | + * @param int $fileId |
|
306 | + */ |
|
307 | + protected function updateCache($path, $data, $fileId = -1) { |
|
308 | + \OC_Hook::emit('Scanner', 'addToCache', ['file' => $path, 'data' => $data]); |
|
309 | + $this->emit('\OC\Files\Cache\Scanner', 'updateCache', [$path, $this->storageId, $data]); |
|
310 | + if ($this->cacheActive) { |
|
311 | + if ($fileId !== -1) { |
|
312 | + $this->cache->update($fileId, $data); |
|
313 | + } else { |
|
314 | + $this->cache->put($path, $data); |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * scan a folder and all it's children |
|
321 | + * |
|
322 | + * @param string $path |
|
323 | + * @param bool $recursive |
|
324 | + * @param int $reuse |
|
325 | + * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
326 | + * @return array an array of the meta data of the scanned file or folder |
|
327 | + */ |
|
328 | + public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
329 | + if ($reuse === -1) { |
|
330 | + $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG; |
|
331 | + } |
|
332 | + if ($lock) { |
|
333 | + if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
334 | + $this->storage->acquireLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider); |
|
335 | + $this->storage->acquireLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
336 | + } |
|
337 | + } |
|
338 | + try { |
|
339 | + $data = $this->scanFile($path, $reuse, -1, null, $lock); |
|
340 | + if ($data and $data['mimetype'] === 'httpd/unix-directory') { |
|
341 | + $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock); |
|
342 | + $data['size'] = $size; |
|
343 | + } |
|
344 | + } finally { |
|
345 | + if ($lock) { |
|
346 | + if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
347 | + $this->storage->releaseLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider); |
|
348 | + $this->storage->releaseLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider); |
|
349 | + } |
|
350 | + } |
|
351 | + } |
|
352 | + return $data; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Get the children currently in the cache |
|
357 | + * |
|
358 | + * @param int $folderId |
|
359 | + * @return array[] |
|
360 | + */ |
|
361 | + protected function getExistingChildren($folderId) { |
|
362 | + $existingChildren = []; |
|
363 | + $children = $this->cache->getFolderContentsById($folderId); |
|
364 | + foreach ($children as $child) { |
|
365 | + $existingChildren[$child['name']] = $child; |
|
366 | + } |
|
367 | + return $existingChildren; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * scan all the files and folders in a folder |
|
372 | + * |
|
373 | + * @param string $path |
|
374 | + * @param bool $recursive |
|
375 | + * @param int $reuse |
|
376 | + * @param int $folderId id for the folder to be scanned |
|
377 | + * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
378 | + * @return int the size of the scanned folder or -1 if the size is unknown at this stage |
|
379 | + */ |
|
380 | + protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderId = null, $lock = true) { |
|
381 | + if ($reuse === -1) { |
|
382 | + $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG; |
|
383 | + } |
|
384 | + $this->emit('\OC\Files\Cache\Scanner', 'scanFolder', [$path, $this->storageId]); |
|
385 | + $size = 0; |
|
386 | + if (!is_null($folderId)) { |
|
387 | + $folderId = $this->cache->getId($path); |
|
388 | + } |
|
389 | + $childQueue = $this->handleChildren($path, $recursive, $reuse, $folderId, $lock, $size); |
|
390 | + |
|
391 | + foreach ($childQueue as $child => $childId) { |
|
392 | + $childSize = $this->scanChildren($child, $recursive, $reuse, $childId, $lock); |
|
393 | + if ($childSize === -1) { |
|
394 | + $size = -1; |
|
395 | + } elseif ($size !== -1) { |
|
396 | + $size += $childSize; |
|
397 | + } |
|
398 | + } |
|
399 | + if ($this->cacheActive) { |
|
400 | + $this->cache->update($folderId, ['size' => $size]); |
|
401 | + } |
|
402 | + $this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', [$path, $this->storageId]); |
|
403 | + return $size; |
|
404 | + } |
|
405 | + |
|
406 | + private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$size) { |
|
407 | + // we put this in it's own function so it cleans up the memory before we start recursing |
|
408 | + $existingChildren = $this->getExistingChildren($folderId); |
|
409 | + $newChildren = iterator_to_array($this->storage->getDirectoryContent($path)); |
|
410 | + |
|
411 | + if ($this->useTransactions) { |
|
412 | + \OC::$server->getDatabaseConnection()->beginTransaction(); |
|
413 | + } |
|
414 | + |
|
415 | + $exceptionOccurred = false; |
|
416 | + $childQueue = []; |
|
417 | + $newChildNames = []; |
|
418 | + foreach ($newChildren as $fileMeta) { |
|
419 | + $permissions = isset($fileMeta['scan_permissions']) ? $fileMeta['scan_permissions'] : $fileMeta['permissions']; |
|
420 | + if ($permissions === 0) { |
|
421 | + continue; |
|
422 | + } |
|
423 | + $file = $fileMeta['name']; |
|
424 | + $newChildNames[] = $file; |
|
425 | + $child = $path ? $path . '/' . $file : $file; |
|
426 | + try { |
|
427 | + $existingData = isset($existingChildren[$file]) ? $existingChildren[$file] : false; |
|
428 | + $data = $this->scanFile($child, $reuse, $folderId, $existingData, $lock, $fileMeta); |
|
429 | + if ($data) { |
|
430 | + if ($data['mimetype'] === 'httpd/unix-directory' and $recursive === self::SCAN_RECURSIVE) { |
|
431 | + $childQueue[$child] = $data['fileid']; |
|
432 | + } elseif ($data['mimetype'] === 'httpd/unix-directory' and $recursive === self::SCAN_RECURSIVE_INCOMPLETE and $data['size'] === -1) { |
|
433 | + // only recurse into folders which aren't fully scanned |
|
434 | + $childQueue[$child] = $data['fileid']; |
|
435 | + } elseif ($data['size'] === -1) { |
|
436 | + $size = -1; |
|
437 | + } elseif ($size !== -1) { |
|
438 | + $size += $data['size']; |
|
439 | + } |
|
440 | + } |
|
441 | + } catch (Exception $ex) { |
|
442 | + // might happen if inserting duplicate while a scanning |
|
443 | + // process is running in parallel |
|
444 | + // log and ignore |
|
445 | + if ($this->useTransactions) { |
|
446 | + \OC::$server->getDatabaseConnection()->rollback(); |
|
447 | + \OC::$server->getDatabaseConnection()->beginTransaction(); |
|
448 | + } |
|
449 | + \OC::$server->getLogger()->logException($ex, [ |
|
450 | + 'message' => 'Exception while scanning file "' . $child . '"', |
|
451 | + 'level' => ILogger::DEBUG, |
|
452 | + 'app' => 'core', |
|
453 | + ]); |
|
454 | + $exceptionOccurred = true; |
|
455 | + } catch (\OCP\Lock\LockedException $e) { |
|
456 | + if ($this->useTransactions) { |
|
457 | + \OC::$server->getDatabaseConnection()->rollback(); |
|
458 | + } |
|
459 | + throw $e; |
|
460 | + } |
|
461 | + } |
|
462 | + $removedChildren = \array_diff(array_keys($existingChildren), $newChildNames); |
|
463 | + foreach ($removedChildren as $childName) { |
|
464 | + $child = $path ? $path . '/' . $childName : $childName; |
|
465 | + $this->removeFromCache($child); |
|
466 | + } |
|
467 | + if ($this->useTransactions) { |
|
468 | + \OC::$server->getDatabaseConnection()->commit(); |
|
469 | + } |
|
470 | + if ($exceptionOccurred) { |
|
471 | + // It might happen that the parallel scan process has already |
|
472 | + // inserted mimetypes but those weren't available yet inside the transaction |
|
473 | + // To make sure to have the updated mime types in such cases, |
|
474 | + // we reload them here |
|
475 | + \OC::$server->getMimeTypeLoader()->reset(); |
|
476 | + } |
|
477 | + return $childQueue; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * check if the file should be ignored when scanning |
|
482 | + * NOTE: files with a '.part' extension are ignored as well! |
|
483 | + * prevents unfinished put requests to be scanned |
|
484 | + * |
|
485 | + * @param string $file |
|
486 | + * @return boolean |
|
487 | + */ |
|
488 | + public static function isPartialFile($file) { |
|
489 | + if (pathinfo($file, PATHINFO_EXTENSION) === 'part') { |
|
490 | + return true; |
|
491 | + } |
|
492 | + if (strpos($file, '.part/') !== false) { |
|
493 | + return true; |
|
494 | + } |
|
495 | + |
|
496 | + return false; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * walk over any folders that are not fully scanned yet and scan them |
|
501 | + */ |
|
502 | + public function backgroundScan() { |
|
503 | + if (!$this->cache->inCache('')) { |
|
504 | + $this->runBackgroundScanJob(function () { |
|
505 | + $this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG); |
|
506 | + }, ''); |
|
507 | + } else { |
|
508 | + $lastPath = null; |
|
509 | + while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { |
|
510 | + $this->runBackgroundScanJob(function () use ($path) { |
|
511 | + $this->scan($path, self::SCAN_RECURSIVE_INCOMPLETE, self::REUSE_ETAG | self::REUSE_SIZE); |
|
512 | + }, $path); |
|
513 | + // FIXME: this won't proceed with the next item, needs revamping of getIncomplete() |
|
514 | + // to make this possible |
|
515 | + $lastPath = $path; |
|
516 | + } |
|
517 | + } |
|
518 | + } |
|
519 | + |
|
520 | + private function runBackgroundScanJob(callable $callback, $path) { |
|
521 | + try { |
|
522 | + $callback(); |
|
523 | + \OC_Hook::emit('Scanner', 'correctFolderSize', ['path' => $path]); |
|
524 | + if ($this->cacheActive && $this->cache instanceof Cache) { |
|
525 | + $this->cache->correctFolderSize($path, null, true); |
|
526 | + } |
|
527 | + } catch (\OCP\Files\StorageInvalidException $e) { |
|
528 | + // skip unavailable storages |
|
529 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
530 | + // skip unavailable storages |
|
531 | + } catch (\OCP\Files\ForbiddenException $e) { |
|
532 | + // skip forbidden storages |
|
533 | + } catch (\OCP\Lock\LockedException $e) { |
|
534 | + // skip unavailable storages |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Set whether the cache is affected by scan operations |
|
540 | + * |
|
541 | + * @param boolean $active The active state of the cache |
|
542 | + */ |
|
543 | + public function setCacheActive($active) { |
|
544 | + $this->cacheActive = $active; |
|
545 | + } |
|
546 | 546 | } |
@@ -250,2041 +250,2041 @@ |
||
250 | 250 | */ |
251 | 251 | class Server extends ServerContainer implements IServerContainer { |
252 | 252 | |
253 | - /** @var string */ |
|
254 | - private $webRoot; |
|
255 | - |
|
256 | - /** |
|
257 | - * @param string $webRoot |
|
258 | - * @param \OC\Config $config |
|
259 | - */ |
|
260 | - public function __construct($webRoot, \OC\Config $config) { |
|
261 | - parent::__construct(); |
|
262 | - $this->webRoot = $webRoot; |
|
263 | - |
|
264 | - // To find out if we are running from CLI or not |
|
265 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
266 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
267 | - |
|
268 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
269 | - return $c; |
|
270 | - }); |
|
271 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
272 | - return $c; |
|
273 | - }); |
|
274 | - |
|
275 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
276 | - /** @deprecated 19.0.0 */ |
|
277 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
278 | - |
|
279 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
280 | - /** @deprecated 19.0.0 */ |
|
281 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
282 | - |
|
283 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
284 | - /** @deprecated 19.0.0 */ |
|
285 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
286 | - |
|
287 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
288 | - /** @deprecated 19.0.0 */ |
|
289 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
290 | - |
|
291 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
292 | - |
|
293 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
294 | - |
|
295 | - $this->registerService(View::class, function (Server $c) { |
|
296 | - return new View(); |
|
297 | - }, false); |
|
298 | - |
|
299 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
300 | - return new PreviewManager( |
|
301 | - $c->get(\OCP\IConfig::class), |
|
302 | - $c->get(IRootFolder::class), |
|
303 | - new \OC\Preview\Storage\Root( |
|
304 | - $c->get(IRootFolder::class), |
|
305 | - $c->get(SystemConfig::class) |
|
306 | - ), |
|
307 | - $c->get(SymfonyAdapter::class), |
|
308 | - $c->get(GeneratorHelper::class), |
|
309 | - $c->get(ISession::class)->get('user_id') |
|
310 | - ); |
|
311 | - }); |
|
312 | - /** @deprecated 19.0.0 */ |
|
313 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
314 | - |
|
315 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
316 | - return new \OC\Preview\Watcher( |
|
317 | - new \OC\Preview\Storage\Root( |
|
318 | - $c->get(IRootFolder::class), |
|
319 | - $c->get(SystemConfig::class) |
|
320 | - ) |
|
321 | - ); |
|
322 | - }); |
|
323 | - |
|
324 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
325 | - $view = new View(); |
|
326 | - $util = new Encryption\Util( |
|
327 | - $view, |
|
328 | - $c->get(IUserManager::class), |
|
329 | - $c->get(IGroupManager::class), |
|
330 | - $c->get(\OCP\IConfig::class) |
|
331 | - ); |
|
332 | - return new Encryption\Manager( |
|
333 | - $c->get(\OCP\IConfig::class), |
|
334 | - $c->get(ILogger::class), |
|
335 | - $c->getL10N('core'), |
|
336 | - new View(), |
|
337 | - $util, |
|
338 | - new ArrayCache() |
|
339 | - ); |
|
340 | - }); |
|
341 | - /** @deprecated 19.0.0 */ |
|
342 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
343 | - |
|
344 | - /** @deprecated 21.0.0 */ |
|
345 | - $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
346 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
347 | - $util = new Encryption\Util( |
|
348 | - new View(), |
|
349 | - $c->get(IUserManager::class), |
|
350 | - $c->get(IGroupManager::class), |
|
351 | - $c->get(\OCP\IConfig::class) |
|
352 | - ); |
|
353 | - return new Encryption\File( |
|
354 | - $util, |
|
355 | - $c->get(IRootFolder::class), |
|
356 | - $c->get(\OCP\Share\IManager::class) |
|
357 | - ); |
|
358 | - }); |
|
359 | - |
|
360 | - /** @deprecated 21.0.0 */ |
|
361 | - $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
362 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
363 | - $view = new View(); |
|
364 | - $util = new Encryption\Util( |
|
365 | - $view, |
|
366 | - $c->get(IUserManager::class), |
|
367 | - $c->get(IGroupManager::class), |
|
368 | - $c->get(\OCP\IConfig::class) |
|
369 | - ); |
|
370 | - |
|
371 | - return new Encryption\Keys\Storage( |
|
372 | - $view, |
|
373 | - $util, |
|
374 | - $c->get(ICrypto::class), |
|
375 | - $c->get(\OCP\IConfig::class) |
|
376 | - ); |
|
377 | - }); |
|
378 | - /** @deprecated 20.0.0 */ |
|
379 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
380 | - |
|
381 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
382 | - /** @deprecated 19.0.0 */ |
|
383 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
384 | - |
|
385 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
386 | - /** @var \OCP\IConfig $config */ |
|
387 | - $config = $c->get(\OCP\IConfig::class); |
|
388 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
389 | - return new $factoryClass($this); |
|
390 | - }); |
|
391 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
392 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
393 | - }); |
|
394 | - /** @deprecated 19.0.0 */ |
|
395 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
396 | - |
|
397 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
398 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
399 | - }); |
|
400 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
401 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
402 | - $view = new View(); |
|
403 | - $root = new Root( |
|
404 | - $manager, |
|
405 | - $view, |
|
406 | - null, |
|
407 | - $c->get(IUserMountCache::class), |
|
408 | - $this->get(ILogger::class), |
|
409 | - $this->get(IUserManager::class) |
|
410 | - ); |
|
411 | - |
|
412 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
413 | - $root, |
|
414 | - $c->get(SystemConfig::class) |
|
415 | - ); |
|
416 | - $previewConnector->connectWatcher(); |
|
417 | - |
|
418 | - return $root; |
|
419 | - }); |
|
420 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
421 | - return new HookConnector( |
|
422 | - $c->get(IRootFolder::class), |
|
423 | - new View(), |
|
424 | - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
425 | - $c->get(IEventDispatcher::class) |
|
426 | - ); |
|
427 | - }); |
|
428 | - |
|
429 | - /** @deprecated 19.0.0 */ |
|
430 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
431 | - |
|
432 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
433 | - return new LazyRoot(function () use ($c) { |
|
434 | - return $c->get('RootFolder'); |
|
435 | - }); |
|
436 | - }); |
|
437 | - /** @deprecated 19.0.0 */ |
|
438 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
439 | - |
|
440 | - /** @deprecated 19.0.0 */ |
|
441 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
442 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
443 | - |
|
444 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
445 | - $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
446 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
447 | - /** @var IEventDispatcher $dispatcher */ |
|
448 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
449 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
450 | - }); |
|
451 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
452 | - /** @var IEventDispatcher $dispatcher */ |
|
453 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
454 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
455 | - }); |
|
456 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
457 | - /** @var IEventDispatcher $dispatcher */ |
|
458 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
459 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
460 | - }); |
|
461 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
462 | - /** @var IEventDispatcher $dispatcher */ |
|
463 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
464 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
465 | - }); |
|
466 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
467 | - /** @var IEventDispatcher $dispatcher */ |
|
468 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
469 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
470 | - }); |
|
471 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
472 | - /** @var IEventDispatcher $dispatcher */ |
|
473 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
474 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
475 | - }); |
|
476 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
477 | - /** @var IEventDispatcher $dispatcher */ |
|
478 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
479 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
480 | - }); |
|
481 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
482 | - /** @var IEventDispatcher $dispatcher */ |
|
483 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
484 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
485 | - }); |
|
486 | - return $groupManager; |
|
487 | - }); |
|
488 | - /** @deprecated 19.0.0 */ |
|
489 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
490 | - |
|
491 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
492 | - $session = $c->get(ISession::class); |
|
493 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
494 | - $tokenProvider = $c->get(IProvider::class); |
|
495 | - } else { |
|
496 | - $tokenProvider = null; |
|
497 | - } |
|
498 | - $logger = $c->get(LoggerInterface::class); |
|
499 | - return new Store($session, $logger, $tokenProvider); |
|
500 | - }); |
|
501 | - $this->registerAlias(IStore::class, Store::class); |
|
502 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
503 | - |
|
504 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
505 | - $manager = $c->get(IUserManager::class); |
|
506 | - $session = new \OC\Session\Memory(''); |
|
507 | - $timeFactory = new TimeFactory(); |
|
508 | - // Token providers might require a working database. This code |
|
509 | - // might however be called when ownCloud is not yet setup. |
|
510 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
511 | - $defaultTokenProvider = $c->get(IProvider::class); |
|
512 | - } else { |
|
513 | - $defaultTokenProvider = null; |
|
514 | - } |
|
515 | - |
|
516 | - $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
517 | - |
|
518 | - $userSession = new \OC\User\Session( |
|
519 | - $manager, |
|
520 | - $session, |
|
521 | - $timeFactory, |
|
522 | - $defaultTokenProvider, |
|
523 | - $c->get(\OCP\IConfig::class), |
|
524 | - $c->get(ISecureRandom::class), |
|
525 | - $c->getLockdownManager(), |
|
526 | - $c->get(ILogger::class), |
|
527 | - $c->get(IEventDispatcher::class) |
|
528 | - ); |
|
529 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
530 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
531 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
532 | - }); |
|
533 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
534 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
535 | - /** @var \OC\User\User $user */ |
|
536 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
537 | - }); |
|
538 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
539 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
540 | - /** @var \OC\User\User $user */ |
|
541 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
542 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
543 | - }); |
|
544 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
545 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
546 | - /** @var \OC\User\User $user */ |
|
547 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
548 | - }); |
|
549 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
550 | - /** @var \OC\User\User $user */ |
|
551 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
552 | - |
|
553 | - /** @var IEventDispatcher $dispatcher */ |
|
554 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
555 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
556 | - }); |
|
557 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
558 | - /** @var \OC\User\User $user */ |
|
559 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
560 | - |
|
561 | - /** @var IEventDispatcher $dispatcher */ |
|
562 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
563 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
564 | - }); |
|
565 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
566 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
567 | - |
|
568 | - /** @var IEventDispatcher $dispatcher */ |
|
569 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
570 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
571 | - }); |
|
572 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
573 | - /** @var \OC\User\User $user */ |
|
574 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
575 | - |
|
576 | - /** @var IEventDispatcher $dispatcher */ |
|
577 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
578 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
579 | - }); |
|
580 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
581 | - /** @var IEventDispatcher $dispatcher */ |
|
582 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
583 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
584 | - }); |
|
585 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
586 | - /** @var \OC\User\User $user */ |
|
587 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
588 | - |
|
589 | - /** @var IEventDispatcher $dispatcher */ |
|
590 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
591 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
592 | - }); |
|
593 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
594 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
595 | - |
|
596 | - /** @var IEventDispatcher $dispatcher */ |
|
597 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
598 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
599 | - }); |
|
600 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
601 | - /** @var IEventDispatcher $dispatcher */ |
|
602 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
603 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
604 | - }); |
|
605 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
606 | - /** @var \OC\User\User $user */ |
|
607 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
608 | - |
|
609 | - /** @var IEventDispatcher $dispatcher */ |
|
610 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
611 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
612 | - }); |
|
613 | - return $userSession; |
|
614 | - }); |
|
615 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
616 | - /** @deprecated 19.0.0 */ |
|
617 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
618 | - |
|
619 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
620 | - |
|
621 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
622 | - /** @deprecated 19.0.0 */ |
|
623 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
624 | - |
|
625 | - /** @deprecated 19.0.0 */ |
|
626 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
627 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
628 | - |
|
629 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
630 | - return new \OC\SystemConfig($config); |
|
631 | - }); |
|
632 | - /** @deprecated 19.0.0 */ |
|
633 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
634 | - |
|
635 | - /** @deprecated 19.0.0 */ |
|
636 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
637 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
638 | - |
|
639 | - $this->registerService(IFactory::class, function (Server $c) { |
|
640 | - return new \OC\L10N\Factory( |
|
641 | - $c->get(\OCP\IConfig::class), |
|
642 | - $c->getRequest(), |
|
643 | - $c->get(IUserSession::class), |
|
644 | - \OC::$SERVERROOT |
|
645 | - ); |
|
646 | - }); |
|
647 | - /** @deprecated 19.0.0 */ |
|
648 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
649 | - |
|
650 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
651 | - /** @deprecated 19.0.0 */ |
|
652 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
653 | - |
|
654 | - /** @deprecated 19.0.0 */ |
|
655 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
656 | - /** @deprecated 19.0.0 */ |
|
657 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
658 | - |
|
659 | - $this->registerService(ICache::class, function ($c) { |
|
660 | - return new Cache\File(); |
|
661 | - }); |
|
662 | - /** @deprecated 19.0.0 */ |
|
663 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
664 | - |
|
665 | - $this->registerService(Factory::class, function (Server $c) { |
|
666 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
667 | - ArrayCache::class, |
|
668 | - ArrayCache::class, |
|
669 | - ArrayCache::class |
|
670 | - ); |
|
671 | - /** @var \OCP\IConfig $config */ |
|
672 | - $config = $c->get(\OCP\IConfig::class); |
|
673 | - |
|
674 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
675 | - $v = \OC_App::getAppVersions(); |
|
676 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
677 | - $version = implode(',', $v); |
|
678 | - $instanceId = \OC_Util::getInstanceId(); |
|
679 | - $path = \OC::$SERVERROOT; |
|
680 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
681 | - return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
682 | - $config->getSystemValue('memcache.local', null), |
|
683 | - $config->getSystemValue('memcache.distributed', null), |
|
684 | - $config->getSystemValue('memcache.locking', null) |
|
685 | - ); |
|
686 | - } |
|
687 | - return $arrayCacheFactory; |
|
688 | - }); |
|
689 | - /** @deprecated 19.0.0 */ |
|
690 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
691 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
692 | - |
|
693 | - $this->registerService('RedisFactory', function (Server $c) { |
|
694 | - $systemConfig = $c->get(SystemConfig::class); |
|
695 | - return new RedisFactory($systemConfig); |
|
696 | - }); |
|
697 | - |
|
698 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
699 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
700 | - return new \OC\Activity\Manager( |
|
701 | - $c->getRequest(), |
|
702 | - $c->get(IUserSession::class), |
|
703 | - $c->get(\OCP\IConfig::class), |
|
704 | - $c->get(IValidator::class), |
|
705 | - $l10n |
|
706 | - ); |
|
707 | - }); |
|
708 | - /** @deprecated 19.0.0 */ |
|
709 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
710 | - |
|
711 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
712 | - return new \OC\Activity\EventMerger( |
|
713 | - $c->getL10N('lib') |
|
714 | - ); |
|
715 | - }); |
|
716 | - $this->registerAlias(IValidator::class, Validator::class); |
|
717 | - |
|
718 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
719 | - return new AvatarManager( |
|
720 | - $c->get(\OC\User\Manager::class), |
|
721 | - $c->getAppDataDir('avatar'), |
|
722 | - $c->getL10N('lib'), |
|
723 | - $c->get(ILogger::class), |
|
724 | - $c->get(\OCP\IConfig::class) |
|
725 | - ); |
|
726 | - }); |
|
727 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
728 | - /** @deprecated 19.0.0 */ |
|
729 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
730 | - |
|
731 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
732 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
733 | - |
|
734 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
735 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
736 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
737 | - $logger = $factory->get($logType); |
|
738 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
739 | - |
|
740 | - return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
741 | - }); |
|
742 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
743 | - /** @deprecated 19.0.0 */ |
|
744 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
745 | - // PSR-3 logger |
|
746 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
747 | - |
|
748 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
749 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
750 | - }); |
|
751 | - |
|
752 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
753 | - /** @deprecated 19.0.0 */ |
|
754 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
755 | - |
|
756 | - $this->registerService(Router::class, function (Server $c) { |
|
757 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
758 | - $logger = $c->get(ILogger::class); |
|
759 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
760 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
761 | - } else { |
|
762 | - $router = new \OC\Route\Router($logger); |
|
763 | - } |
|
764 | - return $router; |
|
765 | - }); |
|
766 | - $this->registerAlias(IRouter::class, Router::class); |
|
767 | - /** @deprecated 19.0.0 */ |
|
768 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
769 | - |
|
770 | - $this->registerAlias(ISearch::class, Search::class); |
|
771 | - /** @deprecated 19.0.0 */ |
|
772 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
773 | - |
|
774 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
775 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
776 | - $this->get(ICacheFactory::class), |
|
777 | - new \OC\AppFramework\Utility\TimeFactory() |
|
778 | - ); |
|
779 | - }); |
|
780 | - |
|
781 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
782 | - /** @deprecated 19.0.0 */ |
|
783 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
784 | - |
|
785 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
786 | - /** @deprecated 19.0.0 */ |
|
787 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
788 | - |
|
789 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
790 | - /** @deprecated 19.0.0 */ |
|
791 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
792 | - |
|
793 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
794 | - /** @deprecated 19.0.0 */ |
|
795 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
796 | - |
|
797 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
798 | - $this->registerService(Connection::class, function (Server $c) { |
|
799 | - $systemConfig = $c->get(SystemConfig::class); |
|
800 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
801 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
802 | - if (!$factory->isValidType($type)) { |
|
803 | - throw new \OC\DatabaseException('Invalid database type'); |
|
804 | - } |
|
805 | - $connectionParams = $factory->createConnectionParams(); |
|
806 | - $connection = $factory->getConnection($type, $connectionParams); |
|
807 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
808 | - return $connection; |
|
809 | - }); |
|
810 | - /** @deprecated 19.0.0 */ |
|
811 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
812 | - |
|
813 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
814 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
815 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
816 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
817 | - $eventLogger = new EventLogger(); |
|
818 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
819 | - // In debug mode, module is being activated by default |
|
820 | - $eventLogger->activate(); |
|
821 | - } |
|
822 | - return $eventLogger; |
|
823 | - }); |
|
824 | - /** @deprecated 19.0.0 */ |
|
825 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
826 | - |
|
827 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
828 | - $queryLogger = new QueryLogger(); |
|
829 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
830 | - // In debug mode, module is being activated by default |
|
831 | - $queryLogger->activate(); |
|
832 | - } |
|
833 | - return $queryLogger; |
|
834 | - }); |
|
835 | - /** @deprecated 19.0.0 */ |
|
836 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
837 | - |
|
838 | - /** @deprecated 19.0.0 */ |
|
839 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
840 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
841 | - |
|
842 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
843 | - // TODO: use auto-wiring |
|
844 | - return new \OC\App\AppManager( |
|
845 | - $c->get(IUserSession::class), |
|
846 | - $c->get(\OCP\IConfig::class), |
|
847 | - $c->get(\OC\AppConfig::class), |
|
848 | - $c->get(IGroupManager::class), |
|
849 | - $c->get(ICacheFactory::class), |
|
850 | - $c->get(SymfonyAdapter::class), |
|
851 | - $c->get(ILogger::class) |
|
852 | - ); |
|
853 | - }); |
|
854 | - /** @deprecated 19.0.0 */ |
|
855 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
856 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
857 | - |
|
858 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
859 | - /** @deprecated 19.0.0 */ |
|
860 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
861 | - |
|
862 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
863 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
864 | - |
|
865 | - return new DateTimeFormatter( |
|
866 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
867 | - $c->getL10N('lib', $language) |
|
868 | - ); |
|
869 | - }); |
|
870 | - /** @deprecated 19.0.0 */ |
|
871 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
872 | - |
|
873 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
874 | - $mountCache = new UserMountCache( |
|
875 | - $c->get(IDBConnection::class), |
|
876 | - $c->get(IUserManager::class), |
|
877 | - $c->get(ILogger::class) |
|
878 | - ); |
|
879 | - $listener = new UserMountCacheListener($mountCache); |
|
880 | - $listener->listen($c->get(IUserManager::class)); |
|
881 | - return $mountCache; |
|
882 | - }); |
|
883 | - /** @deprecated 19.0.0 */ |
|
884 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
885 | - |
|
886 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
887 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
888 | - $mountCache = $c->get(IUserMountCache::class); |
|
889 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
890 | - |
|
891 | - // builtin providers |
|
892 | - |
|
893 | - $config = $c->get(\OCP\IConfig::class); |
|
894 | - $logger = $c->get(ILogger::class); |
|
895 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
896 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
897 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
898 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
899 | - |
|
900 | - return $manager; |
|
901 | - }); |
|
902 | - /** @deprecated 19.0.0 */ |
|
903 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
904 | - |
|
905 | - /** @deprecated 20.0.0 */ |
|
906 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
907 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
908 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
909 | - if ($busClass) { |
|
910 | - [$app, $class] = explode('::', $busClass, 2); |
|
911 | - if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
912 | - \OC_App::loadApp($app); |
|
913 | - return $c->get($class); |
|
914 | - } else { |
|
915 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
916 | - } |
|
917 | - } else { |
|
918 | - $jobList = $c->get(IJobList::class); |
|
919 | - return new CronBus($jobList); |
|
920 | - } |
|
921 | - }); |
|
922 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
923 | - /** @deprecated 20.0.0 */ |
|
924 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
925 | - /** @deprecated 19.0.0 */ |
|
926 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
927 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
928 | - // IConfig and IAppManager requires a working database. This code |
|
929 | - // might however be called when ownCloud is not yet setup. |
|
930 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
931 | - $config = $c->get(\OCP\IConfig::class); |
|
932 | - $appManager = $c->get(IAppManager::class); |
|
933 | - } else { |
|
934 | - $config = null; |
|
935 | - $appManager = null; |
|
936 | - } |
|
937 | - |
|
938 | - return new Checker( |
|
939 | - new EnvironmentHelper(), |
|
940 | - new FileAccessHelper(), |
|
941 | - new AppLocator(), |
|
942 | - $config, |
|
943 | - $c->get(ICacheFactory::class), |
|
944 | - $appManager, |
|
945 | - $c->get(ITempManager::class), |
|
946 | - $c->get(IMimeTypeDetector::class) |
|
947 | - ); |
|
948 | - }); |
|
949 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
950 | - if (isset($this['urlParams'])) { |
|
951 | - $urlParams = $this['urlParams']; |
|
952 | - } else { |
|
953 | - $urlParams = []; |
|
954 | - } |
|
955 | - |
|
956 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
957 | - && in_array('fakeinput', stream_get_wrappers()) |
|
958 | - ) { |
|
959 | - $stream = 'fakeinput://data'; |
|
960 | - } else { |
|
961 | - $stream = 'php://input'; |
|
962 | - } |
|
963 | - |
|
964 | - return new Request( |
|
965 | - [ |
|
966 | - 'get' => $_GET, |
|
967 | - 'post' => $_POST, |
|
968 | - 'files' => $_FILES, |
|
969 | - 'server' => $_SERVER, |
|
970 | - 'env' => $_ENV, |
|
971 | - 'cookies' => $_COOKIE, |
|
972 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
973 | - ? $_SERVER['REQUEST_METHOD'] |
|
974 | - : '', |
|
975 | - 'urlParams' => $urlParams, |
|
976 | - ], |
|
977 | - $this->get(ISecureRandom::class), |
|
978 | - $this->get(\OCP\IConfig::class), |
|
979 | - $this->get(CsrfTokenManager::class), |
|
980 | - $stream |
|
981 | - ); |
|
982 | - }); |
|
983 | - /** @deprecated 19.0.0 */ |
|
984 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
985 | - |
|
986 | - $this->registerService(IMailer::class, function (Server $c) { |
|
987 | - return new Mailer( |
|
988 | - $c->get(\OCP\IConfig::class), |
|
989 | - $c->get(ILogger::class), |
|
990 | - $c->get(Defaults::class), |
|
991 | - $c->get(IURLGenerator::class), |
|
992 | - $c->getL10N('lib'), |
|
993 | - $c->get(IEventDispatcher::class), |
|
994 | - $c->get(IFactory::class) |
|
995 | - ); |
|
996 | - }); |
|
997 | - /** @deprecated 19.0.0 */ |
|
998 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
999 | - |
|
1000 | - $this->registerService('LDAPProvider', function (ContainerInterface $c) { |
|
1001 | - $config = $c->get(\OCP\IConfig::class); |
|
1002 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1003 | - if (is_null($factoryClass)) { |
|
1004 | - throw new \Exception('ldapProviderFactory not set'); |
|
1005 | - } |
|
1006 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1007 | - $factory = new $factoryClass($this); |
|
1008 | - return $factory->getLDAPProvider(); |
|
1009 | - }); |
|
1010 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1011 | - $ini = $c->get(IniGetWrapper::class); |
|
1012 | - $config = $c->get(\OCP\IConfig::class); |
|
1013 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1014 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1015 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1016 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1017 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
1018 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1019 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
1020 | - } |
|
1021 | - return new DBLockingProvider( |
|
1022 | - $c->get(IDBConnection::class), |
|
1023 | - $c->get(ILogger::class), |
|
1024 | - new TimeFactory(), |
|
1025 | - $ttl, |
|
1026 | - !\OC::$CLI |
|
1027 | - ); |
|
1028 | - } |
|
1029 | - return new NoopLockingProvider(); |
|
1030 | - }); |
|
1031 | - /** @deprecated 19.0.0 */ |
|
1032 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1033 | - |
|
1034 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1035 | - /** @deprecated 19.0.0 */ |
|
1036 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1037 | - |
|
1038 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1039 | - return new \OC\Files\Type\Detection( |
|
1040 | - $c->get(IURLGenerator::class), |
|
1041 | - $c->get(ILogger::class), |
|
1042 | - \OC::$configDir, |
|
1043 | - \OC::$SERVERROOT . '/resources/config/' |
|
1044 | - ); |
|
1045 | - }); |
|
1046 | - /** @deprecated 19.0.0 */ |
|
1047 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1048 | - |
|
1049 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1050 | - /** @deprecated 19.0.0 */ |
|
1051 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1052 | - $this->registerService(BundleFetcher::class, function () { |
|
1053 | - return new BundleFetcher($this->getL10N('lib')); |
|
1054 | - }); |
|
1055 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1056 | - /** @deprecated 19.0.0 */ |
|
1057 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1058 | - |
|
1059 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1060 | - $manager = new CapabilitiesManager($c->get(ILogger::class)); |
|
1061 | - $manager->registerCapability(function () use ($c) { |
|
1062 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1063 | - }); |
|
1064 | - $manager->registerCapability(function () use ($c) { |
|
1065 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1066 | - }); |
|
1067 | - return $manager; |
|
1068 | - }); |
|
1069 | - /** @deprecated 19.0.0 */ |
|
1070 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1071 | - |
|
1072 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1073 | - $config = $c->get(\OCP\IConfig::class); |
|
1074 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1075 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1076 | - $factory = new $factoryClass($this); |
|
1077 | - $manager = $factory->getManager(); |
|
1078 | - |
|
1079 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1080 | - $manager = $c->get(IUserManager::class); |
|
1081 | - $user = $manager->get($id); |
|
1082 | - if (is_null($user)) { |
|
1083 | - $l = $c->getL10N('core'); |
|
1084 | - $displayName = $l->t('Unknown user'); |
|
1085 | - } else { |
|
1086 | - $displayName = $user->getDisplayName(); |
|
1087 | - } |
|
1088 | - return $displayName; |
|
1089 | - }); |
|
1090 | - |
|
1091 | - return $manager; |
|
1092 | - }); |
|
1093 | - /** @deprecated 19.0.0 */ |
|
1094 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1095 | - |
|
1096 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1097 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
1098 | - /* |
|
253 | + /** @var string */ |
|
254 | + private $webRoot; |
|
255 | + |
|
256 | + /** |
|
257 | + * @param string $webRoot |
|
258 | + * @param \OC\Config $config |
|
259 | + */ |
|
260 | + public function __construct($webRoot, \OC\Config $config) { |
|
261 | + parent::__construct(); |
|
262 | + $this->webRoot = $webRoot; |
|
263 | + |
|
264 | + // To find out if we are running from CLI or not |
|
265 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
266 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
267 | + |
|
268 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
269 | + return $c; |
|
270 | + }); |
|
271 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
272 | + return $c; |
|
273 | + }); |
|
274 | + |
|
275 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
276 | + /** @deprecated 19.0.0 */ |
|
277 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
278 | + |
|
279 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
280 | + /** @deprecated 19.0.0 */ |
|
281 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
282 | + |
|
283 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
284 | + /** @deprecated 19.0.0 */ |
|
285 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
286 | + |
|
287 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
288 | + /** @deprecated 19.0.0 */ |
|
289 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
290 | + |
|
291 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
292 | + |
|
293 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
294 | + |
|
295 | + $this->registerService(View::class, function (Server $c) { |
|
296 | + return new View(); |
|
297 | + }, false); |
|
298 | + |
|
299 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
300 | + return new PreviewManager( |
|
301 | + $c->get(\OCP\IConfig::class), |
|
302 | + $c->get(IRootFolder::class), |
|
303 | + new \OC\Preview\Storage\Root( |
|
304 | + $c->get(IRootFolder::class), |
|
305 | + $c->get(SystemConfig::class) |
|
306 | + ), |
|
307 | + $c->get(SymfonyAdapter::class), |
|
308 | + $c->get(GeneratorHelper::class), |
|
309 | + $c->get(ISession::class)->get('user_id') |
|
310 | + ); |
|
311 | + }); |
|
312 | + /** @deprecated 19.0.0 */ |
|
313 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
314 | + |
|
315 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
316 | + return new \OC\Preview\Watcher( |
|
317 | + new \OC\Preview\Storage\Root( |
|
318 | + $c->get(IRootFolder::class), |
|
319 | + $c->get(SystemConfig::class) |
|
320 | + ) |
|
321 | + ); |
|
322 | + }); |
|
323 | + |
|
324 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
325 | + $view = new View(); |
|
326 | + $util = new Encryption\Util( |
|
327 | + $view, |
|
328 | + $c->get(IUserManager::class), |
|
329 | + $c->get(IGroupManager::class), |
|
330 | + $c->get(\OCP\IConfig::class) |
|
331 | + ); |
|
332 | + return new Encryption\Manager( |
|
333 | + $c->get(\OCP\IConfig::class), |
|
334 | + $c->get(ILogger::class), |
|
335 | + $c->getL10N('core'), |
|
336 | + new View(), |
|
337 | + $util, |
|
338 | + new ArrayCache() |
|
339 | + ); |
|
340 | + }); |
|
341 | + /** @deprecated 19.0.0 */ |
|
342 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
343 | + |
|
344 | + /** @deprecated 21.0.0 */ |
|
345 | + $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
346 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
347 | + $util = new Encryption\Util( |
|
348 | + new View(), |
|
349 | + $c->get(IUserManager::class), |
|
350 | + $c->get(IGroupManager::class), |
|
351 | + $c->get(\OCP\IConfig::class) |
|
352 | + ); |
|
353 | + return new Encryption\File( |
|
354 | + $util, |
|
355 | + $c->get(IRootFolder::class), |
|
356 | + $c->get(\OCP\Share\IManager::class) |
|
357 | + ); |
|
358 | + }); |
|
359 | + |
|
360 | + /** @deprecated 21.0.0 */ |
|
361 | + $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
362 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
363 | + $view = new View(); |
|
364 | + $util = new Encryption\Util( |
|
365 | + $view, |
|
366 | + $c->get(IUserManager::class), |
|
367 | + $c->get(IGroupManager::class), |
|
368 | + $c->get(\OCP\IConfig::class) |
|
369 | + ); |
|
370 | + |
|
371 | + return new Encryption\Keys\Storage( |
|
372 | + $view, |
|
373 | + $util, |
|
374 | + $c->get(ICrypto::class), |
|
375 | + $c->get(\OCP\IConfig::class) |
|
376 | + ); |
|
377 | + }); |
|
378 | + /** @deprecated 20.0.0 */ |
|
379 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
380 | + |
|
381 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
382 | + /** @deprecated 19.0.0 */ |
|
383 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
384 | + |
|
385 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
386 | + /** @var \OCP\IConfig $config */ |
|
387 | + $config = $c->get(\OCP\IConfig::class); |
|
388 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
389 | + return new $factoryClass($this); |
|
390 | + }); |
|
391 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
392 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
393 | + }); |
|
394 | + /** @deprecated 19.0.0 */ |
|
395 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
396 | + |
|
397 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
398 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
399 | + }); |
|
400 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
401 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
402 | + $view = new View(); |
|
403 | + $root = new Root( |
|
404 | + $manager, |
|
405 | + $view, |
|
406 | + null, |
|
407 | + $c->get(IUserMountCache::class), |
|
408 | + $this->get(ILogger::class), |
|
409 | + $this->get(IUserManager::class) |
|
410 | + ); |
|
411 | + |
|
412 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
413 | + $root, |
|
414 | + $c->get(SystemConfig::class) |
|
415 | + ); |
|
416 | + $previewConnector->connectWatcher(); |
|
417 | + |
|
418 | + return $root; |
|
419 | + }); |
|
420 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
421 | + return new HookConnector( |
|
422 | + $c->get(IRootFolder::class), |
|
423 | + new View(), |
|
424 | + $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
425 | + $c->get(IEventDispatcher::class) |
|
426 | + ); |
|
427 | + }); |
|
428 | + |
|
429 | + /** @deprecated 19.0.0 */ |
|
430 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
431 | + |
|
432 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
433 | + return new LazyRoot(function () use ($c) { |
|
434 | + return $c->get('RootFolder'); |
|
435 | + }); |
|
436 | + }); |
|
437 | + /** @deprecated 19.0.0 */ |
|
438 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
439 | + |
|
440 | + /** @deprecated 19.0.0 */ |
|
441 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
442 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
443 | + |
|
444 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
445 | + $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
446 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
447 | + /** @var IEventDispatcher $dispatcher */ |
|
448 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
449 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
450 | + }); |
|
451 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
452 | + /** @var IEventDispatcher $dispatcher */ |
|
453 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
454 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
455 | + }); |
|
456 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
457 | + /** @var IEventDispatcher $dispatcher */ |
|
458 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
459 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
460 | + }); |
|
461 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
462 | + /** @var IEventDispatcher $dispatcher */ |
|
463 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
464 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
465 | + }); |
|
466 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
467 | + /** @var IEventDispatcher $dispatcher */ |
|
468 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
469 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
470 | + }); |
|
471 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
472 | + /** @var IEventDispatcher $dispatcher */ |
|
473 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
474 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
475 | + }); |
|
476 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
477 | + /** @var IEventDispatcher $dispatcher */ |
|
478 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
479 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
480 | + }); |
|
481 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
482 | + /** @var IEventDispatcher $dispatcher */ |
|
483 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
484 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
485 | + }); |
|
486 | + return $groupManager; |
|
487 | + }); |
|
488 | + /** @deprecated 19.0.0 */ |
|
489 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
490 | + |
|
491 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
492 | + $session = $c->get(ISession::class); |
|
493 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
494 | + $tokenProvider = $c->get(IProvider::class); |
|
495 | + } else { |
|
496 | + $tokenProvider = null; |
|
497 | + } |
|
498 | + $logger = $c->get(LoggerInterface::class); |
|
499 | + return new Store($session, $logger, $tokenProvider); |
|
500 | + }); |
|
501 | + $this->registerAlias(IStore::class, Store::class); |
|
502 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
503 | + |
|
504 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
505 | + $manager = $c->get(IUserManager::class); |
|
506 | + $session = new \OC\Session\Memory(''); |
|
507 | + $timeFactory = new TimeFactory(); |
|
508 | + // Token providers might require a working database. This code |
|
509 | + // might however be called when ownCloud is not yet setup. |
|
510 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
511 | + $defaultTokenProvider = $c->get(IProvider::class); |
|
512 | + } else { |
|
513 | + $defaultTokenProvider = null; |
|
514 | + } |
|
515 | + |
|
516 | + $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
517 | + |
|
518 | + $userSession = new \OC\User\Session( |
|
519 | + $manager, |
|
520 | + $session, |
|
521 | + $timeFactory, |
|
522 | + $defaultTokenProvider, |
|
523 | + $c->get(\OCP\IConfig::class), |
|
524 | + $c->get(ISecureRandom::class), |
|
525 | + $c->getLockdownManager(), |
|
526 | + $c->get(ILogger::class), |
|
527 | + $c->get(IEventDispatcher::class) |
|
528 | + ); |
|
529 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
530 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
531 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
532 | + }); |
|
533 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
534 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
535 | + /** @var \OC\User\User $user */ |
|
536 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
537 | + }); |
|
538 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
539 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
540 | + /** @var \OC\User\User $user */ |
|
541 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
542 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
543 | + }); |
|
544 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
545 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
546 | + /** @var \OC\User\User $user */ |
|
547 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
548 | + }); |
|
549 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
550 | + /** @var \OC\User\User $user */ |
|
551 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
552 | + |
|
553 | + /** @var IEventDispatcher $dispatcher */ |
|
554 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
555 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
556 | + }); |
|
557 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
558 | + /** @var \OC\User\User $user */ |
|
559 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
560 | + |
|
561 | + /** @var IEventDispatcher $dispatcher */ |
|
562 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
563 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
564 | + }); |
|
565 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
566 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
567 | + |
|
568 | + /** @var IEventDispatcher $dispatcher */ |
|
569 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
570 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
571 | + }); |
|
572 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
573 | + /** @var \OC\User\User $user */ |
|
574 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
575 | + |
|
576 | + /** @var IEventDispatcher $dispatcher */ |
|
577 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
578 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
579 | + }); |
|
580 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
581 | + /** @var IEventDispatcher $dispatcher */ |
|
582 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
583 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
584 | + }); |
|
585 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
586 | + /** @var \OC\User\User $user */ |
|
587 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
588 | + |
|
589 | + /** @var IEventDispatcher $dispatcher */ |
|
590 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
591 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
592 | + }); |
|
593 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
594 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
595 | + |
|
596 | + /** @var IEventDispatcher $dispatcher */ |
|
597 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
598 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
599 | + }); |
|
600 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
601 | + /** @var IEventDispatcher $dispatcher */ |
|
602 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
603 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
604 | + }); |
|
605 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
606 | + /** @var \OC\User\User $user */ |
|
607 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
608 | + |
|
609 | + /** @var IEventDispatcher $dispatcher */ |
|
610 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
611 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
612 | + }); |
|
613 | + return $userSession; |
|
614 | + }); |
|
615 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
616 | + /** @deprecated 19.0.0 */ |
|
617 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
618 | + |
|
619 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
620 | + |
|
621 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
622 | + /** @deprecated 19.0.0 */ |
|
623 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
624 | + |
|
625 | + /** @deprecated 19.0.0 */ |
|
626 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
627 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
628 | + |
|
629 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
630 | + return new \OC\SystemConfig($config); |
|
631 | + }); |
|
632 | + /** @deprecated 19.0.0 */ |
|
633 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
634 | + |
|
635 | + /** @deprecated 19.0.0 */ |
|
636 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
637 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
638 | + |
|
639 | + $this->registerService(IFactory::class, function (Server $c) { |
|
640 | + return new \OC\L10N\Factory( |
|
641 | + $c->get(\OCP\IConfig::class), |
|
642 | + $c->getRequest(), |
|
643 | + $c->get(IUserSession::class), |
|
644 | + \OC::$SERVERROOT |
|
645 | + ); |
|
646 | + }); |
|
647 | + /** @deprecated 19.0.0 */ |
|
648 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
649 | + |
|
650 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
651 | + /** @deprecated 19.0.0 */ |
|
652 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
653 | + |
|
654 | + /** @deprecated 19.0.0 */ |
|
655 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
656 | + /** @deprecated 19.0.0 */ |
|
657 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
658 | + |
|
659 | + $this->registerService(ICache::class, function ($c) { |
|
660 | + return new Cache\File(); |
|
661 | + }); |
|
662 | + /** @deprecated 19.0.0 */ |
|
663 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
664 | + |
|
665 | + $this->registerService(Factory::class, function (Server $c) { |
|
666 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
667 | + ArrayCache::class, |
|
668 | + ArrayCache::class, |
|
669 | + ArrayCache::class |
|
670 | + ); |
|
671 | + /** @var \OCP\IConfig $config */ |
|
672 | + $config = $c->get(\OCP\IConfig::class); |
|
673 | + |
|
674 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
675 | + $v = \OC_App::getAppVersions(); |
|
676 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
677 | + $version = implode(',', $v); |
|
678 | + $instanceId = \OC_Util::getInstanceId(); |
|
679 | + $path = \OC::$SERVERROOT; |
|
680 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
681 | + return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
682 | + $config->getSystemValue('memcache.local', null), |
|
683 | + $config->getSystemValue('memcache.distributed', null), |
|
684 | + $config->getSystemValue('memcache.locking', null) |
|
685 | + ); |
|
686 | + } |
|
687 | + return $arrayCacheFactory; |
|
688 | + }); |
|
689 | + /** @deprecated 19.0.0 */ |
|
690 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
691 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
692 | + |
|
693 | + $this->registerService('RedisFactory', function (Server $c) { |
|
694 | + $systemConfig = $c->get(SystemConfig::class); |
|
695 | + return new RedisFactory($systemConfig); |
|
696 | + }); |
|
697 | + |
|
698 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
699 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
700 | + return new \OC\Activity\Manager( |
|
701 | + $c->getRequest(), |
|
702 | + $c->get(IUserSession::class), |
|
703 | + $c->get(\OCP\IConfig::class), |
|
704 | + $c->get(IValidator::class), |
|
705 | + $l10n |
|
706 | + ); |
|
707 | + }); |
|
708 | + /** @deprecated 19.0.0 */ |
|
709 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
710 | + |
|
711 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
712 | + return new \OC\Activity\EventMerger( |
|
713 | + $c->getL10N('lib') |
|
714 | + ); |
|
715 | + }); |
|
716 | + $this->registerAlias(IValidator::class, Validator::class); |
|
717 | + |
|
718 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
719 | + return new AvatarManager( |
|
720 | + $c->get(\OC\User\Manager::class), |
|
721 | + $c->getAppDataDir('avatar'), |
|
722 | + $c->getL10N('lib'), |
|
723 | + $c->get(ILogger::class), |
|
724 | + $c->get(\OCP\IConfig::class) |
|
725 | + ); |
|
726 | + }); |
|
727 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
728 | + /** @deprecated 19.0.0 */ |
|
729 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
730 | + |
|
731 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
732 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
733 | + |
|
734 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
735 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
736 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
737 | + $logger = $factory->get($logType); |
|
738 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
739 | + |
|
740 | + return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
741 | + }); |
|
742 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
743 | + /** @deprecated 19.0.0 */ |
|
744 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
745 | + // PSR-3 logger |
|
746 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
747 | + |
|
748 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
749 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
750 | + }); |
|
751 | + |
|
752 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
753 | + /** @deprecated 19.0.0 */ |
|
754 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
755 | + |
|
756 | + $this->registerService(Router::class, function (Server $c) { |
|
757 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
758 | + $logger = $c->get(ILogger::class); |
|
759 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
760 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
761 | + } else { |
|
762 | + $router = new \OC\Route\Router($logger); |
|
763 | + } |
|
764 | + return $router; |
|
765 | + }); |
|
766 | + $this->registerAlias(IRouter::class, Router::class); |
|
767 | + /** @deprecated 19.0.0 */ |
|
768 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
769 | + |
|
770 | + $this->registerAlias(ISearch::class, Search::class); |
|
771 | + /** @deprecated 19.0.0 */ |
|
772 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
773 | + |
|
774 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
775 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
776 | + $this->get(ICacheFactory::class), |
|
777 | + new \OC\AppFramework\Utility\TimeFactory() |
|
778 | + ); |
|
779 | + }); |
|
780 | + |
|
781 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
782 | + /** @deprecated 19.0.0 */ |
|
783 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
784 | + |
|
785 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
786 | + /** @deprecated 19.0.0 */ |
|
787 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
788 | + |
|
789 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
790 | + /** @deprecated 19.0.0 */ |
|
791 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
792 | + |
|
793 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
794 | + /** @deprecated 19.0.0 */ |
|
795 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
796 | + |
|
797 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
798 | + $this->registerService(Connection::class, function (Server $c) { |
|
799 | + $systemConfig = $c->get(SystemConfig::class); |
|
800 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
801 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
802 | + if (!$factory->isValidType($type)) { |
|
803 | + throw new \OC\DatabaseException('Invalid database type'); |
|
804 | + } |
|
805 | + $connectionParams = $factory->createConnectionParams(); |
|
806 | + $connection = $factory->getConnection($type, $connectionParams); |
|
807 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
808 | + return $connection; |
|
809 | + }); |
|
810 | + /** @deprecated 19.0.0 */ |
|
811 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
812 | + |
|
813 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
814 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
815 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
816 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
817 | + $eventLogger = new EventLogger(); |
|
818 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
819 | + // In debug mode, module is being activated by default |
|
820 | + $eventLogger->activate(); |
|
821 | + } |
|
822 | + return $eventLogger; |
|
823 | + }); |
|
824 | + /** @deprecated 19.0.0 */ |
|
825 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
826 | + |
|
827 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
828 | + $queryLogger = new QueryLogger(); |
|
829 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
830 | + // In debug mode, module is being activated by default |
|
831 | + $queryLogger->activate(); |
|
832 | + } |
|
833 | + return $queryLogger; |
|
834 | + }); |
|
835 | + /** @deprecated 19.0.0 */ |
|
836 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
837 | + |
|
838 | + /** @deprecated 19.0.0 */ |
|
839 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
840 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
841 | + |
|
842 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
843 | + // TODO: use auto-wiring |
|
844 | + return new \OC\App\AppManager( |
|
845 | + $c->get(IUserSession::class), |
|
846 | + $c->get(\OCP\IConfig::class), |
|
847 | + $c->get(\OC\AppConfig::class), |
|
848 | + $c->get(IGroupManager::class), |
|
849 | + $c->get(ICacheFactory::class), |
|
850 | + $c->get(SymfonyAdapter::class), |
|
851 | + $c->get(ILogger::class) |
|
852 | + ); |
|
853 | + }); |
|
854 | + /** @deprecated 19.0.0 */ |
|
855 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
856 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
857 | + |
|
858 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
859 | + /** @deprecated 19.0.0 */ |
|
860 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
861 | + |
|
862 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
863 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
864 | + |
|
865 | + return new DateTimeFormatter( |
|
866 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
867 | + $c->getL10N('lib', $language) |
|
868 | + ); |
|
869 | + }); |
|
870 | + /** @deprecated 19.0.0 */ |
|
871 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
872 | + |
|
873 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
874 | + $mountCache = new UserMountCache( |
|
875 | + $c->get(IDBConnection::class), |
|
876 | + $c->get(IUserManager::class), |
|
877 | + $c->get(ILogger::class) |
|
878 | + ); |
|
879 | + $listener = new UserMountCacheListener($mountCache); |
|
880 | + $listener->listen($c->get(IUserManager::class)); |
|
881 | + return $mountCache; |
|
882 | + }); |
|
883 | + /** @deprecated 19.0.0 */ |
|
884 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
885 | + |
|
886 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
887 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
888 | + $mountCache = $c->get(IUserMountCache::class); |
|
889 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
890 | + |
|
891 | + // builtin providers |
|
892 | + |
|
893 | + $config = $c->get(\OCP\IConfig::class); |
|
894 | + $logger = $c->get(ILogger::class); |
|
895 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
896 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
897 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
898 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
899 | + |
|
900 | + return $manager; |
|
901 | + }); |
|
902 | + /** @deprecated 19.0.0 */ |
|
903 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
904 | + |
|
905 | + /** @deprecated 20.0.0 */ |
|
906 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
907 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
908 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
909 | + if ($busClass) { |
|
910 | + [$app, $class] = explode('::', $busClass, 2); |
|
911 | + if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
912 | + \OC_App::loadApp($app); |
|
913 | + return $c->get($class); |
|
914 | + } else { |
|
915 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
916 | + } |
|
917 | + } else { |
|
918 | + $jobList = $c->get(IJobList::class); |
|
919 | + return new CronBus($jobList); |
|
920 | + } |
|
921 | + }); |
|
922 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
923 | + /** @deprecated 20.0.0 */ |
|
924 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
925 | + /** @deprecated 19.0.0 */ |
|
926 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
927 | + $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
928 | + // IConfig and IAppManager requires a working database. This code |
|
929 | + // might however be called when ownCloud is not yet setup. |
|
930 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
931 | + $config = $c->get(\OCP\IConfig::class); |
|
932 | + $appManager = $c->get(IAppManager::class); |
|
933 | + } else { |
|
934 | + $config = null; |
|
935 | + $appManager = null; |
|
936 | + } |
|
937 | + |
|
938 | + return new Checker( |
|
939 | + new EnvironmentHelper(), |
|
940 | + new FileAccessHelper(), |
|
941 | + new AppLocator(), |
|
942 | + $config, |
|
943 | + $c->get(ICacheFactory::class), |
|
944 | + $appManager, |
|
945 | + $c->get(ITempManager::class), |
|
946 | + $c->get(IMimeTypeDetector::class) |
|
947 | + ); |
|
948 | + }); |
|
949 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
950 | + if (isset($this['urlParams'])) { |
|
951 | + $urlParams = $this['urlParams']; |
|
952 | + } else { |
|
953 | + $urlParams = []; |
|
954 | + } |
|
955 | + |
|
956 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
957 | + && in_array('fakeinput', stream_get_wrappers()) |
|
958 | + ) { |
|
959 | + $stream = 'fakeinput://data'; |
|
960 | + } else { |
|
961 | + $stream = 'php://input'; |
|
962 | + } |
|
963 | + |
|
964 | + return new Request( |
|
965 | + [ |
|
966 | + 'get' => $_GET, |
|
967 | + 'post' => $_POST, |
|
968 | + 'files' => $_FILES, |
|
969 | + 'server' => $_SERVER, |
|
970 | + 'env' => $_ENV, |
|
971 | + 'cookies' => $_COOKIE, |
|
972 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
973 | + ? $_SERVER['REQUEST_METHOD'] |
|
974 | + : '', |
|
975 | + 'urlParams' => $urlParams, |
|
976 | + ], |
|
977 | + $this->get(ISecureRandom::class), |
|
978 | + $this->get(\OCP\IConfig::class), |
|
979 | + $this->get(CsrfTokenManager::class), |
|
980 | + $stream |
|
981 | + ); |
|
982 | + }); |
|
983 | + /** @deprecated 19.0.0 */ |
|
984 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
985 | + |
|
986 | + $this->registerService(IMailer::class, function (Server $c) { |
|
987 | + return new Mailer( |
|
988 | + $c->get(\OCP\IConfig::class), |
|
989 | + $c->get(ILogger::class), |
|
990 | + $c->get(Defaults::class), |
|
991 | + $c->get(IURLGenerator::class), |
|
992 | + $c->getL10N('lib'), |
|
993 | + $c->get(IEventDispatcher::class), |
|
994 | + $c->get(IFactory::class) |
|
995 | + ); |
|
996 | + }); |
|
997 | + /** @deprecated 19.0.0 */ |
|
998 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
999 | + |
|
1000 | + $this->registerService('LDAPProvider', function (ContainerInterface $c) { |
|
1001 | + $config = $c->get(\OCP\IConfig::class); |
|
1002 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1003 | + if (is_null($factoryClass)) { |
|
1004 | + throw new \Exception('ldapProviderFactory not set'); |
|
1005 | + } |
|
1006 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1007 | + $factory = new $factoryClass($this); |
|
1008 | + return $factory->getLDAPProvider(); |
|
1009 | + }); |
|
1010 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1011 | + $ini = $c->get(IniGetWrapper::class); |
|
1012 | + $config = $c->get(\OCP\IConfig::class); |
|
1013 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1014 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1015 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1016 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1017 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
1018 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1019 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
1020 | + } |
|
1021 | + return new DBLockingProvider( |
|
1022 | + $c->get(IDBConnection::class), |
|
1023 | + $c->get(ILogger::class), |
|
1024 | + new TimeFactory(), |
|
1025 | + $ttl, |
|
1026 | + !\OC::$CLI |
|
1027 | + ); |
|
1028 | + } |
|
1029 | + return new NoopLockingProvider(); |
|
1030 | + }); |
|
1031 | + /** @deprecated 19.0.0 */ |
|
1032 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1033 | + |
|
1034 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1035 | + /** @deprecated 19.0.0 */ |
|
1036 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1037 | + |
|
1038 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1039 | + return new \OC\Files\Type\Detection( |
|
1040 | + $c->get(IURLGenerator::class), |
|
1041 | + $c->get(ILogger::class), |
|
1042 | + \OC::$configDir, |
|
1043 | + \OC::$SERVERROOT . '/resources/config/' |
|
1044 | + ); |
|
1045 | + }); |
|
1046 | + /** @deprecated 19.0.0 */ |
|
1047 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1048 | + |
|
1049 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1050 | + /** @deprecated 19.0.0 */ |
|
1051 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1052 | + $this->registerService(BundleFetcher::class, function () { |
|
1053 | + return new BundleFetcher($this->getL10N('lib')); |
|
1054 | + }); |
|
1055 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1056 | + /** @deprecated 19.0.0 */ |
|
1057 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1058 | + |
|
1059 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1060 | + $manager = new CapabilitiesManager($c->get(ILogger::class)); |
|
1061 | + $manager->registerCapability(function () use ($c) { |
|
1062 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1063 | + }); |
|
1064 | + $manager->registerCapability(function () use ($c) { |
|
1065 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1066 | + }); |
|
1067 | + return $manager; |
|
1068 | + }); |
|
1069 | + /** @deprecated 19.0.0 */ |
|
1070 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1071 | + |
|
1072 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1073 | + $config = $c->get(\OCP\IConfig::class); |
|
1074 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1075 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1076 | + $factory = new $factoryClass($this); |
|
1077 | + $manager = $factory->getManager(); |
|
1078 | + |
|
1079 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1080 | + $manager = $c->get(IUserManager::class); |
|
1081 | + $user = $manager->get($id); |
|
1082 | + if (is_null($user)) { |
|
1083 | + $l = $c->getL10N('core'); |
|
1084 | + $displayName = $l->t('Unknown user'); |
|
1085 | + } else { |
|
1086 | + $displayName = $user->getDisplayName(); |
|
1087 | + } |
|
1088 | + return $displayName; |
|
1089 | + }); |
|
1090 | + |
|
1091 | + return $manager; |
|
1092 | + }); |
|
1093 | + /** @deprecated 19.0.0 */ |
|
1094 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1095 | + |
|
1096 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1097 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
1098 | + /* |
|
1099 | 1099 | * Dark magic for autoloader. |
1100 | 1100 | * If we do a class_exists it will try to load the class which will |
1101 | 1101 | * make composer cache the result. Resulting in errors when enabling |
1102 | 1102 | * the theming app. |
1103 | 1103 | */ |
1104 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1105 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
1106 | - $classExists = true; |
|
1107 | - } else { |
|
1108 | - $classExists = false; |
|
1109 | - } |
|
1110 | - |
|
1111 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1112 | - return new ThemingDefaults( |
|
1113 | - $c->get(\OCP\IConfig::class), |
|
1114 | - $c->getL10N('theming'), |
|
1115 | - $c->get(IURLGenerator::class), |
|
1116 | - $c->get(ICacheFactory::class), |
|
1117 | - new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
1118 | - new ImageManager( |
|
1119 | - $c->get(\OCP\IConfig::class), |
|
1120 | - $c->getAppDataDir('theming'), |
|
1121 | - $c->get(IURLGenerator::class), |
|
1122 | - $this->get(ICacheFactory::class), |
|
1123 | - $this->get(ILogger::class), |
|
1124 | - $this->get(ITempManager::class) |
|
1125 | - ), |
|
1126 | - $c->get(IAppManager::class), |
|
1127 | - $c->get(INavigationManager::class) |
|
1128 | - ); |
|
1129 | - } |
|
1130 | - return new \OC_Defaults(); |
|
1131 | - }); |
|
1132 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
1133 | - return new JSCombiner( |
|
1134 | - $c->getAppDataDir('js'), |
|
1135 | - $c->get(IURLGenerator::class), |
|
1136 | - $this->get(ICacheFactory::class), |
|
1137 | - $c->get(SystemConfig::class), |
|
1138 | - $c->get(ILogger::class) |
|
1139 | - ); |
|
1140 | - }); |
|
1141 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1142 | - /** @deprecated 19.0.0 */ |
|
1143 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1144 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1145 | - |
|
1146 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1147 | - // FIXME: Instantiiated here due to cyclic dependency |
|
1148 | - $request = new Request( |
|
1149 | - [ |
|
1150 | - 'get' => $_GET, |
|
1151 | - 'post' => $_POST, |
|
1152 | - 'files' => $_FILES, |
|
1153 | - 'server' => $_SERVER, |
|
1154 | - 'env' => $_ENV, |
|
1155 | - 'cookies' => $_COOKIE, |
|
1156 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1157 | - ? $_SERVER['REQUEST_METHOD'] |
|
1158 | - : null, |
|
1159 | - ], |
|
1160 | - $c->get(ISecureRandom::class), |
|
1161 | - $c->get(\OCP\IConfig::class) |
|
1162 | - ); |
|
1163 | - |
|
1164 | - return new CryptoWrapper( |
|
1165 | - $c->get(\OCP\IConfig::class), |
|
1166 | - $c->get(ICrypto::class), |
|
1167 | - $c->get(ISecureRandom::class), |
|
1168 | - $request |
|
1169 | - ); |
|
1170 | - }); |
|
1171 | - /** @deprecated 19.0.0 */ |
|
1172 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1173 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1174 | - return new SessionStorage($c->get(ISession::class)); |
|
1175 | - }); |
|
1176 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1177 | - /** @deprecated 19.0.0 */ |
|
1178 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1179 | - |
|
1180 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1181 | - $config = $c->get(\OCP\IConfig::class); |
|
1182 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1183 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1184 | - $factory = new $factoryClass($this); |
|
1185 | - |
|
1186 | - $manager = new \OC\Share20\Manager( |
|
1187 | - $c->get(ILogger::class), |
|
1188 | - $c->get(\OCP\IConfig::class), |
|
1189 | - $c->get(ISecureRandom::class), |
|
1190 | - $c->get(IHasher::class), |
|
1191 | - $c->get(IMountManager::class), |
|
1192 | - $c->get(IGroupManager::class), |
|
1193 | - $c->getL10N('lib'), |
|
1194 | - $c->get(IFactory::class), |
|
1195 | - $factory, |
|
1196 | - $c->get(IUserManager::class), |
|
1197 | - $c->get(IRootFolder::class), |
|
1198 | - $c->get(SymfonyAdapter::class), |
|
1199 | - $c->get(IMailer::class), |
|
1200 | - $c->get(IURLGenerator::class), |
|
1201 | - $c->get('ThemingDefaults'), |
|
1202 | - $c->get(IEventDispatcher::class) |
|
1203 | - ); |
|
1204 | - |
|
1205 | - return $manager; |
|
1206 | - }); |
|
1207 | - /** @deprecated 19.0.0 */ |
|
1208 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1209 | - |
|
1210 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1211 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1212 | - |
|
1213 | - // register default plugins |
|
1214 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1215 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1216 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1217 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1218 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1219 | - |
|
1220 | - return $instance; |
|
1221 | - }); |
|
1222 | - /** @deprecated 19.0.0 */ |
|
1223 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1224 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1225 | - |
|
1226 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1227 | - |
|
1228 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1229 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1230 | - |
|
1231 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1232 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1233 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1234 | - return new \OC\Files\AppData\Factory( |
|
1235 | - $c->get(IRootFolder::class), |
|
1236 | - $c->get(SystemConfig::class) |
|
1237 | - ); |
|
1238 | - }); |
|
1239 | - |
|
1240 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1241 | - return new LockdownManager(function () use ($c) { |
|
1242 | - return $c->get(ISession::class); |
|
1243 | - }); |
|
1244 | - }); |
|
1245 | - |
|
1246 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1247 | - return new DiscoveryService( |
|
1248 | - $c->get(ICacheFactory::class), |
|
1249 | - $c->get(IClientService::class) |
|
1250 | - ); |
|
1251 | - }); |
|
1252 | - |
|
1253 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1254 | - return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
|
1255 | - }); |
|
1256 | - |
|
1257 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1258 | - |
|
1259 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1260 | - return new CloudFederationProviderManager( |
|
1261 | - $c->get(IAppManager::class), |
|
1262 | - $c->get(IClientService::class), |
|
1263 | - $c->get(ICloudIdManager::class), |
|
1264 | - $c->get(ILogger::class) |
|
1265 | - ); |
|
1266 | - }); |
|
1267 | - |
|
1268 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1269 | - return new CloudFederationFactory(); |
|
1270 | - }); |
|
1271 | - |
|
1272 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1273 | - /** @deprecated 19.0.0 */ |
|
1274 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1275 | - |
|
1276 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1277 | - /** @deprecated 19.0.0 */ |
|
1278 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1279 | - |
|
1280 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1281 | - return new Defaults( |
|
1282 | - $c->getThemingDefaults() |
|
1283 | - ); |
|
1284 | - }); |
|
1285 | - /** @deprecated 19.0.0 */ |
|
1286 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1287 | - |
|
1288 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1289 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1290 | - }, false); |
|
1291 | - |
|
1292 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1293 | - return new ShareHelper( |
|
1294 | - $c->get(\OCP\Share\IManager::class) |
|
1295 | - ); |
|
1296 | - }); |
|
1297 | - |
|
1298 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1299 | - return new Installer( |
|
1300 | - $c->get(AppFetcher::class), |
|
1301 | - $c->get(IClientService::class), |
|
1302 | - $c->get(ITempManager::class), |
|
1303 | - $c->get(ILogger::class), |
|
1304 | - $c->get(\OCP\IConfig::class), |
|
1305 | - \OC::$CLI |
|
1306 | - ); |
|
1307 | - }); |
|
1308 | - |
|
1309 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1310 | - return new ApiFactory($c->get(IClientService::class)); |
|
1311 | - }); |
|
1312 | - |
|
1313 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1314 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1315 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1316 | - }); |
|
1317 | - |
|
1318 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1319 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1320 | - |
|
1321 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1322 | - |
|
1323 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1324 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1325 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1326 | - |
|
1327 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1328 | - |
|
1329 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1330 | - |
|
1331 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1332 | - |
|
1333 | - $this->connectDispatcher(); |
|
1334 | - } |
|
1335 | - |
|
1336 | - public function boot() { |
|
1337 | - /** @var HookConnector $hookConnector */ |
|
1338 | - $hookConnector = $this->get(HookConnector::class); |
|
1339 | - $hookConnector->viewToNode(); |
|
1340 | - } |
|
1341 | - |
|
1342 | - /** |
|
1343 | - * @return \OCP\Calendar\IManager |
|
1344 | - * @deprecated 20.0.0 |
|
1345 | - */ |
|
1346 | - public function getCalendarManager() { |
|
1347 | - return $this->get(\OC\Calendar\Manager::class); |
|
1348 | - } |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * @return \OCP\Calendar\Resource\IManager |
|
1352 | - * @deprecated 20.0.0 |
|
1353 | - */ |
|
1354 | - public function getCalendarResourceBackendManager() { |
|
1355 | - return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1356 | - } |
|
1357 | - |
|
1358 | - /** |
|
1359 | - * @return \OCP\Calendar\Room\IManager |
|
1360 | - * @deprecated 20.0.0 |
|
1361 | - */ |
|
1362 | - public function getCalendarRoomBackendManager() { |
|
1363 | - return $this->get(\OC\Calendar\Room\Manager::class); |
|
1364 | - } |
|
1365 | - |
|
1366 | - private function connectDispatcher() { |
|
1367 | - $dispatcher = $this->get(SymfonyAdapter::class); |
|
1368 | - |
|
1369 | - // Delete avatar on user deletion |
|
1370 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1371 | - $logger = $this->get(ILogger::class); |
|
1372 | - $manager = $this->getAvatarManager(); |
|
1373 | - /** @var IUser $user */ |
|
1374 | - $user = $e->getSubject(); |
|
1375 | - |
|
1376 | - try { |
|
1377 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1378 | - $avatar->remove(); |
|
1379 | - } catch (NotFoundException $e) { |
|
1380 | - // no avatar to remove |
|
1381 | - } catch (\Exception $e) { |
|
1382 | - // Ignore exceptions |
|
1383 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1384 | - } |
|
1385 | - }); |
|
1386 | - |
|
1387 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1388 | - $manager = $this->getAvatarManager(); |
|
1389 | - /** @var IUser $user */ |
|
1390 | - $user = $e->getSubject(); |
|
1391 | - $feature = $e->getArgument('feature'); |
|
1392 | - $oldValue = $e->getArgument('oldValue'); |
|
1393 | - $value = $e->getArgument('value'); |
|
1394 | - |
|
1395 | - // We only change the avatar on display name changes |
|
1396 | - if ($feature !== 'displayName') { |
|
1397 | - return; |
|
1398 | - } |
|
1399 | - |
|
1400 | - try { |
|
1401 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1402 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1403 | - } catch (NotFoundException $e) { |
|
1404 | - // no avatar to remove |
|
1405 | - } |
|
1406 | - }); |
|
1407 | - |
|
1408 | - /** @var IEventDispatcher $eventDispatched */ |
|
1409 | - $eventDispatched = $this->get(IEventDispatcher::class); |
|
1410 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1411 | - $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1412 | - } |
|
1413 | - |
|
1414 | - /** |
|
1415 | - * @return \OCP\Contacts\IManager |
|
1416 | - * @deprecated 20.0.0 |
|
1417 | - */ |
|
1418 | - public function getContactsManager() { |
|
1419 | - return $this->get(\OCP\Contacts\IManager::class); |
|
1420 | - } |
|
1421 | - |
|
1422 | - /** |
|
1423 | - * @return \OC\Encryption\Manager |
|
1424 | - * @deprecated 20.0.0 |
|
1425 | - */ |
|
1426 | - public function getEncryptionManager() { |
|
1427 | - return $this->get(\OCP\Encryption\IManager::class); |
|
1428 | - } |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * @return \OC\Encryption\File |
|
1432 | - * @deprecated 20.0.0 |
|
1433 | - */ |
|
1434 | - public function getEncryptionFilesHelper() { |
|
1435 | - return $this->get(IFile::class); |
|
1436 | - } |
|
1437 | - |
|
1438 | - /** |
|
1439 | - * @return \OCP\Encryption\Keys\IStorage |
|
1440 | - * @deprecated 20.0.0 |
|
1441 | - */ |
|
1442 | - public function getEncryptionKeyStorage() { |
|
1443 | - return $this->get(IStorage::class); |
|
1444 | - } |
|
1445 | - |
|
1446 | - /** |
|
1447 | - * The current request object holding all information about the request |
|
1448 | - * currently being processed is returned from this method. |
|
1449 | - * In case the current execution was not initiated by a web request null is returned |
|
1450 | - * |
|
1451 | - * @return \OCP\IRequest |
|
1452 | - * @deprecated 20.0.0 |
|
1453 | - */ |
|
1454 | - public function getRequest() { |
|
1455 | - return $this->get(IRequest::class); |
|
1456 | - } |
|
1457 | - |
|
1458 | - /** |
|
1459 | - * Returns the preview manager which can create preview images for a given file |
|
1460 | - * |
|
1461 | - * @return IPreview |
|
1462 | - * @deprecated 20.0.0 |
|
1463 | - */ |
|
1464 | - public function getPreviewManager() { |
|
1465 | - return $this->get(IPreview::class); |
|
1466 | - } |
|
1467 | - |
|
1468 | - /** |
|
1469 | - * Returns the tag manager which can get and set tags for different object types |
|
1470 | - * |
|
1471 | - * @see \OCP\ITagManager::load() |
|
1472 | - * @return ITagManager |
|
1473 | - * @deprecated 20.0.0 |
|
1474 | - */ |
|
1475 | - public function getTagManager() { |
|
1476 | - return $this->get(ITagManager::class); |
|
1477 | - } |
|
1478 | - |
|
1479 | - /** |
|
1480 | - * Returns the system-tag manager |
|
1481 | - * |
|
1482 | - * @return ISystemTagManager |
|
1483 | - * |
|
1484 | - * @since 9.0.0 |
|
1485 | - * @deprecated 20.0.0 |
|
1486 | - */ |
|
1487 | - public function getSystemTagManager() { |
|
1488 | - return $this->get(ISystemTagManager::class); |
|
1489 | - } |
|
1490 | - |
|
1491 | - /** |
|
1492 | - * Returns the system-tag object mapper |
|
1493 | - * |
|
1494 | - * @return ISystemTagObjectMapper |
|
1495 | - * |
|
1496 | - * @since 9.0.0 |
|
1497 | - * @deprecated 20.0.0 |
|
1498 | - */ |
|
1499 | - public function getSystemTagObjectMapper() { |
|
1500 | - return $this->get(ISystemTagObjectMapper::class); |
|
1501 | - } |
|
1502 | - |
|
1503 | - /** |
|
1504 | - * Returns the avatar manager, used for avatar functionality |
|
1505 | - * |
|
1506 | - * @return IAvatarManager |
|
1507 | - * @deprecated 20.0.0 |
|
1508 | - */ |
|
1509 | - public function getAvatarManager() { |
|
1510 | - return $this->get(IAvatarManager::class); |
|
1511 | - } |
|
1512 | - |
|
1513 | - /** |
|
1514 | - * Returns the root folder of ownCloud's data directory |
|
1515 | - * |
|
1516 | - * @return IRootFolder |
|
1517 | - * @deprecated 20.0.0 |
|
1518 | - */ |
|
1519 | - public function getRootFolder() { |
|
1520 | - return $this->get(IRootFolder::class); |
|
1521 | - } |
|
1522 | - |
|
1523 | - /** |
|
1524 | - * Returns the root folder of ownCloud's data directory |
|
1525 | - * This is the lazy variant so this gets only initialized once it |
|
1526 | - * is actually used. |
|
1527 | - * |
|
1528 | - * @return IRootFolder |
|
1529 | - * @deprecated 20.0.0 |
|
1530 | - */ |
|
1531 | - public function getLazyRootFolder() { |
|
1532 | - return $this->get(IRootFolder::class); |
|
1533 | - } |
|
1534 | - |
|
1535 | - /** |
|
1536 | - * Returns a view to ownCloud's files folder |
|
1537 | - * |
|
1538 | - * @param string $userId user ID |
|
1539 | - * @return \OCP\Files\Folder|null |
|
1540 | - * @deprecated 20.0.0 |
|
1541 | - */ |
|
1542 | - public function getUserFolder($userId = null) { |
|
1543 | - if ($userId === null) { |
|
1544 | - $user = $this->get(IUserSession::class)->getUser(); |
|
1545 | - if (!$user) { |
|
1546 | - return null; |
|
1547 | - } |
|
1548 | - $userId = $user->getUID(); |
|
1549 | - } |
|
1550 | - $root = $this->get(IRootFolder::class); |
|
1551 | - return $root->getUserFolder($userId); |
|
1552 | - } |
|
1553 | - |
|
1554 | - /** |
|
1555 | - * @return \OC\User\Manager |
|
1556 | - * @deprecated 20.0.0 |
|
1557 | - */ |
|
1558 | - public function getUserManager() { |
|
1559 | - return $this->get(IUserManager::class); |
|
1560 | - } |
|
1561 | - |
|
1562 | - /** |
|
1563 | - * @return \OC\Group\Manager |
|
1564 | - * @deprecated 20.0.0 |
|
1565 | - */ |
|
1566 | - public function getGroupManager() { |
|
1567 | - return $this->get(IGroupManager::class); |
|
1568 | - } |
|
1569 | - |
|
1570 | - /** |
|
1571 | - * @return \OC\User\Session |
|
1572 | - * @deprecated 20.0.0 |
|
1573 | - */ |
|
1574 | - public function getUserSession() { |
|
1575 | - return $this->get(IUserSession::class); |
|
1576 | - } |
|
1577 | - |
|
1578 | - /** |
|
1579 | - * @return \OCP\ISession |
|
1580 | - * @deprecated 20.0.0 |
|
1581 | - */ |
|
1582 | - public function getSession() { |
|
1583 | - return $this->get(IUserSession::class)->getSession(); |
|
1584 | - } |
|
1585 | - |
|
1586 | - /** |
|
1587 | - * @param \OCP\ISession $session |
|
1588 | - */ |
|
1589 | - public function setSession(\OCP\ISession $session) { |
|
1590 | - $this->get(SessionStorage::class)->setSession($session); |
|
1591 | - $this->get(IUserSession::class)->setSession($session); |
|
1592 | - $this->get(Store::class)->setSession($session); |
|
1593 | - } |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1597 | - * @deprecated 20.0.0 |
|
1598 | - */ |
|
1599 | - public function getTwoFactorAuthManager() { |
|
1600 | - return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1601 | - } |
|
1602 | - |
|
1603 | - /** |
|
1604 | - * @return \OC\NavigationManager |
|
1605 | - * @deprecated 20.0.0 |
|
1606 | - */ |
|
1607 | - public function getNavigationManager() { |
|
1608 | - return $this->get(INavigationManager::class); |
|
1609 | - } |
|
1610 | - |
|
1611 | - /** |
|
1612 | - * @return \OCP\IConfig |
|
1613 | - * @deprecated 20.0.0 |
|
1614 | - */ |
|
1615 | - public function getConfig() { |
|
1616 | - return $this->get(AllConfig::class); |
|
1617 | - } |
|
1618 | - |
|
1619 | - /** |
|
1620 | - * @return \OC\SystemConfig |
|
1621 | - * @deprecated 20.0.0 |
|
1622 | - */ |
|
1623 | - public function getSystemConfig() { |
|
1624 | - return $this->get(SystemConfig::class); |
|
1625 | - } |
|
1626 | - |
|
1627 | - /** |
|
1628 | - * Returns the app config manager |
|
1629 | - * |
|
1630 | - * @return IAppConfig |
|
1631 | - * @deprecated 20.0.0 |
|
1632 | - */ |
|
1633 | - public function getAppConfig() { |
|
1634 | - return $this->get(IAppConfig::class); |
|
1635 | - } |
|
1636 | - |
|
1637 | - /** |
|
1638 | - * @return IFactory |
|
1639 | - * @deprecated 20.0.0 |
|
1640 | - */ |
|
1641 | - public function getL10NFactory() { |
|
1642 | - return $this->get(IFactory::class); |
|
1643 | - } |
|
1644 | - |
|
1645 | - /** |
|
1646 | - * get an L10N instance |
|
1647 | - * |
|
1648 | - * @param string $app appid |
|
1649 | - * @param string $lang |
|
1650 | - * @return IL10N |
|
1651 | - * @deprecated 20.0.0 |
|
1652 | - */ |
|
1653 | - public function getL10N($app, $lang = null) { |
|
1654 | - return $this->get(IFactory::class)->get($app, $lang); |
|
1655 | - } |
|
1656 | - |
|
1657 | - /** |
|
1658 | - * @return IURLGenerator |
|
1659 | - * @deprecated 20.0.0 |
|
1660 | - */ |
|
1661 | - public function getURLGenerator() { |
|
1662 | - return $this->get(IURLGenerator::class); |
|
1663 | - } |
|
1664 | - |
|
1665 | - /** |
|
1666 | - * @return AppFetcher |
|
1667 | - * @deprecated 20.0.0 |
|
1668 | - */ |
|
1669 | - public function getAppFetcher() { |
|
1670 | - return $this->get(AppFetcher::class); |
|
1671 | - } |
|
1672 | - |
|
1673 | - /** |
|
1674 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1675 | - * getMemCacheFactory() instead. |
|
1676 | - * |
|
1677 | - * @return ICache |
|
1678 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1679 | - */ |
|
1680 | - public function getCache() { |
|
1681 | - return $this->get(ICache::class); |
|
1682 | - } |
|
1683 | - |
|
1684 | - /** |
|
1685 | - * Returns an \OCP\CacheFactory instance |
|
1686 | - * |
|
1687 | - * @return \OCP\ICacheFactory |
|
1688 | - * @deprecated 20.0.0 |
|
1689 | - */ |
|
1690 | - public function getMemCacheFactory() { |
|
1691 | - return $this->get(ICacheFactory::class); |
|
1692 | - } |
|
1693 | - |
|
1694 | - /** |
|
1695 | - * Returns an \OC\RedisFactory instance |
|
1696 | - * |
|
1697 | - * @return \OC\RedisFactory |
|
1698 | - * @deprecated 20.0.0 |
|
1699 | - */ |
|
1700 | - public function getGetRedisFactory() { |
|
1701 | - return $this->get('RedisFactory'); |
|
1702 | - } |
|
1703 | - |
|
1704 | - |
|
1705 | - /** |
|
1706 | - * Returns the current session |
|
1707 | - * |
|
1708 | - * @return \OCP\IDBConnection |
|
1709 | - * @deprecated 20.0.0 |
|
1710 | - */ |
|
1711 | - public function getDatabaseConnection() { |
|
1712 | - return $this->get(IDBConnection::class); |
|
1713 | - } |
|
1714 | - |
|
1715 | - /** |
|
1716 | - * Returns the activity manager |
|
1717 | - * |
|
1718 | - * @return \OCP\Activity\IManager |
|
1719 | - * @deprecated 20.0.0 |
|
1720 | - */ |
|
1721 | - public function getActivityManager() { |
|
1722 | - return $this->get(\OCP\Activity\IManager::class); |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * Returns an job list for controlling background jobs |
|
1727 | - * |
|
1728 | - * @return IJobList |
|
1729 | - * @deprecated 20.0.0 |
|
1730 | - */ |
|
1731 | - public function getJobList() { |
|
1732 | - return $this->get(IJobList::class); |
|
1733 | - } |
|
1734 | - |
|
1735 | - /** |
|
1736 | - * Returns a logger instance |
|
1737 | - * |
|
1738 | - * @return ILogger |
|
1739 | - * @deprecated 20.0.0 |
|
1740 | - */ |
|
1741 | - public function getLogger() { |
|
1742 | - return $this->get(ILogger::class); |
|
1743 | - } |
|
1744 | - |
|
1745 | - /** |
|
1746 | - * @return ILogFactory |
|
1747 | - * @throws \OCP\AppFramework\QueryException |
|
1748 | - * @deprecated 20.0.0 |
|
1749 | - */ |
|
1750 | - public function getLogFactory() { |
|
1751 | - return $this->get(ILogFactory::class); |
|
1752 | - } |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * Returns a router for generating and matching urls |
|
1756 | - * |
|
1757 | - * @return IRouter |
|
1758 | - * @deprecated 20.0.0 |
|
1759 | - */ |
|
1760 | - public function getRouter() { |
|
1761 | - return $this->get(IRouter::class); |
|
1762 | - } |
|
1763 | - |
|
1764 | - /** |
|
1765 | - * Returns a search instance |
|
1766 | - * |
|
1767 | - * @return ISearch |
|
1768 | - * @deprecated 20.0.0 |
|
1769 | - */ |
|
1770 | - public function getSearch() { |
|
1771 | - return $this->get(ISearch::class); |
|
1772 | - } |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * Returns a SecureRandom instance |
|
1776 | - * |
|
1777 | - * @return \OCP\Security\ISecureRandom |
|
1778 | - * @deprecated 20.0.0 |
|
1779 | - */ |
|
1780 | - public function getSecureRandom() { |
|
1781 | - return $this->get(ISecureRandom::class); |
|
1782 | - } |
|
1783 | - |
|
1784 | - /** |
|
1785 | - * Returns a Crypto instance |
|
1786 | - * |
|
1787 | - * @return ICrypto |
|
1788 | - * @deprecated 20.0.0 |
|
1789 | - */ |
|
1790 | - public function getCrypto() { |
|
1791 | - return $this->get(ICrypto::class); |
|
1792 | - } |
|
1793 | - |
|
1794 | - /** |
|
1795 | - * Returns a Hasher instance |
|
1796 | - * |
|
1797 | - * @return IHasher |
|
1798 | - * @deprecated 20.0.0 |
|
1799 | - */ |
|
1800 | - public function getHasher() { |
|
1801 | - return $this->get(IHasher::class); |
|
1802 | - } |
|
1803 | - |
|
1804 | - /** |
|
1805 | - * Returns a CredentialsManager instance |
|
1806 | - * |
|
1807 | - * @return ICredentialsManager |
|
1808 | - * @deprecated 20.0.0 |
|
1809 | - */ |
|
1810 | - public function getCredentialsManager() { |
|
1811 | - return $this->get(ICredentialsManager::class); |
|
1812 | - } |
|
1813 | - |
|
1814 | - /** |
|
1815 | - * Get the certificate manager |
|
1816 | - * |
|
1817 | - * @return \OCP\ICertificateManager |
|
1818 | - */ |
|
1819 | - public function getCertificateManager() { |
|
1820 | - return $this->get(ICertificateManager::class); |
|
1821 | - } |
|
1822 | - |
|
1823 | - /** |
|
1824 | - * Returns an instance of the HTTP client service |
|
1825 | - * |
|
1826 | - * @return IClientService |
|
1827 | - * @deprecated 20.0.0 |
|
1828 | - */ |
|
1829 | - public function getHTTPClientService() { |
|
1830 | - return $this->get(IClientService::class); |
|
1831 | - } |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * Create a new event source |
|
1835 | - * |
|
1836 | - * @return \OCP\IEventSource |
|
1837 | - * @deprecated 20.0.0 |
|
1838 | - */ |
|
1839 | - public function createEventSource() { |
|
1840 | - return new \OC_EventSource(); |
|
1841 | - } |
|
1842 | - |
|
1843 | - /** |
|
1844 | - * Get the active event logger |
|
1845 | - * |
|
1846 | - * The returned logger only logs data when debug mode is enabled |
|
1847 | - * |
|
1848 | - * @return IEventLogger |
|
1849 | - * @deprecated 20.0.0 |
|
1850 | - */ |
|
1851 | - public function getEventLogger() { |
|
1852 | - return $this->get(IEventLogger::class); |
|
1853 | - } |
|
1854 | - |
|
1855 | - /** |
|
1856 | - * Get the active query logger |
|
1857 | - * |
|
1858 | - * The returned logger only logs data when debug mode is enabled |
|
1859 | - * |
|
1860 | - * @return IQueryLogger |
|
1861 | - * @deprecated 20.0.0 |
|
1862 | - */ |
|
1863 | - public function getQueryLogger() { |
|
1864 | - return $this->get(IQueryLogger::class); |
|
1865 | - } |
|
1866 | - |
|
1867 | - /** |
|
1868 | - * Get the manager for temporary files and folders |
|
1869 | - * |
|
1870 | - * @return \OCP\ITempManager |
|
1871 | - * @deprecated 20.0.0 |
|
1872 | - */ |
|
1873 | - public function getTempManager() { |
|
1874 | - return $this->get(ITempManager::class); |
|
1875 | - } |
|
1876 | - |
|
1877 | - /** |
|
1878 | - * Get the app manager |
|
1879 | - * |
|
1880 | - * @return \OCP\App\IAppManager |
|
1881 | - * @deprecated 20.0.0 |
|
1882 | - */ |
|
1883 | - public function getAppManager() { |
|
1884 | - return $this->get(IAppManager::class); |
|
1885 | - } |
|
1886 | - |
|
1887 | - /** |
|
1888 | - * Creates a new mailer |
|
1889 | - * |
|
1890 | - * @return IMailer |
|
1891 | - * @deprecated 20.0.0 |
|
1892 | - */ |
|
1893 | - public function getMailer() { |
|
1894 | - return $this->get(IMailer::class); |
|
1895 | - } |
|
1896 | - |
|
1897 | - /** |
|
1898 | - * Get the webroot |
|
1899 | - * |
|
1900 | - * @return string |
|
1901 | - * @deprecated 20.0.0 |
|
1902 | - */ |
|
1903 | - public function getWebRoot() { |
|
1904 | - return $this->webRoot; |
|
1905 | - } |
|
1906 | - |
|
1907 | - /** |
|
1908 | - * @return \OC\OCSClient |
|
1909 | - * @deprecated 20.0.0 |
|
1910 | - */ |
|
1911 | - public function getOcsClient() { |
|
1912 | - return $this->get('OcsClient'); |
|
1913 | - } |
|
1914 | - |
|
1915 | - /** |
|
1916 | - * @return IDateTimeZone |
|
1917 | - * @deprecated 20.0.0 |
|
1918 | - */ |
|
1919 | - public function getDateTimeZone() { |
|
1920 | - return $this->get(IDateTimeZone::class); |
|
1921 | - } |
|
1922 | - |
|
1923 | - /** |
|
1924 | - * @return IDateTimeFormatter |
|
1925 | - * @deprecated 20.0.0 |
|
1926 | - */ |
|
1927 | - public function getDateTimeFormatter() { |
|
1928 | - return $this->get(IDateTimeFormatter::class); |
|
1929 | - } |
|
1930 | - |
|
1931 | - /** |
|
1932 | - * @return IMountProviderCollection |
|
1933 | - * @deprecated 20.0.0 |
|
1934 | - */ |
|
1935 | - public function getMountProviderCollection() { |
|
1936 | - return $this->get(IMountProviderCollection::class); |
|
1937 | - } |
|
1938 | - |
|
1939 | - /** |
|
1940 | - * Get the IniWrapper |
|
1941 | - * |
|
1942 | - * @return IniGetWrapper |
|
1943 | - * @deprecated 20.0.0 |
|
1944 | - */ |
|
1945 | - public function getIniWrapper() { |
|
1946 | - return $this->get(IniGetWrapper::class); |
|
1947 | - } |
|
1948 | - |
|
1949 | - /** |
|
1950 | - * @return \OCP\Command\IBus |
|
1951 | - * @deprecated 20.0.0 |
|
1952 | - */ |
|
1953 | - public function getCommandBus() { |
|
1954 | - return $this->get(IBus::class); |
|
1955 | - } |
|
1956 | - |
|
1957 | - /** |
|
1958 | - * Get the trusted domain helper |
|
1959 | - * |
|
1960 | - * @return TrustedDomainHelper |
|
1961 | - * @deprecated 20.0.0 |
|
1962 | - */ |
|
1963 | - public function getTrustedDomainHelper() { |
|
1964 | - return $this->get(TrustedDomainHelper::class); |
|
1965 | - } |
|
1966 | - |
|
1967 | - /** |
|
1968 | - * Get the locking provider |
|
1969 | - * |
|
1970 | - * @return ILockingProvider |
|
1971 | - * @since 8.1.0 |
|
1972 | - * @deprecated 20.0.0 |
|
1973 | - */ |
|
1974 | - public function getLockingProvider() { |
|
1975 | - return $this->get(ILockingProvider::class); |
|
1976 | - } |
|
1977 | - |
|
1978 | - /** |
|
1979 | - * @return IMountManager |
|
1980 | - * @deprecated 20.0.0 |
|
1981 | - **/ |
|
1982 | - public function getMountManager() { |
|
1983 | - return $this->get(IMountManager::class); |
|
1984 | - } |
|
1985 | - |
|
1986 | - /** |
|
1987 | - * @return IUserMountCache |
|
1988 | - * @deprecated 20.0.0 |
|
1989 | - */ |
|
1990 | - public function getUserMountCache() { |
|
1991 | - return $this->get(IUserMountCache::class); |
|
1992 | - } |
|
1993 | - |
|
1994 | - /** |
|
1995 | - * Get the MimeTypeDetector |
|
1996 | - * |
|
1997 | - * @return IMimeTypeDetector |
|
1998 | - * @deprecated 20.0.0 |
|
1999 | - */ |
|
2000 | - public function getMimeTypeDetector() { |
|
2001 | - return $this->get(IMimeTypeDetector::class); |
|
2002 | - } |
|
2003 | - |
|
2004 | - /** |
|
2005 | - * Get the MimeTypeLoader |
|
2006 | - * |
|
2007 | - * @return IMimeTypeLoader |
|
2008 | - * @deprecated 20.0.0 |
|
2009 | - */ |
|
2010 | - public function getMimeTypeLoader() { |
|
2011 | - return $this->get(IMimeTypeLoader::class); |
|
2012 | - } |
|
2013 | - |
|
2014 | - /** |
|
2015 | - * Get the manager of all the capabilities |
|
2016 | - * |
|
2017 | - * @return CapabilitiesManager |
|
2018 | - * @deprecated 20.0.0 |
|
2019 | - */ |
|
2020 | - public function getCapabilitiesManager() { |
|
2021 | - return $this->get(CapabilitiesManager::class); |
|
2022 | - } |
|
2023 | - |
|
2024 | - /** |
|
2025 | - * Get the EventDispatcher |
|
2026 | - * |
|
2027 | - * @return EventDispatcherInterface |
|
2028 | - * @since 8.2.0 |
|
2029 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2030 | - */ |
|
2031 | - public function getEventDispatcher() { |
|
2032 | - return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2033 | - } |
|
2034 | - |
|
2035 | - /** |
|
2036 | - * Get the Notification Manager |
|
2037 | - * |
|
2038 | - * @return \OCP\Notification\IManager |
|
2039 | - * @since 8.2.0 |
|
2040 | - * @deprecated 20.0.0 |
|
2041 | - */ |
|
2042 | - public function getNotificationManager() { |
|
2043 | - return $this->get(\OCP\Notification\IManager::class); |
|
2044 | - } |
|
2045 | - |
|
2046 | - /** |
|
2047 | - * @return ICommentsManager |
|
2048 | - * @deprecated 20.0.0 |
|
2049 | - */ |
|
2050 | - public function getCommentsManager() { |
|
2051 | - return $this->get(ICommentsManager::class); |
|
2052 | - } |
|
2053 | - |
|
2054 | - /** |
|
2055 | - * @return \OCA\Theming\ThemingDefaults |
|
2056 | - * @deprecated 20.0.0 |
|
2057 | - */ |
|
2058 | - public function getThemingDefaults() { |
|
2059 | - return $this->get('ThemingDefaults'); |
|
2060 | - } |
|
2061 | - |
|
2062 | - /** |
|
2063 | - * @return \OC\IntegrityCheck\Checker |
|
2064 | - * @deprecated 20.0.0 |
|
2065 | - */ |
|
2066 | - public function getIntegrityCodeChecker() { |
|
2067 | - return $this->get('IntegrityCodeChecker'); |
|
2068 | - } |
|
2069 | - |
|
2070 | - /** |
|
2071 | - * @return \OC\Session\CryptoWrapper |
|
2072 | - * @deprecated 20.0.0 |
|
2073 | - */ |
|
2074 | - public function getSessionCryptoWrapper() { |
|
2075 | - return $this->get('CryptoWrapper'); |
|
2076 | - } |
|
2077 | - |
|
2078 | - /** |
|
2079 | - * @return CsrfTokenManager |
|
2080 | - * @deprecated 20.0.0 |
|
2081 | - */ |
|
2082 | - public function getCsrfTokenManager() { |
|
2083 | - return $this->get(CsrfTokenManager::class); |
|
2084 | - } |
|
2085 | - |
|
2086 | - /** |
|
2087 | - * @return Throttler |
|
2088 | - * @deprecated 20.0.0 |
|
2089 | - */ |
|
2090 | - public function getBruteForceThrottler() { |
|
2091 | - return $this->get(Throttler::class); |
|
2092 | - } |
|
2093 | - |
|
2094 | - /** |
|
2095 | - * @return IContentSecurityPolicyManager |
|
2096 | - * @deprecated 20.0.0 |
|
2097 | - */ |
|
2098 | - public function getContentSecurityPolicyManager() { |
|
2099 | - return $this->get(ContentSecurityPolicyManager::class); |
|
2100 | - } |
|
2101 | - |
|
2102 | - /** |
|
2103 | - * @return ContentSecurityPolicyNonceManager |
|
2104 | - * @deprecated 20.0.0 |
|
2105 | - */ |
|
2106 | - public function getContentSecurityPolicyNonceManager() { |
|
2107 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2108 | - } |
|
2109 | - |
|
2110 | - /** |
|
2111 | - * Not a public API as of 8.2, wait for 9.0 |
|
2112 | - * |
|
2113 | - * @return \OCA\Files_External\Service\BackendService |
|
2114 | - * @deprecated 20.0.0 |
|
2115 | - */ |
|
2116 | - public function getStoragesBackendService() { |
|
2117 | - return $this->get(BackendService::class); |
|
2118 | - } |
|
2119 | - |
|
2120 | - /** |
|
2121 | - * Not a public API as of 8.2, wait for 9.0 |
|
2122 | - * |
|
2123 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2124 | - * @deprecated 20.0.0 |
|
2125 | - */ |
|
2126 | - public function getGlobalStoragesService() { |
|
2127 | - return $this->get(GlobalStoragesService::class); |
|
2128 | - } |
|
2129 | - |
|
2130 | - /** |
|
2131 | - * Not a public API as of 8.2, wait for 9.0 |
|
2132 | - * |
|
2133 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2134 | - * @deprecated 20.0.0 |
|
2135 | - */ |
|
2136 | - public function getUserGlobalStoragesService() { |
|
2137 | - return $this->get(UserGlobalStoragesService::class); |
|
2138 | - } |
|
2139 | - |
|
2140 | - /** |
|
2141 | - * Not a public API as of 8.2, wait for 9.0 |
|
2142 | - * |
|
2143 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
2144 | - * @deprecated 20.0.0 |
|
2145 | - */ |
|
2146 | - public function getUserStoragesService() { |
|
2147 | - return $this->get(UserStoragesService::class); |
|
2148 | - } |
|
2149 | - |
|
2150 | - /** |
|
2151 | - * @return \OCP\Share\IManager |
|
2152 | - * @deprecated 20.0.0 |
|
2153 | - */ |
|
2154 | - public function getShareManager() { |
|
2155 | - return $this->get(\OCP\Share\IManager::class); |
|
2156 | - } |
|
2157 | - |
|
2158 | - /** |
|
2159 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
2160 | - * @deprecated 20.0.0 |
|
2161 | - */ |
|
2162 | - public function getCollaboratorSearch() { |
|
2163 | - return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2164 | - } |
|
2165 | - |
|
2166 | - /** |
|
2167 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
2168 | - * @deprecated 20.0.0 |
|
2169 | - */ |
|
2170 | - public function getAutoCompleteManager() { |
|
2171 | - return $this->get(IManager::class); |
|
2172 | - } |
|
2173 | - |
|
2174 | - /** |
|
2175 | - * Returns the LDAP Provider |
|
2176 | - * |
|
2177 | - * @return \OCP\LDAP\ILDAPProvider |
|
2178 | - * @deprecated 20.0.0 |
|
2179 | - */ |
|
2180 | - public function getLDAPProvider() { |
|
2181 | - return $this->get('LDAPProvider'); |
|
2182 | - } |
|
2183 | - |
|
2184 | - /** |
|
2185 | - * @return \OCP\Settings\IManager |
|
2186 | - * @deprecated 20.0.0 |
|
2187 | - */ |
|
2188 | - public function getSettingsManager() { |
|
2189 | - return $this->get(\OC\Settings\Manager::class); |
|
2190 | - } |
|
2191 | - |
|
2192 | - /** |
|
2193 | - * @return \OCP\Files\IAppData |
|
2194 | - * @deprecated 20.0.0 |
|
2195 | - */ |
|
2196 | - public function getAppDataDir($app) { |
|
2197 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
2198 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2199 | - return $factory->get($app); |
|
2200 | - } |
|
2201 | - |
|
2202 | - /** |
|
2203 | - * @return \OCP\Lockdown\ILockdownManager |
|
2204 | - * @deprecated 20.0.0 |
|
2205 | - */ |
|
2206 | - public function getLockdownManager() { |
|
2207 | - return $this->get('LockdownManager'); |
|
2208 | - } |
|
2209 | - |
|
2210 | - /** |
|
2211 | - * @return \OCP\Federation\ICloudIdManager |
|
2212 | - * @deprecated 20.0.0 |
|
2213 | - */ |
|
2214 | - public function getCloudIdManager() { |
|
2215 | - return $this->get(ICloudIdManager::class); |
|
2216 | - } |
|
2217 | - |
|
2218 | - /** |
|
2219 | - * @return \OCP\GlobalScale\IConfig |
|
2220 | - * @deprecated 20.0.0 |
|
2221 | - */ |
|
2222 | - public function getGlobalScaleConfig() { |
|
2223 | - return $this->get(IConfig::class); |
|
2224 | - } |
|
2225 | - |
|
2226 | - /** |
|
2227 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2228 | - * @deprecated 20.0.0 |
|
2229 | - */ |
|
2230 | - public function getCloudFederationProviderManager() { |
|
2231 | - return $this->get(ICloudFederationProviderManager::class); |
|
2232 | - } |
|
2233 | - |
|
2234 | - /** |
|
2235 | - * @return \OCP\Remote\Api\IApiFactory |
|
2236 | - * @deprecated 20.0.0 |
|
2237 | - */ |
|
2238 | - public function getRemoteApiFactory() { |
|
2239 | - return $this->get(IApiFactory::class); |
|
2240 | - } |
|
2241 | - |
|
2242 | - /** |
|
2243 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2244 | - * @deprecated 20.0.0 |
|
2245 | - */ |
|
2246 | - public function getCloudFederationFactory() { |
|
2247 | - return $this->get(ICloudFederationFactory::class); |
|
2248 | - } |
|
2249 | - |
|
2250 | - /** |
|
2251 | - * @return \OCP\Remote\IInstanceFactory |
|
2252 | - * @deprecated 20.0.0 |
|
2253 | - */ |
|
2254 | - public function getRemoteInstanceFactory() { |
|
2255 | - return $this->get(IInstanceFactory::class); |
|
2256 | - } |
|
2257 | - |
|
2258 | - /** |
|
2259 | - * @return IStorageFactory |
|
2260 | - * @deprecated 20.0.0 |
|
2261 | - */ |
|
2262 | - public function getStorageFactory() { |
|
2263 | - return $this->get(IStorageFactory::class); |
|
2264 | - } |
|
2265 | - |
|
2266 | - /** |
|
2267 | - * Get the Preview GeneratorHelper |
|
2268 | - * |
|
2269 | - * @return GeneratorHelper |
|
2270 | - * @since 17.0.0 |
|
2271 | - * @deprecated 20.0.0 |
|
2272 | - */ |
|
2273 | - public function getGeneratorHelper() { |
|
2274 | - return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2275 | - } |
|
2276 | - |
|
2277 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
2278 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2279 | - try { |
|
2280 | - /** @var ILogger $logger */ |
|
2281 | - $logger = $container->get(ILogger::class); |
|
2282 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2283 | - } catch (ContainerExceptionInterface $e) { |
|
2284 | - // Could not get logger. Continue |
|
2285 | - } |
|
2286 | - |
|
2287 | - return $container->get($target); |
|
2288 | - }, false); |
|
2289 | - } |
|
1104 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1105 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
1106 | + $classExists = true; |
|
1107 | + } else { |
|
1108 | + $classExists = false; |
|
1109 | + } |
|
1110 | + |
|
1111 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1112 | + return new ThemingDefaults( |
|
1113 | + $c->get(\OCP\IConfig::class), |
|
1114 | + $c->getL10N('theming'), |
|
1115 | + $c->get(IURLGenerator::class), |
|
1116 | + $c->get(ICacheFactory::class), |
|
1117 | + new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
1118 | + new ImageManager( |
|
1119 | + $c->get(\OCP\IConfig::class), |
|
1120 | + $c->getAppDataDir('theming'), |
|
1121 | + $c->get(IURLGenerator::class), |
|
1122 | + $this->get(ICacheFactory::class), |
|
1123 | + $this->get(ILogger::class), |
|
1124 | + $this->get(ITempManager::class) |
|
1125 | + ), |
|
1126 | + $c->get(IAppManager::class), |
|
1127 | + $c->get(INavigationManager::class) |
|
1128 | + ); |
|
1129 | + } |
|
1130 | + return new \OC_Defaults(); |
|
1131 | + }); |
|
1132 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
1133 | + return new JSCombiner( |
|
1134 | + $c->getAppDataDir('js'), |
|
1135 | + $c->get(IURLGenerator::class), |
|
1136 | + $this->get(ICacheFactory::class), |
|
1137 | + $c->get(SystemConfig::class), |
|
1138 | + $c->get(ILogger::class) |
|
1139 | + ); |
|
1140 | + }); |
|
1141 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1142 | + /** @deprecated 19.0.0 */ |
|
1143 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1144 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1145 | + |
|
1146 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1147 | + // FIXME: Instantiiated here due to cyclic dependency |
|
1148 | + $request = new Request( |
|
1149 | + [ |
|
1150 | + 'get' => $_GET, |
|
1151 | + 'post' => $_POST, |
|
1152 | + 'files' => $_FILES, |
|
1153 | + 'server' => $_SERVER, |
|
1154 | + 'env' => $_ENV, |
|
1155 | + 'cookies' => $_COOKIE, |
|
1156 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1157 | + ? $_SERVER['REQUEST_METHOD'] |
|
1158 | + : null, |
|
1159 | + ], |
|
1160 | + $c->get(ISecureRandom::class), |
|
1161 | + $c->get(\OCP\IConfig::class) |
|
1162 | + ); |
|
1163 | + |
|
1164 | + return new CryptoWrapper( |
|
1165 | + $c->get(\OCP\IConfig::class), |
|
1166 | + $c->get(ICrypto::class), |
|
1167 | + $c->get(ISecureRandom::class), |
|
1168 | + $request |
|
1169 | + ); |
|
1170 | + }); |
|
1171 | + /** @deprecated 19.0.0 */ |
|
1172 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1173 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1174 | + return new SessionStorage($c->get(ISession::class)); |
|
1175 | + }); |
|
1176 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1177 | + /** @deprecated 19.0.0 */ |
|
1178 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1179 | + |
|
1180 | + $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1181 | + $config = $c->get(\OCP\IConfig::class); |
|
1182 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1183 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1184 | + $factory = new $factoryClass($this); |
|
1185 | + |
|
1186 | + $manager = new \OC\Share20\Manager( |
|
1187 | + $c->get(ILogger::class), |
|
1188 | + $c->get(\OCP\IConfig::class), |
|
1189 | + $c->get(ISecureRandom::class), |
|
1190 | + $c->get(IHasher::class), |
|
1191 | + $c->get(IMountManager::class), |
|
1192 | + $c->get(IGroupManager::class), |
|
1193 | + $c->getL10N('lib'), |
|
1194 | + $c->get(IFactory::class), |
|
1195 | + $factory, |
|
1196 | + $c->get(IUserManager::class), |
|
1197 | + $c->get(IRootFolder::class), |
|
1198 | + $c->get(SymfonyAdapter::class), |
|
1199 | + $c->get(IMailer::class), |
|
1200 | + $c->get(IURLGenerator::class), |
|
1201 | + $c->get('ThemingDefaults'), |
|
1202 | + $c->get(IEventDispatcher::class) |
|
1203 | + ); |
|
1204 | + |
|
1205 | + return $manager; |
|
1206 | + }); |
|
1207 | + /** @deprecated 19.0.0 */ |
|
1208 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1209 | + |
|
1210 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1211 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1212 | + |
|
1213 | + // register default plugins |
|
1214 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1215 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1216 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1217 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1218 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1219 | + |
|
1220 | + return $instance; |
|
1221 | + }); |
|
1222 | + /** @deprecated 19.0.0 */ |
|
1223 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1224 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1225 | + |
|
1226 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1227 | + |
|
1228 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1229 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1230 | + |
|
1231 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1232 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1233 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1234 | + return new \OC\Files\AppData\Factory( |
|
1235 | + $c->get(IRootFolder::class), |
|
1236 | + $c->get(SystemConfig::class) |
|
1237 | + ); |
|
1238 | + }); |
|
1239 | + |
|
1240 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1241 | + return new LockdownManager(function () use ($c) { |
|
1242 | + return $c->get(ISession::class); |
|
1243 | + }); |
|
1244 | + }); |
|
1245 | + |
|
1246 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1247 | + return new DiscoveryService( |
|
1248 | + $c->get(ICacheFactory::class), |
|
1249 | + $c->get(IClientService::class) |
|
1250 | + ); |
|
1251 | + }); |
|
1252 | + |
|
1253 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1254 | + return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
|
1255 | + }); |
|
1256 | + |
|
1257 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1258 | + |
|
1259 | + $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1260 | + return new CloudFederationProviderManager( |
|
1261 | + $c->get(IAppManager::class), |
|
1262 | + $c->get(IClientService::class), |
|
1263 | + $c->get(ICloudIdManager::class), |
|
1264 | + $c->get(ILogger::class) |
|
1265 | + ); |
|
1266 | + }); |
|
1267 | + |
|
1268 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1269 | + return new CloudFederationFactory(); |
|
1270 | + }); |
|
1271 | + |
|
1272 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1273 | + /** @deprecated 19.0.0 */ |
|
1274 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1275 | + |
|
1276 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1277 | + /** @deprecated 19.0.0 */ |
|
1278 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1279 | + |
|
1280 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1281 | + return new Defaults( |
|
1282 | + $c->getThemingDefaults() |
|
1283 | + ); |
|
1284 | + }); |
|
1285 | + /** @deprecated 19.0.0 */ |
|
1286 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1287 | + |
|
1288 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1289 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1290 | + }, false); |
|
1291 | + |
|
1292 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1293 | + return new ShareHelper( |
|
1294 | + $c->get(\OCP\Share\IManager::class) |
|
1295 | + ); |
|
1296 | + }); |
|
1297 | + |
|
1298 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1299 | + return new Installer( |
|
1300 | + $c->get(AppFetcher::class), |
|
1301 | + $c->get(IClientService::class), |
|
1302 | + $c->get(ITempManager::class), |
|
1303 | + $c->get(ILogger::class), |
|
1304 | + $c->get(\OCP\IConfig::class), |
|
1305 | + \OC::$CLI |
|
1306 | + ); |
|
1307 | + }); |
|
1308 | + |
|
1309 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1310 | + return new ApiFactory($c->get(IClientService::class)); |
|
1311 | + }); |
|
1312 | + |
|
1313 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1314 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1315 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1316 | + }); |
|
1317 | + |
|
1318 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1319 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1320 | + |
|
1321 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1322 | + |
|
1323 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1324 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1325 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1326 | + |
|
1327 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1328 | + |
|
1329 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1330 | + |
|
1331 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1332 | + |
|
1333 | + $this->connectDispatcher(); |
|
1334 | + } |
|
1335 | + |
|
1336 | + public function boot() { |
|
1337 | + /** @var HookConnector $hookConnector */ |
|
1338 | + $hookConnector = $this->get(HookConnector::class); |
|
1339 | + $hookConnector->viewToNode(); |
|
1340 | + } |
|
1341 | + |
|
1342 | + /** |
|
1343 | + * @return \OCP\Calendar\IManager |
|
1344 | + * @deprecated 20.0.0 |
|
1345 | + */ |
|
1346 | + public function getCalendarManager() { |
|
1347 | + return $this->get(\OC\Calendar\Manager::class); |
|
1348 | + } |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * @return \OCP\Calendar\Resource\IManager |
|
1352 | + * @deprecated 20.0.0 |
|
1353 | + */ |
|
1354 | + public function getCalendarResourceBackendManager() { |
|
1355 | + return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1356 | + } |
|
1357 | + |
|
1358 | + /** |
|
1359 | + * @return \OCP\Calendar\Room\IManager |
|
1360 | + * @deprecated 20.0.0 |
|
1361 | + */ |
|
1362 | + public function getCalendarRoomBackendManager() { |
|
1363 | + return $this->get(\OC\Calendar\Room\Manager::class); |
|
1364 | + } |
|
1365 | + |
|
1366 | + private function connectDispatcher() { |
|
1367 | + $dispatcher = $this->get(SymfonyAdapter::class); |
|
1368 | + |
|
1369 | + // Delete avatar on user deletion |
|
1370 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1371 | + $logger = $this->get(ILogger::class); |
|
1372 | + $manager = $this->getAvatarManager(); |
|
1373 | + /** @var IUser $user */ |
|
1374 | + $user = $e->getSubject(); |
|
1375 | + |
|
1376 | + try { |
|
1377 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1378 | + $avatar->remove(); |
|
1379 | + } catch (NotFoundException $e) { |
|
1380 | + // no avatar to remove |
|
1381 | + } catch (\Exception $e) { |
|
1382 | + // Ignore exceptions |
|
1383 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1384 | + } |
|
1385 | + }); |
|
1386 | + |
|
1387 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1388 | + $manager = $this->getAvatarManager(); |
|
1389 | + /** @var IUser $user */ |
|
1390 | + $user = $e->getSubject(); |
|
1391 | + $feature = $e->getArgument('feature'); |
|
1392 | + $oldValue = $e->getArgument('oldValue'); |
|
1393 | + $value = $e->getArgument('value'); |
|
1394 | + |
|
1395 | + // We only change the avatar on display name changes |
|
1396 | + if ($feature !== 'displayName') { |
|
1397 | + return; |
|
1398 | + } |
|
1399 | + |
|
1400 | + try { |
|
1401 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1402 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1403 | + } catch (NotFoundException $e) { |
|
1404 | + // no avatar to remove |
|
1405 | + } |
|
1406 | + }); |
|
1407 | + |
|
1408 | + /** @var IEventDispatcher $eventDispatched */ |
|
1409 | + $eventDispatched = $this->get(IEventDispatcher::class); |
|
1410 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1411 | + $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1412 | + } |
|
1413 | + |
|
1414 | + /** |
|
1415 | + * @return \OCP\Contacts\IManager |
|
1416 | + * @deprecated 20.0.0 |
|
1417 | + */ |
|
1418 | + public function getContactsManager() { |
|
1419 | + return $this->get(\OCP\Contacts\IManager::class); |
|
1420 | + } |
|
1421 | + |
|
1422 | + /** |
|
1423 | + * @return \OC\Encryption\Manager |
|
1424 | + * @deprecated 20.0.0 |
|
1425 | + */ |
|
1426 | + public function getEncryptionManager() { |
|
1427 | + return $this->get(\OCP\Encryption\IManager::class); |
|
1428 | + } |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * @return \OC\Encryption\File |
|
1432 | + * @deprecated 20.0.0 |
|
1433 | + */ |
|
1434 | + public function getEncryptionFilesHelper() { |
|
1435 | + return $this->get(IFile::class); |
|
1436 | + } |
|
1437 | + |
|
1438 | + /** |
|
1439 | + * @return \OCP\Encryption\Keys\IStorage |
|
1440 | + * @deprecated 20.0.0 |
|
1441 | + */ |
|
1442 | + public function getEncryptionKeyStorage() { |
|
1443 | + return $this->get(IStorage::class); |
|
1444 | + } |
|
1445 | + |
|
1446 | + /** |
|
1447 | + * The current request object holding all information about the request |
|
1448 | + * currently being processed is returned from this method. |
|
1449 | + * In case the current execution was not initiated by a web request null is returned |
|
1450 | + * |
|
1451 | + * @return \OCP\IRequest |
|
1452 | + * @deprecated 20.0.0 |
|
1453 | + */ |
|
1454 | + public function getRequest() { |
|
1455 | + return $this->get(IRequest::class); |
|
1456 | + } |
|
1457 | + |
|
1458 | + /** |
|
1459 | + * Returns the preview manager which can create preview images for a given file |
|
1460 | + * |
|
1461 | + * @return IPreview |
|
1462 | + * @deprecated 20.0.0 |
|
1463 | + */ |
|
1464 | + public function getPreviewManager() { |
|
1465 | + return $this->get(IPreview::class); |
|
1466 | + } |
|
1467 | + |
|
1468 | + /** |
|
1469 | + * Returns the tag manager which can get and set tags for different object types |
|
1470 | + * |
|
1471 | + * @see \OCP\ITagManager::load() |
|
1472 | + * @return ITagManager |
|
1473 | + * @deprecated 20.0.0 |
|
1474 | + */ |
|
1475 | + public function getTagManager() { |
|
1476 | + return $this->get(ITagManager::class); |
|
1477 | + } |
|
1478 | + |
|
1479 | + /** |
|
1480 | + * Returns the system-tag manager |
|
1481 | + * |
|
1482 | + * @return ISystemTagManager |
|
1483 | + * |
|
1484 | + * @since 9.0.0 |
|
1485 | + * @deprecated 20.0.0 |
|
1486 | + */ |
|
1487 | + public function getSystemTagManager() { |
|
1488 | + return $this->get(ISystemTagManager::class); |
|
1489 | + } |
|
1490 | + |
|
1491 | + /** |
|
1492 | + * Returns the system-tag object mapper |
|
1493 | + * |
|
1494 | + * @return ISystemTagObjectMapper |
|
1495 | + * |
|
1496 | + * @since 9.0.0 |
|
1497 | + * @deprecated 20.0.0 |
|
1498 | + */ |
|
1499 | + public function getSystemTagObjectMapper() { |
|
1500 | + return $this->get(ISystemTagObjectMapper::class); |
|
1501 | + } |
|
1502 | + |
|
1503 | + /** |
|
1504 | + * Returns the avatar manager, used for avatar functionality |
|
1505 | + * |
|
1506 | + * @return IAvatarManager |
|
1507 | + * @deprecated 20.0.0 |
|
1508 | + */ |
|
1509 | + public function getAvatarManager() { |
|
1510 | + return $this->get(IAvatarManager::class); |
|
1511 | + } |
|
1512 | + |
|
1513 | + /** |
|
1514 | + * Returns the root folder of ownCloud's data directory |
|
1515 | + * |
|
1516 | + * @return IRootFolder |
|
1517 | + * @deprecated 20.0.0 |
|
1518 | + */ |
|
1519 | + public function getRootFolder() { |
|
1520 | + return $this->get(IRootFolder::class); |
|
1521 | + } |
|
1522 | + |
|
1523 | + /** |
|
1524 | + * Returns the root folder of ownCloud's data directory |
|
1525 | + * This is the lazy variant so this gets only initialized once it |
|
1526 | + * is actually used. |
|
1527 | + * |
|
1528 | + * @return IRootFolder |
|
1529 | + * @deprecated 20.0.0 |
|
1530 | + */ |
|
1531 | + public function getLazyRootFolder() { |
|
1532 | + return $this->get(IRootFolder::class); |
|
1533 | + } |
|
1534 | + |
|
1535 | + /** |
|
1536 | + * Returns a view to ownCloud's files folder |
|
1537 | + * |
|
1538 | + * @param string $userId user ID |
|
1539 | + * @return \OCP\Files\Folder|null |
|
1540 | + * @deprecated 20.0.0 |
|
1541 | + */ |
|
1542 | + public function getUserFolder($userId = null) { |
|
1543 | + if ($userId === null) { |
|
1544 | + $user = $this->get(IUserSession::class)->getUser(); |
|
1545 | + if (!$user) { |
|
1546 | + return null; |
|
1547 | + } |
|
1548 | + $userId = $user->getUID(); |
|
1549 | + } |
|
1550 | + $root = $this->get(IRootFolder::class); |
|
1551 | + return $root->getUserFolder($userId); |
|
1552 | + } |
|
1553 | + |
|
1554 | + /** |
|
1555 | + * @return \OC\User\Manager |
|
1556 | + * @deprecated 20.0.0 |
|
1557 | + */ |
|
1558 | + public function getUserManager() { |
|
1559 | + return $this->get(IUserManager::class); |
|
1560 | + } |
|
1561 | + |
|
1562 | + /** |
|
1563 | + * @return \OC\Group\Manager |
|
1564 | + * @deprecated 20.0.0 |
|
1565 | + */ |
|
1566 | + public function getGroupManager() { |
|
1567 | + return $this->get(IGroupManager::class); |
|
1568 | + } |
|
1569 | + |
|
1570 | + /** |
|
1571 | + * @return \OC\User\Session |
|
1572 | + * @deprecated 20.0.0 |
|
1573 | + */ |
|
1574 | + public function getUserSession() { |
|
1575 | + return $this->get(IUserSession::class); |
|
1576 | + } |
|
1577 | + |
|
1578 | + /** |
|
1579 | + * @return \OCP\ISession |
|
1580 | + * @deprecated 20.0.0 |
|
1581 | + */ |
|
1582 | + public function getSession() { |
|
1583 | + return $this->get(IUserSession::class)->getSession(); |
|
1584 | + } |
|
1585 | + |
|
1586 | + /** |
|
1587 | + * @param \OCP\ISession $session |
|
1588 | + */ |
|
1589 | + public function setSession(\OCP\ISession $session) { |
|
1590 | + $this->get(SessionStorage::class)->setSession($session); |
|
1591 | + $this->get(IUserSession::class)->setSession($session); |
|
1592 | + $this->get(Store::class)->setSession($session); |
|
1593 | + } |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1597 | + * @deprecated 20.0.0 |
|
1598 | + */ |
|
1599 | + public function getTwoFactorAuthManager() { |
|
1600 | + return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1601 | + } |
|
1602 | + |
|
1603 | + /** |
|
1604 | + * @return \OC\NavigationManager |
|
1605 | + * @deprecated 20.0.0 |
|
1606 | + */ |
|
1607 | + public function getNavigationManager() { |
|
1608 | + return $this->get(INavigationManager::class); |
|
1609 | + } |
|
1610 | + |
|
1611 | + /** |
|
1612 | + * @return \OCP\IConfig |
|
1613 | + * @deprecated 20.0.0 |
|
1614 | + */ |
|
1615 | + public function getConfig() { |
|
1616 | + return $this->get(AllConfig::class); |
|
1617 | + } |
|
1618 | + |
|
1619 | + /** |
|
1620 | + * @return \OC\SystemConfig |
|
1621 | + * @deprecated 20.0.0 |
|
1622 | + */ |
|
1623 | + public function getSystemConfig() { |
|
1624 | + return $this->get(SystemConfig::class); |
|
1625 | + } |
|
1626 | + |
|
1627 | + /** |
|
1628 | + * Returns the app config manager |
|
1629 | + * |
|
1630 | + * @return IAppConfig |
|
1631 | + * @deprecated 20.0.0 |
|
1632 | + */ |
|
1633 | + public function getAppConfig() { |
|
1634 | + return $this->get(IAppConfig::class); |
|
1635 | + } |
|
1636 | + |
|
1637 | + /** |
|
1638 | + * @return IFactory |
|
1639 | + * @deprecated 20.0.0 |
|
1640 | + */ |
|
1641 | + public function getL10NFactory() { |
|
1642 | + return $this->get(IFactory::class); |
|
1643 | + } |
|
1644 | + |
|
1645 | + /** |
|
1646 | + * get an L10N instance |
|
1647 | + * |
|
1648 | + * @param string $app appid |
|
1649 | + * @param string $lang |
|
1650 | + * @return IL10N |
|
1651 | + * @deprecated 20.0.0 |
|
1652 | + */ |
|
1653 | + public function getL10N($app, $lang = null) { |
|
1654 | + return $this->get(IFactory::class)->get($app, $lang); |
|
1655 | + } |
|
1656 | + |
|
1657 | + /** |
|
1658 | + * @return IURLGenerator |
|
1659 | + * @deprecated 20.0.0 |
|
1660 | + */ |
|
1661 | + public function getURLGenerator() { |
|
1662 | + return $this->get(IURLGenerator::class); |
|
1663 | + } |
|
1664 | + |
|
1665 | + /** |
|
1666 | + * @return AppFetcher |
|
1667 | + * @deprecated 20.0.0 |
|
1668 | + */ |
|
1669 | + public function getAppFetcher() { |
|
1670 | + return $this->get(AppFetcher::class); |
|
1671 | + } |
|
1672 | + |
|
1673 | + /** |
|
1674 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1675 | + * getMemCacheFactory() instead. |
|
1676 | + * |
|
1677 | + * @return ICache |
|
1678 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1679 | + */ |
|
1680 | + public function getCache() { |
|
1681 | + return $this->get(ICache::class); |
|
1682 | + } |
|
1683 | + |
|
1684 | + /** |
|
1685 | + * Returns an \OCP\CacheFactory instance |
|
1686 | + * |
|
1687 | + * @return \OCP\ICacheFactory |
|
1688 | + * @deprecated 20.0.0 |
|
1689 | + */ |
|
1690 | + public function getMemCacheFactory() { |
|
1691 | + return $this->get(ICacheFactory::class); |
|
1692 | + } |
|
1693 | + |
|
1694 | + /** |
|
1695 | + * Returns an \OC\RedisFactory instance |
|
1696 | + * |
|
1697 | + * @return \OC\RedisFactory |
|
1698 | + * @deprecated 20.0.0 |
|
1699 | + */ |
|
1700 | + public function getGetRedisFactory() { |
|
1701 | + return $this->get('RedisFactory'); |
|
1702 | + } |
|
1703 | + |
|
1704 | + |
|
1705 | + /** |
|
1706 | + * Returns the current session |
|
1707 | + * |
|
1708 | + * @return \OCP\IDBConnection |
|
1709 | + * @deprecated 20.0.0 |
|
1710 | + */ |
|
1711 | + public function getDatabaseConnection() { |
|
1712 | + return $this->get(IDBConnection::class); |
|
1713 | + } |
|
1714 | + |
|
1715 | + /** |
|
1716 | + * Returns the activity manager |
|
1717 | + * |
|
1718 | + * @return \OCP\Activity\IManager |
|
1719 | + * @deprecated 20.0.0 |
|
1720 | + */ |
|
1721 | + public function getActivityManager() { |
|
1722 | + return $this->get(\OCP\Activity\IManager::class); |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * Returns an job list for controlling background jobs |
|
1727 | + * |
|
1728 | + * @return IJobList |
|
1729 | + * @deprecated 20.0.0 |
|
1730 | + */ |
|
1731 | + public function getJobList() { |
|
1732 | + return $this->get(IJobList::class); |
|
1733 | + } |
|
1734 | + |
|
1735 | + /** |
|
1736 | + * Returns a logger instance |
|
1737 | + * |
|
1738 | + * @return ILogger |
|
1739 | + * @deprecated 20.0.0 |
|
1740 | + */ |
|
1741 | + public function getLogger() { |
|
1742 | + return $this->get(ILogger::class); |
|
1743 | + } |
|
1744 | + |
|
1745 | + /** |
|
1746 | + * @return ILogFactory |
|
1747 | + * @throws \OCP\AppFramework\QueryException |
|
1748 | + * @deprecated 20.0.0 |
|
1749 | + */ |
|
1750 | + public function getLogFactory() { |
|
1751 | + return $this->get(ILogFactory::class); |
|
1752 | + } |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * Returns a router for generating and matching urls |
|
1756 | + * |
|
1757 | + * @return IRouter |
|
1758 | + * @deprecated 20.0.0 |
|
1759 | + */ |
|
1760 | + public function getRouter() { |
|
1761 | + return $this->get(IRouter::class); |
|
1762 | + } |
|
1763 | + |
|
1764 | + /** |
|
1765 | + * Returns a search instance |
|
1766 | + * |
|
1767 | + * @return ISearch |
|
1768 | + * @deprecated 20.0.0 |
|
1769 | + */ |
|
1770 | + public function getSearch() { |
|
1771 | + return $this->get(ISearch::class); |
|
1772 | + } |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * Returns a SecureRandom instance |
|
1776 | + * |
|
1777 | + * @return \OCP\Security\ISecureRandom |
|
1778 | + * @deprecated 20.0.0 |
|
1779 | + */ |
|
1780 | + public function getSecureRandom() { |
|
1781 | + return $this->get(ISecureRandom::class); |
|
1782 | + } |
|
1783 | + |
|
1784 | + /** |
|
1785 | + * Returns a Crypto instance |
|
1786 | + * |
|
1787 | + * @return ICrypto |
|
1788 | + * @deprecated 20.0.0 |
|
1789 | + */ |
|
1790 | + public function getCrypto() { |
|
1791 | + return $this->get(ICrypto::class); |
|
1792 | + } |
|
1793 | + |
|
1794 | + /** |
|
1795 | + * Returns a Hasher instance |
|
1796 | + * |
|
1797 | + * @return IHasher |
|
1798 | + * @deprecated 20.0.0 |
|
1799 | + */ |
|
1800 | + public function getHasher() { |
|
1801 | + return $this->get(IHasher::class); |
|
1802 | + } |
|
1803 | + |
|
1804 | + /** |
|
1805 | + * Returns a CredentialsManager instance |
|
1806 | + * |
|
1807 | + * @return ICredentialsManager |
|
1808 | + * @deprecated 20.0.0 |
|
1809 | + */ |
|
1810 | + public function getCredentialsManager() { |
|
1811 | + return $this->get(ICredentialsManager::class); |
|
1812 | + } |
|
1813 | + |
|
1814 | + /** |
|
1815 | + * Get the certificate manager |
|
1816 | + * |
|
1817 | + * @return \OCP\ICertificateManager |
|
1818 | + */ |
|
1819 | + public function getCertificateManager() { |
|
1820 | + return $this->get(ICertificateManager::class); |
|
1821 | + } |
|
1822 | + |
|
1823 | + /** |
|
1824 | + * Returns an instance of the HTTP client service |
|
1825 | + * |
|
1826 | + * @return IClientService |
|
1827 | + * @deprecated 20.0.0 |
|
1828 | + */ |
|
1829 | + public function getHTTPClientService() { |
|
1830 | + return $this->get(IClientService::class); |
|
1831 | + } |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * Create a new event source |
|
1835 | + * |
|
1836 | + * @return \OCP\IEventSource |
|
1837 | + * @deprecated 20.0.0 |
|
1838 | + */ |
|
1839 | + public function createEventSource() { |
|
1840 | + return new \OC_EventSource(); |
|
1841 | + } |
|
1842 | + |
|
1843 | + /** |
|
1844 | + * Get the active event logger |
|
1845 | + * |
|
1846 | + * The returned logger only logs data when debug mode is enabled |
|
1847 | + * |
|
1848 | + * @return IEventLogger |
|
1849 | + * @deprecated 20.0.0 |
|
1850 | + */ |
|
1851 | + public function getEventLogger() { |
|
1852 | + return $this->get(IEventLogger::class); |
|
1853 | + } |
|
1854 | + |
|
1855 | + /** |
|
1856 | + * Get the active query logger |
|
1857 | + * |
|
1858 | + * The returned logger only logs data when debug mode is enabled |
|
1859 | + * |
|
1860 | + * @return IQueryLogger |
|
1861 | + * @deprecated 20.0.0 |
|
1862 | + */ |
|
1863 | + public function getQueryLogger() { |
|
1864 | + return $this->get(IQueryLogger::class); |
|
1865 | + } |
|
1866 | + |
|
1867 | + /** |
|
1868 | + * Get the manager for temporary files and folders |
|
1869 | + * |
|
1870 | + * @return \OCP\ITempManager |
|
1871 | + * @deprecated 20.0.0 |
|
1872 | + */ |
|
1873 | + public function getTempManager() { |
|
1874 | + return $this->get(ITempManager::class); |
|
1875 | + } |
|
1876 | + |
|
1877 | + /** |
|
1878 | + * Get the app manager |
|
1879 | + * |
|
1880 | + * @return \OCP\App\IAppManager |
|
1881 | + * @deprecated 20.0.0 |
|
1882 | + */ |
|
1883 | + public function getAppManager() { |
|
1884 | + return $this->get(IAppManager::class); |
|
1885 | + } |
|
1886 | + |
|
1887 | + /** |
|
1888 | + * Creates a new mailer |
|
1889 | + * |
|
1890 | + * @return IMailer |
|
1891 | + * @deprecated 20.0.0 |
|
1892 | + */ |
|
1893 | + public function getMailer() { |
|
1894 | + return $this->get(IMailer::class); |
|
1895 | + } |
|
1896 | + |
|
1897 | + /** |
|
1898 | + * Get the webroot |
|
1899 | + * |
|
1900 | + * @return string |
|
1901 | + * @deprecated 20.0.0 |
|
1902 | + */ |
|
1903 | + public function getWebRoot() { |
|
1904 | + return $this->webRoot; |
|
1905 | + } |
|
1906 | + |
|
1907 | + /** |
|
1908 | + * @return \OC\OCSClient |
|
1909 | + * @deprecated 20.0.0 |
|
1910 | + */ |
|
1911 | + public function getOcsClient() { |
|
1912 | + return $this->get('OcsClient'); |
|
1913 | + } |
|
1914 | + |
|
1915 | + /** |
|
1916 | + * @return IDateTimeZone |
|
1917 | + * @deprecated 20.0.0 |
|
1918 | + */ |
|
1919 | + public function getDateTimeZone() { |
|
1920 | + return $this->get(IDateTimeZone::class); |
|
1921 | + } |
|
1922 | + |
|
1923 | + /** |
|
1924 | + * @return IDateTimeFormatter |
|
1925 | + * @deprecated 20.0.0 |
|
1926 | + */ |
|
1927 | + public function getDateTimeFormatter() { |
|
1928 | + return $this->get(IDateTimeFormatter::class); |
|
1929 | + } |
|
1930 | + |
|
1931 | + /** |
|
1932 | + * @return IMountProviderCollection |
|
1933 | + * @deprecated 20.0.0 |
|
1934 | + */ |
|
1935 | + public function getMountProviderCollection() { |
|
1936 | + return $this->get(IMountProviderCollection::class); |
|
1937 | + } |
|
1938 | + |
|
1939 | + /** |
|
1940 | + * Get the IniWrapper |
|
1941 | + * |
|
1942 | + * @return IniGetWrapper |
|
1943 | + * @deprecated 20.0.0 |
|
1944 | + */ |
|
1945 | + public function getIniWrapper() { |
|
1946 | + return $this->get(IniGetWrapper::class); |
|
1947 | + } |
|
1948 | + |
|
1949 | + /** |
|
1950 | + * @return \OCP\Command\IBus |
|
1951 | + * @deprecated 20.0.0 |
|
1952 | + */ |
|
1953 | + public function getCommandBus() { |
|
1954 | + return $this->get(IBus::class); |
|
1955 | + } |
|
1956 | + |
|
1957 | + /** |
|
1958 | + * Get the trusted domain helper |
|
1959 | + * |
|
1960 | + * @return TrustedDomainHelper |
|
1961 | + * @deprecated 20.0.0 |
|
1962 | + */ |
|
1963 | + public function getTrustedDomainHelper() { |
|
1964 | + return $this->get(TrustedDomainHelper::class); |
|
1965 | + } |
|
1966 | + |
|
1967 | + /** |
|
1968 | + * Get the locking provider |
|
1969 | + * |
|
1970 | + * @return ILockingProvider |
|
1971 | + * @since 8.1.0 |
|
1972 | + * @deprecated 20.0.0 |
|
1973 | + */ |
|
1974 | + public function getLockingProvider() { |
|
1975 | + return $this->get(ILockingProvider::class); |
|
1976 | + } |
|
1977 | + |
|
1978 | + /** |
|
1979 | + * @return IMountManager |
|
1980 | + * @deprecated 20.0.0 |
|
1981 | + **/ |
|
1982 | + public function getMountManager() { |
|
1983 | + return $this->get(IMountManager::class); |
|
1984 | + } |
|
1985 | + |
|
1986 | + /** |
|
1987 | + * @return IUserMountCache |
|
1988 | + * @deprecated 20.0.0 |
|
1989 | + */ |
|
1990 | + public function getUserMountCache() { |
|
1991 | + return $this->get(IUserMountCache::class); |
|
1992 | + } |
|
1993 | + |
|
1994 | + /** |
|
1995 | + * Get the MimeTypeDetector |
|
1996 | + * |
|
1997 | + * @return IMimeTypeDetector |
|
1998 | + * @deprecated 20.0.0 |
|
1999 | + */ |
|
2000 | + public function getMimeTypeDetector() { |
|
2001 | + return $this->get(IMimeTypeDetector::class); |
|
2002 | + } |
|
2003 | + |
|
2004 | + /** |
|
2005 | + * Get the MimeTypeLoader |
|
2006 | + * |
|
2007 | + * @return IMimeTypeLoader |
|
2008 | + * @deprecated 20.0.0 |
|
2009 | + */ |
|
2010 | + public function getMimeTypeLoader() { |
|
2011 | + return $this->get(IMimeTypeLoader::class); |
|
2012 | + } |
|
2013 | + |
|
2014 | + /** |
|
2015 | + * Get the manager of all the capabilities |
|
2016 | + * |
|
2017 | + * @return CapabilitiesManager |
|
2018 | + * @deprecated 20.0.0 |
|
2019 | + */ |
|
2020 | + public function getCapabilitiesManager() { |
|
2021 | + return $this->get(CapabilitiesManager::class); |
|
2022 | + } |
|
2023 | + |
|
2024 | + /** |
|
2025 | + * Get the EventDispatcher |
|
2026 | + * |
|
2027 | + * @return EventDispatcherInterface |
|
2028 | + * @since 8.2.0 |
|
2029 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2030 | + */ |
|
2031 | + public function getEventDispatcher() { |
|
2032 | + return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2033 | + } |
|
2034 | + |
|
2035 | + /** |
|
2036 | + * Get the Notification Manager |
|
2037 | + * |
|
2038 | + * @return \OCP\Notification\IManager |
|
2039 | + * @since 8.2.0 |
|
2040 | + * @deprecated 20.0.0 |
|
2041 | + */ |
|
2042 | + public function getNotificationManager() { |
|
2043 | + return $this->get(\OCP\Notification\IManager::class); |
|
2044 | + } |
|
2045 | + |
|
2046 | + /** |
|
2047 | + * @return ICommentsManager |
|
2048 | + * @deprecated 20.0.0 |
|
2049 | + */ |
|
2050 | + public function getCommentsManager() { |
|
2051 | + return $this->get(ICommentsManager::class); |
|
2052 | + } |
|
2053 | + |
|
2054 | + /** |
|
2055 | + * @return \OCA\Theming\ThemingDefaults |
|
2056 | + * @deprecated 20.0.0 |
|
2057 | + */ |
|
2058 | + public function getThemingDefaults() { |
|
2059 | + return $this->get('ThemingDefaults'); |
|
2060 | + } |
|
2061 | + |
|
2062 | + /** |
|
2063 | + * @return \OC\IntegrityCheck\Checker |
|
2064 | + * @deprecated 20.0.0 |
|
2065 | + */ |
|
2066 | + public function getIntegrityCodeChecker() { |
|
2067 | + return $this->get('IntegrityCodeChecker'); |
|
2068 | + } |
|
2069 | + |
|
2070 | + /** |
|
2071 | + * @return \OC\Session\CryptoWrapper |
|
2072 | + * @deprecated 20.0.0 |
|
2073 | + */ |
|
2074 | + public function getSessionCryptoWrapper() { |
|
2075 | + return $this->get('CryptoWrapper'); |
|
2076 | + } |
|
2077 | + |
|
2078 | + /** |
|
2079 | + * @return CsrfTokenManager |
|
2080 | + * @deprecated 20.0.0 |
|
2081 | + */ |
|
2082 | + public function getCsrfTokenManager() { |
|
2083 | + return $this->get(CsrfTokenManager::class); |
|
2084 | + } |
|
2085 | + |
|
2086 | + /** |
|
2087 | + * @return Throttler |
|
2088 | + * @deprecated 20.0.0 |
|
2089 | + */ |
|
2090 | + public function getBruteForceThrottler() { |
|
2091 | + return $this->get(Throttler::class); |
|
2092 | + } |
|
2093 | + |
|
2094 | + /** |
|
2095 | + * @return IContentSecurityPolicyManager |
|
2096 | + * @deprecated 20.0.0 |
|
2097 | + */ |
|
2098 | + public function getContentSecurityPolicyManager() { |
|
2099 | + return $this->get(ContentSecurityPolicyManager::class); |
|
2100 | + } |
|
2101 | + |
|
2102 | + /** |
|
2103 | + * @return ContentSecurityPolicyNonceManager |
|
2104 | + * @deprecated 20.0.0 |
|
2105 | + */ |
|
2106 | + public function getContentSecurityPolicyNonceManager() { |
|
2107 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2108 | + } |
|
2109 | + |
|
2110 | + /** |
|
2111 | + * Not a public API as of 8.2, wait for 9.0 |
|
2112 | + * |
|
2113 | + * @return \OCA\Files_External\Service\BackendService |
|
2114 | + * @deprecated 20.0.0 |
|
2115 | + */ |
|
2116 | + public function getStoragesBackendService() { |
|
2117 | + return $this->get(BackendService::class); |
|
2118 | + } |
|
2119 | + |
|
2120 | + /** |
|
2121 | + * Not a public API as of 8.2, wait for 9.0 |
|
2122 | + * |
|
2123 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2124 | + * @deprecated 20.0.0 |
|
2125 | + */ |
|
2126 | + public function getGlobalStoragesService() { |
|
2127 | + return $this->get(GlobalStoragesService::class); |
|
2128 | + } |
|
2129 | + |
|
2130 | + /** |
|
2131 | + * Not a public API as of 8.2, wait for 9.0 |
|
2132 | + * |
|
2133 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2134 | + * @deprecated 20.0.0 |
|
2135 | + */ |
|
2136 | + public function getUserGlobalStoragesService() { |
|
2137 | + return $this->get(UserGlobalStoragesService::class); |
|
2138 | + } |
|
2139 | + |
|
2140 | + /** |
|
2141 | + * Not a public API as of 8.2, wait for 9.0 |
|
2142 | + * |
|
2143 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
2144 | + * @deprecated 20.0.0 |
|
2145 | + */ |
|
2146 | + public function getUserStoragesService() { |
|
2147 | + return $this->get(UserStoragesService::class); |
|
2148 | + } |
|
2149 | + |
|
2150 | + /** |
|
2151 | + * @return \OCP\Share\IManager |
|
2152 | + * @deprecated 20.0.0 |
|
2153 | + */ |
|
2154 | + public function getShareManager() { |
|
2155 | + return $this->get(\OCP\Share\IManager::class); |
|
2156 | + } |
|
2157 | + |
|
2158 | + /** |
|
2159 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
2160 | + * @deprecated 20.0.0 |
|
2161 | + */ |
|
2162 | + public function getCollaboratorSearch() { |
|
2163 | + return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2164 | + } |
|
2165 | + |
|
2166 | + /** |
|
2167 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
2168 | + * @deprecated 20.0.0 |
|
2169 | + */ |
|
2170 | + public function getAutoCompleteManager() { |
|
2171 | + return $this->get(IManager::class); |
|
2172 | + } |
|
2173 | + |
|
2174 | + /** |
|
2175 | + * Returns the LDAP Provider |
|
2176 | + * |
|
2177 | + * @return \OCP\LDAP\ILDAPProvider |
|
2178 | + * @deprecated 20.0.0 |
|
2179 | + */ |
|
2180 | + public function getLDAPProvider() { |
|
2181 | + return $this->get('LDAPProvider'); |
|
2182 | + } |
|
2183 | + |
|
2184 | + /** |
|
2185 | + * @return \OCP\Settings\IManager |
|
2186 | + * @deprecated 20.0.0 |
|
2187 | + */ |
|
2188 | + public function getSettingsManager() { |
|
2189 | + return $this->get(\OC\Settings\Manager::class); |
|
2190 | + } |
|
2191 | + |
|
2192 | + /** |
|
2193 | + * @return \OCP\Files\IAppData |
|
2194 | + * @deprecated 20.0.0 |
|
2195 | + */ |
|
2196 | + public function getAppDataDir($app) { |
|
2197 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
2198 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2199 | + return $factory->get($app); |
|
2200 | + } |
|
2201 | + |
|
2202 | + /** |
|
2203 | + * @return \OCP\Lockdown\ILockdownManager |
|
2204 | + * @deprecated 20.0.0 |
|
2205 | + */ |
|
2206 | + public function getLockdownManager() { |
|
2207 | + return $this->get('LockdownManager'); |
|
2208 | + } |
|
2209 | + |
|
2210 | + /** |
|
2211 | + * @return \OCP\Federation\ICloudIdManager |
|
2212 | + * @deprecated 20.0.0 |
|
2213 | + */ |
|
2214 | + public function getCloudIdManager() { |
|
2215 | + return $this->get(ICloudIdManager::class); |
|
2216 | + } |
|
2217 | + |
|
2218 | + /** |
|
2219 | + * @return \OCP\GlobalScale\IConfig |
|
2220 | + * @deprecated 20.0.0 |
|
2221 | + */ |
|
2222 | + public function getGlobalScaleConfig() { |
|
2223 | + return $this->get(IConfig::class); |
|
2224 | + } |
|
2225 | + |
|
2226 | + /** |
|
2227 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2228 | + * @deprecated 20.0.0 |
|
2229 | + */ |
|
2230 | + public function getCloudFederationProviderManager() { |
|
2231 | + return $this->get(ICloudFederationProviderManager::class); |
|
2232 | + } |
|
2233 | + |
|
2234 | + /** |
|
2235 | + * @return \OCP\Remote\Api\IApiFactory |
|
2236 | + * @deprecated 20.0.0 |
|
2237 | + */ |
|
2238 | + public function getRemoteApiFactory() { |
|
2239 | + return $this->get(IApiFactory::class); |
|
2240 | + } |
|
2241 | + |
|
2242 | + /** |
|
2243 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2244 | + * @deprecated 20.0.0 |
|
2245 | + */ |
|
2246 | + public function getCloudFederationFactory() { |
|
2247 | + return $this->get(ICloudFederationFactory::class); |
|
2248 | + } |
|
2249 | + |
|
2250 | + /** |
|
2251 | + * @return \OCP\Remote\IInstanceFactory |
|
2252 | + * @deprecated 20.0.0 |
|
2253 | + */ |
|
2254 | + public function getRemoteInstanceFactory() { |
|
2255 | + return $this->get(IInstanceFactory::class); |
|
2256 | + } |
|
2257 | + |
|
2258 | + /** |
|
2259 | + * @return IStorageFactory |
|
2260 | + * @deprecated 20.0.0 |
|
2261 | + */ |
|
2262 | + public function getStorageFactory() { |
|
2263 | + return $this->get(IStorageFactory::class); |
|
2264 | + } |
|
2265 | + |
|
2266 | + /** |
|
2267 | + * Get the Preview GeneratorHelper |
|
2268 | + * |
|
2269 | + * @return GeneratorHelper |
|
2270 | + * @since 17.0.0 |
|
2271 | + * @deprecated 20.0.0 |
|
2272 | + */ |
|
2273 | + public function getGeneratorHelper() { |
|
2274 | + return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2275 | + } |
|
2276 | + |
|
2277 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
2278 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2279 | + try { |
|
2280 | + /** @var ILogger $logger */ |
|
2281 | + $logger = $container->get(ILogger::class); |
|
2282 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2283 | + } catch (ContainerExceptionInterface $e) { |
|
2284 | + // Could not get logger. Continue |
|
2285 | + } |
|
2286 | + |
|
2287 | + return $container->get($target); |
|
2288 | + }, false); |
|
2289 | + } |
|
2290 | 2290 | } |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | $this->registerParameter('isCLI', \OC::$CLI); |
266 | 266 | $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
267 | 267 | |
268 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
268 | + $this->registerService(ContainerInterface::class, function(ContainerInterface $c) { |
|
269 | 269 | return $c; |
270 | 270 | }); |
271 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
271 | + $this->registerService(\OCP\IServerContainer::class, function(ContainerInterface $c) { |
|
272 | 272 | return $c; |
273 | 273 | }); |
274 | 274 | |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | |
293 | 293 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
294 | 294 | |
295 | - $this->registerService(View::class, function (Server $c) { |
|
295 | + $this->registerService(View::class, function(Server $c) { |
|
296 | 296 | return new View(); |
297 | 297 | }, false); |
298 | 298 | |
299 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
299 | + $this->registerService(IPreview::class, function(ContainerInterface $c) { |
|
300 | 300 | return new PreviewManager( |
301 | 301 | $c->get(\OCP\IConfig::class), |
302 | 302 | $c->get(IRootFolder::class), |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | /** @deprecated 19.0.0 */ |
313 | 313 | $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
314 | 314 | |
315 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
315 | + $this->registerService(\OC\Preview\Watcher::class, function(ContainerInterface $c) { |
|
316 | 316 | return new \OC\Preview\Watcher( |
317 | 317 | new \OC\Preview\Storage\Root( |
318 | 318 | $c->get(IRootFolder::class), |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | ); |
322 | 322 | }); |
323 | 323 | |
324 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
324 | + $this->registerService(\OCP\Encryption\IManager::class, function(Server $c) { |
|
325 | 325 | $view = new View(); |
326 | 326 | $util = new Encryption\Util( |
327 | 327 | $view, |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | |
344 | 344 | /** @deprecated 21.0.0 */ |
345 | 345 | $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
346 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
346 | + $this->registerService(IFile::class, function(ContainerInterface $c) { |
|
347 | 347 | $util = new Encryption\Util( |
348 | 348 | new View(), |
349 | 349 | $c->get(IUserManager::class), |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | |
360 | 360 | /** @deprecated 21.0.0 */ |
361 | 361 | $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
362 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
362 | + $this->registerService(IStorage::class, function(ContainerInterface $c) { |
|
363 | 363 | $view = new View(); |
364 | 364 | $util = new Encryption\Util( |
365 | 365 | $view, |
@@ -382,22 +382,22 @@ discard block |
||
382 | 382 | /** @deprecated 19.0.0 */ |
383 | 383 | $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
384 | 384 | |
385 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
385 | + $this->registerService('SystemTagManagerFactory', function(ContainerInterface $c) { |
|
386 | 386 | /** @var \OCP\IConfig $config */ |
387 | 387 | $config = $c->get(\OCP\IConfig::class); |
388 | 388 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
389 | 389 | return new $factoryClass($this); |
390 | 390 | }); |
391 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
391 | + $this->registerService(ISystemTagManager::class, function(ContainerInterface $c) { |
|
392 | 392 | return $c->get('SystemTagManagerFactory')->getManager(); |
393 | 393 | }); |
394 | 394 | /** @deprecated 19.0.0 */ |
395 | 395 | $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
396 | 396 | |
397 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
397 | + $this->registerService(ISystemTagObjectMapper::class, function(ContainerInterface $c) { |
|
398 | 398 | return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
399 | 399 | }); |
400 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
400 | + $this->registerService('RootFolder', function(ContainerInterface $c) { |
|
401 | 401 | $manager = \OC\Files\Filesystem::getMountManager(null); |
402 | 402 | $view = new View(); |
403 | 403 | $root = new Root( |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | |
418 | 418 | return $root; |
419 | 419 | }); |
420 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
420 | + $this->registerService(HookConnector::class, function(ContainerInterface $c) { |
|
421 | 421 | return new HookConnector( |
422 | 422 | $c->get(IRootFolder::class), |
423 | 423 | new View(), |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | /** @deprecated 19.0.0 */ |
430 | 430 | $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
431 | 431 | |
432 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
433 | - return new LazyRoot(function () use ($c) { |
|
432 | + $this->registerService(IRootFolder::class, function(ContainerInterface $c) { |
|
433 | + return new LazyRoot(function() use ($c) { |
|
434 | 434 | return $c->get('RootFolder'); |
435 | 435 | }); |
436 | 436 | }); |
@@ -441,44 +441,44 @@ discard block |
||
441 | 441 | $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
442 | 442 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
443 | 443 | |
444 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
444 | + $this->registerService(\OCP\IGroupManager::class, function(ContainerInterface $c) { |
|
445 | 445 | $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
446 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
446 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
447 | 447 | /** @var IEventDispatcher $dispatcher */ |
448 | 448 | $dispatcher = $this->get(IEventDispatcher::class); |
449 | 449 | $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
450 | 450 | }); |
451 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
451 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $group) { |
|
452 | 452 | /** @var IEventDispatcher $dispatcher */ |
453 | 453 | $dispatcher = $this->get(IEventDispatcher::class); |
454 | 454 | $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
455 | 455 | }); |
456 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
456 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
457 | 457 | /** @var IEventDispatcher $dispatcher */ |
458 | 458 | $dispatcher = $this->get(IEventDispatcher::class); |
459 | 459 | $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
460 | 460 | }); |
461 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
461 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
462 | 462 | /** @var IEventDispatcher $dispatcher */ |
463 | 463 | $dispatcher = $this->get(IEventDispatcher::class); |
464 | 464 | $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
465 | 465 | }); |
466 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
466 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
467 | 467 | /** @var IEventDispatcher $dispatcher */ |
468 | 468 | $dispatcher = $this->get(IEventDispatcher::class); |
469 | 469 | $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
470 | 470 | }); |
471 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
471 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
472 | 472 | /** @var IEventDispatcher $dispatcher */ |
473 | 473 | $dispatcher = $this->get(IEventDispatcher::class); |
474 | 474 | $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
475 | 475 | }); |
476 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
476 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
477 | 477 | /** @var IEventDispatcher $dispatcher */ |
478 | 478 | $dispatcher = $this->get(IEventDispatcher::class); |
479 | 479 | $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
480 | 480 | }); |
481 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
481 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
482 | 482 | /** @var IEventDispatcher $dispatcher */ |
483 | 483 | $dispatcher = $this->get(IEventDispatcher::class); |
484 | 484 | $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | /** @deprecated 19.0.0 */ |
489 | 489 | $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
490 | 490 | |
491 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
491 | + $this->registerService(Store::class, function(ContainerInterface $c) { |
|
492 | 492 | $session = $c->get(ISession::class); |
493 | 493 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
494 | 494 | $tokenProvider = $c->get(IProvider::class); |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | $this->registerAlias(IStore::class, Store::class); |
502 | 502 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
503 | 503 | |
504 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
504 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
505 | 505 | $manager = $c->get(IUserManager::class); |
506 | 506 | $session = new \OC\Session\Memory(''); |
507 | 507 | $timeFactory = new TimeFactory(); |
@@ -527,26 +527,26 @@ discard block |
||
527 | 527 | $c->get(IEventDispatcher::class) |
528 | 528 | ); |
529 | 529 | /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
530 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
530 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
531 | 531 | \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
532 | 532 | }); |
533 | 533 | /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
534 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
534 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
535 | 535 | /** @var \OC\User\User $user */ |
536 | 536 | \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
537 | 537 | }); |
538 | 538 | /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
539 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
539 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($legacyDispatcher) { |
|
540 | 540 | /** @var \OC\User\User $user */ |
541 | 541 | \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
542 | 542 | $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
543 | 543 | }); |
544 | 544 | /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
545 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
545 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
546 | 546 | /** @var \OC\User\User $user */ |
547 | 547 | \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
548 | 548 | }); |
549 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
549 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
550 | 550 | /** @var \OC\User\User $user */ |
551 | 551 | \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
552 | 552 | |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $dispatcher = $this->get(IEventDispatcher::class); |
555 | 555 | $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
556 | 556 | }); |
557 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
557 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
558 | 558 | /** @var \OC\User\User $user */ |
559 | 559 | \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
560 | 560 | |
@@ -562,14 +562,14 @@ discard block |
||
562 | 562 | $dispatcher = $this->get(IEventDispatcher::class); |
563 | 563 | $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
564 | 564 | }); |
565 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
565 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
566 | 566 | \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
567 | 567 | |
568 | 568 | /** @var IEventDispatcher $dispatcher */ |
569 | 569 | $dispatcher = $this->get(IEventDispatcher::class); |
570 | 570 | $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
571 | 571 | }); |
572 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
572 | + $userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) { |
|
573 | 573 | /** @var \OC\User\User $user */ |
574 | 574 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
575 | 575 | |
@@ -577,12 +577,12 @@ discard block |
||
577 | 577 | $dispatcher = $this->get(IEventDispatcher::class); |
578 | 578 | $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
579 | 579 | }); |
580 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
580 | + $userSession->listen('\OC\User', 'preRememberedLogin', function($uid) { |
|
581 | 581 | /** @var IEventDispatcher $dispatcher */ |
582 | 582 | $dispatcher = $this->get(IEventDispatcher::class); |
583 | 583 | $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
584 | 584 | }); |
585 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
585 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
586 | 586 | /** @var \OC\User\User $user */ |
587 | 587 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
588 | 588 | |
@@ -590,19 +590,19 @@ discard block |
||
590 | 590 | $dispatcher = $this->get(IEventDispatcher::class); |
591 | 591 | $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
592 | 592 | }); |
593 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
593 | + $userSession->listen('\OC\User', 'logout', function($user) { |
|
594 | 594 | \OC_Hook::emit('OC_User', 'logout', []); |
595 | 595 | |
596 | 596 | /** @var IEventDispatcher $dispatcher */ |
597 | 597 | $dispatcher = $this->get(IEventDispatcher::class); |
598 | 598 | $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
599 | 599 | }); |
600 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
600 | + $userSession->listen('\OC\User', 'postLogout', function($user) { |
|
601 | 601 | /** @var IEventDispatcher $dispatcher */ |
602 | 602 | $dispatcher = $this->get(IEventDispatcher::class); |
603 | 603 | $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
604 | 604 | }); |
605 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
605 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
606 | 606 | /** @var \OC\User\User $user */ |
607 | 607 | \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
608 | 608 | |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
627 | 627 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
628 | 628 | |
629 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
629 | + $this->registerService(\OC\SystemConfig::class, function($c) use ($config) { |
|
630 | 630 | return new \OC\SystemConfig($config); |
631 | 631 | }); |
632 | 632 | /** @deprecated 19.0.0 */ |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
637 | 637 | $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
638 | 638 | |
639 | - $this->registerService(IFactory::class, function (Server $c) { |
|
639 | + $this->registerService(IFactory::class, function(Server $c) { |
|
640 | 640 | return new \OC\L10N\Factory( |
641 | 641 | $c->get(\OCP\IConfig::class), |
642 | 642 | $c->getRequest(), |
@@ -656,13 +656,13 @@ discard block |
||
656 | 656 | /** @deprecated 19.0.0 */ |
657 | 657 | $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
658 | 658 | |
659 | - $this->registerService(ICache::class, function ($c) { |
|
659 | + $this->registerService(ICache::class, function($c) { |
|
660 | 660 | return new Cache\File(); |
661 | 661 | }); |
662 | 662 | /** @deprecated 19.0.0 */ |
663 | 663 | $this->registerDeprecatedAlias('UserCache', ICache::class); |
664 | 664 | |
665 | - $this->registerService(Factory::class, function (Server $c) { |
|
665 | + $this->registerService(Factory::class, function(Server $c) { |
|
666 | 666 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
667 | 667 | ArrayCache::class, |
668 | 668 | ArrayCache::class, |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | $version = implode(',', $v); |
678 | 678 | $instanceId = \OC_Util::getInstanceId(); |
679 | 679 | $path = \OC::$SERVERROOT; |
680 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
680 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
681 | 681 | return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
682 | 682 | $config->getSystemValue('memcache.local', null), |
683 | 683 | $config->getSystemValue('memcache.distributed', null), |
@@ -690,12 +690,12 @@ discard block |
||
690 | 690 | $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
691 | 691 | $this->registerAlias(ICacheFactory::class, Factory::class); |
692 | 692 | |
693 | - $this->registerService('RedisFactory', function (Server $c) { |
|
693 | + $this->registerService('RedisFactory', function(Server $c) { |
|
694 | 694 | $systemConfig = $c->get(SystemConfig::class); |
695 | 695 | return new RedisFactory($systemConfig); |
696 | 696 | }); |
697 | 697 | |
698 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
698 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
699 | 699 | $l10n = $this->get(IFactory::class)->get('lib'); |
700 | 700 | return new \OC\Activity\Manager( |
701 | 701 | $c->getRequest(), |
@@ -708,14 +708,14 @@ discard block |
||
708 | 708 | /** @deprecated 19.0.0 */ |
709 | 709 | $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
710 | 710 | |
711 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
711 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
712 | 712 | return new \OC\Activity\EventMerger( |
713 | 713 | $c->getL10N('lib') |
714 | 714 | ); |
715 | 715 | }); |
716 | 716 | $this->registerAlias(IValidator::class, Validator::class); |
717 | 717 | |
718 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
718 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
719 | 719 | return new AvatarManager( |
720 | 720 | $c->get(\OC\User\Manager::class), |
721 | 721 | $c->getAppDataDir('avatar'), |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
732 | 732 | $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
733 | 733 | |
734 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
734 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
735 | 735 | $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
736 | 736 | $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
737 | 737 | $logger = $factory->get($logType); |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | // PSR-3 logger |
746 | 746 | $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
747 | 747 | |
748 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
748 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
749 | 749 | return new LogFactory($c, $this->get(SystemConfig::class)); |
750 | 750 | }); |
751 | 751 | |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | /** @deprecated 19.0.0 */ |
754 | 754 | $this->registerDeprecatedAlias('JobList', IJobList::class); |
755 | 755 | |
756 | - $this->registerService(Router::class, function (Server $c) { |
|
756 | + $this->registerService(Router::class, function(Server $c) { |
|
757 | 757 | $cacheFactory = $c->get(ICacheFactory::class); |
758 | 758 | $logger = $c->get(ILogger::class); |
759 | 759 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | /** @deprecated 19.0.0 */ |
772 | 772 | $this->registerDeprecatedAlias('Search', ISearch::class); |
773 | 773 | |
774 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
774 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
775 | 775 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
776 | 776 | $this->get(ICacheFactory::class), |
777 | 777 | new \OC\AppFramework\Utility\TimeFactory() |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
796 | 796 | |
797 | 797 | $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
798 | - $this->registerService(Connection::class, function (Server $c) { |
|
798 | + $this->registerService(Connection::class, function(Server $c) { |
|
799 | 799 | $systemConfig = $c->get(SystemConfig::class); |
800 | 800 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
801 | 801 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
814 | 814 | $this->registerAlias(IClientService::class, ClientService::class); |
815 | 815 | $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
816 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
816 | + $this->registerService(IEventLogger::class, function(ContainerInterface $c) { |
|
817 | 817 | $eventLogger = new EventLogger(); |
818 | 818 | if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
819 | 819 | // In debug mode, module is being activated by default |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | /** @deprecated 19.0.0 */ |
825 | 825 | $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
826 | 826 | |
827 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
827 | + $this->registerService(IQueryLogger::class, function(ContainerInterface $c) { |
|
828 | 828 | $queryLogger = new QueryLogger(); |
829 | 829 | if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
830 | 830 | // In debug mode, module is being activated by default |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | $this->registerDeprecatedAlias('TempManager', TempManager::class); |
840 | 840 | $this->registerAlias(ITempManager::class, TempManager::class); |
841 | 841 | |
842 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
842 | + $this->registerService(AppManager::class, function(ContainerInterface $c) { |
|
843 | 843 | // TODO: use auto-wiring |
844 | 844 | return new \OC\App\AppManager( |
845 | 845 | $c->get(IUserSession::class), |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | /** @deprecated 19.0.0 */ |
860 | 860 | $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
861 | 861 | |
862 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
862 | + $this->registerService(IDateTimeFormatter::class, function(Server $c) { |
|
863 | 863 | $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
864 | 864 | |
865 | 865 | return new DateTimeFormatter( |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | /** @deprecated 19.0.0 */ |
871 | 871 | $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
872 | 872 | |
873 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
873 | + $this->registerService(IUserMountCache::class, function(ContainerInterface $c) { |
|
874 | 874 | $mountCache = new UserMountCache( |
875 | 875 | $c->get(IDBConnection::class), |
876 | 876 | $c->get(IUserManager::class), |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | /** @deprecated 19.0.0 */ |
884 | 884 | $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
885 | 885 | |
886 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
886 | + $this->registerService(IMountProviderCollection::class, function(ContainerInterface $c) { |
|
887 | 887 | $loader = \OC\Files\Filesystem::getLoader(); |
888 | 888 | $mountCache = $c->get(IUserMountCache::class); |
889 | 889 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | |
905 | 905 | /** @deprecated 20.0.0 */ |
906 | 906 | $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
907 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
907 | + $this->registerService(IBus::class, function(ContainerInterface $c) { |
|
908 | 908 | $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
909 | 909 | if ($busClass) { |
910 | 910 | [$app, $class] = explode('::', $busClass, 2); |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
925 | 925 | /** @deprecated 19.0.0 */ |
926 | 926 | $this->registerDeprecatedAlias('Throttler', Throttler::class); |
927 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
927 | + $this->registerService('IntegrityCodeChecker', function(ContainerInterface $c) { |
|
928 | 928 | // IConfig and IAppManager requires a working database. This code |
929 | 929 | // might however be called when ownCloud is not yet setup. |
930 | 930 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | $c->get(IMimeTypeDetector::class) |
947 | 947 | ); |
948 | 948 | }); |
949 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
949 | + $this->registerService(\OCP\IRequest::class, function(ContainerInterface $c) { |
|
950 | 950 | if (isset($this['urlParams'])) { |
951 | 951 | $urlParams = $this['urlParams']; |
952 | 952 | } else { |
@@ -983,7 +983,7 @@ discard block |
||
983 | 983 | /** @deprecated 19.0.0 */ |
984 | 984 | $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
985 | 985 | |
986 | - $this->registerService(IMailer::class, function (Server $c) { |
|
986 | + $this->registerService(IMailer::class, function(Server $c) { |
|
987 | 987 | return new Mailer( |
988 | 988 | $c->get(\OCP\IConfig::class), |
989 | 989 | $c->get(ILogger::class), |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | /** @deprecated 19.0.0 */ |
998 | 998 | $this->registerDeprecatedAlias('Mailer', IMailer::class); |
999 | 999 | |
1000 | - $this->registerService('LDAPProvider', function (ContainerInterface $c) { |
|
1000 | + $this->registerService('LDAPProvider', function(ContainerInterface $c) { |
|
1001 | 1001 | $config = $c->get(\OCP\IConfig::class); |
1002 | 1002 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
1003 | 1003 | if (is_null($factoryClass)) { |
@@ -1007,7 +1007,7 @@ discard block |
||
1007 | 1007 | $factory = new $factoryClass($this); |
1008 | 1008 | return $factory->getLDAPProvider(); |
1009 | 1009 | }); |
1010 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1010 | + $this->registerService(ILockingProvider::class, function(ContainerInterface $c) { |
|
1011 | 1011 | $ini = $c->get(IniGetWrapper::class); |
1012 | 1012 | $config = $c->get(\OCP\IConfig::class); |
1013 | 1013 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -1035,12 +1035,12 @@ discard block |
||
1035 | 1035 | /** @deprecated 19.0.0 */ |
1036 | 1036 | $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
1037 | 1037 | |
1038 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1038 | + $this->registerService(IMimeTypeDetector::class, function(ContainerInterface $c) { |
|
1039 | 1039 | return new \OC\Files\Type\Detection( |
1040 | 1040 | $c->get(IURLGenerator::class), |
1041 | 1041 | $c->get(ILogger::class), |
1042 | 1042 | \OC::$configDir, |
1043 | - \OC::$SERVERROOT . '/resources/config/' |
|
1043 | + \OC::$SERVERROOT.'/resources/config/' |
|
1044 | 1044 | ); |
1045 | 1045 | }); |
1046 | 1046 | /** @deprecated 19.0.0 */ |
@@ -1049,19 +1049,19 @@ discard block |
||
1049 | 1049 | $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
1050 | 1050 | /** @deprecated 19.0.0 */ |
1051 | 1051 | $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
1052 | - $this->registerService(BundleFetcher::class, function () { |
|
1052 | + $this->registerService(BundleFetcher::class, function() { |
|
1053 | 1053 | return new BundleFetcher($this->getL10N('lib')); |
1054 | 1054 | }); |
1055 | 1055 | $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
1056 | 1056 | /** @deprecated 19.0.0 */ |
1057 | 1057 | $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
1058 | 1058 | |
1059 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1059 | + $this->registerService(CapabilitiesManager::class, function(ContainerInterface $c) { |
|
1060 | 1060 | $manager = new CapabilitiesManager($c->get(ILogger::class)); |
1061 | - $manager->registerCapability(function () use ($c) { |
|
1061 | + $manager->registerCapability(function() use ($c) { |
|
1062 | 1062 | return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
1063 | 1063 | }); |
1064 | - $manager->registerCapability(function () use ($c) { |
|
1064 | + $manager->registerCapability(function() use ($c) { |
|
1065 | 1065 | return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
1066 | 1066 | }); |
1067 | 1067 | return $manager; |
@@ -1069,14 +1069,14 @@ discard block |
||
1069 | 1069 | /** @deprecated 19.0.0 */ |
1070 | 1070 | $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
1071 | 1071 | |
1072 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1072 | + $this->registerService(ICommentsManager::class, function(Server $c) { |
|
1073 | 1073 | $config = $c->get(\OCP\IConfig::class); |
1074 | 1074 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
1075 | 1075 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
1076 | 1076 | $factory = new $factoryClass($this); |
1077 | 1077 | $manager = $factory->getManager(); |
1078 | 1078 | |
1079 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1079 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
1080 | 1080 | $manager = $c->get(IUserManager::class); |
1081 | 1081 | $user = $manager->get($id); |
1082 | 1082 | if (is_null($user)) { |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
1095 | 1095 | |
1096 | 1096 | $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
1097 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
1097 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
1098 | 1098 | /* |
1099 | 1099 | * Dark magic for autoloader. |
1100 | 1100 | * If we do a class_exists it will try to load the class which will |
@@ -1129,7 +1129,7 @@ discard block |
||
1129 | 1129 | } |
1130 | 1130 | return new \OC_Defaults(); |
1131 | 1131 | }); |
1132 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
1132 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
1133 | 1133 | return new JSCombiner( |
1134 | 1134 | $c->getAppDataDir('js'), |
1135 | 1135 | $c->get(IURLGenerator::class), |
@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
1144 | 1144 | $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
1145 | 1145 | |
1146 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1146 | + $this->registerService('CryptoWrapper', function(ContainerInterface $c) { |
|
1147 | 1147 | // FIXME: Instantiiated here due to cyclic dependency |
1148 | 1148 | $request = new Request( |
1149 | 1149 | [ |
@@ -1170,14 +1170,14 @@ discard block |
||
1170 | 1170 | }); |
1171 | 1171 | /** @deprecated 19.0.0 */ |
1172 | 1172 | $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
1173 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1173 | + $this->registerService(SessionStorage::class, function(ContainerInterface $c) { |
|
1174 | 1174 | return new SessionStorage($c->get(ISession::class)); |
1175 | 1175 | }); |
1176 | 1176 | $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
1177 | 1177 | /** @deprecated 19.0.0 */ |
1178 | 1178 | $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
1179 | 1179 | |
1180 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1180 | + $this->registerService(\OCP\Share\IManager::class, function(IServerContainer $c) { |
|
1181 | 1181 | $config = $c->get(\OCP\IConfig::class); |
1182 | 1182 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1183 | 1183 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1207,7 +1207,7 @@ discard block |
||
1207 | 1207 | /** @deprecated 19.0.0 */ |
1208 | 1208 | $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
1209 | 1209 | |
1210 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1210 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1211 | 1211 | $instance = new Collaboration\Collaborators\Search($c); |
1212 | 1212 | |
1213 | 1213 | // register default plugins |
@@ -1230,33 +1230,33 @@ discard block |
||
1230 | 1230 | |
1231 | 1231 | $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
1232 | 1232 | $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
1233 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1233 | + $this->registerService(\OC\Files\AppData\Factory::class, function(ContainerInterface $c) { |
|
1234 | 1234 | return new \OC\Files\AppData\Factory( |
1235 | 1235 | $c->get(IRootFolder::class), |
1236 | 1236 | $c->get(SystemConfig::class) |
1237 | 1237 | ); |
1238 | 1238 | }); |
1239 | 1239 | |
1240 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1241 | - return new LockdownManager(function () use ($c) { |
|
1240 | + $this->registerService('LockdownManager', function(ContainerInterface $c) { |
|
1241 | + return new LockdownManager(function() use ($c) { |
|
1242 | 1242 | return $c->get(ISession::class); |
1243 | 1243 | }); |
1244 | 1244 | }); |
1245 | 1245 | |
1246 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1246 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(ContainerInterface $c) { |
|
1247 | 1247 | return new DiscoveryService( |
1248 | 1248 | $c->get(ICacheFactory::class), |
1249 | 1249 | $c->get(IClientService::class) |
1250 | 1250 | ); |
1251 | 1251 | }); |
1252 | 1252 | |
1253 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1253 | + $this->registerService(ICloudIdManager::class, function(ContainerInterface $c) { |
|
1254 | 1254 | return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
1255 | 1255 | }); |
1256 | 1256 | |
1257 | 1257 | $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
1258 | 1258 | |
1259 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1259 | + $this->registerService(ICloudFederationProviderManager::class, function(ContainerInterface $c) { |
|
1260 | 1260 | return new CloudFederationProviderManager( |
1261 | 1261 | $c->get(IAppManager::class), |
1262 | 1262 | $c->get(IClientService::class), |
@@ -1265,7 +1265,7 @@ discard block |
||
1265 | 1265 | ); |
1266 | 1266 | }); |
1267 | 1267 | |
1268 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1268 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
1269 | 1269 | return new CloudFederationFactory(); |
1270 | 1270 | }); |
1271 | 1271 | |
@@ -1277,7 +1277,7 @@ discard block |
||
1277 | 1277 | /** @deprecated 19.0.0 */ |
1278 | 1278 | $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1279 | 1279 | |
1280 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1280 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1281 | 1281 | return new Defaults( |
1282 | 1282 | $c->getThemingDefaults() |
1283 | 1283 | ); |
@@ -1285,17 +1285,17 @@ discard block |
||
1285 | 1285 | /** @deprecated 19.0.0 */ |
1286 | 1286 | $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
1287 | 1287 | |
1288 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1288 | + $this->registerService(\OCP\ISession::class, function(ContainerInterface $c) { |
|
1289 | 1289 | return $c->get(\OCP\IUserSession::class)->getSession(); |
1290 | 1290 | }, false); |
1291 | 1291 | |
1292 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1292 | + $this->registerService(IShareHelper::class, function(ContainerInterface $c) { |
|
1293 | 1293 | return new ShareHelper( |
1294 | 1294 | $c->get(\OCP\Share\IManager::class) |
1295 | 1295 | ); |
1296 | 1296 | }); |
1297 | 1297 | |
1298 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1298 | + $this->registerService(Installer::class, function(ContainerInterface $c) { |
|
1299 | 1299 | return new Installer( |
1300 | 1300 | $c->get(AppFetcher::class), |
1301 | 1301 | $c->get(IClientService::class), |
@@ -1306,11 +1306,11 @@ discard block |
||
1306 | 1306 | ); |
1307 | 1307 | }); |
1308 | 1308 | |
1309 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1309 | + $this->registerService(IApiFactory::class, function(ContainerInterface $c) { |
|
1310 | 1310 | return new ApiFactory($c->get(IClientService::class)); |
1311 | 1311 | }); |
1312 | 1312 | |
1313 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1313 | + $this->registerService(IInstanceFactory::class, function(ContainerInterface $c) { |
|
1314 | 1314 | $memcacheFactory = $c->get(ICacheFactory::class); |
1315 | 1315 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
1316 | 1316 | }); |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | $dispatcher = $this->get(SymfonyAdapter::class); |
1368 | 1368 | |
1369 | 1369 | // Delete avatar on user deletion |
1370 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1370 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1371 | 1371 | $logger = $this->get(ILogger::class); |
1372 | 1372 | $manager = $this->getAvatarManager(); |
1373 | 1373 | /** @var IUser $user */ |
@@ -1380,11 +1380,11 @@ discard block |
||
1380 | 1380 | // no avatar to remove |
1381 | 1381 | } catch (\Exception $e) { |
1382 | 1382 | // Ignore exceptions |
1383 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1383 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1384 | 1384 | } |
1385 | 1385 | }); |
1386 | 1386 | |
1387 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1387 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1388 | 1388 | $manager = $this->getAvatarManager(); |
1389 | 1389 | /** @var IUser $user */ |
1390 | 1390 | $user = $e->getSubject(); |
@@ -2275,11 +2275,11 @@ discard block |
||
2275 | 2275 | } |
2276 | 2276 | |
2277 | 2277 | private function registerDeprecatedAlias(string $alias, string $target) { |
2278 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2278 | + $this->registerService($alias, function(ContainerInterface $container) use ($target, $alias) { |
|
2279 | 2279 | try { |
2280 | 2280 | /** @var ILogger $logger */ |
2281 | 2281 | $logger = $container->get(ILogger::class); |
2282 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2282 | + $logger->debug('The requested alias "'.$alias.'" is deprecated. Please request "'.$target.'" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2283 | 2283 | } catch (ContainerExceptionInterface $e) { |
2284 | 2284 | // Could not get logger. Continue |
2285 | 2285 | } |
@@ -49,193 +49,193 @@ |
||
49 | 49 | */ |
50 | 50 | class Dispatcher { |
51 | 51 | |
52 | - /** @var MiddlewareDispatcher */ |
|
53 | - private $middlewareDispatcher; |
|
54 | - |
|
55 | - /** @var Http */ |
|
56 | - private $protocol; |
|
57 | - |
|
58 | - /** @var ControllerMethodReflector */ |
|
59 | - private $reflector; |
|
60 | - |
|
61 | - /** @var IRequest */ |
|
62 | - private $request; |
|
63 | - |
|
64 | - /** @var IConfig */ |
|
65 | - private $config; |
|
66 | - |
|
67 | - /** @var ConnectionAdapter */ |
|
68 | - private $connection; |
|
69 | - |
|
70 | - /** @var LoggerInterface */ |
|
71 | - private $logger; |
|
72 | - |
|
73 | - /** |
|
74 | - * @param Http $protocol the http protocol with contains all status headers |
|
75 | - * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
76 | - * runs the middleware |
|
77 | - * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
78 | - * the arguments for the controller |
|
79 | - * @param IRequest $request the incoming request |
|
80 | - * @param IConfig $config |
|
81 | - * @param ConnectionAdapter $connection |
|
82 | - * @param LoggerInterface $logger |
|
83 | - */ |
|
84 | - public function __construct(Http $protocol, |
|
85 | - MiddlewareDispatcher $middlewareDispatcher, |
|
86 | - ControllerMethodReflector $reflector, |
|
87 | - IRequest $request, |
|
88 | - IConfig $config, |
|
89 | - ConnectionAdapter $connection, |
|
90 | - LoggerInterface $logger) { |
|
91 | - $this->protocol = $protocol; |
|
92 | - $this->middlewareDispatcher = $middlewareDispatcher; |
|
93 | - $this->reflector = $reflector; |
|
94 | - $this->request = $request; |
|
95 | - $this->config = $config; |
|
96 | - $this->connection = $connection; |
|
97 | - $this->logger = $logger; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Handles a request and calls the dispatcher on the controller |
|
103 | - * @param Controller $controller the controller which will be called |
|
104 | - * @param string $methodName the method name which will be called on |
|
105 | - * the controller |
|
106 | - * @return array $array[0] contains a string with the http main header, |
|
107 | - * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
108 | - * the response output |
|
109 | - * @throws \Exception |
|
110 | - */ |
|
111 | - public function dispatch(Controller $controller, string $methodName): array { |
|
112 | - $out = [null, [], null]; |
|
113 | - |
|
114 | - try { |
|
115 | - // prefill reflector with everything thats needed for the |
|
116 | - // middlewares |
|
117 | - $this->reflector->reflect($controller, $methodName); |
|
118 | - |
|
119 | - $this->middlewareDispatcher->beforeController($controller, |
|
120 | - $methodName); |
|
121 | - |
|
122 | - $databaseStatsBefore = []; |
|
123 | - if ($this->config->getSystemValueBool('debug', false)) { |
|
124 | - $databaseStatsBefore = $this->connection->getInner()->getStats(); |
|
125 | - } |
|
126 | - |
|
127 | - $response = $this->executeController($controller, $methodName); |
|
128 | - |
|
129 | - if (!empty($databaseStatsBefore)) { |
|
130 | - $databaseStatsAfter = $this->connection->getInner()->getStats(); |
|
131 | - $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built']; |
|
132 | - $numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed']; |
|
133 | - |
|
134 | - if ($numBuilt > 50) { |
|
135 | - $this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.' , [ |
|
136 | - 'class' => (string) get_class($controller), |
|
137 | - 'method' => $methodName, |
|
138 | - 'count' => $numBuilt, |
|
139 | - ]); |
|
140 | - } |
|
141 | - |
|
142 | - if ($numExecuted > 100) { |
|
143 | - $this->logger->warning('Controller {class}::{method} executed {count} queries.' , [ |
|
144 | - 'class' => (string) get_class($controller), |
|
145 | - 'method' => $methodName, |
|
146 | - 'count' => $numExecuted, |
|
147 | - ]); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - // if an exception appears, the middleware checks if it can handle the |
|
152 | - // exception and creates a response. If no response is created, it is |
|
153 | - // assumed that theres no middleware who can handle it and the error is |
|
154 | - // thrown again |
|
155 | - } catch (\Exception $exception) { |
|
156 | - $response = $this->middlewareDispatcher->afterException( |
|
157 | - $controller, $methodName, $exception); |
|
158 | - } catch (\Throwable $throwable) { |
|
159 | - $exception = new \Exception($throwable->getMessage(), $throwable->getCode(), $throwable); |
|
160 | - $response = $this->middlewareDispatcher->afterException( |
|
161 | - $controller, $methodName, $exception); |
|
162 | - } |
|
163 | - |
|
164 | - $response = $this->middlewareDispatcher->afterController( |
|
165 | - $controller, $methodName, $response); |
|
166 | - |
|
167 | - // depending on the cache object the headers need to be changed |
|
168 | - $out[0] = $this->protocol->getStatusHeader($response->getStatus()); |
|
169 | - $out[1] = array_merge($response->getHeaders()); |
|
170 | - $out[2] = $response->getCookies(); |
|
171 | - $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
172 | - $controller, $methodName, $response->render() |
|
173 | - ); |
|
174 | - $out[4] = $response; |
|
175 | - |
|
176 | - return $out; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Uses the reflected parameters, types and request parameters to execute |
|
182 | - * the controller |
|
183 | - * @param Controller $controller the controller to be executed |
|
184 | - * @param string $methodName the method on the controller that should be executed |
|
185 | - * @return Response |
|
186 | - */ |
|
187 | - private function executeController(Controller $controller, string $methodName): Response { |
|
188 | - $arguments = []; |
|
189 | - |
|
190 | - // valid types that will be casted |
|
191 | - $types = ['int', 'integer', 'bool', 'boolean', 'float']; |
|
192 | - |
|
193 | - foreach ($this->reflector->getParameters() as $param => $default) { |
|
194 | - |
|
195 | - // try to get the parameter from the request object and cast |
|
196 | - // it to the type annotated in the @param annotation |
|
197 | - $value = $this->request->getParam($param, $default); |
|
198 | - $type = $this->reflector->getType($param); |
|
199 | - |
|
200 | - // if this is submitted using GET or a POST form, 'false' should be |
|
201 | - // converted to false |
|
202 | - if (($type === 'bool' || $type === 'boolean') && |
|
203 | - $value === 'false' && |
|
204 | - ( |
|
205 | - $this->request->method === 'GET' || |
|
206 | - strpos($this->request->getHeader('Content-Type'), |
|
207 | - 'application/x-www-form-urlencoded') !== false |
|
208 | - ) |
|
209 | - ) { |
|
210 | - $value = false; |
|
211 | - } elseif ($value !== null && \in_array($type, $types, true)) { |
|
212 | - settype($value, $type); |
|
213 | - } |
|
214 | - |
|
215 | - $arguments[] = $value; |
|
216 | - } |
|
217 | - |
|
218 | - $response = \call_user_func_array([$controller, $methodName], $arguments); |
|
219 | - |
|
220 | - // format response |
|
221 | - if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
222 | - |
|
223 | - // get format from the url format or request format parameter |
|
224 | - $format = $this->request->getParam('format'); |
|
225 | - |
|
226 | - // if none is given try the first Accept header |
|
227 | - if ($format === null) { |
|
228 | - $headers = $this->request->getHeader('Accept'); |
|
229 | - $format = $controller->getResponderByHTTPHeader($headers, null); |
|
230 | - } |
|
231 | - |
|
232 | - if ($format !== null) { |
|
233 | - $response = $controller->buildResponse($response, $format); |
|
234 | - } else { |
|
235 | - $response = $controller->buildResponse($response); |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - return $response; |
|
240 | - } |
|
52 | + /** @var MiddlewareDispatcher */ |
|
53 | + private $middlewareDispatcher; |
|
54 | + |
|
55 | + /** @var Http */ |
|
56 | + private $protocol; |
|
57 | + |
|
58 | + /** @var ControllerMethodReflector */ |
|
59 | + private $reflector; |
|
60 | + |
|
61 | + /** @var IRequest */ |
|
62 | + private $request; |
|
63 | + |
|
64 | + /** @var IConfig */ |
|
65 | + private $config; |
|
66 | + |
|
67 | + /** @var ConnectionAdapter */ |
|
68 | + private $connection; |
|
69 | + |
|
70 | + /** @var LoggerInterface */ |
|
71 | + private $logger; |
|
72 | + |
|
73 | + /** |
|
74 | + * @param Http $protocol the http protocol with contains all status headers |
|
75 | + * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
76 | + * runs the middleware |
|
77 | + * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
78 | + * the arguments for the controller |
|
79 | + * @param IRequest $request the incoming request |
|
80 | + * @param IConfig $config |
|
81 | + * @param ConnectionAdapter $connection |
|
82 | + * @param LoggerInterface $logger |
|
83 | + */ |
|
84 | + public function __construct(Http $protocol, |
|
85 | + MiddlewareDispatcher $middlewareDispatcher, |
|
86 | + ControllerMethodReflector $reflector, |
|
87 | + IRequest $request, |
|
88 | + IConfig $config, |
|
89 | + ConnectionAdapter $connection, |
|
90 | + LoggerInterface $logger) { |
|
91 | + $this->protocol = $protocol; |
|
92 | + $this->middlewareDispatcher = $middlewareDispatcher; |
|
93 | + $this->reflector = $reflector; |
|
94 | + $this->request = $request; |
|
95 | + $this->config = $config; |
|
96 | + $this->connection = $connection; |
|
97 | + $this->logger = $logger; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Handles a request and calls the dispatcher on the controller |
|
103 | + * @param Controller $controller the controller which will be called |
|
104 | + * @param string $methodName the method name which will be called on |
|
105 | + * the controller |
|
106 | + * @return array $array[0] contains a string with the http main header, |
|
107 | + * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
108 | + * the response output |
|
109 | + * @throws \Exception |
|
110 | + */ |
|
111 | + public function dispatch(Controller $controller, string $methodName): array { |
|
112 | + $out = [null, [], null]; |
|
113 | + |
|
114 | + try { |
|
115 | + // prefill reflector with everything thats needed for the |
|
116 | + // middlewares |
|
117 | + $this->reflector->reflect($controller, $methodName); |
|
118 | + |
|
119 | + $this->middlewareDispatcher->beforeController($controller, |
|
120 | + $methodName); |
|
121 | + |
|
122 | + $databaseStatsBefore = []; |
|
123 | + if ($this->config->getSystemValueBool('debug', false)) { |
|
124 | + $databaseStatsBefore = $this->connection->getInner()->getStats(); |
|
125 | + } |
|
126 | + |
|
127 | + $response = $this->executeController($controller, $methodName); |
|
128 | + |
|
129 | + if (!empty($databaseStatsBefore)) { |
|
130 | + $databaseStatsAfter = $this->connection->getInner()->getStats(); |
|
131 | + $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built']; |
|
132 | + $numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed']; |
|
133 | + |
|
134 | + if ($numBuilt > 50) { |
|
135 | + $this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.' , [ |
|
136 | + 'class' => (string) get_class($controller), |
|
137 | + 'method' => $methodName, |
|
138 | + 'count' => $numBuilt, |
|
139 | + ]); |
|
140 | + } |
|
141 | + |
|
142 | + if ($numExecuted > 100) { |
|
143 | + $this->logger->warning('Controller {class}::{method} executed {count} queries.' , [ |
|
144 | + 'class' => (string) get_class($controller), |
|
145 | + 'method' => $methodName, |
|
146 | + 'count' => $numExecuted, |
|
147 | + ]); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + // if an exception appears, the middleware checks if it can handle the |
|
152 | + // exception and creates a response. If no response is created, it is |
|
153 | + // assumed that theres no middleware who can handle it and the error is |
|
154 | + // thrown again |
|
155 | + } catch (\Exception $exception) { |
|
156 | + $response = $this->middlewareDispatcher->afterException( |
|
157 | + $controller, $methodName, $exception); |
|
158 | + } catch (\Throwable $throwable) { |
|
159 | + $exception = new \Exception($throwable->getMessage(), $throwable->getCode(), $throwable); |
|
160 | + $response = $this->middlewareDispatcher->afterException( |
|
161 | + $controller, $methodName, $exception); |
|
162 | + } |
|
163 | + |
|
164 | + $response = $this->middlewareDispatcher->afterController( |
|
165 | + $controller, $methodName, $response); |
|
166 | + |
|
167 | + // depending on the cache object the headers need to be changed |
|
168 | + $out[0] = $this->protocol->getStatusHeader($response->getStatus()); |
|
169 | + $out[1] = array_merge($response->getHeaders()); |
|
170 | + $out[2] = $response->getCookies(); |
|
171 | + $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
172 | + $controller, $methodName, $response->render() |
|
173 | + ); |
|
174 | + $out[4] = $response; |
|
175 | + |
|
176 | + return $out; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Uses the reflected parameters, types and request parameters to execute |
|
182 | + * the controller |
|
183 | + * @param Controller $controller the controller to be executed |
|
184 | + * @param string $methodName the method on the controller that should be executed |
|
185 | + * @return Response |
|
186 | + */ |
|
187 | + private function executeController(Controller $controller, string $methodName): Response { |
|
188 | + $arguments = []; |
|
189 | + |
|
190 | + // valid types that will be casted |
|
191 | + $types = ['int', 'integer', 'bool', 'boolean', 'float']; |
|
192 | + |
|
193 | + foreach ($this->reflector->getParameters() as $param => $default) { |
|
194 | + |
|
195 | + // try to get the parameter from the request object and cast |
|
196 | + // it to the type annotated in the @param annotation |
|
197 | + $value = $this->request->getParam($param, $default); |
|
198 | + $type = $this->reflector->getType($param); |
|
199 | + |
|
200 | + // if this is submitted using GET or a POST form, 'false' should be |
|
201 | + // converted to false |
|
202 | + if (($type === 'bool' || $type === 'boolean') && |
|
203 | + $value === 'false' && |
|
204 | + ( |
|
205 | + $this->request->method === 'GET' || |
|
206 | + strpos($this->request->getHeader('Content-Type'), |
|
207 | + 'application/x-www-form-urlencoded') !== false |
|
208 | + ) |
|
209 | + ) { |
|
210 | + $value = false; |
|
211 | + } elseif ($value !== null && \in_array($type, $types, true)) { |
|
212 | + settype($value, $type); |
|
213 | + } |
|
214 | + |
|
215 | + $arguments[] = $value; |
|
216 | + } |
|
217 | + |
|
218 | + $response = \call_user_func_array([$controller, $methodName], $arguments); |
|
219 | + |
|
220 | + // format response |
|
221 | + if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
222 | + |
|
223 | + // get format from the url format or request format parameter |
|
224 | + $format = $this->request->getParam('format'); |
|
225 | + |
|
226 | + // if none is given try the first Accept header |
|
227 | + if ($format === null) { |
|
228 | + $headers = $this->request->getHeader('Accept'); |
|
229 | + $format = $controller->getResponderByHTTPHeader($headers, null); |
|
230 | + } |
|
231 | + |
|
232 | + if ($format !== null) { |
|
233 | + $response = $controller->buildResponse($response, $format); |
|
234 | + } else { |
|
235 | + $response = $controller->buildResponse($response); |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + return $response; |
|
240 | + } |
|
241 | 241 | } |
@@ -37,136 +37,136 @@ |
||
37 | 37 | */ |
38 | 38 | class ConnectionAdapter implements IDBConnection { |
39 | 39 | |
40 | - /** @var Connection */ |
|
41 | - private $inner; |
|
42 | - |
|
43 | - public function __construct(Connection $inner) { |
|
44 | - $this->inner = $inner; |
|
45 | - } |
|
46 | - |
|
47 | - public function getQueryBuilder(): IQueryBuilder { |
|
48 | - return $this->inner->getQueryBuilder(); |
|
49 | - } |
|
50 | - |
|
51 | - public function prepare($sql, $limit = null, $offset = null): IPreparedStatement { |
|
52 | - return new PreparedStatement( |
|
53 | - $this->inner->prepare($sql, $limit, $offset) |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - public function executeQuery(string $sql, array $params = [], $types = []): IResult { |
|
58 | - return new ResultAdapter( |
|
59 | - $this->inner->executeQuery($sql, $params, $types) |
|
60 | - ); |
|
61 | - } |
|
62 | - |
|
63 | - public function executeUpdate(string $sql, array $params = [], array $types = []): int { |
|
64 | - return $this->inner->executeUpdate($sql, $params, $types); |
|
65 | - } |
|
66 | - |
|
67 | - public function executeStatement($sql, array $params = [], array $types = []): int { |
|
68 | - return $this->inner->executeStatement($sql, $params, $types); |
|
69 | - } |
|
70 | - |
|
71 | - public function lastInsertId(string $table): int { |
|
72 | - return (int) $this->inner->lastInsertId($table); |
|
73 | - } |
|
74 | - |
|
75 | - public function insertIfNotExist(string $table, array $input, array $compare = null) { |
|
76 | - return $this->inner->insertIfNotExist($table, $input, $compare); |
|
77 | - } |
|
78 | - |
|
79 | - public function insertIgnoreConflict(string $table, array $values): int { |
|
80 | - return $this->inner->insertIgnoreConflict($table, $values); |
|
81 | - } |
|
82 | - |
|
83 | - public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []): int { |
|
84 | - return $this->inner->setValues($table, $keys, $values, $updatePreconditionValues); |
|
85 | - } |
|
86 | - |
|
87 | - public function lockTable($tableName): void { |
|
88 | - $this->inner->lockTable($tableName); |
|
89 | - } |
|
90 | - |
|
91 | - public function unlockTable(): void { |
|
92 | - $this->inner->unlockTable(); |
|
93 | - } |
|
94 | - |
|
95 | - public function beginTransaction(): void { |
|
96 | - $this->inner->beginTransaction(); |
|
97 | - } |
|
98 | - |
|
99 | - public function inTransaction(): bool { |
|
100 | - return $this->inner->inTransaction(); |
|
101 | - } |
|
102 | - |
|
103 | - public function commit(): void { |
|
104 | - $this->inner->commit(); |
|
105 | - } |
|
106 | - |
|
107 | - public function rollBack(): void { |
|
108 | - $this->inner->rollBack(); |
|
109 | - } |
|
110 | - |
|
111 | - public function getError(): string { |
|
112 | - return $this->inner->getError(); |
|
113 | - } |
|
114 | - |
|
115 | - public function errorCode() { |
|
116 | - return $this->inner->errorCode(); |
|
117 | - } |
|
118 | - |
|
119 | - public function errorInfo() { |
|
120 | - return $this->inner->errorInfo(); |
|
121 | - } |
|
122 | - |
|
123 | - public function connect(): bool { |
|
124 | - return $this->inner->connect(); |
|
125 | - } |
|
126 | - |
|
127 | - public function close(): void { |
|
128 | - $this->inner->close(); |
|
129 | - } |
|
130 | - |
|
131 | - public function quote($input, $type = IQueryBuilder::PARAM_STR) { |
|
132 | - return $this->inner->quote($input, $type); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * @todo we are leaking a 3rdparty type here |
|
137 | - */ |
|
138 | - public function getDatabasePlatform(): AbstractPlatform { |
|
139 | - return $this->inner->getDatabasePlatform(); |
|
140 | - } |
|
141 | - |
|
142 | - public function dropTable(string $table): void { |
|
143 | - $this->inner->dropTable($table); |
|
144 | - } |
|
145 | - |
|
146 | - public function tableExists(string $table): bool { |
|
147 | - return $this->inner->tableExists($table); |
|
148 | - } |
|
149 | - |
|
150 | - public function escapeLikeParameter(string $param): string { |
|
151 | - return $this->inner->escapeLikeParameter($param); |
|
152 | - } |
|
153 | - |
|
154 | - public function supports4ByteText(): bool { |
|
155 | - return $this->inner->supports4ByteText(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @todo leaks a 3rdparty type |
|
160 | - */ |
|
161 | - public function createSchema(): Schema { |
|
162 | - return $this->inner->createSchema(); |
|
163 | - } |
|
164 | - |
|
165 | - public function migrateToSchema(Schema $toSchema): void { |
|
166 | - $this->inner->migrateToSchema($toSchema); |
|
167 | - } |
|
168 | - |
|
169 | - public function getInner(): Connection { |
|
170 | - return $this->inner; |
|
171 | - } |
|
40 | + /** @var Connection */ |
|
41 | + private $inner; |
|
42 | + |
|
43 | + public function __construct(Connection $inner) { |
|
44 | + $this->inner = $inner; |
|
45 | + } |
|
46 | + |
|
47 | + public function getQueryBuilder(): IQueryBuilder { |
|
48 | + return $this->inner->getQueryBuilder(); |
|
49 | + } |
|
50 | + |
|
51 | + public function prepare($sql, $limit = null, $offset = null): IPreparedStatement { |
|
52 | + return new PreparedStatement( |
|
53 | + $this->inner->prepare($sql, $limit, $offset) |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + public function executeQuery(string $sql, array $params = [], $types = []): IResult { |
|
58 | + return new ResultAdapter( |
|
59 | + $this->inner->executeQuery($sql, $params, $types) |
|
60 | + ); |
|
61 | + } |
|
62 | + |
|
63 | + public function executeUpdate(string $sql, array $params = [], array $types = []): int { |
|
64 | + return $this->inner->executeUpdate($sql, $params, $types); |
|
65 | + } |
|
66 | + |
|
67 | + public function executeStatement($sql, array $params = [], array $types = []): int { |
|
68 | + return $this->inner->executeStatement($sql, $params, $types); |
|
69 | + } |
|
70 | + |
|
71 | + public function lastInsertId(string $table): int { |
|
72 | + return (int) $this->inner->lastInsertId($table); |
|
73 | + } |
|
74 | + |
|
75 | + public function insertIfNotExist(string $table, array $input, array $compare = null) { |
|
76 | + return $this->inner->insertIfNotExist($table, $input, $compare); |
|
77 | + } |
|
78 | + |
|
79 | + public function insertIgnoreConflict(string $table, array $values): int { |
|
80 | + return $this->inner->insertIgnoreConflict($table, $values); |
|
81 | + } |
|
82 | + |
|
83 | + public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []): int { |
|
84 | + return $this->inner->setValues($table, $keys, $values, $updatePreconditionValues); |
|
85 | + } |
|
86 | + |
|
87 | + public function lockTable($tableName): void { |
|
88 | + $this->inner->lockTable($tableName); |
|
89 | + } |
|
90 | + |
|
91 | + public function unlockTable(): void { |
|
92 | + $this->inner->unlockTable(); |
|
93 | + } |
|
94 | + |
|
95 | + public function beginTransaction(): void { |
|
96 | + $this->inner->beginTransaction(); |
|
97 | + } |
|
98 | + |
|
99 | + public function inTransaction(): bool { |
|
100 | + return $this->inner->inTransaction(); |
|
101 | + } |
|
102 | + |
|
103 | + public function commit(): void { |
|
104 | + $this->inner->commit(); |
|
105 | + } |
|
106 | + |
|
107 | + public function rollBack(): void { |
|
108 | + $this->inner->rollBack(); |
|
109 | + } |
|
110 | + |
|
111 | + public function getError(): string { |
|
112 | + return $this->inner->getError(); |
|
113 | + } |
|
114 | + |
|
115 | + public function errorCode() { |
|
116 | + return $this->inner->errorCode(); |
|
117 | + } |
|
118 | + |
|
119 | + public function errorInfo() { |
|
120 | + return $this->inner->errorInfo(); |
|
121 | + } |
|
122 | + |
|
123 | + public function connect(): bool { |
|
124 | + return $this->inner->connect(); |
|
125 | + } |
|
126 | + |
|
127 | + public function close(): void { |
|
128 | + $this->inner->close(); |
|
129 | + } |
|
130 | + |
|
131 | + public function quote($input, $type = IQueryBuilder::PARAM_STR) { |
|
132 | + return $this->inner->quote($input, $type); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * @todo we are leaking a 3rdparty type here |
|
137 | + */ |
|
138 | + public function getDatabasePlatform(): AbstractPlatform { |
|
139 | + return $this->inner->getDatabasePlatform(); |
|
140 | + } |
|
141 | + |
|
142 | + public function dropTable(string $table): void { |
|
143 | + $this->inner->dropTable($table); |
|
144 | + } |
|
145 | + |
|
146 | + public function tableExists(string $table): bool { |
|
147 | + return $this->inner->tableExists($table); |
|
148 | + } |
|
149 | + |
|
150 | + public function escapeLikeParameter(string $param): string { |
|
151 | + return $this->inner->escapeLikeParameter($param); |
|
152 | + } |
|
153 | + |
|
154 | + public function supports4ByteText(): bool { |
|
155 | + return $this->inner->supports4ByteText(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @todo leaks a 3rdparty type |
|
160 | + */ |
|
161 | + public function createSchema(): Schema { |
|
162 | + return $this->inner->createSchema(); |
|
163 | + } |
|
164 | + |
|
165 | + public function migrateToSchema(Schema $toSchema): void { |
|
166 | + $this->inner->migrateToSchema($toSchema); |
|
167 | + } |
|
168 | + |
|
169 | + public function getInner(): Connection { |
|
170 | + return $this->inner; |
|
171 | + } |
|
172 | 172 | } |
@@ -56,1218 +56,1218 @@ |
||
56 | 56 | |
57 | 57 | class QueryBuilder implements IQueryBuilder { |
58 | 58 | |
59 | - /** @var ConnectionAdapter */ |
|
60 | - private $connection; |
|
61 | - |
|
62 | - /** @var SystemConfig */ |
|
63 | - private $systemConfig; |
|
64 | - |
|
65 | - /** @var ILogger */ |
|
66 | - private $logger; |
|
67 | - |
|
68 | - /** @var \Doctrine\DBAL\Query\QueryBuilder */ |
|
69 | - private $queryBuilder; |
|
70 | - |
|
71 | - /** @var QuoteHelper */ |
|
72 | - private $helper; |
|
73 | - |
|
74 | - /** @var bool */ |
|
75 | - private $automaticTablePrefix = true; |
|
76 | - |
|
77 | - /** @var string */ |
|
78 | - protected $lastInsertedTable; |
|
79 | - |
|
80 | - /** |
|
81 | - * Initializes a new QueryBuilder. |
|
82 | - * |
|
83 | - * @param ConnectionAdapter $connection |
|
84 | - * @param SystemConfig $systemConfig |
|
85 | - * @param ILogger $logger |
|
86 | - */ |
|
87 | - public function __construct(ConnectionAdapter $connection, SystemConfig $systemConfig, ILogger $logger) { |
|
88 | - $this->connection = $connection; |
|
89 | - $this->systemConfig = $systemConfig; |
|
90 | - $this->logger = $logger; |
|
91 | - $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection->getInner()); |
|
92 | - $this->helper = new QuoteHelper(); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Enable/disable automatic prefixing of table names with the oc_ prefix |
|
97 | - * |
|
98 | - * @param bool $enabled If set to true table names will be prefixed with the |
|
99 | - * owncloud database prefix automatically. |
|
100 | - * @since 8.2.0 |
|
101 | - */ |
|
102 | - public function automaticTablePrefix($enabled) { |
|
103 | - $this->automaticTablePrefix = (bool) $enabled; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Gets an ExpressionBuilder used for object-oriented construction of query expressions. |
|
108 | - * This producer method is intended for convenient inline usage. Example: |
|
109 | - * |
|
110 | - * <code> |
|
111 | - * $qb = $conn->getQueryBuilder() |
|
112 | - * ->select('u') |
|
113 | - * ->from('users', 'u') |
|
114 | - * ->where($qb->expr()->eq('u.id', 1)); |
|
115 | - * </code> |
|
116 | - * |
|
117 | - * For more complex expression construction, consider storing the expression |
|
118 | - * builder object in a local variable. |
|
119 | - * |
|
120 | - * @return \OCP\DB\QueryBuilder\IExpressionBuilder |
|
121 | - */ |
|
122 | - public function expr() { |
|
123 | - if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { |
|
124 | - return new OCIExpressionBuilder($this->connection, $this); |
|
125 | - } |
|
126 | - if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
127 | - return new PgSqlExpressionBuilder($this->connection, $this); |
|
128 | - } |
|
129 | - if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) { |
|
130 | - return new MySqlExpressionBuilder($this->connection, $this); |
|
131 | - } |
|
132 | - if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
133 | - return new SqliteExpressionBuilder($this->connection, $this); |
|
134 | - } |
|
135 | - |
|
136 | - return new ExpressionBuilder($this->connection, $this); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Gets an FunctionBuilder used for object-oriented construction of query functions. |
|
141 | - * This producer method is intended for convenient inline usage. Example: |
|
142 | - * |
|
143 | - * <code> |
|
144 | - * $qb = $conn->getQueryBuilder() |
|
145 | - * ->select('u') |
|
146 | - * ->from('users', 'u') |
|
147 | - * ->where($qb->fun()->md5('u.id')); |
|
148 | - * </code> |
|
149 | - * |
|
150 | - * For more complex function construction, consider storing the function |
|
151 | - * builder object in a local variable. |
|
152 | - * |
|
153 | - * @return \OCP\DB\QueryBuilder\IFunctionBuilder |
|
154 | - */ |
|
155 | - public function func() { |
|
156 | - if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { |
|
157 | - return new OCIFunctionBuilder($this->helper); |
|
158 | - } |
|
159 | - if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
160 | - return new SqliteFunctionBuilder($this->helper); |
|
161 | - } |
|
162 | - if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
163 | - return new PgSqlFunctionBuilder($this->helper); |
|
164 | - } |
|
165 | - |
|
166 | - return new FunctionBuilder($this->helper); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Gets the type of the currently built query. |
|
171 | - * |
|
172 | - * @return integer |
|
173 | - */ |
|
174 | - public function getType() { |
|
175 | - return $this->queryBuilder->getType(); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Gets the associated DBAL Connection for this query builder. |
|
180 | - * |
|
181 | - * @return \OCP\IDBConnection |
|
182 | - */ |
|
183 | - public function getConnection() { |
|
184 | - return $this->connection; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Gets the state of this query builder instance. |
|
189 | - * |
|
190 | - * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN. |
|
191 | - */ |
|
192 | - public function getState() { |
|
193 | - return $this->queryBuilder->getState(); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Executes this query using the bound parameters and their types. |
|
198 | - * |
|
199 | - * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate} |
|
200 | - * for insert, update and delete statements. |
|
201 | - * |
|
202 | - * @return IResult|int |
|
203 | - */ |
|
204 | - public function execute() { |
|
205 | - if ($this->systemConfig->getValue('log_query', false)) { |
|
206 | - try { |
|
207 | - $params = []; |
|
208 | - foreach ($this->getParameters() as $placeholder => $value) { |
|
209 | - if ($value instanceof \DateTime) { |
|
210 | - $params[] = $placeholder . ' => DateTime:\'' . $value->format('c') . '\''; |
|
211 | - } elseif (is_array($value)) { |
|
212 | - $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; |
|
213 | - } else { |
|
214 | - $params[] = $placeholder . ' => \'' . $value . '\''; |
|
215 | - } |
|
216 | - } |
|
217 | - if (empty($params)) { |
|
218 | - $this->logger->debug('DB QueryBuilder: \'{query}\'', [ |
|
219 | - 'query' => $this->getSQL(), |
|
220 | - 'app' => 'core', |
|
221 | - ]); |
|
222 | - } else { |
|
223 | - $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ |
|
224 | - 'query' => $this->getSQL(), |
|
225 | - 'params' => implode(', ', $params), |
|
226 | - 'app' => 'core', |
|
227 | - ]); |
|
228 | - } |
|
229 | - } catch (\Error $e) { |
|
230 | - // likely an error during conversion of $value to string |
|
231 | - $this->logger->debug('DB QueryBuilder: error trying to log SQL query'); |
|
232 | - $this->logger->logException($e); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - if (!empty($this->getQueryPart('select'))) { |
|
237 | - $select = $this->getQueryPart('select'); |
|
238 | - $hasSelectAll = array_filter($select, static function ($s) { |
|
239 | - return $s === '*'; |
|
240 | - }); |
|
241 | - $hasSelectSpecific = array_filter($select, static function ($s) { |
|
242 | - return $s !== '*'; |
|
243 | - }); |
|
244 | - |
|
245 | - if (empty($hasSelectAll) === empty($hasSelectSpecific)) { |
|
246 | - $exception = new QueryException('Query is selecting * and specific values in the same query. This is not supported in Oracle.'); |
|
247 | - $this->logger->logException($exception, [ |
|
248 | - 'message' => 'Query is selecting * and specific values in the same query. This is not supported in Oracle.', |
|
249 | - 'query' => $this->getSQL(), |
|
250 | - 'level' => ILogger::ERROR, |
|
251 | - 'app' => 'core', |
|
252 | - ]); |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - $result = $this->queryBuilder->execute(); |
|
257 | - if (is_int($result)) { |
|
258 | - return $result; |
|
259 | - } |
|
260 | - return new ResultAdapter($result); |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Gets the complete SQL string formed by the current specifications of this QueryBuilder. |
|
265 | - * |
|
266 | - * <code> |
|
267 | - * $qb = $conn->getQueryBuilder() |
|
268 | - * ->select('u') |
|
269 | - * ->from('User', 'u') |
|
270 | - * echo $qb->getSQL(); // SELECT u FROM User u |
|
271 | - * </code> |
|
272 | - * |
|
273 | - * @return string The SQL query string. |
|
274 | - */ |
|
275 | - public function getSQL() { |
|
276 | - return $this->queryBuilder->getSQL(); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Sets a query parameter for the query being constructed. |
|
281 | - * |
|
282 | - * <code> |
|
283 | - * $qb = $conn->getQueryBuilder() |
|
284 | - * ->select('u') |
|
285 | - * ->from('users', 'u') |
|
286 | - * ->where('u.id = :user_id') |
|
287 | - * ->setParameter(':user_id', 1); |
|
288 | - * </code> |
|
289 | - * |
|
290 | - * @param string|integer $key The parameter position or name. |
|
291 | - * @param mixed $value The parameter value. |
|
292 | - * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants. |
|
293 | - * |
|
294 | - * @return $this This QueryBuilder instance. |
|
295 | - */ |
|
296 | - public function setParameter($key, $value, $type = null) { |
|
297 | - $this->queryBuilder->setParameter($key, $value, $type); |
|
298 | - |
|
299 | - return $this; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Sets a collection of query parameters for the query being constructed. |
|
304 | - * |
|
305 | - * <code> |
|
306 | - * $qb = $conn->getQueryBuilder() |
|
307 | - * ->select('u') |
|
308 | - * ->from('users', 'u') |
|
309 | - * ->where('u.id = :user_id1 OR u.id = :user_id2') |
|
310 | - * ->setParameters(array( |
|
311 | - * ':user_id1' => 1, |
|
312 | - * ':user_id2' => 2 |
|
313 | - * )); |
|
314 | - * </code> |
|
315 | - * |
|
316 | - * @param array $params The query parameters to set. |
|
317 | - * @param array $types The query parameters types to set. |
|
318 | - * |
|
319 | - * @return $this This QueryBuilder instance. |
|
320 | - */ |
|
321 | - public function setParameters(array $params, array $types = []) { |
|
322 | - $this->queryBuilder->setParameters($params, $types); |
|
323 | - |
|
324 | - return $this; |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Gets all defined query parameters for the query being constructed indexed by parameter index or name. |
|
329 | - * |
|
330 | - * @return array The currently defined query parameters indexed by parameter index or name. |
|
331 | - */ |
|
332 | - public function getParameters() { |
|
333 | - return $this->queryBuilder->getParameters(); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Gets a (previously set) query parameter of the query being constructed. |
|
338 | - * |
|
339 | - * @param mixed $key The key (index or name) of the bound parameter. |
|
340 | - * |
|
341 | - * @return mixed The value of the bound parameter. |
|
342 | - */ |
|
343 | - public function getParameter($key) { |
|
344 | - return $this->queryBuilder->getParameter($key); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Gets all defined query parameter types for the query being constructed indexed by parameter index or name. |
|
349 | - * |
|
350 | - * @return array The currently defined query parameter types indexed by parameter index or name. |
|
351 | - */ |
|
352 | - public function getParameterTypes() { |
|
353 | - return $this->queryBuilder->getParameterTypes(); |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Gets a (previously set) query parameter type of the query being constructed. |
|
358 | - * |
|
359 | - * @param mixed $key The key (index or name) of the bound parameter type. |
|
360 | - * |
|
361 | - * @return mixed The value of the bound parameter type. |
|
362 | - */ |
|
363 | - public function getParameterType($key) { |
|
364 | - return $this->queryBuilder->getParameterType($key); |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Sets the position of the first result to retrieve (the "offset"). |
|
369 | - * |
|
370 | - * @param integer $firstResult The first result to return. |
|
371 | - * |
|
372 | - * @return $this This QueryBuilder instance. |
|
373 | - */ |
|
374 | - public function setFirstResult($firstResult) { |
|
375 | - $this->queryBuilder->setFirstResult($firstResult); |
|
376 | - |
|
377 | - return $this; |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Gets the position of the first result the query object was set to retrieve (the "offset"). |
|
382 | - * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder. |
|
383 | - * |
|
384 | - * @return integer The position of the first result. |
|
385 | - */ |
|
386 | - public function getFirstResult() { |
|
387 | - return $this->queryBuilder->getFirstResult(); |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Sets the maximum number of results to retrieve (the "limit"). |
|
392 | - * |
|
393 | - * NOTE: Setting max results to "0" will cause mixed behaviour. While most |
|
394 | - * of the databases will just return an empty result set, Oracle will return |
|
395 | - * all entries. |
|
396 | - * |
|
397 | - * @param integer $maxResults The maximum number of results to retrieve. |
|
398 | - * |
|
399 | - * @return $this This QueryBuilder instance. |
|
400 | - */ |
|
401 | - public function setMaxResults($maxResults) { |
|
402 | - $this->queryBuilder->setMaxResults($maxResults); |
|
403 | - |
|
404 | - return $this; |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Gets the maximum number of results the query object was set to retrieve (the "limit"). |
|
409 | - * Returns NULL if {@link setMaxResults} was not applied to this query builder. |
|
410 | - * |
|
411 | - * @return int|null The maximum number of results. |
|
412 | - */ |
|
413 | - public function getMaxResults() { |
|
414 | - return $this->queryBuilder->getMaxResults(); |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * Specifies an item that is to be returned in the query result. |
|
419 | - * Replaces any previously specified selections, if any. |
|
420 | - * |
|
421 | - * <code> |
|
422 | - * $qb = $conn->getQueryBuilder() |
|
423 | - * ->select('u.id', 'p.id') |
|
424 | - * ->from('users', 'u') |
|
425 | - * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
426 | - * </code> |
|
427 | - * |
|
428 | - * @param mixed ...$selects The selection expressions. |
|
429 | - * |
|
430 | - * '@return $this This QueryBuilder instance. |
|
431 | - */ |
|
432 | - public function select(...$selects) { |
|
433 | - if (count($selects) === 1 && is_array($selects[0])) { |
|
434 | - $selects = $selects[0]; |
|
435 | - } |
|
436 | - |
|
437 | - $this->queryBuilder->select( |
|
438 | - $this->helper->quoteColumnNames($selects) |
|
439 | - ); |
|
440 | - |
|
441 | - return $this; |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Specifies an item that is to be returned with a different name in the query result. |
|
446 | - * |
|
447 | - * <code> |
|
448 | - * $qb = $conn->getQueryBuilder() |
|
449 | - * ->selectAlias('u.id', 'user_id') |
|
450 | - * ->from('users', 'u') |
|
451 | - * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
452 | - * </code> |
|
453 | - * |
|
454 | - * @param mixed $select The selection expressions. |
|
455 | - * @param string $alias The column alias used in the constructed query. |
|
456 | - * |
|
457 | - * @return $this This QueryBuilder instance. |
|
458 | - */ |
|
459 | - public function selectAlias($select, $alias) { |
|
460 | - $this->queryBuilder->addSelect( |
|
461 | - $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias) |
|
462 | - ); |
|
463 | - |
|
464 | - return $this; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Specifies an item that is to be returned uniquely in the query result. |
|
469 | - * |
|
470 | - * <code> |
|
471 | - * $qb = $conn->getQueryBuilder() |
|
472 | - * ->selectDistinct('type') |
|
473 | - * ->from('users'); |
|
474 | - * </code> |
|
475 | - * |
|
476 | - * @param mixed $select The selection expressions. |
|
477 | - * |
|
478 | - * @return $this This QueryBuilder instance. |
|
479 | - */ |
|
480 | - public function selectDistinct($select) { |
|
481 | - if (!is_array($select)) { |
|
482 | - $select = [$select]; |
|
483 | - } |
|
484 | - |
|
485 | - $quotedSelect = $this->helper->quoteColumnNames($select); |
|
486 | - |
|
487 | - $this->queryBuilder->addSelect( |
|
488 | - 'DISTINCT ' . implode(', ', $quotedSelect) |
|
489 | - ); |
|
490 | - |
|
491 | - return $this; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * Adds an item that is to be returned in the query result. |
|
496 | - * |
|
497 | - * <code> |
|
498 | - * $qb = $conn->getQueryBuilder() |
|
499 | - * ->select('u.id') |
|
500 | - * ->addSelect('p.id') |
|
501 | - * ->from('users', 'u') |
|
502 | - * ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id'); |
|
503 | - * </code> |
|
504 | - * |
|
505 | - * @param mixed ...$selects The selection expression. |
|
506 | - * |
|
507 | - * @return $this This QueryBuilder instance. |
|
508 | - */ |
|
509 | - public function addSelect(...$selects) { |
|
510 | - if (count($selects) === 1 && is_array($selects[0])) { |
|
511 | - $selects = $selects[0]; |
|
512 | - } |
|
513 | - |
|
514 | - $this->queryBuilder->addSelect( |
|
515 | - $this->helper->quoteColumnNames($selects) |
|
516 | - ); |
|
517 | - |
|
518 | - return $this; |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * Turns the query being built into a bulk delete query that ranges over |
|
523 | - * a certain table. |
|
524 | - * |
|
525 | - * <code> |
|
526 | - * $qb = $conn->getQueryBuilder() |
|
527 | - * ->delete('users', 'u') |
|
528 | - * ->where('u.id = :user_id'); |
|
529 | - * ->setParameter(':user_id', 1); |
|
530 | - * </code> |
|
531 | - * |
|
532 | - * @param string $delete The table whose rows are subject to the deletion. |
|
533 | - * @param string $alias The table alias used in the constructed query. |
|
534 | - * |
|
535 | - * @return $this This QueryBuilder instance. |
|
536 | - */ |
|
537 | - public function delete($delete = null, $alias = null) { |
|
538 | - $this->queryBuilder->delete( |
|
539 | - $this->getTableName($delete), |
|
540 | - $alias |
|
541 | - ); |
|
542 | - |
|
543 | - return $this; |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Turns the query being built into a bulk update query that ranges over |
|
548 | - * a certain table |
|
549 | - * |
|
550 | - * <code> |
|
551 | - * $qb = $conn->getQueryBuilder() |
|
552 | - * ->update('users', 'u') |
|
553 | - * ->set('u.password', md5('password')) |
|
554 | - * ->where('u.id = ?'); |
|
555 | - * </code> |
|
556 | - * |
|
557 | - * @param string $update The table whose rows are subject to the update. |
|
558 | - * @param string $alias The table alias used in the constructed query. |
|
559 | - * |
|
560 | - * @return $this This QueryBuilder instance. |
|
561 | - */ |
|
562 | - public function update($update = null, $alias = null) { |
|
563 | - $this->queryBuilder->update( |
|
564 | - $this->getTableName($update), |
|
565 | - $alias |
|
566 | - ); |
|
567 | - |
|
568 | - return $this; |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Turns the query being built into an insert query that inserts into |
|
573 | - * a certain table |
|
574 | - * |
|
575 | - * <code> |
|
576 | - * $qb = $conn->getQueryBuilder() |
|
577 | - * ->insert('users') |
|
578 | - * ->values( |
|
579 | - * array( |
|
580 | - * 'name' => '?', |
|
581 | - * 'password' => '?' |
|
582 | - * ) |
|
583 | - * ); |
|
584 | - * </code> |
|
585 | - * |
|
586 | - * @param string $insert The table into which the rows should be inserted. |
|
587 | - * |
|
588 | - * @return $this This QueryBuilder instance. |
|
589 | - */ |
|
590 | - public function insert($insert = null) { |
|
591 | - $this->queryBuilder->insert( |
|
592 | - $this->getTableName($insert) |
|
593 | - ); |
|
594 | - |
|
595 | - $this->lastInsertedTable = $insert; |
|
596 | - |
|
597 | - return $this; |
|
598 | - } |
|
599 | - |
|
600 | - /** |
|
601 | - * Creates and adds a query root corresponding to the table identified by the |
|
602 | - * given alias, forming a cartesian product with any existing query roots. |
|
603 | - * |
|
604 | - * <code> |
|
605 | - * $qb = $conn->getQueryBuilder() |
|
606 | - * ->select('u.id') |
|
607 | - * ->from('users', 'u') |
|
608 | - * </code> |
|
609 | - * |
|
610 | - * @param string $from The table. |
|
611 | - * @param string|null $alias The alias of the table. |
|
612 | - * |
|
613 | - * @return $this This QueryBuilder instance. |
|
614 | - */ |
|
615 | - public function from($from, $alias = null) { |
|
616 | - $this->queryBuilder->from( |
|
617 | - $this->getTableName($from), |
|
618 | - $this->quoteAlias($alias) |
|
619 | - ); |
|
620 | - |
|
621 | - return $this; |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Creates and adds a join to the query. |
|
626 | - * |
|
627 | - * <code> |
|
628 | - * $qb = $conn->getQueryBuilder() |
|
629 | - * ->select('u.name') |
|
630 | - * ->from('users', 'u') |
|
631 | - * ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
632 | - * </code> |
|
633 | - * |
|
634 | - * @param string $fromAlias The alias that points to a from clause. |
|
635 | - * @param string $join The table name to join. |
|
636 | - * @param string $alias The alias of the join table. |
|
637 | - * @param string $condition The condition for the join. |
|
638 | - * |
|
639 | - * @return $this This QueryBuilder instance. |
|
640 | - */ |
|
641 | - public function join($fromAlias, $join, $alias, $condition = null) { |
|
642 | - $this->queryBuilder->join( |
|
643 | - $this->quoteAlias($fromAlias), |
|
644 | - $this->getTableName($join), |
|
645 | - $this->quoteAlias($alias), |
|
646 | - $condition |
|
647 | - ); |
|
648 | - |
|
649 | - return $this; |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Creates and adds a join to the query. |
|
654 | - * |
|
655 | - * <code> |
|
656 | - * $qb = $conn->getQueryBuilder() |
|
657 | - * ->select('u.name') |
|
658 | - * ->from('users', 'u') |
|
659 | - * ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
660 | - * </code> |
|
661 | - * |
|
662 | - * @param string $fromAlias The alias that points to a from clause. |
|
663 | - * @param string $join The table name to join. |
|
664 | - * @param string $alias The alias of the join table. |
|
665 | - * @param string $condition The condition for the join. |
|
666 | - * |
|
667 | - * @return $this This QueryBuilder instance. |
|
668 | - */ |
|
669 | - public function innerJoin($fromAlias, $join, $alias, $condition = null) { |
|
670 | - $this->queryBuilder->innerJoin( |
|
671 | - $this->quoteAlias($fromAlias), |
|
672 | - $this->getTableName($join), |
|
673 | - $this->quoteAlias($alias), |
|
674 | - $condition |
|
675 | - ); |
|
676 | - |
|
677 | - return $this; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Creates and adds a left join to the query. |
|
682 | - * |
|
683 | - * <code> |
|
684 | - * $qb = $conn->getQueryBuilder() |
|
685 | - * ->select('u.name') |
|
686 | - * ->from('users', 'u') |
|
687 | - * ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
688 | - * </code> |
|
689 | - * |
|
690 | - * @param string $fromAlias The alias that points to a from clause. |
|
691 | - * @param string $join The table name to join. |
|
692 | - * @param string $alias The alias of the join table. |
|
693 | - * @param string $condition The condition for the join. |
|
694 | - * |
|
695 | - * @return $this This QueryBuilder instance. |
|
696 | - */ |
|
697 | - public function leftJoin($fromAlias, $join, $alias, $condition = null) { |
|
698 | - $this->queryBuilder->leftJoin( |
|
699 | - $this->quoteAlias($fromAlias), |
|
700 | - $this->getTableName($join), |
|
701 | - $this->quoteAlias($alias), |
|
702 | - $condition |
|
703 | - ); |
|
704 | - |
|
705 | - return $this; |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Creates and adds a right join to the query. |
|
710 | - * |
|
711 | - * <code> |
|
712 | - * $qb = $conn->getQueryBuilder() |
|
713 | - * ->select('u.name') |
|
714 | - * ->from('users', 'u') |
|
715 | - * ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
716 | - * </code> |
|
717 | - * |
|
718 | - * @param string $fromAlias The alias that points to a from clause. |
|
719 | - * @param string $join The table name to join. |
|
720 | - * @param string $alias The alias of the join table. |
|
721 | - * @param string $condition The condition for the join. |
|
722 | - * |
|
723 | - * @return $this This QueryBuilder instance. |
|
724 | - */ |
|
725 | - public function rightJoin($fromAlias, $join, $alias, $condition = null) { |
|
726 | - $this->queryBuilder->rightJoin( |
|
727 | - $this->quoteAlias($fromAlias), |
|
728 | - $this->getTableName($join), |
|
729 | - $this->quoteAlias($alias), |
|
730 | - $condition |
|
731 | - ); |
|
732 | - |
|
733 | - return $this; |
|
734 | - } |
|
735 | - |
|
736 | - /** |
|
737 | - * Sets a new value for a column in a bulk update query. |
|
738 | - * |
|
739 | - * <code> |
|
740 | - * $qb = $conn->getQueryBuilder() |
|
741 | - * ->update('users', 'u') |
|
742 | - * ->set('u.password', md5('password')) |
|
743 | - * ->where('u.id = ?'); |
|
744 | - * </code> |
|
745 | - * |
|
746 | - * @param string $key The column to set. |
|
747 | - * @param ILiteral|IParameter|IQueryFunction|string $value The value, expression, placeholder, etc. |
|
748 | - * |
|
749 | - * @return $this This QueryBuilder instance. |
|
750 | - */ |
|
751 | - public function set($key, $value) { |
|
752 | - $this->queryBuilder->set( |
|
753 | - $this->helper->quoteColumnName($key), |
|
754 | - $this->helper->quoteColumnName($value) |
|
755 | - ); |
|
756 | - |
|
757 | - return $this; |
|
758 | - } |
|
759 | - |
|
760 | - /** |
|
761 | - * Specifies one or more restrictions to the query result. |
|
762 | - * Replaces any previously specified restrictions, if any. |
|
763 | - * |
|
764 | - * <code> |
|
765 | - * $qb = $conn->getQueryBuilder() |
|
766 | - * ->select('u.name') |
|
767 | - * ->from('users', 'u') |
|
768 | - * ->where('u.id = ?'); |
|
769 | - * |
|
770 | - * // You can optionally programatically build and/or expressions |
|
771 | - * $qb = $conn->getQueryBuilder(); |
|
772 | - * |
|
773 | - * $or = $qb->expr()->orx(); |
|
774 | - * $or->add($qb->expr()->eq('u.id', 1)); |
|
775 | - * $or->add($qb->expr()->eq('u.id', 2)); |
|
776 | - * |
|
777 | - * $qb->update('users', 'u') |
|
778 | - * ->set('u.password', md5('password')) |
|
779 | - * ->where($or); |
|
780 | - * </code> |
|
781 | - * |
|
782 | - * @param mixed ...$predicates The restriction predicates. |
|
783 | - * |
|
784 | - * @return $this This QueryBuilder instance. |
|
785 | - */ |
|
786 | - public function where(...$predicates) { |
|
787 | - call_user_func_array( |
|
788 | - [$this->queryBuilder, 'where'], |
|
789 | - $predicates |
|
790 | - ); |
|
791 | - |
|
792 | - return $this; |
|
793 | - } |
|
794 | - |
|
795 | - /** |
|
796 | - * Adds one or more restrictions to the query results, forming a logical |
|
797 | - * conjunction with any previously specified restrictions. |
|
798 | - * |
|
799 | - * <code> |
|
800 | - * $qb = $conn->getQueryBuilder() |
|
801 | - * ->select('u') |
|
802 | - * ->from('users', 'u') |
|
803 | - * ->where('u.username LIKE ?') |
|
804 | - * ->andWhere('u.is_active = 1'); |
|
805 | - * </code> |
|
806 | - * |
|
807 | - * @param mixed ...$where The query restrictions. |
|
808 | - * |
|
809 | - * @return $this This QueryBuilder instance. |
|
810 | - * |
|
811 | - * @see where() |
|
812 | - */ |
|
813 | - public function andWhere(...$where) { |
|
814 | - call_user_func_array( |
|
815 | - [$this->queryBuilder, 'andWhere'], |
|
816 | - $where |
|
817 | - ); |
|
818 | - |
|
819 | - return $this; |
|
820 | - } |
|
821 | - |
|
822 | - /** |
|
823 | - * Adds one or more restrictions to the query results, forming a logical |
|
824 | - * disjunction with any previously specified restrictions. |
|
825 | - * |
|
826 | - * <code> |
|
827 | - * $qb = $conn->getQueryBuilder() |
|
828 | - * ->select('u.name') |
|
829 | - * ->from('users', 'u') |
|
830 | - * ->where('u.id = 1') |
|
831 | - * ->orWhere('u.id = 2'); |
|
832 | - * </code> |
|
833 | - * |
|
834 | - * @param mixed ...$where The WHERE statement. |
|
835 | - * |
|
836 | - * @return $this This QueryBuilder instance. |
|
837 | - * |
|
838 | - * @see where() |
|
839 | - */ |
|
840 | - public function orWhere(...$where) { |
|
841 | - call_user_func_array( |
|
842 | - [$this->queryBuilder, 'orWhere'], |
|
843 | - $where |
|
844 | - ); |
|
845 | - |
|
846 | - return $this; |
|
847 | - } |
|
848 | - |
|
849 | - /** |
|
850 | - * Specifies a grouping over the results of the query. |
|
851 | - * Replaces any previously specified groupings, if any. |
|
852 | - * |
|
853 | - * <code> |
|
854 | - * $qb = $conn->getQueryBuilder() |
|
855 | - * ->select('u.name') |
|
856 | - * ->from('users', 'u') |
|
857 | - * ->groupBy('u.id'); |
|
858 | - * </code> |
|
859 | - * |
|
860 | - * @param mixed ...$groupBys The grouping expression. |
|
861 | - * |
|
862 | - * @return $this This QueryBuilder instance. |
|
863 | - */ |
|
864 | - public function groupBy(...$groupBys) { |
|
865 | - if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
866 | - $groupBys = $groupBys[0]; |
|
867 | - } |
|
868 | - |
|
869 | - call_user_func_array( |
|
870 | - [$this->queryBuilder, 'groupBy'], |
|
871 | - $this->helper->quoteColumnNames($groupBys) |
|
872 | - ); |
|
873 | - |
|
874 | - return $this; |
|
875 | - } |
|
876 | - |
|
877 | - /** |
|
878 | - * Adds a grouping expression to the query. |
|
879 | - * |
|
880 | - * <code> |
|
881 | - * $qb = $conn->getQueryBuilder() |
|
882 | - * ->select('u.name') |
|
883 | - * ->from('users', 'u') |
|
884 | - * ->groupBy('u.lastLogin'); |
|
885 | - * ->addGroupBy('u.createdAt') |
|
886 | - * </code> |
|
887 | - * |
|
888 | - * @param mixed ...$groupBy The grouping expression. |
|
889 | - * |
|
890 | - * @return $this This QueryBuilder instance. |
|
891 | - */ |
|
892 | - public function addGroupBy(...$groupBys) { |
|
893 | - if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
894 | - $$groupBys = $groupBys[0]; |
|
895 | - } |
|
896 | - |
|
897 | - call_user_func_array( |
|
898 | - [$this->queryBuilder, 'addGroupBy'], |
|
899 | - $this->helper->quoteColumnNames($groupBys) |
|
900 | - ); |
|
901 | - |
|
902 | - return $this; |
|
903 | - } |
|
904 | - |
|
905 | - /** |
|
906 | - * Sets a value for a column in an insert query. |
|
907 | - * |
|
908 | - * <code> |
|
909 | - * $qb = $conn->getQueryBuilder() |
|
910 | - * ->insert('users') |
|
911 | - * ->values( |
|
912 | - * array( |
|
913 | - * 'name' => '?' |
|
914 | - * ) |
|
915 | - * ) |
|
916 | - * ->setValue('password', '?'); |
|
917 | - * </code> |
|
918 | - * |
|
919 | - * @param string $column The column into which the value should be inserted. |
|
920 | - * @param IParameter|string $value The value that should be inserted into the column. |
|
921 | - * |
|
922 | - * @return $this This QueryBuilder instance. |
|
923 | - */ |
|
924 | - public function setValue($column, $value) { |
|
925 | - $this->queryBuilder->setValue( |
|
926 | - $this->helper->quoteColumnName($column), |
|
927 | - (string) $value |
|
928 | - ); |
|
929 | - |
|
930 | - return $this; |
|
931 | - } |
|
932 | - |
|
933 | - /** |
|
934 | - * Specifies values for an insert query indexed by column names. |
|
935 | - * Replaces any previous values, if any. |
|
936 | - * |
|
937 | - * <code> |
|
938 | - * $qb = $conn->getQueryBuilder() |
|
939 | - * ->insert('users') |
|
940 | - * ->values( |
|
941 | - * array( |
|
942 | - * 'name' => '?', |
|
943 | - * 'password' => '?' |
|
944 | - * ) |
|
945 | - * ); |
|
946 | - * </code> |
|
947 | - * |
|
948 | - * @param array $values The values to specify for the insert query indexed by column names. |
|
949 | - * |
|
950 | - * @return $this This QueryBuilder instance. |
|
951 | - */ |
|
952 | - public function values(array $values) { |
|
953 | - $quotedValues = []; |
|
954 | - foreach ($values as $key => $value) { |
|
955 | - $quotedValues[$this->helper->quoteColumnName($key)] = $value; |
|
956 | - } |
|
957 | - |
|
958 | - $this->queryBuilder->values($quotedValues); |
|
959 | - |
|
960 | - return $this; |
|
961 | - } |
|
962 | - |
|
963 | - /** |
|
964 | - * Specifies a restriction over the groups of the query. |
|
965 | - * Replaces any previous having restrictions, if any. |
|
966 | - * |
|
967 | - * @param mixed ...$having The restriction over the groups. |
|
968 | - * |
|
969 | - * @return $this This QueryBuilder instance. |
|
970 | - */ |
|
971 | - public function having(...$having) { |
|
972 | - call_user_func_array( |
|
973 | - [$this->queryBuilder, 'having'], |
|
974 | - $having |
|
975 | - ); |
|
976 | - |
|
977 | - return $this; |
|
978 | - } |
|
979 | - |
|
980 | - /** |
|
981 | - * Adds a restriction over the groups of the query, forming a logical |
|
982 | - * conjunction with any existing having restrictions. |
|
983 | - * |
|
984 | - * @param mixed ...$having The restriction to append. |
|
985 | - * |
|
986 | - * @return $this This QueryBuilder instance. |
|
987 | - */ |
|
988 | - public function andHaving(...$having) { |
|
989 | - call_user_func_array( |
|
990 | - [$this->queryBuilder, 'andHaving'], |
|
991 | - $having |
|
992 | - ); |
|
993 | - |
|
994 | - return $this; |
|
995 | - } |
|
996 | - |
|
997 | - /** |
|
998 | - * Adds a restriction over the groups of the query, forming a logical |
|
999 | - * disjunction with any existing having restrictions. |
|
1000 | - * |
|
1001 | - * @param mixed ...$having The restriction to add. |
|
1002 | - * |
|
1003 | - * @return $this This QueryBuilder instance. |
|
1004 | - */ |
|
1005 | - public function orHaving(...$having) { |
|
1006 | - call_user_func_array( |
|
1007 | - [$this->queryBuilder, 'orHaving'], |
|
1008 | - $having |
|
1009 | - ); |
|
1010 | - |
|
1011 | - return $this; |
|
1012 | - } |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * Specifies an ordering for the query results. |
|
1016 | - * Replaces any previously specified orderings, if any. |
|
1017 | - * |
|
1018 | - * @param string $sort The ordering expression. |
|
1019 | - * @param string $order The ordering direction. |
|
1020 | - * |
|
1021 | - * @return $this This QueryBuilder instance. |
|
1022 | - */ |
|
1023 | - public function orderBy($sort, $order = null) { |
|
1024 | - $this->queryBuilder->orderBy( |
|
1025 | - $this->helper->quoteColumnName($sort), |
|
1026 | - $order |
|
1027 | - ); |
|
1028 | - |
|
1029 | - return $this; |
|
1030 | - } |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * Adds an ordering to the query results. |
|
1034 | - * |
|
1035 | - * @param string $sort The ordering expression. |
|
1036 | - * @param string $order The ordering direction. |
|
1037 | - * |
|
1038 | - * @return $this This QueryBuilder instance. |
|
1039 | - */ |
|
1040 | - public function addOrderBy($sort, $order = null) { |
|
1041 | - $this->queryBuilder->addOrderBy( |
|
1042 | - $this->helper->quoteColumnName($sort), |
|
1043 | - $order |
|
1044 | - ); |
|
1045 | - |
|
1046 | - return $this; |
|
1047 | - } |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * Gets a query part by its name. |
|
1051 | - * |
|
1052 | - * @param string $queryPartName |
|
1053 | - * |
|
1054 | - * @return mixed |
|
1055 | - */ |
|
1056 | - public function getQueryPart($queryPartName) { |
|
1057 | - return $this->queryBuilder->getQueryPart($queryPartName); |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Gets all query parts. |
|
1062 | - * |
|
1063 | - * @return array |
|
1064 | - */ |
|
1065 | - public function getQueryParts() { |
|
1066 | - return $this->queryBuilder->getQueryParts(); |
|
1067 | - } |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * Resets SQL parts. |
|
1071 | - * |
|
1072 | - * @param array|null $queryPartNames |
|
1073 | - * |
|
1074 | - * @return $this This QueryBuilder instance. |
|
1075 | - */ |
|
1076 | - public function resetQueryParts($queryPartNames = null) { |
|
1077 | - $this->queryBuilder->resetQueryParts($queryPartNames); |
|
1078 | - |
|
1079 | - return $this; |
|
1080 | - } |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * Resets a single SQL part. |
|
1084 | - * |
|
1085 | - * @param string $queryPartName |
|
1086 | - * |
|
1087 | - * @return $this This QueryBuilder instance. |
|
1088 | - */ |
|
1089 | - public function resetQueryPart($queryPartName) { |
|
1090 | - $this->queryBuilder->resetQueryPart($queryPartName); |
|
1091 | - |
|
1092 | - return $this; |
|
1093 | - } |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * Creates a new named parameter and bind the value $value to it. |
|
1097 | - * |
|
1098 | - * This method provides a shortcut for PDOStatement::bindValue |
|
1099 | - * when using prepared statements. |
|
1100 | - * |
|
1101 | - * The parameter $value specifies the value that you want to bind. If |
|
1102 | - * $placeholder is not provided bindValue() will automatically create a |
|
1103 | - * placeholder for you. An automatic placeholder will be of the name |
|
1104 | - * ':dcValue1', ':dcValue2' etc. |
|
1105 | - * |
|
1106 | - * For more information see {@link https://www.php.net/pdostatement-bindparam} |
|
1107 | - * |
|
1108 | - * Example: |
|
1109 | - * <code> |
|
1110 | - * $value = 2; |
|
1111 | - * $q->eq( 'id', $q->bindValue( $value ) ); |
|
1112 | - * $stmt = $q->executeQuery(); // executed with 'id = 2' |
|
1113 | - * </code> |
|
1114 | - * |
|
1115 | - * @license New BSD License |
|
1116 | - * @link http://www.zetacomponents.org |
|
1117 | - * |
|
1118 | - * @param mixed $value |
|
1119 | - * @param mixed $type |
|
1120 | - * @param string $placeHolder The name to bind with. The string must start with a colon ':'. |
|
1121 | - * |
|
1122 | - * @return IParameter the placeholder name used. |
|
1123 | - */ |
|
1124 | - public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) { |
|
1125 | - return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder)); |
|
1126 | - } |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * Creates a new positional parameter and bind the given value to it. |
|
1130 | - * |
|
1131 | - * Attention: If you are using positional parameters with the query builder you have |
|
1132 | - * to be very careful to bind all parameters in the order they appear in the SQL |
|
1133 | - * statement , otherwise they get bound in the wrong order which can lead to serious |
|
1134 | - * bugs in your code. |
|
1135 | - * |
|
1136 | - * Example: |
|
1137 | - * <code> |
|
1138 | - * $qb = $conn->getQueryBuilder(); |
|
1139 | - * $qb->select('u.*') |
|
1140 | - * ->from('users', 'u') |
|
1141 | - * ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR)) |
|
1142 | - * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR)) |
|
1143 | - * </code> |
|
1144 | - * |
|
1145 | - * @param mixed $value |
|
1146 | - * @param integer $type |
|
1147 | - * |
|
1148 | - * @return IParameter |
|
1149 | - */ |
|
1150 | - public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) { |
|
1151 | - return new Parameter($this->queryBuilder->createPositionalParameter($value, $type)); |
|
1152 | - } |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * Creates a new parameter |
|
1156 | - * |
|
1157 | - * Example: |
|
1158 | - * <code> |
|
1159 | - * $qb = $conn->getQueryBuilder(); |
|
1160 | - * $qb->select('u.*') |
|
1161 | - * ->from('users', 'u') |
|
1162 | - * ->where('u.username = ' . $qb->createParameter('name')) |
|
1163 | - * ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR)) |
|
1164 | - * </code> |
|
1165 | - * |
|
1166 | - * @param string $name |
|
1167 | - * |
|
1168 | - * @return IParameter |
|
1169 | - */ |
|
1170 | - public function createParameter($name) { |
|
1171 | - return new Parameter(':' . $name); |
|
1172 | - } |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * Creates a new function |
|
1176 | - * |
|
1177 | - * Attention: Column names inside the call have to be quoted before hand |
|
1178 | - * |
|
1179 | - * Example: |
|
1180 | - * <code> |
|
1181 | - * $qb = $conn->getQueryBuilder(); |
|
1182 | - * $qb->select($qb->createFunction('COUNT(*)')) |
|
1183 | - * ->from('users', 'u') |
|
1184 | - * echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u |
|
1185 | - * </code> |
|
1186 | - * <code> |
|
1187 | - * $qb = $conn->getQueryBuilder(); |
|
1188 | - * $qb->select($qb->createFunction('COUNT(`column`)')) |
|
1189 | - * ->from('users', 'u') |
|
1190 | - * echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u |
|
1191 | - * </code> |
|
1192 | - * |
|
1193 | - * @param string $call |
|
1194 | - * |
|
1195 | - * @return IQueryFunction |
|
1196 | - */ |
|
1197 | - public function createFunction($call) { |
|
1198 | - return new QueryFunction($call); |
|
1199 | - } |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Used to get the id of the last inserted element |
|
1203 | - * @return int |
|
1204 | - * @throws \BadMethodCallException When being called before an insert query has been run. |
|
1205 | - */ |
|
1206 | - public function getLastInsertId() { |
|
1207 | - if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) { |
|
1208 | - // lastInsertId() needs the prefix but no quotes |
|
1209 | - $table = $this->prefixTableName($this->lastInsertedTable); |
|
1210 | - return (int) $this->connection->lastInsertId($table); |
|
1211 | - } |
|
1212 | - |
|
1213 | - throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.'); |
|
1214 | - } |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * Returns the table name quoted and with database prefix as needed by the implementation |
|
1218 | - * |
|
1219 | - * @param string $table |
|
1220 | - * @return string |
|
1221 | - */ |
|
1222 | - public function getTableName($table) { |
|
1223 | - if ($table instanceof IQueryFunction) { |
|
1224 | - return (string) $table; |
|
1225 | - } |
|
1226 | - |
|
1227 | - $table = $this->prefixTableName($table); |
|
1228 | - return $this->helper->quoteColumnName($table); |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * Returns the table name with database prefix as needed by the implementation |
|
1233 | - * |
|
1234 | - * @param string $table |
|
1235 | - * @return string |
|
1236 | - */ |
|
1237 | - protected function prefixTableName($table) { |
|
1238 | - if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) { |
|
1239 | - return $table; |
|
1240 | - } |
|
1241 | - |
|
1242 | - return '*PREFIX*' . $table; |
|
1243 | - } |
|
1244 | - |
|
1245 | - /** |
|
1246 | - * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
1247 | - * |
|
1248 | - * @param string $column |
|
1249 | - * @param string $tableAlias |
|
1250 | - * @return string |
|
1251 | - */ |
|
1252 | - public function getColumnName($column, $tableAlias = '') { |
|
1253 | - if ($tableAlias !== '') { |
|
1254 | - $tableAlias .= '.'; |
|
1255 | - } |
|
1256 | - |
|
1257 | - return $this->helper->quoteColumnName($tableAlias . $column); |
|
1258 | - } |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
1262 | - * |
|
1263 | - * @param string $alias |
|
1264 | - * @return string |
|
1265 | - */ |
|
1266 | - public function quoteAlias($alias) { |
|
1267 | - if ($alias === '' || $alias === null) { |
|
1268 | - return $alias; |
|
1269 | - } |
|
1270 | - |
|
1271 | - return $this->helper->quoteColumnName($alias); |
|
1272 | - } |
|
59 | + /** @var ConnectionAdapter */ |
|
60 | + private $connection; |
|
61 | + |
|
62 | + /** @var SystemConfig */ |
|
63 | + private $systemConfig; |
|
64 | + |
|
65 | + /** @var ILogger */ |
|
66 | + private $logger; |
|
67 | + |
|
68 | + /** @var \Doctrine\DBAL\Query\QueryBuilder */ |
|
69 | + private $queryBuilder; |
|
70 | + |
|
71 | + /** @var QuoteHelper */ |
|
72 | + private $helper; |
|
73 | + |
|
74 | + /** @var bool */ |
|
75 | + private $automaticTablePrefix = true; |
|
76 | + |
|
77 | + /** @var string */ |
|
78 | + protected $lastInsertedTable; |
|
79 | + |
|
80 | + /** |
|
81 | + * Initializes a new QueryBuilder. |
|
82 | + * |
|
83 | + * @param ConnectionAdapter $connection |
|
84 | + * @param SystemConfig $systemConfig |
|
85 | + * @param ILogger $logger |
|
86 | + */ |
|
87 | + public function __construct(ConnectionAdapter $connection, SystemConfig $systemConfig, ILogger $logger) { |
|
88 | + $this->connection = $connection; |
|
89 | + $this->systemConfig = $systemConfig; |
|
90 | + $this->logger = $logger; |
|
91 | + $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection->getInner()); |
|
92 | + $this->helper = new QuoteHelper(); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Enable/disable automatic prefixing of table names with the oc_ prefix |
|
97 | + * |
|
98 | + * @param bool $enabled If set to true table names will be prefixed with the |
|
99 | + * owncloud database prefix automatically. |
|
100 | + * @since 8.2.0 |
|
101 | + */ |
|
102 | + public function automaticTablePrefix($enabled) { |
|
103 | + $this->automaticTablePrefix = (bool) $enabled; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Gets an ExpressionBuilder used for object-oriented construction of query expressions. |
|
108 | + * This producer method is intended for convenient inline usage. Example: |
|
109 | + * |
|
110 | + * <code> |
|
111 | + * $qb = $conn->getQueryBuilder() |
|
112 | + * ->select('u') |
|
113 | + * ->from('users', 'u') |
|
114 | + * ->where($qb->expr()->eq('u.id', 1)); |
|
115 | + * </code> |
|
116 | + * |
|
117 | + * For more complex expression construction, consider storing the expression |
|
118 | + * builder object in a local variable. |
|
119 | + * |
|
120 | + * @return \OCP\DB\QueryBuilder\IExpressionBuilder |
|
121 | + */ |
|
122 | + public function expr() { |
|
123 | + if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { |
|
124 | + return new OCIExpressionBuilder($this->connection, $this); |
|
125 | + } |
|
126 | + if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
127 | + return new PgSqlExpressionBuilder($this->connection, $this); |
|
128 | + } |
|
129 | + if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) { |
|
130 | + return new MySqlExpressionBuilder($this->connection, $this); |
|
131 | + } |
|
132 | + if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
133 | + return new SqliteExpressionBuilder($this->connection, $this); |
|
134 | + } |
|
135 | + |
|
136 | + return new ExpressionBuilder($this->connection, $this); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Gets an FunctionBuilder used for object-oriented construction of query functions. |
|
141 | + * This producer method is intended for convenient inline usage. Example: |
|
142 | + * |
|
143 | + * <code> |
|
144 | + * $qb = $conn->getQueryBuilder() |
|
145 | + * ->select('u') |
|
146 | + * ->from('users', 'u') |
|
147 | + * ->where($qb->fun()->md5('u.id')); |
|
148 | + * </code> |
|
149 | + * |
|
150 | + * For more complex function construction, consider storing the function |
|
151 | + * builder object in a local variable. |
|
152 | + * |
|
153 | + * @return \OCP\DB\QueryBuilder\IFunctionBuilder |
|
154 | + */ |
|
155 | + public function func() { |
|
156 | + if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { |
|
157 | + return new OCIFunctionBuilder($this->helper); |
|
158 | + } |
|
159 | + if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
160 | + return new SqliteFunctionBuilder($this->helper); |
|
161 | + } |
|
162 | + if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
163 | + return new PgSqlFunctionBuilder($this->helper); |
|
164 | + } |
|
165 | + |
|
166 | + return new FunctionBuilder($this->helper); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Gets the type of the currently built query. |
|
171 | + * |
|
172 | + * @return integer |
|
173 | + */ |
|
174 | + public function getType() { |
|
175 | + return $this->queryBuilder->getType(); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Gets the associated DBAL Connection for this query builder. |
|
180 | + * |
|
181 | + * @return \OCP\IDBConnection |
|
182 | + */ |
|
183 | + public function getConnection() { |
|
184 | + return $this->connection; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Gets the state of this query builder instance. |
|
189 | + * |
|
190 | + * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN. |
|
191 | + */ |
|
192 | + public function getState() { |
|
193 | + return $this->queryBuilder->getState(); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Executes this query using the bound parameters and their types. |
|
198 | + * |
|
199 | + * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate} |
|
200 | + * for insert, update and delete statements. |
|
201 | + * |
|
202 | + * @return IResult|int |
|
203 | + */ |
|
204 | + public function execute() { |
|
205 | + if ($this->systemConfig->getValue('log_query', false)) { |
|
206 | + try { |
|
207 | + $params = []; |
|
208 | + foreach ($this->getParameters() as $placeholder => $value) { |
|
209 | + if ($value instanceof \DateTime) { |
|
210 | + $params[] = $placeholder . ' => DateTime:\'' . $value->format('c') . '\''; |
|
211 | + } elseif (is_array($value)) { |
|
212 | + $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; |
|
213 | + } else { |
|
214 | + $params[] = $placeholder . ' => \'' . $value . '\''; |
|
215 | + } |
|
216 | + } |
|
217 | + if (empty($params)) { |
|
218 | + $this->logger->debug('DB QueryBuilder: \'{query}\'', [ |
|
219 | + 'query' => $this->getSQL(), |
|
220 | + 'app' => 'core', |
|
221 | + ]); |
|
222 | + } else { |
|
223 | + $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ |
|
224 | + 'query' => $this->getSQL(), |
|
225 | + 'params' => implode(', ', $params), |
|
226 | + 'app' => 'core', |
|
227 | + ]); |
|
228 | + } |
|
229 | + } catch (\Error $e) { |
|
230 | + // likely an error during conversion of $value to string |
|
231 | + $this->logger->debug('DB QueryBuilder: error trying to log SQL query'); |
|
232 | + $this->logger->logException($e); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + if (!empty($this->getQueryPart('select'))) { |
|
237 | + $select = $this->getQueryPart('select'); |
|
238 | + $hasSelectAll = array_filter($select, static function ($s) { |
|
239 | + return $s === '*'; |
|
240 | + }); |
|
241 | + $hasSelectSpecific = array_filter($select, static function ($s) { |
|
242 | + return $s !== '*'; |
|
243 | + }); |
|
244 | + |
|
245 | + if (empty($hasSelectAll) === empty($hasSelectSpecific)) { |
|
246 | + $exception = new QueryException('Query is selecting * and specific values in the same query. This is not supported in Oracle.'); |
|
247 | + $this->logger->logException($exception, [ |
|
248 | + 'message' => 'Query is selecting * and specific values in the same query. This is not supported in Oracle.', |
|
249 | + 'query' => $this->getSQL(), |
|
250 | + 'level' => ILogger::ERROR, |
|
251 | + 'app' => 'core', |
|
252 | + ]); |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + $result = $this->queryBuilder->execute(); |
|
257 | + if (is_int($result)) { |
|
258 | + return $result; |
|
259 | + } |
|
260 | + return new ResultAdapter($result); |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Gets the complete SQL string formed by the current specifications of this QueryBuilder. |
|
265 | + * |
|
266 | + * <code> |
|
267 | + * $qb = $conn->getQueryBuilder() |
|
268 | + * ->select('u') |
|
269 | + * ->from('User', 'u') |
|
270 | + * echo $qb->getSQL(); // SELECT u FROM User u |
|
271 | + * </code> |
|
272 | + * |
|
273 | + * @return string The SQL query string. |
|
274 | + */ |
|
275 | + public function getSQL() { |
|
276 | + return $this->queryBuilder->getSQL(); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Sets a query parameter for the query being constructed. |
|
281 | + * |
|
282 | + * <code> |
|
283 | + * $qb = $conn->getQueryBuilder() |
|
284 | + * ->select('u') |
|
285 | + * ->from('users', 'u') |
|
286 | + * ->where('u.id = :user_id') |
|
287 | + * ->setParameter(':user_id', 1); |
|
288 | + * </code> |
|
289 | + * |
|
290 | + * @param string|integer $key The parameter position or name. |
|
291 | + * @param mixed $value The parameter value. |
|
292 | + * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants. |
|
293 | + * |
|
294 | + * @return $this This QueryBuilder instance. |
|
295 | + */ |
|
296 | + public function setParameter($key, $value, $type = null) { |
|
297 | + $this->queryBuilder->setParameter($key, $value, $type); |
|
298 | + |
|
299 | + return $this; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Sets a collection of query parameters for the query being constructed. |
|
304 | + * |
|
305 | + * <code> |
|
306 | + * $qb = $conn->getQueryBuilder() |
|
307 | + * ->select('u') |
|
308 | + * ->from('users', 'u') |
|
309 | + * ->where('u.id = :user_id1 OR u.id = :user_id2') |
|
310 | + * ->setParameters(array( |
|
311 | + * ':user_id1' => 1, |
|
312 | + * ':user_id2' => 2 |
|
313 | + * )); |
|
314 | + * </code> |
|
315 | + * |
|
316 | + * @param array $params The query parameters to set. |
|
317 | + * @param array $types The query parameters types to set. |
|
318 | + * |
|
319 | + * @return $this This QueryBuilder instance. |
|
320 | + */ |
|
321 | + public function setParameters(array $params, array $types = []) { |
|
322 | + $this->queryBuilder->setParameters($params, $types); |
|
323 | + |
|
324 | + return $this; |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Gets all defined query parameters for the query being constructed indexed by parameter index or name. |
|
329 | + * |
|
330 | + * @return array The currently defined query parameters indexed by parameter index or name. |
|
331 | + */ |
|
332 | + public function getParameters() { |
|
333 | + return $this->queryBuilder->getParameters(); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Gets a (previously set) query parameter of the query being constructed. |
|
338 | + * |
|
339 | + * @param mixed $key The key (index or name) of the bound parameter. |
|
340 | + * |
|
341 | + * @return mixed The value of the bound parameter. |
|
342 | + */ |
|
343 | + public function getParameter($key) { |
|
344 | + return $this->queryBuilder->getParameter($key); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Gets all defined query parameter types for the query being constructed indexed by parameter index or name. |
|
349 | + * |
|
350 | + * @return array The currently defined query parameter types indexed by parameter index or name. |
|
351 | + */ |
|
352 | + public function getParameterTypes() { |
|
353 | + return $this->queryBuilder->getParameterTypes(); |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Gets a (previously set) query parameter type of the query being constructed. |
|
358 | + * |
|
359 | + * @param mixed $key The key (index or name) of the bound parameter type. |
|
360 | + * |
|
361 | + * @return mixed The value of the bound parameter type. |
|
362 | + */ |
|
363 | + public function getParameterType($key) { |
|
364 | + return $this->queryBuilder->getParameterType($key); |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Sets the position of the first result to retrieve (the "offset"). |
|
369 | + * |
|
370 | + * @param integer $firstResult The first result to return. |
|
371 | + * |
|
372 | + * @return $this This QueryBuilder instance. |
|
373 | + */ |
|
374 | + public function setFirstResult($firstResult) { |
|
375 | + $this->queryBuilder->setFirstResult($firstResult); |
|
376 | + |
|
377 | + return $this; |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Gets the position of the first result the query object was set to retrieve (the "offset"). |
|
382 | + * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder. |
|
383 | + * |
|
384 | + * @return integer The position of the first result. |
|
385 | + */ |
|
386 | + public function getFirstResult() { |
|
387 | + return $this->queryBuilder->getFirstResult(); |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Sets the maximum number of results to retrieve (the "limit"). |
|
392 | + * |
|
393 | + * NOTE: Setting max results to "0" will cause mixed behaviour. While most |
|
394 | + * of the databases will just return an empty result set, Oracle will return |
|
395 | + * all entries. |
|
396 | + * |
|
397 | + * @param integer $maxResults The maximum number of results to retrieve. |
|
398 | + * |
|
399 | + * @return $this This QueryBuilder instance. |
|
400 | + */ |
|
401 | + public function setMaxResults($maxResults) { |
|
402 | + $this->queryBuilder->setMaxResults($maxResults); |
|
403 | + |
|
404 | + return $this; |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Gets the maximum number of results the query object was set to retrieve (the "limit"). |
|
409 | + * Returns NULL if {@link setMaxResults} was not applied to this query builder. |
|
410 | + * |
|
411 | + * @return int|null The maximum number of results. |
|
412 | + */ |
|
413 | + public function getMaxResults() { |
|
414 | + return $this->queryBuilder->getMaxResults(); |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * Specifies an item that is to be returned in the query result. |
|
419 | + * Replaces any previously specified selections, if any. |
|
420 | + * |
|
421 | + * <code> |
|
422 | + * $qb = $conn->getQueryBuilder() |
|
423 | + * ->select('u.id', 'p.id') |
|
424 | + * ->from('users', 'u') |
|
425 | + * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
426 | + * </code> |
|
427 | + * |
|
428 | + * @param mixed ...$selects The selection expressions. |
|
429 | + * |
|
430 | + * '@return $this This QueryBuilder instance. |
|
431 | + */ |
|
432 | + public function select(...$selects) { |
|
433 | + if (count($selects) === 1 && is_array($selects[0])) { |
|
434 | + $selects = $selects[0]; |
|
435 | + } |
|
436 | + |
|
437 | + $this->queryBuilder->select( |
|
438 | + $this->helper->quoteColumnNames($selects) |
|
439 | + ); |
|
440 | + |
|
441 | + return $this; |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Specifies an item that is to be returned with a different name in the query result. |
|
446 | + * |
|
447 | + * <code> |
|
448 | + * $qb = $conn->getQueryBuilder() |
|
449 | + * ->selectAlias('u.id', 'user_id') |
|
450 | + * ->from('users', 'u') |
|
451 | + * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
452 | + * </code> |
|
453 | + * |
|
454 | + * @param mixed $select The selection expressions. |
|
455 | + * @param string $alias The column alias used in the constructed query. |
|
456 | + * |
|
457 | + * @return $this This QueryBuilder instance. |
|
458 | + */ |
|
459 | + public function selectAlias($select, $alias) { |
|
460 | + $this->queryBuilder->addSelect( |
|
461 | + $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias) |
|
462 | + ); |
|
463 | + |
|
464 | + return $this; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Specifies an item that is to be returned uniquely in the query result. |
|
469 | + * |
|
470 | + * <code> |
|
471 | + * $qb = $conn->getQueryBuilder() |
|
472 | + * ->selectDistinct('type') |
|
473 | + * ->from('users'); |
|
474 | + * </code> |
|
475 | + * |
|
476 | + * @param mixed $select The selection expressions. |
|
477 | + * |
|
478 | + * @return $this This QueryBuilder instance. |
|
479 | + */ |
|
480 | + public function selectDistinct($select) { |
|
481 | + if (!is_array($select)) { |
|
482 | + $select = [$select]; |
|
483 | + } |
|
484 | + |
|
485 | + $quotedSelect = $this->helper->quoteColumnNames($select); |
|
486 | + |
|
487 | + $this->queryBuilder->addSelect( |
|
488 | + 'DISTINCT ' . implode(', ', $quotedSelect) |
|
489 | + ); |
|
490 | + |
|
491 | + return $this; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * Adds an item that is to be returned in the query result. |
|
496 | + * |
|
497 | + * <code> |
|
498 | + * $qb = $conn->getQueryBuilder() |
|
499 | + * ->select('u.id') |
|
500 | + * ->addSelect('p.id') |
|
501 | + * ->from('users', 'u') |
|
502 | + * ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id'); |
|
503 | + * </code> |
|
504 | + * |
|
505 | + * @param mixed ...$selects The selection expression. |
|
506 | + * |
|
507 | + * @return $this This QueryBuilder instance. |
|
508 | + */ |
|
509 | + public function addSelect(...$selects) { |
|
510 | + if (count($selects) === 1 && is_array($selects[0])) { |
|
511 | + $selects = $selects[0]; |
|
512 | + } |
|
513 | + |
|
514 | + $this->queryBuilder->addSelect( |
|
515 | + $this->helper->quoteColumnNames($selects) |
|
516 | + ); |
|
517 | + |
|
518 | + return $this; |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * Turns the query being built into a bulk delete query that ranges over |
|
523 | + * a certain table. |
|
524 | + * |
|
525 | + * <code> |
|
526 | + * $qb = $conn->getQueryBuilder() |
|
527 | + * ->delete('users', 'u') |
|
528 | + * ->where('u.id = :user_id'); |
|
529 | + * ->setParameter(':user_id', 1); |
|
530 | + * </code> |
|
531 | + * |
|
532 | + * @param string $delete The table whose rows are subject to the deletion. |
|
533 | + * @param string $alias The table alias used in the constructed query. |
|
534 | + * |
|
535 | + * @return $this This QueryBuilder instance. |
|
536 | + */ |
|
537 | + public function delete($delete = null, $alias = null) { |
|
538 | + $this->queryBuilder->delete( |
|
539 | + $this->getTableName($delete), |
|
540 | + $alias |
|
541 | + ); |
|
542 | + |
|
543 | + return $this; |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Turns the query being built into a bulk update query that ranges over |
|
548 | + * a certain table |
|
549 | + * |
|
550 | + * <code> |
|
551 | + * $qb = $conn->getQueryBuilder() |
|
552 | + * ->update('users', 'u') |
|
553 | + * ->set('u.password', md5('password')) |
|
554 | + * ->where('u.id = ?'); |
|
555 | + * </code> |
|
556 | + * |
|
557 | + * @param string $update The table whose rows are subject to the update. |
|
558 | + * @param string $alias The table alias used in the constructed query. |
|
559 | + * |
|
560 | + * @return $this This QueryBuilder instance. |
|
561 | + */ |
|
562 | + public function update($update = null, $alias = null) { |
|
563 | + $this->queryBuilder->update( |
|
564 | + $this->getTableName($update), |
|
565 | + $alias |
|
566 | + ); |
|
567 | + |
|
568 | + return $this; |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Turns the query being built into an insert query that inserts into |
|
573 | + * a certain table |
|
574 | + * |
|
575 | + * <code> |
|
576 | + * $qb = $conn->getQueryBuilder() |
|
577 | + * ->insert('users') |
|
578 | + * ->values( |
|
579 | + * array( |
|
580 | + * 'name' => '?', |
|
581 | + * 'password' => '?' |
|
582 | + * ) |
|
583 | + * ); |
|
584 | + * </code> |
|
585 | + * |
|
586 | + * @param string $insert The table into which the rows should be inserted. |
|
587 | + * |
|
588 | + * @return $this This QueryBuilder instance. |
|
589 | + */ |
|
590 | + public function insert($insert = null) { |
|
591 | + $this->queryBuilder->insert( |
|
592 | + $this->getTableName($insert) |
|
593 | + ); |
|
594 | + |
|
595 | + $this->lastInsertedTable = $insert; |
|
596 | + |
|
597 | + return $this; |
|
598 | + } |
|
599 | + |
|
600 | + /** |
|
601 | + * Creates and adds a query root corresponding to the table identified by the |
|
602 | + * given alias, forming a cartesian product with any existing query roots. |
|
603 | + * |
|
604 | + * <code> |
|
605 | + * $qb = $conn->getQueryBuilder() |
|
606 | + * ->select('u.id') |
|
607 | + * ->from('users', 'u') |
|
608 | + * </code> |
|
609 | + * |
|
610 | + * @param string $from The table. |
|
611 | + * @param string|null $alias The alias of the table. |
|
612 | + * |
|
613 | + * @return $this This QueryBuilder instance. |
|
614 | + */ |
|
615 | + public function from($from, $alias = null) { |
|
616 | + $this->queryBuilder->from( |
|
617 | + $this->getTableName($from), |
|
618 | + $this->quoteAlias($alias) |
|
619 | + ); |
|
620 | + |
|
621 | + return $this; |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Creates and adds a join to the query. |
|
626 | + * |
|
627 | + * <code> |
|
628 | + * $qb = $conn->getQueryBuilder() |
|
629 | + * ->select('u.name') |
|
630 | + * ->from('users', 'u') |
|
631 | + * ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
632 | + * </code> |
|
633 | + * |
|
634 | + * @param string $fromAlias The alias that points to a from clause. |
|
635 | + * @param string $join The table name to join. |
|
636 | + * @param string $alias The alias of the join table. |
|
637 | + * @param string $condition The condition for the join. |
|
638 | + * |
|
639 | + * @return $this This QueryBuilder instance. |
|
640 | + */ |
|
641 | + public function join($fromAlias, $join, $alias, $condition = null) { |
|
642 | + $this->queryBuilder->join( |
|
643 | + $this->quoteAlias($fromAlias), |
|
644 | + $this->getTableName($join), |
|
645 | + $this->quoteAlias($alias), |
|
646 | + $condition |
|
647 | + ); |
|
648 | + |
|
649 | + return $this; |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Creates and adds a join to the query. |
|
654 | + * |
|
655 | + * <code> |
|
656 | + * $qb = $conn->getQueryBuilder() |
|
657 | + * ->select('u.name') |
|
658 | + * ->from('users', 'u') |
|
659 | + * ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
660 | + * </code> |
|
661 | + * |
|
662 | + * @param string $fromAlias The alias that points to a from clause. |
|
663 | + * @param string $join The table name to join. |
|
664 | + * @param string $alias The alias of the join table. |
|
665 | + * @param string $condition The condition for the join. |
|
666 | + * |
|
667 | + * @return $this This QueryBuilder instance. |
|
668 | + */ |
|
669 | + public function innerJoin($fromAlias, $join, $alias, $condition = null) { |
|
670 | + $this->queryBuilder->innerJoin( |
|
671 | + $this->quoteAlias($fromAlias), |
|
672 | + $this->getTableName($join), |
|
673 | + $this->quoteAlias($alias), |
|
674 | + $condition |
|
675 | + ); |
|
676 | + |
|
677 | + return $this; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Creates and adds a left join to the query. |
|
682 | + * |
|
683 | + * <code> |
|
684 | + * $qb = $conn->getQueryBuilder() |
|
685 | + * ->select('u.name') |
|
686 | + * ->from('users', 'u') |
|
687 | + * ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
688 | + * </code> |
|
689 | + * |
|
690 | + * @param string $fromAlias The alias that points to a from clause. |
|
691 | + * @param string $join The table name to join. |
|
692 | + * @param string $alias The alias of the join table. |
|
693 | + * @param string $condition The condition for the join. |
|
694 | + * |
|
695 | + * @return $this This QueryBuilder instance. |
|
696 | + */ |
|
697 | + public function leftJoin($fromAlias, $join, $alias, $condition = null) { |
|
698 | + $this->queryBuilder->leftJoin( |
|
699 | + $this->quoteAlias($fromAlias), |
|
700 | + $this->getTableName($join), |
|
701 | + $this->quoteAlias($alias), |
|
702 | + $condition |
|
703 | + ); |
|
704 | + |
|
705 | + return $this; |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Creates and adds a right join to the query. |
|
710 | + * |
|
711 | + * <code> |
|
712 | + * $qb = $conn->getQueryBuilder() |
|
713 | + * ->select('u.name') |
|
714 | + * ->from('users', 'u') |
|
715 | + * ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
716 | + * </code> |
|
717 | + * |
|
718 | + * @param string $fromAlias The alias that points to a from clause. |
|
719 | + * @param string $join The table name to join. |
|
720 | + * @param string $alias The alias of the join table. |
|
721 | + * @param string $condition The condition for the join. |
|
722 | + * |
|
723 | + * @return $this This QueryBuilder instance. |
|
724 | + */ |
|
725 | + public function rightJoin($fromAlias, $join, $alias, $condition = null) { |
|
726 | + $this->queryBuilder->rightJoin( |
|
727 | + $this->quoteAlias($fromAlias), |
|
728 | + $this->getTableName($join), |
|
729 | + $this->quoteAlias($alias), |
|
730 | + $condition |
|
731 | + ); |
|
732 | + |
|
733 | + return $this; |
|
734 | + } |
|
735 | + |
|
736 | + /** |
|
737 | + * Sets a new value for a column in a bulk update query. |
|
738 | + * |
|
739 | + * <code> |
|
740 | + * $qb = $conn->getQueryBuilder() |
|
741 | + * ->update('users', 'u') |
|
742 | + * ->set('u.password', md5('password')) |
|
743 | + * ->where('u.id = ?'); |
|
744 | + * </code> |
|
745 | + * |
|
746 | + * @param string $key The column to set. |
|
747 | + * @param ILiteral|IParameter|IQueryFunction|string $value The value, expression, placeholder, etc. |
|
748 | + * |
|
749 | + * @return $this This QueryBuilder instance. |
|
750 | + */ |
|
751 | + public function set($key, $value) { |
|
752 | + $this->queryBuilder->set( |
|
753 | + $this->helper->quoteColumnName($key), |
|
754 | + $this->helper->quoteColumnName($value) |
|
755 | + ); |
|
756 | + |
|
757 | + return $this; |
|
758 | + } |
|
759 | + |
|
760 | + /** |
|
761 | + * Specifies one or more restrictions to the query result. |
|
762 | + * Replaces any previously specified restrictions, if any. |
|
763 | + * |
|
764 | + * <code> |
|
765 | + * $qb = $conn->getQueryBuilder() |
|
766 | + * ->select('u.name') |
|
767 | + * ->from('users', 'u') |
|
768 | + * ->where('u.id = ?'); |
|
769 | + * |
|
770 | + * // You can optionally programatically build and/or expressions |
|
771 | + * $qb = $conn->getQueryBuilder(); |
|
772 | + * |
|
773 | + * $or = $qb->expr()->orx(); |
|
774 | + * $or->add($qb->expr()->eq('u.id', 1)); |
|
775 | + * $or->add($qb->expr()->eq('u.id', 2)); |
|
776 | + * |
|
777 | + * $qb->update('users', 'u') |
|
778 | + * ->set('u.password', md5('password')) |
|
779 | + * ->where($or); |
|
780 | + * </code> |
|
781 | + * |
|
782 | + * @param mixed ...$predicates The restriction predicates. |
|
783 | + * |
|
784 | + * @return $this This QueryBuilder instance. |
|
785 | + */ |
|
786 | + public function where(...$predicates) { |
|
787 | + call_user_func_array( |
|
788 | + [$this->queryBuilder, 'where'], |
|
789 | + $predicates |
|
790 | + ); |
|
791 | + |
|
792 | + return $this; |
|
793 | + } |
|
794 | + |
|
795 | + /** |
|
796 | + * Adds one or more restrictions to the query results, forming a logical |
|
797 | + * conjunction with any previously specified restrictions. |
|
798 | + * |
|
799 | + * <code> |
|
800 | + * $qb = $conn->getQueryBuilder() |
|
801 | + * ->select('u') |
|
802 | + * ->from('users', 'u') |
|
803 | + * ->where('u.username LIKE ?') |
|
804 | + * ->andWhere('u.is_active = 1'); |
|
805 | + * </code> |
|
806 | + * |
|
807 | + * @param mixed ...$where The query restrictions. |
|
808 | + * |
|
809 | + * @return $this This QueryBuilder instance. |
|
810 | + * |
|
811 | + * @see where() |
|
812 | + */ |
|
813 | + public function andWhere(...$where) { |
|
814 | + call_user_func_array( |
|
815 | + [$this->queryBuilder, 'andWhere'], |
|
816 | + $where |
|
817 | + ); |
|
818 | + |
|
819 | + return $this; |
|
820 | + } |
|
821 | + |
|
822 | + /** |
|
823 | + * Adds one or more restrictions to the query results, forming a logical |
|
824 | + * disjunction with any previously specified restrictions. |
|
825 | + * |
|
826 | + * <code> |
|
827 | + * $qb = $conn->getQueryBuilder() |
|
828 | + * ->select('u.name') |
|
829 | + * ->from('users', 'u') |
|
830 | + * ->where('u.id = 1') |
|
831 | + * ->orWhere('u.id = 2'); |
|
832 | + * </code> |
|
833 | + * |
|
834 | + * @param mixed ...$where The WHERE statement. |
|
835 | + * |
|
836 | + * @return $this This QueryBuilder instance. |
|
837 | + * |
|
838 | + * @see where() |
|
839 | + */ |
|
840 | + public function orWhere(...$where) { |
|
841 | + call_user_func_array( |
|
842 | + [$this->queryBuilder, 'orWhere'], |
|
843 | + $where |
|
844 | + ); |
|
845 | + |
|
846 | + return $this; |
|
847 | + } |
|
848 | + |
|
849 | + /** |
|
850 | + * Specifies a grouping over the results of the query. |
|
851 | + * Replaces any previously specified groupings, if any. |
|
852 | + * |
|
853 | + * <code> |
|
854 | + * $qb = $conn->getQueryBuilder() |
|
855 | + * ->select('u.name') |
|
856 | + * ->from('users', 'u') |
|
857 | + * ->groupBy('u.id'); |
|
858 | + * </code> |
|
859 | + * |
|
860 | + * @param mixed ...$groupBys The grouping expression. |
|
861 | + * |
|
862 | + * @return $this This QueryBuilder instance. |
|
863 | + */ |
|
864 | + public function groupBy(...$groupBys) { |
|
865 | + if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
866 | + $groupBys = $groupBys[0]; |
|
867 | + } |
|
868 | + |
|
869 | + call_user_func_array( |
|
870 | + [$this->queryBuilder, 'groupBy'], |
|
871 | + $this->helper->quoteColumnNames($groupBys) |
|
872 | + ); |
|
873 | + |
|
874 | + return $this; |
|
875 | + } |
|
876 | + |
|
877 | + /** |
|
878 | + * Adds a grouping expression to the query. |
|
879 | + * |
|
880 | + * <code> |
|
881 | + * $qb = $conn->getQueryBuilder() |
|
882 | + * ->select('u.name') |
|
883 | + * ->from('users', 'u') |
|
884 | + * ->groupBy('u.lastLogin'); |
|
885 | + * ->addGroupBy('u.createdAt') |
|
886 | + * </code> |
|
887 | + * |
|
888 | + * @param mixed ...$groupBy The grouping expression. |
|
889 | + * |
|
890 | + * @return $this This QueryBuilder instance. |
|
891 | + */ |
|
892 | + public function addGroupBy(...$groupBys) { |
|
893 | + if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
894 | + $$groupBys = $groupBys[0]; |
|
895 | + } |
|
896 | + |
|
897 | + call_user_func_array( |
|
898 | + [$this->queryBuilder, 'addGroupBy'], |
|
899 | + $this->helper->quoteColumnNames($groupBys) |
|
900 | + ); |
|
901 | + |
|
902 | + return $this; |
|
903 | + } |
|
904 | + |
|
905 | + /** |
|
906 | + * Sets a value for a column in an insert query. |
|
907 | + * |
|
908 | + * <code> |
|
909 | + * $qb = $conn->getQueryBuilder() |
|
910 | + * ->insert('users') |
|
911 | + * ->values( |
|
912 | + * array( |
|
913 | + * 'name' => '?' |
|
914 | + * ) |
|
915 | + * ) |
|
916 | + * ->setValue('password', '?'); |
|
917 | + * </code> |
|
918 | + * |
|
919 | + * @param string $column The column into which the value should be inserted. |
|
920 | + * @param IParameter|string $value The value that should be inserted into the column. |
|
921 | + * |
|
922 | + * @return $this This QueryBuilder instance. |
|
923 | + */ |
|
924 | + public function setValue($column, $value) { |
|
925 | + $this->queryBuilder->setValue( |
|
926 | + $this->helper->quoteColumnName($column), |
|
927 | + (string) $value |
|
928 | + ); |
|
929 | + |
|
930 | + return $this; |
|
931 | + } |
|
932 | + |
|
933 | + /** |
|
934 | + * Specifies values for an insert query indexed by column names. |
|
935 | + * Replaces any previous values, if any. |
|
936 | + * |
|
937 | + * <code> |
|
938 | + * $qb = $conn->getQueryBuilder() |
|
939 | + * ->insert('users') |
|
940 | + * ->values( |
|
941 | + * array( |
|
942 | + * 'name' => '?', |
|
943 | + * 'password' => '?' |
|
944 | + * ) |
|
945 | + * ); |
|
946 | + * </code> |
|
947 | + * |
|
948 | + * @param array $values The values to specify for the insert query indexed by column names. |
|
949 | + * |
|
950 | + * @return $this This QueryBuilder instance. |
|
951 | + */ |
|
952 | + public function values(array $values) { |
|
953 | + $quotedValues = []; |
|
954 | + foreach ($values as $key => $value) { |
|
955 | + $quotedValues[$this->helper->quoteColumnName($key)] = $value; |
|
956 | + } |
|
957 | + |
|
958 | + $this->queryBuilder->values($quotedValues); |
|
959 | + |
|
960 | + return $this; |
|
961 | + } |
|
962 | + |
|
963 | + /** |
|
964 | + * Specifies a restriction over the groups of the query. |
|
965 | + * Replaces any previous having restrictions, if any. |
|
966 | + * |
|
967 | + * @param mixed ...$having The restriction over the groups. |
|
968 | + * |
|
969 | + * @return $this This QueryBuilder instance. |
|
970 | + */ |
|
971 | + public function having(...$having) { |
|
972 | + call_user_func_array( |
|
973 | + [$this->queryBuilder, 'having'], |
|
974 | + $having |
|
975 | + ); |
|
976 | + |
|
977 | + return $this; |
|
978 | + } |
|
979 | + |
|
980 | + /** |
|
981 | + * Adds a restriction over the groups of the query, forming a logical |
|
982 | + * conjunction with any existing having restrictions. |
|
983 | + * |
|
984 | + * @param mixed ...$having The restriction to append. |
|
985 | + * |
|
986 | + * @return $this This QueryBuilder instance. |
|
987 | + */ |
|
988 | + public function andHaving(...$having) { |
|
989 | + call_user_func_array( |
|
990 | + [$this->queryBuilder, 'andHaving'], |
|
991 | + $having |
|
992 | + ); |
|
993 | + |
|
994 | + return $this; |
|
995 | + } |
|
996 | + |
|
997 | + /** |
|
998 | + * Adds a restriction over the groups of the query, forming a logical |
|
999 | + * disjunction with any existing having restrictions. |
|
1000 | + * |
|
1001 | + * @param mixed ...$having The restriction to add. |
|
1002 | + * |
|
1003 | + * @return $this This QueryBuilder instance. |
|
1004 | + */ |
|
1005 | + public function orHaving(...$having) { |
|
1006 | + call_user_func_array( |
|
1007 | + [$this->queryBuilder, 'orHaving'], |
|
1008 | + $having |
|
1009 | + ); |
|
1010 | + |
|
1011 | + return $this; |
|
1012 | + } |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * Specifies an ordering for the query results. |
|
1016 | + * Replaces any previously specified orderings, if any. |
|
1017 | + * |
|
1018 | + * @param string $sort The ordering expression. |
|
1019 | + * @param string $order The ordering direction. |
|
1020 | + * |
|
1021 | + * @return $this This QueryBuilder instance. |
|
1022 | + */ |
|
1023 | + public function orderBy($sort, $order = null) { |
|
1024 | + $this->queryBuilder->orderBy( |
|
1025 | + $this->helper->quoteColumnName($sort), |
|
1026 | + $order |
|
1027 | + ); |
|
1028 | + |
|
1029 | + return $this; |
|
1030 | + } |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * Adds an ordering to the query results. |
|
1034 | + * |
|
1035 | + * @param string $sort The ordering expression. |
|
1036 | + * @param string $order The ordering direction. |
|
1037 | + * |
|
1038 | + * @return $this This QueryBuilder instance. |
|
1039 | + */ |
|
1040 | + public function addOrderBy($sort, $order = null) { |
|
1041 | + $this->queryBuilder->addOrderBy( |
|
1042 | + $this->helper->quoteColumnName($sort), |
|
1043 | + $order |
|
1044 | + ); |
|
1045 | + |
|
1046 | + return $this; |
|
1047 | + } |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * Gets a query part by its name. |
|
1051 | + * |
|
1052 | + * @param string $queryPartName |
|
1053 | + * |
|
1054 | + * @return mixed |
|
1055 | + */ |
|
1056 | + public function getQueryPart($queryPartName) { |
|
1057 | + return $this->queryBuilder->getQueryPart($queryPartName); |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Gets all query parts. |
|
1062 | + * |
|
1063 | + * @return array |
|
1064 | + */ |
|
1065 | + public function getQueryParts() { |
|
1066 | + return $this->queryBuilder->getQueryParts(); |
|
1067 | + } |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * Resets SQL parts. |
|
1071 | + * |
|
1072 | + * @param array|null $queryPartNames |
|
1073 | + * |
|
1074 | + * @return $this This QueryBuilder instance. |
|
1075 | + */ |
|
1076 | + public function resetQueryParts($queryPartNames = null) { |
|
1077 | + $this->queryBuilder->resetQueryParts($queryPartNames); |
|
1078 | + |
|
1079 | + return $this; |
|
1080 | + } |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * Resets a single SQL part. |
|
1084 | + * |
|
1085 | + * @param string $queryPartName |
|
1086 | + * |
|
1087 | + * @return $this This QueryBuilder instance. |
|
1088 | + */ |
|
1089 | + public function resetQueryPart($queryPartName) { |
|
1090 | + $this->queryBuilder->resetQueryPart($queryPartName); |
|
1091 | + |
|
1092 | + return $this; |
|
1093 | + } |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * Creates a new named parameter and bind the value $value to it. |
|
1097 | + * |
|
1098 | + * This method provides a shortcut for PDOStatement::bindValue |
|
1099 | + * when using prepared statements. |
|
1100 | + * |
|
1101 | + * The parameter $value specifies the value that you want to bind. If |
|
1102 | + * $placeholder is not provided bindValue() will automatically create a |
|
1103 | + * placeholder for you. An automatic placeholder will be of the name |
|
1104 | + * ':dcValue1', ':dcValue2' etc. |
|
1105 | + * |
|
1106 | + * For more information see {@link https://www.php.net/pdostatement-bindparam} |
|
1107 | + * |
|
1108 | + * Example: |
|
1109 | + * <code> |
|
1110 | + * $value = 2; |
|
1111 | + * $q->eq( 'id', $q->bindValue( $value ) ); |
|
1112 | + * $stmt = $q->executeQuery(); // executed with 'id = 2' |
|
1113 | + * </code> |
|
1114 | + * |
|
1115 | + * @license New BSD License |
|
1116 | + * @link http://www.zetacomponents.org |
|
1117 | + * |
|
1118 | + * @param mixed $value |
|
1119 | + * @param mixed $type |
|
1120 | + * @param string $placeHolder The name to bind with. The string must start with a colon ':'. |
|
1121 | + * |
|
1122 | + * @return IParameter the placeholder name used. |
|
1123 | + */ |
|
1124 | + public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) { |
|
1125 | + return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder)); |
|
1126 | + } |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * Creates a new positional parameter and bind the given value to it. |
|
1130 | + * |
|
1131 | + * Attention: If you are using positional parameters with the query builder you have |
|
1132 | + * to be very careful to bind all parameters in the order they appear in the SQL |
|
1133 | + * statement , otherwise they get bound in the wrong order which can lead to serious |
|
1134 | + * bugs in your code. |
|
1135 | + * |
|
1136 | + * Example: |
|
1137 | + * <code> |
|
1138 | + * $qb = $conn->getQueryBuilder(); |
|
1139 | + * $qb->select('u.*') |
|
1140 | + * ->from('users', 'u') |
|
1141 | + * ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR)) |
|
1142 | + * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR)) |
|
1143 | + * </code> |
|
1144 | + * |
|
1145 | + * @param mixed $value |
|
1146 | + * @param integer $type |
|
1147 | + * |
|
1148 | + * @return IParameter |
|
1149 | + */ |
|
1150 | + public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) { |
|
1151 | + return new Parameter($this->queryBuilder->createPositionalParameter($value, $type)); |
|
1152 | + } |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * Creates a new parameter |
|
1156 | + * |
|
1157 | + * Example: |
|
1158 | + * <code> |
|
1159 | + * $qb = $conn->getQueryBuilder(); |
|
1160 | + * $qb->select('u.*') |
|
1161 | + * ->from('users', 'u') |
|
1162 | + * ->where('u.username = ' . $qb->createParameter('name')) |
|
1163 | + * ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR)) |
|
1164 | + * </code> |
|
1165 | + * |
|
1166 | + * @param string $name |
|
1167 | + * |
|
1168 | + * @return IParameter |
|
1169 | + */ |
|
1170 | + public function createParameter($name) { |
|
1171 | + return new Parameter(':' . $name); |
|
1172 | + } |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * Creates a new function |
|
1176 | + * |
|
1177 | + * Attention: Column names inside the call have to be quoted before hand |
|
1178 | + * |
|
1179 | + * Example: |
|
1180 | + * <code> |
|
1181 | + * $qb = $conn->getQueryBuilder(); |
|
1182 | + * $qb->select($qb->createFunction('COUNT(*)')) |
|
1183 | + * ->from('users', 'u') |
|
1184 | + * echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u |
|
1185 | + * </code> |
|
1186 | + * <code> |
|
1187 | + * $qb = $conn->getQueryBuilder(); |
|
1188 | + * $qb->select($qb->createFunction('COUNT(`column`)')) |
|
1189 | + * ->from('users', 'u') |
|
1190 | + * echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u |
|
1191 | + * </code> |
|
1192 | + * |
|
1193 | + * @param string $call |
|
1194 | + * |
|
1195 | + * @return IQueryFunction |
|
1196 | + */ |
|
1197 | + public function createFunction($call) { |
|
1198 | + return new QueryFunction($call); |
|
1199 | + } |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * Used to get the id of the last inserted element |
|
1203 | + * @return int |
|
1204 | + * @throws \BadMethodCallException When being called before an insert query has been run. |
|
1205 | + */ |
|
1206 | + public function getLastInsertId() { |
|
1207 | + if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) { |
|
1208 | + // lastInsertId() needs the prefix but no quotes |
|
1209 | + $table = $this->prefixTableName($this->lastInsertedTable); |
|
1210 | + return (int) $this->connection->lastInsertId($table); |
|
1211 | + } |
|
1212 | + |
|
1213 | + throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.'); |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * Returns the table name quoted and with database prefix as needed by the implementation |
|
1218 | + * |
|
1219 | + * @param string $table |
|
1220 | + * @return string |
|
1221 | + */ |
|
1222 | + public function getTableName($table) { |
|
1223 | + if ($table instanceof IQueryFunction) { |
|
1224 | + return (string) $table; |
|
1225 | + } |
|
1226 | + |
|
1227 | + $table = $this->prefixTableName($table); |
|
1228 | + return $this->helper->quoteColumnName($table); |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * Returns the table name with database prefix as needed by the implementation |
|
1233 | + * |
|
1234 | + * @param string $table |
|
1235 | + * @return string |
|
1236 | + */ |
|
1237 | + protected function prefixTableName($table) { |
|
1238 | + if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) { |
|
1239 | + return $table; |
|
1240 | + } |
|
1241 | + |
|
1242 | + return '*PREFIX*' . $table; |
|
1243 | + } |
|
1244 | + |
|
1245 | + /** |
|
1246 | + * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
1247 | + * |
|
1248 | + * @param string $column |
|
1249 | + * @param string $tableAlias |
|
1250 | + * @return string |
|
1251 | + */ |
|
1252 | + public function getColumnName($column, $tableAlias = '') { |
|
1253 | + if ($tableAlias !== '') { |
|
1254 | + $tableAlias .= '.'; |
|
1255 | + } |
|
1256 | + |
|
1257 | + return $this->helper->quoteColumnName($tableAlias . $column); |
|
1258 | + } |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
1262 | + * |
|
1263 | + * @param string $alias |
|
1264 | + * @return string |
|
1265 | + */ |
|
1266 | + public function quoteAlias($alias) { |
|
1267 | + if ($alias === '' || $alias === null) { |
|
1268 | + return $alias; |
|
1269 | + } |
|
1270 | + |
|
1271 | + return $this->helper->quoteColumnName($alias); |
|
1272 | + } |
|
1273 | 1273 | } |
@@ -41,396 +41,396 @@ |
||
41 | 41 | use OCP\IDBConnection; |
42 | 42 | |
43 | 43 | class ExpressionBuilder implements IExpressionBuilder { |
44 | - /** @var \Doctrine\DBAL\Query\Expression\ExpressionBuilder */ |
|
45 | - protected $expressionBuilder; |
|
44 | + /** @var \Doctrine\DBAL\Query\Expression\ExpressionBuilder */ |
|
45 | + protected $expressionBuilder; |
|
46 | 46 | |
47 | - /** @var QuoteHelper */ |
|
48 | - protected $helper; |
|
47 | + /** @var QuoteHelper */ |
|
48 | + protected $helper; |
|
49 | 49 | |
50 | - /** @var IDBConnection */ |
|
51 | - protected $connection; |
|
50 | + /** @var IDBConnection */ |
|
51 | + protected $connection; |
|
52 | 52 | |
53 | - /** @var FunctionBuilder */ |
|
54 | - protected $functionBuilder; |
|
53 | + /** @var FunctionBuilder */ |
|
54 | + protected $functionBuilder; |
|
55 | 55 | |
56 | - /** |
|
57 | - * Initializes a new <tt>ExpressionBuilder</tt>. |
|
58 | - * |
|
59 | - * @param ConnectionAdapter $connection |
|
60 | - * @param IQueryBuilder $queryBuilder |
|
61 | - */ |
|
62 | - public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder) { |
|
63 | - $this->connection = $connection; |
|
64 | - $this->helper = new QuoteHelper(); |
|
65 | - $this->expressionBuilder = new DoctrineExpressionBuilder($connection->getInner()); |
|
66 | - $this->functionBuilder = $queryBuilder->func(); |
|
67 | - } |
|
56 | + /** |
|
57 | + * Initializes a new <tt>ExpressionBuilder</tt>. |
|
58 | + * |
|
59 | + * @param ConnectionAdapter $connection |
|
60 | + * @param IQueryBuilder $queryBuilder |
|
61 | + */ |
|
62 | + public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder) { |
|
63 | + $this->connection = $connection; |
|
64 | + $this->helper = new QuoteHelper(); |
|
65 | + $this->expressionBuilder = new DoctrineExpressionBuilder($connection->getInner()); |
|
66 | + $this->functionBuilder = $queryBuilder->func(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Creates a conjunction of the given boolean expressions. |
|
71 | - * |
|
72 | - * Example: |
|
73 | - * |
|
74 | - * [php] |
|
75 | - * // (u.type = ?) AND (u.role = ?) |
|
76 | - * $expr->andX('u.type = ?', 'u.role = ?')); |
|
77 | - * |
|
78 | - * @param mixed ...$x Optional clause. Defaults = null, but requires |
|
79 | - * at least one defined when converting to string. |
|
80 | - * |
|
81 | - * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
82 | - */ |
|
83 | - public function andX(...$x) { |
|
84 | - $compositeExpression = call_user_func_array([$this->expressionBuilder, 'andX'], $x); |
|
85 | - return new CompositeExpression($compositeExpression); |
|
86 | - } |
|
69 | + /** |
|
70 | + * Creates a conjunction of the given boolean expressions. |
|
71 | + * |
|
72 | + * Example: |
|
73 | + * |
|
74 | + * [php] |
|
75 | + * // (u.type = ?) AND (u.role = ?) |
|
76 | + * $expr->andX('u.type = ?', 'u.role = ?')); |
|
77 | + * |
|
78 | + * @param mixed ...$x Optional clause. Defaults = null, but requires |
|
79 | + * at least one defined when converting to string. |
|
80 | + * |
|
81 | + * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
82 | + */ |
|
83 | + public function andX(...$x) { |
|
84 | + $compositeExpression = call_user_func_array([$this->expressionBuilder, 'andX'], $x); |
|
85 | + return new CompositeExpression($compositeExpression); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Creates a disjunction of the given boolean expressions. |
|
90 | - * |
|
91 | - * Example: |
|
92 | - * |
|
93 | - * [php] |
|
94 | - * // (u.type = ?) OR (u.role = ?) |
|
95 | - * $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?')); |
|
96 | - * |
|
97 | - * @param mixed ...$x Optional clause. Defaults = null, but requires |
|
98 | - * at least one defined when converting to string. |
|
99 | - * |
|
100 | - * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
101 | - */ |
|
102 | - public function orX(...$x) { |
|
103 | - $compositeExpression = call_user_func_array([$this->expressionBuilder, 'orX'], $x); |
|
104 | - return new CompositeExpression($compositeExpression); |
|
105 | - } |
|
88 | + /** |
|
89 | + * Creates a disjunction of the given boolean expressions. |
|
90 | + * |
|
91 | + * Example: |
|
92 | + * |
|
93 | + * [php] |
|
94 | + * // (u.type = ?) OR (u.role = ?) |
|
95 | + * $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?')); |
|
96 | + * |
|
97 | + * @param mixed ...$x Optional clause. Defaults = null, but requires |
|
98 | + * at least one defined when converting to string. |
|
99 | + * |
|
100 | + * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
101 | + */ |
|
102 | + public function orX(...$x) { |
|
103 | + $compositeExpression = call_user_func_array([$this->expressionBuilder, 'orX'], $x); |
|
104 | + return new CompositeExpression($compositeExpression); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Creates a comparison expression. |
|
109 | - * |
|
110 | - * @param mixed $x The left expression. |
|
111 | - * @param string $operator One of the IExpressionBuilder::* constants. |
|
112 | - * @param mixed $y The right expression. |
|
113 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
114 | - * required when comparing text fields for oci compatibility |
|
115 | - * |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function comparison($x, $operator, $y, $type = null) { |
|
119 | - $x = $this->helper->quoteColumnName($x); |
|
120 | - $y = $this->helper->quoteColumnName($y); |
|
121 | - return $this->expressionBuilder->comparison($x, $operator, $y); |
|
122 | - } |
|
107 | + /** |
|
108 | + * Creates a comparison expression. |
|
109 | + * |
|
110 | + * @param mixed $x The left expression. |
|
111 | + * @param string $operator One of the IExpressionBuilder::* constants. |
|
112 | + * @param mixed $y The right expression. |
|
113 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
114 | + * required when comparing text fields for oci compatibility |
|
115 | + * |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function comparison($x, $operator, $y, $type = null) { |
|
119 | + $x = $this->helper->quoteColumnName($x); |
|
120 | + $y = $this->helper->quoteColumnName($y); |
|
121 | + return $this->expressionBuilder->comparison($x, $operator, $y); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Creates an equality comparison expression with the given arguments. |
|
126 | - * |
|
127 | - * First argument is considered the left expression and the second is the right expression. |
|
128 | - * When converted to string, it will generated a <left expr> = <right expr>. Example: |
|
129 | - * |
|
130 | - * [php] |
|
131 | - * // u.id = ? |
|
132 | - * $expr->eq('u.id', '?'); |
|
133 | - * |
|
134 | - * @param mixed $x The left expression. |
|
135 | - * @param mixed $y The right expression. |
|
136 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
137 | - * required when comparing text fields for oci compatibility |
|
138 | - * |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function eq($x, $y, $type = null) { |
|
142 | - $x = $this->helper->quoteColumnName($x); |
|
143 | - $y = $this->helper->quoteColumnName($y); |
|
144 | - return $this->expressionBuilder->eq($x, $y); |
|
145 | - } |
|
124 | + /** |
|
125 | + * Creates an equality comparison expression with the given arguments. |
|
126 | + * |
|
127 | + * First argument is considered the left expression and the second is the right expression. |
|
128 | + * When converted to string, it will generated a <left expr> = <right expr>. Example: |
|
129 | + * |
|
130 | + * [php] |
|
131 | + * // u.id = ? |
|
132 | + * $expr->eq('u.id', '?'); |
|
133 | + * |
|
134 | + * @param mixed $x The left expression. |
|
135 | + * @param mixed $y The right expression. |
|
136 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
137 | + * required when comparing text fields for oci compatibility |
|
138 | + * |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function eq($x, $y, $type = null) { |
|
142 | + $x = $this->helper->quoteColumnName($x); |
|
143 | + $y = $this->helper->quoteColumnName($y); |
|
144 | + return $this->expressionBuilder->eq($x, $y); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Creates a non equality comparison expression with the given arguments. |
|
149 | - * First argument is considered the left expression and the second is the right expression. |
|
150 | - * When converted to string, it will generated a <left expr> <> <right expr>. Example: |
|
151 | - * |
|
152 | - * [php] |
|
153 | - * // u.id <> 1 |
|
154 | - * $q->where($q->expr()->neq('u.id', '1')); |
|
155 | - * |
|
156 | - * @param mixed $x The left expression. |
|
157 | - * @param mixed $y The right expression. |
|
158 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
159 | - * required when comparing text fields for oci compatibility |
|
160 | - * |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - public function neq($x, $y, $type = null) { |
|
164 | - $x = $this->helper->quoteColumnName($x); |
|
165 | - $y = $this->helper->quoteColumnName($y); |
|
166 | - return $this->expressionBuilder->neq($x, $y); |
|
167 | - } |
|
147 | + /** |
|
148 | + * Creates a non equality comparison expression with the given arguments. |
|
149 | + * First argument is considered the left expression and the second is the right expression. |
|
150 | + * When converted to string, it will generated a <left expr> <> <right expr>. Example: |
|
151 | + * |
|
152 | + * [php] |
|
153 | + * // u.id <> 1 |
|
154 | + * $q->where($q->expr()->neq('u.id', '1')); |
|
155 | + * |
|
156 | + * @param mixed $x The left expression. |
|
157 | + * @param mixed $y The right expression. |
|
158 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
159 | + * required when comparing text fields for oci compatibility |
|
160 | + * |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + public function neq($x, $y, $type = null) { |
|
164 | + $x = $this->helper->quoteColumnName($x); |
|
165 | + $y = $this->helper->quoteColumnName($y); |
|
166 | + return $this->expressionBuilder->neq($x, $y); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Creates a lower-than comparison expression with the given arguments. |
|
171 | - * First argument is considered the left expression and the second is the right expression. |
|
172 | - * When converted to string, it will generated a <left expr> < <right expr>. Example: |
|
173 | - * |
|
174 | - * [php] |
|
175 | - * // u.id < ? |
|
176 | - * $q->where($q->expr()->lt('u.id', '?')); |
|
177 | - * |
|
178 | - * @param mixed $x The left expression. |
|
179 | - * @param mixed $y The right expression. |
|
180 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
181 | - * required when comparing text fields for oci compatibility |
|
182 | - * |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function lt($x, $y, $type = null) { |
|
186 | - $x = $this->helper->quoteColumnName($x); |
|
187 | - $y = $this->helper->quoteColumnName($y); |
|
188 | - return $this->expressionBuilder->lt($x, $y); |
|
189 | - } |
|
169 | + /** |
|
170 | + * Creates a lower-than comparison expression with the given arguments. |
|
171 | + * First argument is considered the left expression and the second is the right expression. |
|
172 | + * When converted to string, it will generated a <left expr> < <right expr>. Example: |
|
173 | + * |
|
174 | + * [php] |
|
175 | + * // u.id < ? |
|
176 | + * $q->where($q->expr()->lt('u.id', '?')); |
|
177 | + * |
|
178 | + * @param mixed $x The left expression. |
|
179 | + * @param mixed $y The right expression. |
|
180 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
181 | + * required when comparing text fields for oci compatibility |
|
182 | + * |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function lt($x, $y, $type = null) { |
|
186 | + $x = $this->helper->quoteColumnName($x); |
|
187 | + $y = $this->helper->quoteColumnName($y); |
|
188 | + return $this->expressionBuilder->lt($x, $y); |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Creates a lower-than-equal comparison expression with the given arguments. |
|
193 | - * First argument is considered the left expression and the second is the right expression. |
|
194 | - * When converted to string, it will generated a <left expr> <= <right expr>. Example: |
|
195 | - * |
|
196 | - * [php] |
|
197 | - * // u.id <= ? |
|
198 | - * $q->where($q->expr()->lte('u.id', '?')); |
|
199 | - * |
|
200 | - * @param mixed $x The left expression. |
|
201 | - * @param mixed $y The right expression. |
|
202 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
203 | - * required when comparing text fields for oci compatibility |
|
204 | - * |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function lte($x, $y, $type = null) { |
|
208 | - $x = $this->helper->quoteColumnName($x); |
|
209 | - $y = $this->helper->quoteColumnName($y); |
|
210 | - return $this->expressionBuilder->lte($x, $y); |
|
211 | - } |
|
191 | + /** |
|
192 | + * Creates a lower-than-equal comparison expression with the given arguments. |
|
193 | + * First argument is considered the left expression and the second is the right expression. |
|
194 | + * When converted to string, it will generated a <left expr> <= <right expr>. Example: |
|
195 | + * |
|
196 | + * [php] |
|
197 | + * // u.id <= ? |
|
198 | + * $q->where($q->expr()->lte('u.id', '?')); |
|
199 | + * |
|
200 | + * @param mixed $x The left expression. |
|
201 | + * @param mixed $y The right expression. |
|
202 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
203 | + * required when comparing text fields for oci compatibility |
|
204 | + * |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function lte($x, $y, $type = null) { |
|
208 | + $x = $this->helper->quoteColumnName($x); |
|
209 | + $y = $this->helper->quoteColumnName($y); |
|
210 | + return $this->expressionBuilder->lte($x, $y); |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * Creates a greater-than comparison expression with the given arguments. |
|
215 | - * First argument is considered the left expression and the second is the right expression. |
|
216 | - * When converted to string, it will generated a <left expr> > <right expr>. Example: |
|
217 | - * |
|
218 | - * [php] |
|
219 | - * // u.id > ? |
|
220 | - * $q->where($q->expr()->gt('u.id', '?')); |
|
221 | - * |
|
222 | - * @param mixed $x The left expression. |
|
223 | - * @param mixed $y The right expression. |
|
224 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
225 | - * required when comparing text fields for oci compatibility |
|
226 | - * |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function gt($x, $y, $type = null) { |
|
230 | - $x = $this->helper->quoteColumnName($x); |
|
231 | - $y = $this->helper->quoteColumnName($y); |
|
232 | - return $this->expressionBuilder->gt($x, $y); |
|
233 | - } |
|
213 | + /** |
|
214 | + * Creates a greater-than comparison expression with the given arguments. |
|
215 | + * First argument is considered the left expression and the second is the right expression. |
|
216 | + * When converted to string, it will generated a <left expr> > <right expr>. Example: |
|
217 | + * |
|
218 | + * [php] |
|
219 | + * // u.id > ? |
|
220 | + * $q->where($q->expr()->gt('u.id', '?')); |
|
221 | + * |
|
222 | + * @param mixed $x The left expression. |
|
223 | + * @param mixed $y The right expression. |
|
224 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
225 | + * required when comparing text fields for oci compatibility |
|
226 | + * |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function gt($x, $y, $type = null) { |
|
230 | + $x = $this->helper->quoteColumnName($x); |
|
231 | + $y = $this->helper->quoteColumnName($y); |
|
232 | + return $this->expressionBuilder->gt($x, $y); |
|
233 | + } |
|
234 | 234 | |
235 | - /** |
|
236 | - * Creates a greater-than-equal comparison expression with the given arguments. |
|
237 | - * First argument is considered the left expression and the second is the right expression. |
|
238 | - * When converted to string, it will generated a <left expr> >= <right expr>. Example: |
|
239 | - * |
|
240 | - * [php] |
|
241 | - * // u.id >= ? |
|
242 | - * $q->where($q->expr()->gte('u.id', '?')); |
|
243 | - * |
|
244 | - * @param mixed $x The left expression. |
|
245 | - * @param mixed $y The right expression. |
|
246 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
247 | - * required when comparing text fields for oci compatibility |
|
248 | - * |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function gte($x, $y, $type = null) { |
|
252 | - $x = $this->helper->quoteColumnName($x); |
|
253 | - $y = $this->helper->quoteColumnName($y); |
|
254 | - return $this->expressionBuilder->gte($x, $y); |
|
255 | - } |
|
235 | + /** |
|
236 | + * Creates a greater-than-equal comparison expression with the given arguments. |
|
237 | + * First argument is considered the left expression and the second is the right expression. |
|
238 | + * When converted to string, it will generated a <left expr> >= <right expr>. Example: |
|
239 | + * |
|
240 | + * [php] |
|
241 | + * // u.id >= ? |
|
242 | + * $q->where($q->expr()->gte('u.id', '?')); |
|
243 | + * |
|
244 | + * @param mixed $x The left expression. |
|
245 | + * @param mixed $y The right expression. |
|
246 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
247 | + * required when comparing text fields for oci compatibility |
|
248 | + * |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function gte($x, $y, $type = null) { |
|
252 | + $x = $this->helper->quoteColumnName($x); |
|
253 | + $y = $this->helper->quoteColumnName($y); |
|
254 | + return $this->expressionBuilder->gte($x, $y); |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Creates an IS NULL expression with the given arguments. |
|
259 | - * |
|
260 | - * @param string $x The field in string format to be restricted by IS NULL. |
|
261 | - * |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function isNull($x) { |
|
265 | - $x = $this->helper->quoteColumnName($x); |
|
266 | - return $this->expressionBuilder->isNull($x); |
|
267 | - } |
|
257 | + /** |
|
258 | + * Creates an IS NULL expression with the given arguments. |
|
259 | + * |
|
260 | + * @param string $x The field in string format to be restricted by IS NULL. |
|
261 | + * |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function isNull($x) { |
|
265 | + $x = $this->helper->quoteColumnName($x); |
|
266 | + return $this->expressionBuilder->isNull($x); |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * Creates an IS NOT NULL expression with the given arguments. |
|
271 | - * |
|
272 | - * @param string $x The field in string format to be restricted by IS NOT NULL. |
|
273 | - * |
|
274 | - * @return string |
|
275 | - */ |
|
276 | - public function isNotNull($x) { |
|
277 | - $x = $this->helper->quoteColumnName($x); |
|
278 | - return $this->expressionBuilder->isNotNull($x); |
|
279 | - } |
|
269 | + /** |
|
270 | + * Creates an IS NOT NULL expression with the given arguments. |
|
271 | + * |
|
272 | + * @param string $x The field in string format to be restricted by IS NOT NULL. |
|
273 | + * |
|
274 | + * @return string |
|
275 | + */ |
|
276 | + public function isNotNull($x) { |
|
277 | + $x = $this->helper->quoteColumnName($x); |
|
278 | + return $this->expressionBuilder->isNotNull($x); |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Creates a LIKE() comparison expression with the given arguments. |
|
283 | - * |
|
284 | - * @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by LIKE() comparison. |
|
285 | - * @param mixed $y Argument to be used in LIKE() comparison. |
|
286 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
287 | - * required when comparing text fields for oci compatibility |
|
288 | - * |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function like($x, $y, $type = null) { |
|
292 | - $x = $this->helper->quoteColumnName($x); |
|
293 | - $y = $this->helper->quoteColumnName($y); |
|
294 | - return $this->expressionBuilder->like($x, $y); |
|
295 | - } |
|
281 | + /** |
|
282 | + * Creates a LIKE() comparison expression with the given arguments. |
|
283 | + * |
|
284 | + * @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by LIKE() comparison. |
|
285 | + * @param mixed $y Argument to be used in LIKE() comparison. |
|
286 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
287 | + * required when comparing text fields for oci compatibility |
|
288 | + * |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function like($x, $y, $type = null) { |
|
292 | + $x = $this->helper->quoteColumnName($x); |
|
293 | + $y = $this->helper->quoteColumnName($y); |
|
294 | + return $this->expressionBuilder->like($x, $y); |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
298 | - * Creates a ILIKE() comparison expression with the given arguments. |
|
299 | - * |
|
300 | - * @param string $x Field in string format to be inspected by ILIKE() comparison. |
|
301 | - * @param mixed $y Argument to be used in ILIKE() comparison. |
|
302 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
303 | - * required when comparing text fields for oci compatibility |
|
304 | - * |
|
305 | - * @return string |
|
306 | - * @since 9.0.0 |
|
307 | - */ |
|
308 | - public function iLike($x, $y, $type = null) { |
|
309 | - return $this->expressionBuilder->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y)); |
|
310 | - } |
|
297 | + /** |
|
298 | + * Creates a ILIKE() comparison expression with the given arguments. |
|
299 | + * |
|
300 | + * @param string $x Field in string format to be inspected by ILIKE() comparison. |
|
301 | + * @param mixed $y Argument to be used in ILIKE() comparison. |
|
302 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
303 | + * required when comparing text fields for oci compatibility |
|
304 | + * |
|
305 | + * @return string |
|
306 | + * @since 9.0.0 |
|
307 | + */ |
|
308 | + public function iLike($x, $y, $type = null) { |
|
309 | + return $this->expressionBuilder->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y)); |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * Creates a NOT LIKE() comparison expression with the given arguments. |
|
314 | - * |
|
315 | - * @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by NOT LIKE() comparison. |
|
316 | - * @param mixed $y Argument to be used in NOT LIKE() comparison. |
|
317 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
318 | - * required when comparing text fields for oci compatibility |
|
319 | - * |
|
320 | - * @return string |
|
321 | - */ |
|
322 | - public function notLike($x, $y, $type = null) { |
|
323 | - $x = $this->helper->quoteColumnName($x); |
|
324 | - $y = $this->helper->quoteColumnName($y); |
|
325 | - return $this->expressionBuilder->notLike($x, $y); |
|
326 | - } |
|
312 | + /** |
|
313 | + * Creates a NOT LIKE() comparison expression with the given arguments. |
|
314 | + * |
|
315 | + * @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by NOT LIKE() comparison. |
|
316 | + * @param mixed $y Argument to be used in NOT LIKE() comparison. |
|
317 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
318 | + * required when comparing text fields for oci compatibility |
|
319 | + * |
|
320 | + * @return string |
|
321 | + */ |
|
322 | + public function notLike($x, $y, $type = null) { |
|
323 | + $x = $this->helper->quoteColumnName($x); |
|
324 | + $y = $this->helper->quoteColumnName($y); |
|
325 | + return $this->expressionBuilder->notLike($x, $y); |
|
326 | + } |
|
327 | 327 | |
328 | - /** |
|
329 | - * Creates a IN () comparison expression with the given arguments. |
|
330 | - * |
|
331 | - * @param ILiteral|IParameter|IQueryFunction|string $x The field in string format to be inspected by IN() comparison. |
|
332 | - * @param ILiteral|IParameter|IQueryFunction|string|array $y The placeholder or the array of values to be used by IN() comparison. |
|
333 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
334 | - * required when comparing text fields for oci compatibility |
|
335 | - * |
|
336 | - * @return string |
|
337 | - */ |
|
338 | - public function in($x, $y, $type = null) { |
|
339 | - $x = $this->helper->quoteColumnName($x); |
|
340 | - $y = $this->helper->quoteColumnNames($y); |
|
341 | - return $this->expressionBuilder->in($x, $y); |
|
342 | - } |
|
328 | + /** |
|
329 | + * Creates a IN () comparison expression with the given arguments. |
|
330 | + * |
|
331 | + * @param ILiteral|IParameter|IQueryFunction|string $x The field in string format to be inspected by IN() comparison. |
|
332 | + * @param ILiteral|IParameter|IQueryFunction|string|array $y The placeholder or the array of values to be used by IN() comparison. |
|
333 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
334 | + * required when comparing text fields for oci compatibility |
|
335 | + * |
|
336 | + * @return string |
|
337 | + */ |
|
338 | + public function in($x, $y, $type = null) { |
|
339 | + $x = $this->helper->quoteColumnName($x); |
|
340 | + $y = $this->helper->quoteColumnNames($y); |
|
341 | + return $this->expressionBuilder->in($x, $y); |
|
342 | + } |
|
343 | 343 | |
344 | - /** |
|
345 | - * Creates a NOT IN () comparison expression with the given arguments. |
|
346 | - * |
|
347 | - * @param ILiteral|IParameter|IQueryFunction|string $x The field in string format to be inspected by NOT IN() comparison. |
|
348 | - * @param ILiteral|IParameter|IQueryFunction|string|array $y The placeholder or the array of values to be used by NOT IN() comparison. |
|
349 | - * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
350 | - * required when comparing text fields for oci compatibility |
|
351 | - * |
|
352 | - * @return string |
|
353 | - */ |
|
354 | - public function notIn($x, $y, $type = null) { |
|
355 | - $x = $this->helper->quoteColumnName($x); |
|
356 | - $y = $this->helper->quoteColumnNames($y); |
|
357 | - return $this->expressionBuilder->notIn($x, $y); |
|
358 | - } |
|
344 | + /** |
|
345 | + * Creates a NOT IN () comparison expression with the given arguments. |
|
346 | + * |
|
347 | + * @param ILiteral|IParameter|IQueryFunction|string $x The field in string format to be inspected by NOT IN() comparison. |
|
348 | + * @param ILiteral|IParameter|IQueryFunction|string|array $y The placeholder or the array of values to be used by NOT IN() comparison. |
|
349 | + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants |
|
350 | + * required when comparing text fields for oci compatibility |
|
351 | + * |
|
352 | + * @return string |
|
353 | + */ |
|
354 | + public function notIn($x, $y, $type = null) { |
|
355 | + $x = $this->helper->quoteColumnName($x); |
|
356 | + $y = $this->helper->quoteColumnNames($y); |
|
357 | + return $this->expressionBuilder->notIn($x, $y); |
|
358 | + } |
|
359 | 359 | |
360 | - /** |
|
361 | - * Creates a $x = '' statement, because Oracle needs a different check |
|
362 | - * |
|
363 | - * @param string $x The field in string format to be inspected by the comparison. |
|
364 | - * @return string |
|
365 | - * @since 13.0.0 |
|
366 | - */ |
|
367 | - public function emptyString($x) { |
|
368 | - return $this->eq($x, $this->literal('', IQueryBuilder::PARAM_STR)); |
|
369 | - } |
|
360 | + /** |
|
361 | + * Creates a $x = '' statement, because Oracle needs a different check |
|
362 | + * |
|
363 | + * @param string $x The field in string format to be inspected by the comparison. |
|
364 | + * @return string |
|
365 | + * @since 13.0.0 |
|
366 | + */ |
|
367 | + public function emptyString($x) { |
|
368 | + return $this->eq($x, $this->literal('', IQueryBuilder::PARAM_STR)); |
|
369 | + } |
|
370 | 370 | |
371 | - /** |
|
372 | - * Creates a `$x <> ''` statement, because Oracle needs a different check |
|
373 | - * |
|
374 | - * @param string $x The field in string format to be inspected by the comparison. |
|
375 | - * @return string |
|
376 | - * @since 13.0.0 |
|
377 | - */ |
|
378 | - public function nonEmptyString($x) { |
|
379 | - return $this->neq($x, $this->literal('', IQueryBuilder::PARAM_STR)); |
|
380 | - } |
|
371 | + /** |
|
372 | + * Creates a `$x <> ''` statement, because Oracle needs a different check |
|
373 | + * |
|
374 | + * @param string $x The field in string format to be inspected by the comparison. |
|
375 | + * @return string |
|
376 | + * @since 13.0.0 |
|
377 | + */ |
|
378 | + public function nonEmptyString($x) { |
|
379 | + return $this->neq($x, $this->literal('', IQueryBuilder::PARAM_STR)); |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
383 | - * Binary AND Operator copies a bit to the result if it exists in both operands. |
|
384 | - * |
|
385 | - * @param string|ILiteral $x The field or value to check |
|
386 | - * @param int $y Bitmap that must be set |
|
387 | - * @return IQueryFunction |
|
388 | - * @since 12.0.0 |
|
389 | - */ |
|
390 | - public function bitwiseAnd($x, $y) { |
|
391 | - return new QueryFunction($this->connection->getDatabasePlatform()->getBitAndComparisonExpression( |
|
392 | - $this->helper->quoteColumnName($x), |
|
393 | - $y |
|
394 | - )); |
|
395 | - } |
|
382 | + /** |
|
383 | + * Binary AND Operator copies a bit to the result if it exists in both operands. |
|
384 | + * |
|
385 | + * @param string|ILiteral $x The field or value to check |
|
386 | + * @param int $y Bitmap that must be set |
|
387 | + * @return IQueryFunction |
|
388 | + * @since 12.0.0 |
|
389 | + */ |
|
390 | + public function bitwiseAnd($x, $y) { |
|
391 | + return new QueryFunction($this->connection->getDatabasePlatform()->getBitAndComparisonExpression( |
|
392 | + $this->helper->quoteColumnName($x), |
|
393 | + $y |
|
394 | + )); |
|
395 | + } |
|
396 | 396 | |
397 | - /** |
|
398 | - * Binary OR Operator copies a bit if it exists in either operand. |
|
399 | - * |
|
400 | - * @param string|ILiteral $x The field or value to check |
|
401 | - * @param int $y Bitmap that must be set |
|
402 | - * @return IQueryFunction |
|
403 | - * @since 12.0.0 |
|
404 | - */ |
|
405 | - public function bitwiseOr($x, $y) { |
|
406 | - return new QueryFunction($this->connection->getDatabasePlatform()->getBitOrComparisonExpression( |
|
407 | - $this->helper->quoteColumnName($x), |
|
408 | - $y |
|
409 | - )); |
|
410 | - } |
|
397 | + /** |
|
398 | + * Binary OR Operator copies a bit if it exists in either operand. |
|
399 | + * |
|
400 | + * @param string|ILiteral $x The field or value to check |
|
401 | + * @param int $y Bitmap that must be set |
|
402 | + * @return IQueryFunction |
|
403 | + * @since 12.0.0 |
|
404 | + */ |
|
405 | + public function bitwiseOr($x, $y) { |
|
406 | + return new QueryFunction($this->connection->getDatabasePlatform()->getBitOrComparisonExpression( |
|
407 | + $this->helper->quoteColumnName($x), |
|
408 | + $y |
|
409 | + )); |
|
410 | + } |
|
411 | 411 | |
412 | - /** |
|
413 | - * Quotes a given input parameter. |
|
414 | - * |
|
415 | - * @param mixed $input The parameter to be quoted. |
|
416 | - * @param mixed|null $type One of the IQueryBuilder::PARAM_* constants |
|
417 | - * |
|
418 | - * @return ILiteral |
|
419 | - */ |
|
420 | - public function literal($input, $type = null) { |
|
421 | - return new Literal($this->expressionBuilder->literal($input, $type)); |
|
422 | - } |
|
412 | + /** |
|
413 | + * Quotes a given input parameter. |
|
414 | + * |
|
415 | + * @param mixed $input The parameter to be quoted. |
|
416 | + * @param mixed|null $type One of the IQueryBuilder::PARAM_* constants |
|
417 | + * |
|
418 | + * @return ILiteral |
|
419 | + */ |
|
420 | + public function literal($input, $type = null) { |
|
421 | + return new Literal($this->expressionBuilder->literal($input, $type)); |
|
422 | + } |
|
423 | 423 | |
424 | - /** |
|
425 | - * Returns a IQueryFunction that casts the column to the given type |
|
426 | - * |
|
427 | - * @param string $column |
|
428 | - * @param mixed $type One of IQueryBuilder::PARAM_* |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public function castColumn($column, $type) { |
|
432 | - return new QueryFunction( |
|
433 | - $this->helper->quoteColumnName($column) |
|
434 | - ); |
|
435 | - } |
|
424 | + /** |
|
425 | + * Returns a IQueryFunction that casts the column to the given type |
|
426 | + * |
|
427 | + * @param string $column |
|
428 | + * @param mixed $type One of IQueryBuilder::PARAM_* |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public function castColumn($column, $type) { |
|
432 | + return new QueryFunction( |
|
433 | + $this->helper->quoteColumnName($column) |
|
434 | + ); |
|
435 | + } |
|
436 | 436 | } |
@@ -29,26 +29,26 @@ |
||
29 | 29 | |
30 | 30 | class MySqlExpressionBuilder extends ExpressionBuilder { |
31 | 31 | |
32 | - /** @var string */ |
|
33 | - protected $charset; |
|
32 | + /** @var string */ |
|
33 | + protected $charset; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param ConnectionAdapter $connection |
|
37 | - * @param IQueryBuilder $queryBuilder |
|
38 | - */ |
|
39 | - public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder) { |
|
40 | - parent::__construct($connection, $queryBuilder); |
|
35 | + /** |
|
36 | + * @param ConnectionAdapter $connection |
|
37 | + * @param IQueryBuilder $queryBuilder |
|
38 | + */ |
|
39 | + public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder) { |
|
40 | + parent::__construct($connection, $queryBuilder); |
|
41 | 41 | |
42 | - $params = $connection->getInner()->getParams(); |
|
43 | - $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; |
|
44 | - } |
|
42 | + $params = $connection->getInner()->getParams(); |
|
43 | + $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @inheritdoc |
|
48 | - */ |
|
49 | - public function iLike($x, $y, $type = null) { |
|
50 | - $x = $this->helper->quoteColumnName($x); |
|
51 | - $y = $this->helper->quoteColumnName($y); |
|
52 | - return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->charset . '_general_ci LIKE', $y); |
|
53 | - } |
|
46 | + /** |
|
47 | + * @inheritdoc |
|
48 | + */ |
|
49 | + public function iLike($x, $y, $type = null) { |
|
50 | + $x = $this->helper->quoteColumnName($x); |
|
51 | + $y = $this->helper->quoteColumnName($y); |
|
52 | + return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->charset . '_general_ci LIKE', $y); |
|
53 | + } |
|
54 | 54 | } |
@@ -31,42 +31,42 @@ |
||
31 | 31 | use Doctrine\DBAL\Events; |
32 | 32 | |
33 | 33 | class SQLiteSessionInit implements EventSubscriber { |
34 | - /** |
|
35 | - * @var bool |
|
36 | - */ |
|
37 | - private $caseSensitiveLike; |
|
34 | + /** |
|
35 | + * @var bool |
|
36 | + */ |
|
37 | + private $caseSensitiveLike; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private $journalMode; |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private $journalMode; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Configure case sensitive like for each connection |
|
46 | - * |
|
47 | - * @param bool $caseSensitiveLike |
|
48 | - * @param string $journalMode |
|
49 | - */ |
|
50 | - public function __construct($caseSensitiveLike, $journalMode) { |
|
51 | - $this->caseSensitiveLike = $caseSensitiveLike; |
|
52 | - $this->journalMode = $journalMode; |
|
53 | - } |
|
44 | + /** |
|
45 | + * Configure case sensitive like for each connection |
|
46 | + * |
|
47 | + * @param bool $caseSensitiveLike |
|
48 | + * @param string $journalMode |
|
49 | + */ |
|
50 | + public function __construct($caseSensitiveLike, $journalMode) { |
|
51 | + $this->caseSensitiveLike = $caseSensitiveLike; |
|
52 | + $this->journalMode = $journalMode; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param ConnectionEventArgs $args |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function postConnect(ConnectionEventArgs $args) { |
|
60 | - $sensitive = $this->caseSensitiveLike ? 'true' : 'false'; |
|
61 | - $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive); |
|
62 | - $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode); |
|
63 | - /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */ |
|
64 | - $connection = $args->getConnection()->getWrappedConnection(); |
|
65 | - $pdo = $connection->getWrappedConnection(); |
|
66 | - $pdo->sqliteCreateFunction('md5', 'md5', 1); |
|
67 | - } |
|
55 | + /** |
|
56 | + * @param ConnectionEventArgs $args |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function postConnect(ConnectionEventArgs $args) { |
|
60 | + $sensitive = $this->caseSensitiveLike ? 'true' : 'false'; |
|
61 | + $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive); |
|
62 | + $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode); |
|
63 | + /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */ |
|
64 | + $connection = $args->getConnection()->getWrappedConnection(); |
|
65 | + $pdo = $connection->getWrappedConnection(); |
|
66 | + $pdo->sqliteCreateFunction('md5', 'md5', 1); |
|
67 | + } |
|
68 | 68 | |
69 | - public function getSubscribedEvents() { |
|
70 | - return [Events::postConnect]; |
|
71 | - } |
|
69 | + public function getSubscribedEvents() { |
|
70 | + return [Events::postConnect]; |
|
71 | + } |
|
72 | 72 | } |
@@ -58,8 +58,8 @@ |
||
58 | 58 | */ |
59 | 59 | public function postConnect(ConnectionEventArgs $args) { |
60 | 60 | $sensitive = $this->caseSensitiveLike ? 'true' : 'false'; |
61 | - $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive); |
|
62 | - $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode); |
|
61 | + $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = '.$sensitive); |
|
62 | + $args->getConnection()->executeUpdate('PRAGMA journal_mode = '.$this->journalMode); |
|
63 | 63 | /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */ |
64 | 64 | $connection = $args->getConnection()->getWrappedConnection(); |
65 | 65 | $pdo = $connection->getWrappedConnection(); |
@@ -38,108 +38,108 @@ |
||
38 | 38 | */ |
39 | 39 | class Adapter { |
40 | 40 | |
41 | - /** |
|
42 | - * @var \OC\DB\Connection $conn |
|
43 | - */ |
|
44 | - protected $conn; |
|
41 | + /** |
|
42 | + * @var \OC\DB\Connection $conn |
|
43 | + */ |
|
44 | + protected $conn; |
|
45 | 45 | |
46 | - public function __construct($conn) { |
|
47 | - $this->conn = $conn; |
|
48 | - } |
|
46 | + public function __construct($conn) { |
|
47 | + $this->conn = $conn; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $table name |
|
52 | - * @return int id of last insert statement |
|
53 | - */ |
|
54 | - public function lastInsertId($table) { |
|
55 | - return (int) $this->conn->realLastInsertId($table); |
|
56 | - } |
|
50 | + /** |
|
51 | + * @param string $table name |
|
52 | + * @return int id of last insert statement |
|
53 | + */ |
|
54 | + public function lastInsertId($table) { |
|
55 | + return (int) $this->conn->realLastInsertId($table); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $statement that needs to be changed so the db can handle it |
|
60 | - * @return string changed statement |
|
61 | - */ |
|
62 | - public function fixupStatement($statement) { |
|
63 | - return $statement; |
|
64 | - } |
|
58 | + /** |
|
59 | + * @param string $statement that needs to be changed so the db can handle it |
|
60 | + * @return string changed statement |
|
61 | + */ |
|
62 | + public function fixupStatement($statement) { |
|
63 | + return $statement; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Create an exclusive read+write lock on a table |
|
68 | - * |
|
69 | - * @param string $tableName |
|
70 | - * @since 9.1.0 |
|
71 | - */ |
|
72 | - public function lockTable($tableName) { |
|
73 | - $this->conn->beginTransaction(); |
|
74 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
75 | - } |
|
66 | + /** |
|
67 | + * Create an exclusive read+write lock on a table |
|
68 | + * |
|
69 | + * @param string $tableName |
|
70 | + * @since 9.1.0 |
|
71 | + */ |
|
72 | + public function lockTable($tableName) { |
|
73 | + $this->conn->beginTransaction(); |
|
74 | + $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Release a previous acquired lock again |
|
79 | - * |
|
80 | - * @since 9.1.0 |
|
81 | - */ |
|
82 | - public function unlockTable() { |
|
83 | - $this->conn->commit(); |
|
84 | - } |
|
77 | + /** |
|
78 | + * Release a previous acquired lock again |
|
79 | + * |
|
80 | + * @since 9.1.0 |
|
81 | + */ |
|
82 | + public function unlockTable() { |
|
83 | + $this->conn->commit(); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
88 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
89 | - * catch the exception and return 0. |
|
90 | - * |
|
91 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
92 | - * @param array $input data that should be inserted into the table (column name => value) |
|
93 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
94 | - * If this is null or an empty array, all keys of $input will be compared |
|
95 | - * Please note: text fields (clob) must not be used in the compare array |
|
96 | - * @return int number of inserted rows |
|
97 | - * @throws \Doctrine\DBAL\Exception |
|
98 | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
99 | - */ |
|
100 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
101 | - if (empty($compare)) { |
|
102 | - $compare = array_keys($input); |
|
103 | - } |
|
104 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
105 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
106 | - . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
107 | - . 'FROM `' . $table . '` WHERE '; |
|
86 | + /** |
|
87 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
88 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
89 | + * catch the exception and return 0. |
|
90 | + * |
|
91 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
92 | + * @param array $input data that should be inserted into the table (column name => value) |
|
93 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
94 | + * If this is null or an empty array, all keys of $input will be compared |
|
95 | + * Please note: text fields (clob) must not be used in the compare array |
|
96 | + * @return int number of inserted rows |
|
97 | + * @throws \Doctrine\DBAL\Exception |
|
98 | + * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
99 | + */ |
|
100 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
101 | + if (empty($compare)) { |
|
102 | + $compare = array_keys($input); |
|
103 | + } |
|
104 | + $query = 'INSERT INTO `' .$table . '` (`' |
|
105 | + . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
106 | + . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
107 | + . 'FROM `' . $table . '` WHERE '; |
|
108 | 108 | |
109 | - $inserts = array_values($input); |
|
110 | - foreach ($compare as $key) { |
|
111 | - $query .= '`' . $key . '`'; |
|
112 | - if (is_null($input[$key])) { |
|
113 | - $query .= ' IS NULL AND '; |
|
114 | - } else { |
|
115 | - $inserts[] = $input[$key]; |
|
116 | - $query .= ' = ? AND '; |
|
117 | - } |
|
118 | - } |
|
119 | - $query = substr($query, 0, -5); |
|
120 | - $query .= ' HAVING COUNT(*) = 0'; |
|
109 | + $inserts = array_values($input); |
|
110 | + foreach ($compare as $key) { |
|
111 | + $query .= '`' . $key . '`'; |
|
112 | + if (is_null($input[$key])) { |
|
113 | + $query .= ' IS NULL AND '; |
|
114 | + } else { |
|
115 | + $inserts[] = $input[$key]; |
|
116 | + $query .= ' = ? AND '; |
|
117 | + } |
|
118 | + } |
|
119 | + $query = substr($query, 0, -5); |
|
120 | + $query .= ' HAVING COUNT(*) = 0'; |
|
121 | 121 | |
122 | - try { |
|
123 | - return $this->conn->executeUpdate($query, $inserts); |
|
124 | - } catch (UniqueConstraintViolationException $e) { |
|
125 | - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
126 | - // it's fine to ignore this then |
|
127 | - // |
|
128 | - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
129 | - return 0; |
|
130 | - } |
|
131 | - } |
|
122 | + try { |
|
123 | + return $this->conn->executeUpdate($query, $inserts); |
|
124 | + } catch (UniqueConstraintViolationException $e) { |
|
125 | + // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
126 | + // it's fine to ignore this then |
|
127 | + // |
|
128 | + // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
129 | + return 0; |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - public function insertIgnoreConflict(string $table,array $values) : int { |
|
134 | - try { |
|
135 | - $builder = $this->conn->getQueryBuilder(); |
|
136 | - $builder->insert($table); |
|
137 | - foreach ($values as $key => $value) { |
|
138 | - $builder->setValue($key, $builder->createNamedParameter($value)); |
|
139 | - } |
|
140 | - return $builder->execute(); |
|
141 | - } catch (UniqueConstraintViolationException $e) { |
|
142 | - return 0; |
|
143 | - } |
|
144 | - } |
|
133 | + public function insertIgnoreConflict(string $table,array $values) : int { |
|
134 | + try { |
|
135 | + $builder = $this->conn->getQueryBuilder(); |
|
136 | + $builder->insert($table); |
|
137 | + foreach ($values as $key => $value) { |
|
138 | + $builder->setValue($key, $builder->createNamedParameter($value)); |
|
139 | + } |
|
140 | + return $builder->execute(); |
|
141 | + } catch (UniqueConstraintViolationException $e) { |
|
142 | + return 0; |
|
143 | + } |
|
144 | + } |
|
145 | 145 | } |