@@ -248,1474 +248,1474 @@ |
||
| 248 | 248 | * TODO: hookup all manager classes |
| 249 | 249 | */ |
| 250 | 250 | class Server extends ServerContainer implements IServerContainer { |
| 251 | - /** @var string */ |
|
| 252 | - private $webRoot; |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param string $webRoot |
|
| 256 | - * @param \OC\Config $config |
|
| 257 | - */ |
|
| 258 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 259 | - parent::__construct(); |
|
| 260 | - $this->webRoot = $webRoot; |
|
| 261 | - |
|
| 262 | - // To find out if we are running from CLI or not |
|
| 263 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 264 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 265 | - |
|
| 266 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 267 | - return $c; |
|
| 268 | - }); |
|
| 269 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 270 | - return $c; |
|
| 271 | - }); |
|
| 272 | - |
|
| 273 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 274 | - |
|
| 275 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 276 | - |
|
| 277 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 278 | - |
|
| 279 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 280 | - |
|
| 281 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 282 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 283 | - $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 284 | - |
|
| 285 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 286 | - |
|
| 287 | - $this->registerService(View::class, function (Server $c) { |
|
| 288 | - return new View(); |
|
| 289 | - }, false); |
|
| 290 | - |
|
| 291 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 292 | - return new PreviewManager( |
|
| 293 | - $c->get(\OCP\IConfig::class), |
|
| 294 | - $c->get(IRootFolder::class), |
|
| 295 | - new \OC\Preview\Storage\Root( |
|
| 296 | - $c->get(IRootFolder::class), |
|
| 297 | - $c->get(SystemConfig::class) |
|
| 298 | - ), |
|
| 299 | - $c->get(IEventDispatcher::class), |
|
| 300 | - $c->get(GeneratorHelper::class), |
|
| 301 | - $c->get(ISession::class)->get('user_id'), |
|
| 302 | - $c->get(Coordinator::class), |
|
| 303 | - $c->get(IServerContainer::class), |
|
| 304 | - $c->get(IBinaryFinder::class), |
|
| 305 | - $c->get(IMagickSupport::class) |
|
| 306 | - ); |
|
| 307 | - }); |
|
| 308 | - $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 309 | - |
|
| 310 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 311 | - return new \OC\Preview\Watcher( |
|
| 312 | - new \OC\Preview\Storage\Root( |
|
| 313 | - $c->get(IRootFolder::class), |
|
| 314 | - $c->get(SystemConfig::class) |
|
| 315 | - ) |
|
| 316 | - ); |
|
| 317 | - }); |
|
| 318 | - |
|
| 319 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
| 320 | - return new Profiler($c->get(SystemConfig::class)); |
|
| 321 | - }); |
|
| 322 | - |
|
| 323 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager { |
|
| 324 | - $view = new View(); |
|
| 325 | - $util = new Encryption\Util( |
|
| 326 | - $view, |
|
| 327 | - $c->get(IUserManager::class), |
|
| 328 | - $c->get(IGroupManager::class), |
|
| 329 | - $c->get(\OCP\IConfig::class) |
|
| 330 | - ); |
|
| 331 | - return new Encryption\Manager( |
|
| 332 | - $c->get(\OCP\IConfig::class), |
|
| 333 | - $c->get(LoggerInterface::class), |
|
| 334 | - $c->getL10N('core'), |
|
| 335 | - new View(), |
|
| 336 | - $util, |
|
| 337 | - new ArrayCache() |
|
| 338 | - ); |
|
| 339 | - }); |
|
| 340 | - |
|
| 341 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 342 | - $util = new Encryption\Util( |
|
| 343 | - new View(), |
|
| 344 | - $c->get(IUserManager::class), |
|
| 345 | - $c->get(IGroupManager::class), |
|
| 346 | - $c->get(\OCP\IConfig::class) |
|
| 347 | - ); |
|
| 348 | - return new Encryption\File( |
|
| 349 | - $util, |
|
| 350 | - $c->get(IRootFolder::class), |
|
| 351 | - $c->get(\OCP\Share\IManager::class) |
|
| 352 | - ); |
|
| 353 | - }); |
|
| 354 | - |
|
| 355 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 356 | - $view = new View(); |
|
| 357 | - $util = new Encryption\Util( |
|
| 358 | - $view, |
|
| 359 | - $c->get(IUserManager::class), |
|
| 360 | - $c->get(IGroupManager::class), |
|
| 361 | - $c->get(\OCP\IConfig::class) |
|
| 362 | - ); |
|
| 363 | - |
|
| 364 | - return new Encryption\Keys\Storage( |
|
| 365 | - $view, |
|
| 366 | - $util, |
|
| 367 | - $c->get(ICrypto::class), |
|
| 368 | - $c->get(\OCP\IConfig::class) |
|
| 369 | - ); |
|
| 370 | - }); |
|
| 371 | - |
|
| 372 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 373 | - |
|
| 374 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 375 | - /** @var \OCP\IConfig $config */ |
|
| 376 | - $config = $c->get(\OCP\IConfig::class); |
|
| 377 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 378 | - return new $factoryClass($this); |
|
| 379 | - }); |
|
| 380 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 381 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 382 | - }); |
|
| 383 | - /** @deprecated 19.0.0 */ |
|
| 384 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 385 | - |
|
| 386 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 387 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 388 | - }); |
|
| 389 | - $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 390 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 391 | - $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 392 | - $view = new View(); |
|
| 393 | - /** @var IUserSession $userSession */ |
|
| 394 | - $userSession = $c->get(IUserSession::class); |
|
| 395 | - $root = new Root( |
|
| 396 | - $manager, |
|
| 397 | - $view, |
|
| 398 | - $userSession->getUser(), |
|
| 399 | - $c->get(IUserMountCache::class), |
|
| 400 | - $this->get(LoggerInterface::class), |
|
| 401 | - $this->get(IUserManager::class), |
|
| 402 | - $this->get(IEventDispatcher::class), |
|
| 403 | - $this->get(ICacheFactory::class), |
|
| 404 | - ); |
|
| 405 | - |
|
| 406 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 407 | - $root, |
|
| 408 | - $c->get(SystemConfig::class), |
|
| 409 | - $this->get(IEventDispatcher::class) |
|
| 410 | - ); |
|
| 411 | - $previewConnector->connectWatcher(); |
|
| 412 | - |
|
| 413 | - return $root; |
|
| 414 | - }); |
|
| 415 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 416 | - return new HookConnector( |
|
| 417 | - $c->get(IRootFolder::class), |
|
| 418 | - new View(), |
|
| 419 | - $c->get(IEventDispatcher::class), |
|
| 420 | - $c->get(LoggerInterface::class) |
|
| 421 | - ); |
|
| 422 | - }); |
|
| 423 | - |
|
| 424 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 425 | - return new LazyRoot(function () use ($c) { |
|
| 426 | - return $c->get('RootFolder'); |
|
| 427 | - }); |
|
| 428 | - }); |
|
| 429 | - |
|
| 430 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 431 | - |
|
| 432 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 433 | - return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 434 | - }); |
|
| 435 | - |
|
| 436 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 437 | - $groupManager = new \OC\Group\Manager( |
|
| 438 | - $this->get(IUserManager::class), |
|
| 439 | - $this->get(IEventDispatcher::class), |
|
| 440 | - $this->get(LoggerInterface::class), |
|
| 441 | - $this->get(ICacheFactory::class), |
|
| 442 | - $this->get(IRemoteAddress::class), |
|
| 443 | - ); |
|
| 444 | - return $groupManager; |
|
| 445 | - }); |
|
| 446 | - |
|
| 447 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 448 | - $session = $c->get(ISession::class); |
|
| 449 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 450 | - $tokenProvider = $c->get(IProvider::class); |
|
| 451 | - } else { |
|
| 452 | - $tokenProvider = null; |
|
| 453 | - } |
|
| 454 | - $logger = $c->get(LoggerInterface::class); |
|
| 455 | - $crypto = $c->get(ICrypto::class); |
|
| 456 | - return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 457 | - }); |
|
| 458 | - $this->registerAlias(IStore::class, Store::class); |
|
| 459 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 460 | - $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 461 | - |
|
| 462 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 463 | - $manager = $c->get(IUserManager::class); |
|
| 464 | - $session = new \OC\Session\Memory(); |
|
| 465 | - $timeFactory = new TimeFactory(); |
|
| 466 | - // Token providers might require a working database. This code |
|
| 467 | - // might however be called when Nextcloud is not yet setup. |
|
| 468 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 469 | - $provider = $c->get(IProvider::class); |
|
| 470 | - } else { |
|
| 471 | - $provider = null; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $userSession = new \OC\User\Session( |
|
| 475 | - $manager, |
|
| 476 | - $session, |
|
| 477 | - $timeFactory, |
|
| 478 | - $provider, |
|
| 479 | - $c->get(\OCP\IConfig::class), |
|
| 480 | - $c->get(ISecureRandom::class), |
|
| 481 | - $c->get('LockdownManager'), |
|
| 482 | - $c->get(LoggerInterface::class), |
|
| 483 | - $c->get(IEventDispatcher::class), |
|
| 484 | - ); |
|
| 485 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 486 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 487 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 488 | - }); |
|
| 489 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 490 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 491 | - /** @var \OC\User\User $user */ |
|
| 492 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 493 | - }); |
|
| 494 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 495 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 496 | - /** @var \OC\User\User $user */ |
|
| 497 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 498 | - }); |
|
| 499 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 500 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 501 | - /** @var \OC\User\User $user */ |
|
| 502 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 503 | - }); |
|
| 504 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 505 | - /** @var \OC\User\User $user */ |
|
| 506 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 507 | - }); |
|
| 508 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 509 | - /** @var \OC\User\User $user */ |
|
| 510 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 511 | - }); |
|
| 512 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 513 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 514 | - |
|
| 515 | - /** @var IEventDispatcher $dispatcher */ |
|
| 516 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 517 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 518 | - }); |
|
| 519 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 520 | - /** @var \OC\User\User $user */ |
|
| 521 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 522 | - |
|
| 523 | - /** @var IEventDispatcher $dispatcher */ |
|
| 524 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 525 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 526 | - }); |
|
| 527 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 528 | - /** @var IEventDispatcher $dispatcher */ |
|
| 529 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 530 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 531 | - }); |
|
| 532 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 533 | - /** @var \OC\User\User $user */ |
|
| 534 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 535 | - |
|
| 536 | - /** @var IEventDispatcher $dispatcher */ |
|
| 537 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 538 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 539 | - }); |
|
| 540 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 541 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 542 | - |
|
| 543 | - /** @var IEventDispatcher $dispatcher */ |
|
| 544 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 545 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 546 | - }); |
|
| 547 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 548 | - /** @var IEventDispatcher $dispatcher */ |
|
| 549 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 550 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 551 | - }); |
|
| 552 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 553 | - /** @var \OC\User\User $user */ |
|
| 554 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 555 | - }); |
|
| 556 | - return $userSession; |
|
| 557 | - }); |
|
| 558 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 559 | - |
|
| 560 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 561 | - |
|
| 562 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 563 | - |
|
| 564 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 565 | - |
|
| 566 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 567 | - return new \OC\SystemConfig($config); |
|
| 568 | - }); |
|
| 569 | - |
|
| 570 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 571 | - $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 572 | - |
|
| 573 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 574 | - return new \OC\L10N\Factory( |
|
| 575 | - $c->get(\OCP\IConfig::class), |
|
| 576 | - $c->getRequest(), |
|
| 577 | - $c->get(IUserSession::class), |
|
| 578 | - $c->get(ICacheFactory::class), |
|
| 579 | - \OC::$SERVERROOT, |
|
| 580 | - $c->get(IAppManager::class), |
|
| 581 | - ); |
|
| 582 | - }); |
|
| 583 | - |
|
| 584 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 585 | - |
|
| 586 | - $this->registerService(ICache::class, function ($c) { |
|
| 587 | - return new Cache\File(); |
|
| 588 | - }); |
|
| 589 | - |
|
| 590 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 591 | - $profiler = $c->get(IProfiler::class); |
|
| 592 | - $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 593 | - $profiler, |
|
| 594 | - ArrayCache::class, |
|
| 595 | - ArrayCache::class, |
|
| 596 | - ArrayCache::class |
|
| 597 | - ); |
|
| 598 | - /** @var SystemConfig $config */ |
|
| 599 | - $config = $c->get(SystemConfig::class); |
|
| 600 | - /** @var ServerVersion $serverVersion */ |
|
| 601 | - $serverVersion = $c->get(ServerVersion::class); |
|
| 602 | - |
|
| 603 | - if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 604 | - $logQuery = $config->getValue('log_query'); |
|
| 605 | - $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 606 | - if (!$logQuery) { |
|
| 607 | - try { |
|
| 608 | - $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(); |
|
| 609 | - } catch (\Doctrine\DBAL\Exception $e) { |
|
| 610 | - // Database service probably unavailable |
|
| 611 | - // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 612 | - return null; |
|
| 613 | - } |
|
| 614 | - } else { |
|
| 615 | - // If the log_query is enabled, we can not get the app versions |
|
| 616 | - // as that does a query, which will be logged and the logging |
|
| 617 | - // depends on redis and here we are back again in the same function. |
|
| 618 | - $v = [ |
|
| 619 | - 'log_query' => 'enabled', |
|
| 620 | - ]; |
|
| 621 | - } |
|
| 622 | - $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 623 | - $version = implode(',', $v); |
|
| 624 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 625 | - $path = \OC::$SERVERROOT; |
|
| 626 | - return md5($instanceId . '-' . $version . '-' . $path); |
|
| 627 | - }; |
|
| 628 | - return new \OC\Memcache\Factory($prefixClosure, |
|
| 629 | - $c->get(LoggerInterface::class), |
|
| 630 | - $profiler, |
|
| 631 | - /** @psalm-taint-escape callable */ |
|
| 632 | - $config->getValue('memcache.local', null), |
|
| 633 | - /** @psalm-taint-escape callable */ |
|
| 634 | - $config->getValue('memcache.distributed', null), |
|
| 635 | - /** @psalm-taint-escape callable */ |
|
| 636 | - $config->getValue('memcache.locking', null), |
|
| 637 | - /** @psalm-taint-escape callable */ |
|
| 638 | - $config->getValue('redis_log_file') |
|
| 639 | - ); |
|
| 640 | - } |
|
| 641 | - return $arrayCacheFactory; |
|
| 642 | - }); |
|
| 643 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 644 | - |
|
| 645 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 646 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 647 | - return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 648 | - }); |
|
| 649 | - |
|
| 650 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 651 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 652 | - return new \OC\Activity\Manager( |
|
| 653 | - $c->getRequest(), |
|
| 654 | - $c->get(IUserSession::class), |
|
| 655 | - $c->get(\OCP\IConfig::class), |
|
| 656 | - $c->get(IValidator::class), |
|
| 657 | - $c->get(IRichTextFormatter::class), |
|
| 658 | - $l10n |
|
| 659 | - ); |
|
| 660 | - }); |
|
| 661 | - |
|
| 662 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 663 | - return new \OC\Activity\EventMerger( |
|
| 664 | - $c->getL10N('lib') |
|
| 665 | - ); |
|
| 666 | - }); |
|
| 667 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 668 | - |
|
| 669 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 670 | - return new AvatarManager( |
|
| 671 | - $c->get(IUserSession::class), |
|
| 672 | - $c->get(\OC\User\Manager::class), |
|
| 673 | - $c->getAppDataDir('avatar'), |
|
| 674 | - $c->getL10N('lib'), |
|
| 675 | - $c->get(LoggerInterface::class), |
|
| 676 | - $c->get(\OCP\IConfig::class), |
|
| 677 | - $c->get(IAccountManager::class), |
|
| 678 | - $c->get(KnownUserService::class) |
|
| 679 | - ); |
|
| 680 | - }); |
|
| 681 | - |
|
| 682 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 683 | - |
|
| 684 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 685 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 686 | - $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 687 | - |
|
| 688 | - /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 689 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 690 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 691 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 692 | - $logger = $factory->get($logType); |
|
| 693 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 694 | - |
|
| 695 | - return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 696 | - }); |
|
| 697 | - // PSR-3 logger |
|
| 698 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 699 | - |
|
| 700 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 701 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 702 | - }); |
|
| 703 | - |
|
| 704 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 705 | - |
|
| 706 | - $this->registerService(Router::class, function (Server $c) { |
|
| 707 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 708 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 709 | - $router = $c->resolve(CachingRouter::class); |
|
| 710 | - } else { |
|
| 711 | - $router = $c->resolve(Router::class); |
|
| 712 | - } |
|
| 713 | - return $router; |
|
| 714 | - }); |
|
| 715 | - $this->registerAlias(IRouter::class, Router::class); |
|
| 716 | - |
|
| 717 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 718 | - $config = $c->get(\OCP\IConfig::class); |
|
| 719 | - if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 720 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 721 | - $c->get(AllConfig::class), |
|
| 722 | - $this->get(ICacheFactory::class), |
|
| 723 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 724 | - ); |
|
| 725 | - } else { |
|
| 726 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 727 | - $c->get(AllConfig::class), |
|
| 728 | - $c->get(IDBConnection::class), |
|
| 729 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 730 | - ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - return $backend; |
|
| 734 | - }); |
|
| 735 | - |
|
| 736 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 737 | - $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 738 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 739 | - |
|
| 740 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 741 | - |
|
| 742 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 743 | - |
|
| 744 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 745 | - |
|
| 746 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 747 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 748 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 749 | - $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 750 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 751 | - if (!$factory->isValidType($type)) { |
|
| 752 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 753 | - } |
|
| 754 | - $connection = $factory->getConnection($type, []); |
|
| 755 | - return $connection; |
|
| 756 | - }); |
|
| 757 | - |
|
| 758 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 759 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
| 760 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 761 | - return new NegativeDnsCache( |
|
| 762 | - $c->get(ICacheFactory::class), |
|
| 763 | - ); |
|
| 764 | - }); |
|
| 765 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 766 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 767 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 768 | - }); |
|
| 769 | - |
|
| 770 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 771 | - $queryLogger = new QueryLogger(); |
|
| 772 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 773 | - // In debug mode, module is being activated by default |
|
| 774 | - $queryLogger->activate(); |
|
| 775 | - } |
|
| 776 | - return $queryLogger; |
|
| 777 | - }); |
|
| 778 | - |
|
| 779 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 780 | - |
|
| 781 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 782 | - // TODO: use auto-wiring |
|
| 783 | - return new \OC\App\AppManager( |
|
| 784 | - $c->get(IUserSession::class), |
|
| 785 | - $c->get(\OCP\IConfig::class), |
|
| 786 | - $c->get(IGroupManager::class), |
|
| 787 | - $c->get(ICacheFactory::class), |
|
| 788 | - $c->get(IEventDispatcher::class), |
|
| 789 | - $c->get(LoggerInterface::class), |
|
| 790 | - $c->get(ServerVersion::class), |
|
| 791 | - ); |
|
| 792 | - }); |
|
| 793 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 794 | - |
|
| 795 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 796 | - |
|
| 797 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 798 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 799 | - |
|
| 800 | - return new DateTimeFormatter( |
|
| 801 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 802 | - $c->getL10N('lib', $language) |
|
| 803 | - ); |
|
| 804 | - }); |
|
| 805 | - |
|
| 806 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 807 | - $mountCache = $c->get(UserMountCache::class); |
|
| 808 | - $listener = new UserMountCacheListener($mountCache); |
|
| 809 | - $listener->listen($c->get(IUserManager::class)); |
|
| 810 | - return $mountCache; |
|
| 811 | - }); |
|
| 812 | - |
|
| 813 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 814 | - $loader = $c->get(IStorageFactory::class); |
|
| 815 | - $mountCache = $c->get(IUserMountCache::class); |
|
| 816 | - $eventLogger = $c->get(IEventLogger::class); |
|
| 817 | - $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 818 | - |
|
| 819 | - // builtin providers |
|
| 820 | - |
|
| 821 | - $config = $c->get(\OCP\IConfig::class); |
|
| 822 | - $logger = $c->get(LoggerInterface::class); |
|
| 823 | - $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 824 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 825 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 826 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 827 | - $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 828 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 829 | - |
|
| 830 | - return $manager; |
|
| 831 | - }); |
|
| 832 | - |
|
| 833 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 834 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 835 | - if ($busClass) { |
|
| 836 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 837 | - if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 838 | - $c->get(IAppManager::class)->loadApp($app); |
|
| 839 | - return $c->get($class); |
|
| 840 | - } else { |
|
| 841 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 842 | - } |
|
| 843 | - } else { |
|
| 844 | - $jobList = $c->get(IJobList::class); |
|
| 845 | - return new CronBus($jobList); |
|
| 846 | - } |
|
| 847 | - }); |
|
| 848 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 849 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 850 | - $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 851 | - |
|
| 852 | - $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 853 | - $config = $c->get(\OCP\IConfig::class); |
|
| 854 | - if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 855 | - && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 856 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 857 | - } else { |
|
| 858 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - return $backend; |
|
| 862 | - }); |
|
| 863 | - |
|
| 864 | - $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 865 | - $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 866 | - // IConfig requires a working database. This code |
|
| 867 | - // might however be called when Nextcloud is not yet setup. |
|
| 868 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 869 | - $config = $c->get(\OCP\IConfig::class); |
|
| 870 | - $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 871 | - } else { |
|
| 872 | - $config = null; |
|
| 873 | - $appConfig = null; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - return new Checker( |
|
| 877 | - $c->get(ServerVersion::class), |
|
| 878 | - $c->get(EnvironmentHelper::class), |
|
| 879 | - new FileAccessHelper(), |
|
| 880 | - new AppLocator(), |
|
| 881 | - $config, |
|
| 882 | - $appConfig, |
|
| 883 | - $c->get(ICacheFactory::class), |
|
| 884 | - $c->get(IAppManager::class), |
|
| 885 | - $c->get(IMimeTypeDetector::class) |
|
| 886 | - ); |
|
| 887 | - }); |
|
| 888 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 889 | - if (isset($this['urlParams'])) { |
|
| 890 | - $urlParams = $this['urlParams']; |
|
| 891 | - } else { |
|
| 892 | - $urlParams = []; |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 896 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 897 | - ) { |
|
| 898 | - $stream = 'fakeinput://data'; |
|
| 899 | - } else { |
|
| 900 | - $stream = 'php://input'; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - return new Request( |
|
| 904 | - [ |
|
| 905 | - 'get' => $_GET, |
|
| 906 | - 'post' => $_POST, |
|
| 907 | - 'files' => $_FILES, |
|
| 908 | - 'server' => $_SERVER, |
|
| 909 | - 'env' => $_ENV, |
|
| 910 | - 'cookies' => $_COOKIE, |
|
| 911 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 912 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 913 | - : '', |
|
| 914 | - 'urlParams' => $urlParams, |
|
| 915 | - ], |
|
| 916 | - $this->get(IRequestId::class), |
|
| 917 | - $this->get(\OCP\IConfig::class), |
|
| 918 | - $this->get(CsrfTokenManager::class), |
|
| 919 | - $stream |
|
| 920 | - ); |
|
| 921 | - }); |
|
| 922 | - |
|
| 923 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 924 | - return new RequestId( |
|
| 925 | - $_SERVER['UNIQUE_ID'] ?? '', |
|
| 926 | - $this->get(ISecureRandom::class) |
|
| 927 | - ); |
|
| 928 | - }); |
|
| 929 | - |
|
| 930 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 931 | - return new Mailer( |
|
| 932 | - $c->get(\OCP\IConfig::class), |
|
| 933 | - $c->get(LoggerInterface::class), |
|
| 934 | - $c->get(Defaults::class), |
|
| 935 | - $c->get(IURLGenerator::class), |
|
| 936 | - $c->getL10N('lib'), |
|
| 937 | - $c->get(IEventDispatcher::class), |
|
| 938 | - $c->get(IFactory::class) |
|
| 939 | - ); |
|
| 940 | - }); |
|
| 941 | - |
|
| 942 | - /** @since 30.0.0 */ |
|
| 943 | - $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 944 | - |
|
| 945 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 946 | - $config = $c->get(\OCP\IConfig::class); |
|
| 947 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 948 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 949 | - return new NullLDAPProviderFactory($this); |
|
| 950 | - } |
|
| 951 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 952 | - return new $factoryClass($this); |
|
| 953 | - }); |
|
| 954 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 955 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
| 956 | - return $factory->getLDAPProvider(); |
|
| 957 | - }); |
|
| 958 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 959 | - $ini = $c->get(IniGetWrapper::class); |
|
| 960 | - $config = $c->get(\OCP\IConfig::class); |
|
| 961 | - $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 962 | - if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 963 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 964 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 965 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 966 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 967 | - $timeFactory = $c->get(ITimeFactory::class); |
|
| 968 | - return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 969 | - } |
|
| 970 | - return new DBLockingProvider( |
|
| 971 | - $c->get(IDBConnection::class), |
|
| 972 | - new TimeFactory(), |
|
| 973 | - $ttl, |
|
| 974 | - !\OC::$CLI |
|
| 975 | - ); |
|
| 976 | - } |
|
| 977 | - return new NoopLockingProvider(); |
|
| 978 | - }); |
|
| 979 | - |
|
| 980 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 981 | - return new LockManager(); |
|
| 982 | - }); |
|
| 983 | - |
|
| 984 | - $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 985 | - $this->registerService(SetupManager::class, function ($c) { |
|
| 986 | - // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 987 | - return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 988 | - }); |
|
| 989 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 990 | - |
|
| 991 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 992 | - return new \OC\Files\Type\Detection( |
|
| 993 | - $c->get(IURLGenerator::class), |
|
| 994 | - $c->get(LoggerInterface::class), |
|
| 995 | - \OC::$configDir, |
|
| 996 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 997 | - ); |
|
| 998 | - }); |
|
| 999 | - |
|
| 1000 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1001 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1002 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 1003 | - }); |
|
| 1004 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1005 | - |
|
| 1006 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1007 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1008 | - $manager->registerCapability(function () use ($c) { |
|
| 1009 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1010 | - }); |
|
| 1011 | - $manager->registerCapability(function () use ($c) { |
|
| 1012 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1013 | - }); |
|
| 1014 | - return $manager; |
|
| 1015 | - }); |
|
| 1016 | - |
|
| 1017 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1018 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1019 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1020 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1021 | - $factory = new $factoryClass($this); |
|
| 1022 | - $manager = $factory->getManager(); |
|
| 1023 | - |
|
| 1024 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1025 | - $manager = $c->get(IUserManager::class); |
|
| 1026 | - $userDisplayName = $manager->getDisplayName($id); |
|
| 1027 | - if ($userDisplayName === null) { |
|
| 1028 | - $l = $c->get(IFactory::class)->get('core'); |
|
| 1029 | - return $l->t('Unknown account'); |
|
| 1030 | - } |
|
| 1031 | - return $userDisplayName; |
|
| 1032 | - }); |
|
| 1033 | - |
|
| 1034 | - return $manager; |
|
| 1035 | - }); |
|
| 1036 | - |
|
| 1037 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1038 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1039 | - try { |
|
| 1040 | - $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1041 | - } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1042 | - // App disabled or in maintenance mode |
|
| 1043 | - $classExists = false; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1047 | - $backgroundService = new BackgroundService( |
|
| 1048 | - $c->get(IRootFolder::class), |
|
| 1049 | - $c->getAppDataDir('theming'), |
|
| 1050 | - $c->get(IAppConfig::class), |
|
| 1051 | - $c->get(\OCP\IConfig::class), |
|
| 1052 | - $c->get(ISession::class)->get('user_id'), |
|
| 1053 | - ); |
|
| 1054 | - $imageManager = new ImageManager( |
|
| 1055 | - $c->get(\OCP\IConfig::class), |
|
| 1056 | - $c->getAppDataDir('theming'), |
|
| 1057 | - $c->get(IURLGenerator::class), |
|
| 1058 | - $c->get(ICacheFactory::class), |
|
| 1059 | - $c->get(LoggerInterface::class), |
|
| 1060 | - $c->get(ITempManager::class), |
|
| 1061 | - $backgroundService, |
|
| 1062 | - ); |
|
| 1063 | - return new ThemingDefaults( |
|
| 1064 | - $c->get(\OCP\IConfig::class), |
|
| 1065 | - $c->get(\OCP\IAppConfig::class), |
|
| 1066 | - $c->getL10N('theming'), |
|
| 1067 | - $c->get(IUserSession::class), |
|
| 1068 | - $c->get(IURLGenerator::class), |
|
| 1069 | - $c->get(ICacheFactory::class), |
|
| 1070 | - new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1071 | - $imageManager, |
|
| 1072 | - $c->get(IAppManager::class), |
|
| 1073 | - $c->get(INavigationManager::class), |
|
| 1074 | - $backgroundService, |
|
| 1075 | - ); |
|
| 1076 | - } |
|
| 1077 | - return new \OC_Defaults(); |
|
| 1078 | - }); |
|
| 1079 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1080 | - return new JSCombiner( |
|
| 1081 | - $c->getAppDataDir('js'), |
|
| 1082 | - $c->get(IURLGenerator::class), |
|
| 1083 | - $this->get(ICacheFactory::class), |
|
| 1084 | - $c->get(SystemConfig::class), |
|
| 1085 | - $c->get(LoggerInterface::class) |
|
| 1086 | - ); |
|
| 1087 | - }); |
|
| 1088 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1089 | - |
|
| 1090 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1091 | - // FIXME: Instantiated here due to cyclic dependency |
|
| 1092 | - $request = new Request( |
|
| 1093 | - [ |
|
| 1094 | - 'get' => $_GET, |
|
| 1095 | - 'post' => $_POST, |
|
| 1096 | - 'files' => $_FILES, |
|
| 1097 | - 'server' => $_SERVER, |
|
| 1098 | - 'env' => $_ENV, |
|
| 1099 | - 'cookies' => $_COOKIE, |
|
| 1100 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1101 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1102 | - : null, |
|
| 1103 | - ], |
|
| 1104 | - $c->get(IRequestId::class), |
|
| 1105 | - $c->get(\OCP\IConfig::class) |
|
| 1106 | - ); |
|
| 1107 | - |
|
| 1108 | - return new CryptoWrapper( |
|
| 1109 | - $c->get(ICrypto::class), |
|
| 1110 | - $c->get(ISecureRandom::class), |
|
| 1111 | - $request |
|
| 1112 | - ); |
|
| 1113 | - }); |
|
| 1114 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1115 | - return new SessionStorage($c->get(ISession::class)); |
|
| 1116 | - }); |
|
| 1117 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1118 | - |
|
| 1119 | - $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1120 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1121 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1122 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1123 | - return $c->get($factoryClass); |
|
| 1124 | - }); |
|
| 1125 | - |
|
| 1126 | - $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1127 | - |
|
| 1128 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1129 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1130 | - |
|
| 1131 | - // register default plugins |
|
| 1132 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1133 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1134 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1135 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1136 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1137 | - |
|
| 1138 | - return $instance; |
|
| 1139 | - }); |
|
| 1140 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1141 | - |
|
| 1142 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1143 | - |
|
| 1144 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1145 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1146 | - |
|
| 1147 | - $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1148 | - $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1149 | - |
|
| 1150 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1151 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1152 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1153 | - return new \OC\Files\AppData\Factory( |
|
| 1154 | - $c->get(IRootFolder::class), |
|
| 1155 | - $c->get(SystemConfig::class) |
|
| 1156 | - ); |
|
| 1157 | - }); |
|
| 1158 | - |
|
| 1159 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1160 | - return new LockdownManager(function () use ($c) { |
|
| 1161 | - return $c->get(ISession::class); |
|
| 1162 | - }); |
|
| 1163 | - }); |
|
| 1164 | - |
|
| 1165 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1166 | - return new DiscoveryService( |
|
| 1167 | - $c->get(ICacheFactory::class), |
|
| 1168 | - $c->get(IClientService::class) |
|
| 1169 | - ); |
|
| 1170 | - }); |
|
| 1171 | - $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1172 | - |
|
| 1173 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1174 | - return new CloudIdManager( |
|
| 1175 | - $c->get(\OCP\Contacts\IManager::class), |
|
| 1176 | - $c->get(IURLGenerator::class), |
|
| 1177 | - $c->get(IUserManager::class), |
|
| 1178 | - $c->get(ICacheFactory::class), |
|
| 1179 | - $c->get(IEventDispatcher::class), |
|
| 1180 | - ); |
|
| 1181 | - }); |
|
| 1182 | - |
|
| 1183 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1184 | - $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1185 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1186 | - return new CloudFederationFactory(); |
|
| 1187 | - }); |
|
| 251 | + /** @var string */ |
|
| 252 | + private $webRoot; |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param string $webRoot |
|
| 256 | + * @param \OC\Config $config |
|
| 257 | + */ |
|
| 258 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 259 | + parent::__construct(); |
|
| 260 | + $this->webRoot = $webRoot; |
|
| 261 | + |
|
| 262 | + // To find out if we are running from CLI or not |
|
| 263 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 264 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 265 | + |
|
| 266 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 267 | + return $c; |
|
| 268 | + }); |
|
| 269 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 270 | + return $c; |
|
| 271 | + }); |
|
| 272 | + |
|
| 273 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 274 | + |
|
| 275 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 276 | + |
|
| 277 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 278 | + |
|
| 279 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 280 | + |
|
| 281 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 282 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 283 | + $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 284 | + |
|
| 285 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 286 | + |
|
| 287 | + $this->registerService(View::class, function (Server $c) { |
|
| 288 | + return new View(); |
|
| 289 | + }, false); |
|
| 290 | + |
|
| 291 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 292 | + return new PreviewManager( |
|
| 293 | + $c->get(\OCP\IConfig::class), |
|
| 294 | + $c->get(IRootFolder::class), |
|
| 295 | + new \OC\Preview\Storage\Root( |
|
| 296 | + $c->get(IRootFolder::class), |
|
| 297 | + $c->get(SystemConfig::class) |
|
| 298 | + ), |
|
| 299 | + $c->get(IEventDispatcher::class), |
|
| 300 | + $c->get(GeneratorHelper::class), |
|
| 301 | + $c->get(ISession::class)->get('user_id'), |
|
| 302 | + $c->get(Coordinator::class), |
|
| 303 | + $c->get(IServerContainer::class), |
|
| 304 | + $c->get(IBinaryFinder::class), |
|
| 305 | + $c->get(IMagickSupport::class) |
|
| 306 | + ); |
|
| 307 | + }); |
|
| 308 | + $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 309 | + |
|
| 310 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 311 | + return new \OC\Preview\Watcher( |
|
| 312 | + new \OC\Preview\Storage\Root( |
|
| 313 | + $c->get(IRootFolder::class), |
|
| 314 | + $c->get(SystemConfig::class) |
|
| 315 | + ) |
|
| 316 | + ); |
|
| 317 | + }); |
|
| 318 | + |
|
| 319 | + $this->registerService(IProfiler::class, function (Server $c) { |
|
| 320 | + return new Profiler($c->get(SystemConfig::class)); |
|
| 321 | + }); |
|
| 322 | + |
|
| 323 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager { |
|
| 324 | + $view = new View(); |
|
| 325 | + $util = new Encryption\Util( |
|
| 326 | + $view, |
|
| 327 | + $c->get(IUserManager::class), |
|
| 328 | + $c->get(IGroupManager::class), |
|
| 329 | + $c->get(\OCP\IConfig::class) |
|
| 330 | + ); |
|
| 331 | + return new Encryption\Manager( |
|
| 332 | + $c->get(\OCP\IConfig::class), |
|
| 333 | + $c->get(LoggerInterface::class), |
|
| 334 | + $c->getL10N('core'), |
|
| 335 | + new View(), |
|
| 336 | + $util, |
|
| 337 | + new ArrayCache() |
|
| 338 | + ); |
|
| 339 | + }); |
|
| 340 | + |
|
| 341 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 342 | + $util = new Encryption\Util( |
|
| 343 | + new View(), |
|
| 344 | + $c->get(IUserManager::class), |
|
| 345 | + $c->get(IGroupManager::class), |
|
| 346 | + $c->get(\OCP\IConfig::class) |
|
| 347 | + ); |
|
| 348 | + return new Encryption\File( |
|
| 349 | + $util, |
|
| 350 | + $c->get(IRootFolder::class), |
|
| 351 | + $c->get(\OCP\Share\IManager::class) |
|
| 352 | + ); |
|
| 353 | + }); |
|
| 354 | + |
|
| 355 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 356 | + $view = new View(); |
|
| 357 | + $util = new Encryption\Util( |
|
| 358 | + $view, |
|
| 359 | + $c->get(IUserManager::class), |
|
| 360 | + $c->get(IGroupManager::class), |
|
| 361 | + $c->get(\OCP\IConfig::class) |
|
| 362 | + ); |
|
| 363 | + |
|
| 364 | + return new Encryption\Keys\Storage( |
|
| 365 | + $view, |
|
| 366 | + $util, |
|
| 367 | + $c->get(ICrypto::class), |
|
| 368 | + $c->get(\OCP\IConfig::class) |
|
| 369 | + ); |
|
| 370 | + }); |
|
| 371 | + |
|
| 372 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 373 | + |
|
| 374 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 375 | + /** @var \OCP\IConfig $config */ |
|
| 376 | + $config = $c->get(\OCP\IConfig::class); |
|
| 377 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 378 | + return new $factoryClass($this); |
|
| 379 | + }); |
|
| 380 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 381 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 382 | + }); |
|
| 383 | + /** @deprecated 19.0.0 */ |
|
| 384 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 385 | + |
|
| 386 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 387 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 388 | + }); |
|
| 389 | + $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 390 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 391 | + $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 392 | + $view = new View(); |
|
| 393 | + /** @var IUserSession $userSession */ |
|
| 394 | + $userSession = $c->get(IUserSession::class); |
|
| 395 | + $root = new Root( |
|
| 396 | + $manager, |
|
| 397 | + $view, |
|
| 398 | + $userSession->getUser(), |
|
| 399 | + $c->get(IUserMountCache::class), |
|
| 400 | + $this->get(LoggerInterface::class), |
|
| 401 | + $this->get(IUserManager::class), |
|
| 402 | + $this->get(IEventDispatcher::class), |
|
| 403 | + $this->get(ICacheFactory::class), |
|
| 404 | + ); |
|
| 405 | + |
|
| 406 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 407 | + $root, |
|
| 408 | + $c->get(SystemConfig::class), |
|
| 409 | + $this->get(IEventDispatcher::class) |
|
| 410 | + ); |
|
| 411 | + $previewConnector->connectWatcher(); |
|
| 412 | + |
|
| 413 | + return $root; |
|
| 414 | + }); |
|
| 415 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 416 | + return new HookConnector( |
|
| 417 | + $c->get(IRootFolder::class), |
|
| 418 | + new View(), |
|
| 419 | + $c->get(IEventDispatcher::class), |
|
| 420 | + $c->get(LoggerInterface::class) |
|
| 421 | + ); |
|
| 422 | + }); |
|
| 423 | + |
|
| 424 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 425 | + return new LazyRoot(function () use ($c) { |
|
| 426 | + return $c->get('RootFolder'); |
|
| 427 | + }); |
|
| 428 | + }); |
|
| 429 | + |
|
| 430 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 431 | + |
|
| 432 | + $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 433 | + return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 434 | + }); |
|
| 435 | + |
|
| 436 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 437 | + $groupManager = new \OC\Group\Manager( |
|
| 438 | + $this->get(IUserManager::class), |
|
| 439 | + $this->get(IEventDispatcher::class), |
|
| 440 | + $this->get(LoggerInterface::class), |
|
| 441 | + $this->get(ICacheFactory::class), |
|
| 442 | + $this->get(IRemoteAddress::class), |
|
| 443 | + ); |
|
| 444 | + return $groupManager; |
|
| 445 | + }); |
|
| 446 | + |
|
| 447 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 448 | + $session = $c->get(ISession::class); |
|
| 449 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 450 | + $tokenProvider = $c->get(IProvider::class); |
|
| 451 | + } else { |
|
| 452 | + $tokenProvider = null; |
|
| 453 | + } |
|
| 454 | + $logger = $c->get(LoggerInterface::class); |
|
| 455 | + $crypto = $c->get(ICrypto::class); |
|
| 456 | + return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 457 | + }); |
|
| 458 | + $this->registerAlias(IStore::class, Store::class); |
|
| 459 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 460 | + $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 461 | + |
|
| 462 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 463 | + $manager = $c->get(IUserManager::class); |
|
| 464 | + $session = new \OC\Session\Memory(); |
|
| 465 | + $timeFactory = new TimeFactory(); |
|
| 466 | + // Token providers might require a working database. This code |
|
| 467 | + // might however be called when Nextcloud is not yet setup. |
|
| 468 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 469 | + $provider = $c->get(IProvider::class); |
|
| 470 | + } else { |
|
| 471 | + $provider = null; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $userSession = new \OC\User\Session( |
|
| 475 | + $manager, |
|
| 476 | + $session, |
|
| 477 | + $timeFactory, |
|
| 478 | + $provider, |
|
| 479 | + $c->get(\OCP\IConfig::class), |
|
| 480 | + $c->get(ISecureRandom::class), |
|
| 481 | + $c->get('LockdownManager'), |
|
| 482 | + $c->get(LoggerInterface::class), |
|
| 483 | + $c->get(IEventDispatcher::class), |
|
| 484 | + ); |
|
| 485 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 486 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 487 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 488 | + }); |
|
| 489 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 490 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 491 | + /** @var \OC\User\User $user */ |
|
| 492 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 493 | + }); |
|
| 494 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 495 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 496 | + /** @var \OC\User\User $user */ |
|
| 497 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 498 | + }); |
|
| 499 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 500 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 501 | + /** @var \OC\User\User $user */ |
|
| 502 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 503 | + }); |
|
| 504 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 505 | + /** @var \OC\User\User $user */ |
|
| 506 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 507 | + }); |
|
| 508 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 509 | + /** @var \OC\User\User $user */ |
|
| 510 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 511 | + }); |
|
| 512 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 513 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 514 | + |
|
| 515 | + /** @var IEventDispatcher $dispatcher */ |
|
| 516 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 517 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 518 | + }); |
|
| 519 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 520 | + /** @var \OC\User\User $user */ |
|
| 521 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 522 | + |
|
| 523 | + /** @var IEventDispatcher $dispatcher */ |
|
| 524 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 525 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 526 | + }); |
|
| 527 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 528 | + /** @var IEventDispatcher $dispatcher */ |
|
| 529 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 530 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 531 | + }); |
|
| 532 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 533 | + /** @var \OC\User\User $user */ |
|
| 534 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 535 | + |
|
| 536 | + /** @var IEventDispatcher $dispatcher */ |
|
| 537 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 538 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 539 | + }); |
|
| 540 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 541 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 542 | + |
|
| 543 | + /** @var IEventDispatcher $dispatcher */ |
|
| 544 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 545 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 546 | + }); |
|
| 547 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 548 | + /** @var IEventDispatcher $dispatcher */ |
|
| 549 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 550 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 551 | + }); |
|
| 552 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 553 | + /** @var \OC\User\User $user */ |
|
| 554 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 555 | + }); |
|
| 556 | + return $userSession; |
|
| 557 | + }); |
|
| 558 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 559 | + |
|
| 560 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 561 | + |
|
| 562 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 563 | + |
|
| 564 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 565 | + |
|
| 566 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 567 | + return new \OC\SystemConfig($config); |
|
| 568 | + }); |
|
| 569 | + |
|
| 570 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 571 | + $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 572 | + |
|
| 573 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 574 | + return new \OC\L10N\Factory( |
|
| 575 | + $c->get(\OCP\IConfig::class), |
|
| 576 | + $c->getRequest(), |
|
| 577 | + $c->get(IUserSession::class), |
|
| 578 | + $c->get(ICacheFactory::class), |
|
| 579 | + \OC::$SERVERROOT, |
|
| 580 | + $c->get(IAppManager::class), |
|
| 581 | + ); |
|
| 582 | + }); |
|
| 583 | + |
|
| 584 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 585 | + |
|
| 586 | + $this->registerService(ICache::class, function ($c) { |
|
| 587 | + return new Cache\File(); |
|
| 588 | + }); |
|
| 589 | + |
|
| 590 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 591 | + $profiler = $c->get(IProfiler::class); |
|
| 592 | + $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 593 | + $profiler, |
|
| 594 | + ArrayCache::class, |
|
| 595 | + ArrayCache::class, |
|
| 596 | + ArrayCache::class |
|
| 597 | + ); |
|
| 598 | + /** @var SystemConfig $config */ |
|
| 599 | + $config = $c->get(SystemConfig::class); |
|
| 600 | + /** @var ServerVersion $serverVersion */ |
|
| 601 | + $serverVersion = $c->get(ServerVersion::class); |
|
| 602 | + |
|
| 603 | + if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 604 | + $logQuery = $config->getValue('log_query'); |
|
| 605 | + $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 606 | + if (!$logQuery) { |
|
| 607 | + try { |
|
| 608 | + $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(); |
|
| 609 | + } catch (\Doctrine\DBAL\Exception $e) { |
|
| 610 | + // Database service probably unavailable |
|
| 611 | + // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 612 | + return null; |
|
| 613 | + } |
|
| 614 | + } else { |
|
| 615 | + // If the log_query is enabled, we can not get the app versions |
|
| 616 | + // as that does a query, which will be logged and the logging |
|
| 617 | + // depends on redis and here we are back again in the same function. |
|
| 618 | + $v = [ |
|
| 619 | + 'log_query' => 'enabled', |
|
| 620 | + ]; |
|
| 621 | + } |
|
| 622 | + $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 623 | + $version = implode(',', $v); |
|
| 624 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 625 | + $path = \OC::$SERVERROOT; |
|
| 626 | + return md5($instanceId . '-' . $version . '-' . $path); |
|
| 627 | + }; |
|
| 628 | + return new \OC\Memcache\Factory($prefixClosure, |
|
| 629 | + $c->get(LoggerInterface::class), |
|
| 630 | + $profiler, |
|
| 631 | + /** @psalm-taint-escape callable */ |
|
| 632 | + $config->getValue('memcache.local', null), |
|
| 633 | + /** @psalm-taint-escape callable */ |
|
| 634 | + $config->getValue('memcache.distributed', null), |
|
| 635 | + /** @psalm-taint-escape callable */ |
|
| 636 | + $config->getValue('memcache.locking', null), |
|
| 637 | + /** @psalm-taint-escape callable */ |
|
| 638 | + $config->getValue('redis_log_file') |
|
| 639 | + ); |
|
| 640 | + } |
|
| 641 | + return $arrayCacheFactory; |
|
| 642 | + }); |
|
| 643 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 644 | + |
|
| 645 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 646 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 647 | + return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 648 | + }); |
|
| 649 | + |
|
| 650 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 651 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 652 | + return new \OC\Activity\Manager( |
|
| 653 | + $c->getRequest(), |
|
| 654 | + $c->get(IUserSession::class), |
|
| 655 | + $c->get(\OCP\IConfig::class), |
|
| 656 | + $c->get(IValidator::class), |
|
| 657 | + $c->get(IRichTextFormatter::class), |
|
| 658 | + $l10n |
|
| 659 | + ); |
|
| 660 | + }); |
|
| 661 | + |
|
| 662 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 663 | + return new \OC\Activity\EventMerger( |
|
| 664 | + $c->getL10N('lib') |
|
| 665 | + ); |
|
| 666 | + }); |
|
| 667 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 668 | + |
|
| 669 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 670 | + return new AvatarManager( |
|
| 671 | + $c->get(IUserSession::class), |
|
| 672 | + $c->get(\OC\User\Manager::class), |
|
| 673 | + $c->getAppDataDir('avatar'), |
|
| 674 | + $c->getL10N('lib'), |
|
| 675 | + $c->get(LoggerInterface::class), |
|
| 676 | + $c->get(\OCP\IConfig::class), |
|
| 677 | + $c->get(IAccountManager::class), |
|
| 678 | + $c->get(KnownUserService::class) |
|
| 679 | + ); |
|
| 680 | + }); |
|
| 681 | + |
|
| 682 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 683 | + |
|
| 684 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 685 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 686 | + $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 687 | + |
|
| 688 | + /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 689 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 690 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 691 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 692 | + $logger = $factory->get($logType); |
|
| 693 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 694 | + |
|
| 695 | + return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 696 | + }); |
|
| 697 | + // PSR-3 logger |
|
| 698 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 699 | + |
|
| 700 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 701 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 702 | + }); |
|
| 703 | + |
|
| 704 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 705 | + |
|
| 706 | + $this->registerService(Router::class, function (Server $c) { |
|
| 707 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 708 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 709 | + $router = $c->resolve(CachingRouter::class); |
|
| 710 | + } else { |
|
| 711 | + $router = $c->resolve(Router::class); |
|
| 712 | + } |
|
| 713 | + return $router; |
|
| 714 | + }); |
|
| 715 | + $this->registerAlias(IRouter::class, Router::class); |
|
| 716 | + |
|
| 717 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 718 | + $config = $c->get(\OCP\IConfig::class); |
|
| 719 | + if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 720 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 721 | + $c->get(AllConfig::class), |
|
| 722 | + $this->get(ICacheFactory::class), |
|
| 723 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 724 | + ); |
|
| 725 | + } else { |
|
| 726 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 727 | + $c->get(AllConfig::class), |
|
| 728 | + $c->get(IDBConnection::class), |
|
| 729 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 730 | + ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + return $backend; |
|
| 734 | + }); |
|
| 735 | + |
|
| 736 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 737 | + $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 738 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 739 | + |
|
| 740 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 741 | + |
|
| 742 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 743 | + |
|
| 744 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 745 | + |
|
| 746 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 747 | + $this->registerService(Connection::class, function (Server $c) { |
|
| 748 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 749 | + $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 750 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 751 | + if (!$factory->isValidType($type)) { |
|
| 752 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 753 | + } |
|
| 754 | + $connection = $factory->getConnection($type, []); |
|
| 755 | + return $connection; |
|
| 756 | + }); |
|
| 757 | + |
|
| 758 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 759 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
| 760 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 761 | + return new NegativeDnsCache( |
|
| 762 | + $c->get(ICacheFactory::class), |
|
| 763 | + ); |
|
| 764 | + }); |
|
| 765 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 766 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 767 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 768 | + }); |
|
| 769 | + |
|
| 770 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 771 | + $queryLogger = new QueryLogger(); |
|
| 772 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 773 | + // In debug mode, module is being activated by default |
|
| 774 | + $queryLogger->activate(); |
|
| 775 | + } |
|
| 776 | + return $queryLogger; |
|
| 777 | + }); |
|
| 778 | + |
|
| 779 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 780 | + |
|
| 781 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 782 | + // TODO: use auto-wiring |
|
| 783 | + return new \OC\App\AppManager( |
|
| 784 | + $c->get(IUserSession::class), |
|
| 785 | + $c->get(\OCP\IConfig::class), |
|
| 786 | + $c->get(IGroupManager::class), |
|
| 787 | + $c->get(ICacheFactory::class), |
|
| 788 | + $c->get(IEventDispatcher::class), |
|
| 789 | + $c->get(LoggerInterface::class), |
|
| 790 | + $c->get(ServerVersion::class), |
|
| 791 | + ); |
|
| 792 | + }); |
|
| 793 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 794 | + |
|
| 795 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 796 | + |
|
| 797 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 798 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 799 | + |
|
| 800 | + return new DateTimeFormatter( |
|
| 801 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 802 | + $c->getL10N('lib', $language) |
|
| 803 | + ); |
|
| 804 | + }); |
|
| 805 | + |
|
| 806 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 807 | + $mountCache = $c->get(UserMountCache::class); |
|
| 808 | + $listener = new UserMountCacheListener($mountCache); |
|
| 809 | + $listener->listen($c->get(IUserManager::class)); |
|
| 810 | + return $mountCache; |
|
| 811 | + }); |
|
| 812 | + |
|
| 813 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 814 | + $loader = $c->get(IStorageFactory::class); |
|
| 815 | + $mountCache = $c->get(IUserMountCache::class); |
|
| 816 | + $eventLogger = $c->get(IEventLogger::class); |
|
| 817 | + $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 818 | + |
|
| 819 | + // builtin providers |
|
| 820 | + |
|
| 821 | + $config = $c->get(\OCP\IConfig::class); |
|
| 822 | + $logger = $c->get(LoggerInterface::class); |
|
| 823 | + $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 824 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 825 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 826 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 827 | + $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 828 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 829 | + |
|
| 830 | + return $manager; |
|
| 831 | + }); |
|
| 832 | + |
|
| 833 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 834 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 835 | + if ($busClass) { |
|
| 836 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 837 | + if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 838 | + $c->get(IAppManager::class)->loadApp($app); |
|
| 839 | + return $c->get($class); |
|
| 840 | + } else { |
|
| 841 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 842 | + } |
|
| 843 | + } else { |
|
| 844 | + $jobList = $c->get(IJobList::class); |
|
| 845 | + return new CronBus($jobList); |
|
| 846 | + } |
|
| 847 | + }); |
|
| 848 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 849 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 850 | + $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 851 | + |
|
| 852 | + $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 853 | + $config = $c->get(\OCP\IConfig::class); |
|
| 854 | + if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 855 | + && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 856 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 857 | + } else { |
|
| 858 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + return $backend; |
|
| 862 | + }); |
|
| 863 | + |
|
| 864 | + $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 865 | + $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 866 | + // IConfig requires a working database. This code |
|
| 867 | + // might however be called when Nextcloud is not yet setup. |
|
| 868 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 869 | + $config = $c->get(\OCP\IConfig::class); |
|
| 870 | + $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 871 | + } else { |
|
| 872 | + $config = null; |
|
| 873 | + $appConfig = null; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + return new Checker( |
|
| 877 | + $c->get(ServerVersion::class), |
|
| 878 | + $c->get(EnvironmentHelper::class), |
|
| 879 | + new FileAccessHelper(), |
|
| 880 | + new AppLocator(), |
|
| 881 | + $config, |
|
| 882 | + $appConfig, |
|
| 883 | + $c->get(ICacheFactory::class), |
|
| 884 | + $c->get(IAppManager::class), |
|
| 885 | + $c->get(IMimeTypeDetector::class) |
|
| 886 | + ); |
|
| 887 | + }); |
|
| 888 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 889 | + if (isset($this['urlParams'])) { |
|
| 890 | + $urlParams = $this['urlParams']; |
|
| 891 | + } else { |
|
| 892 | + $urlParams = []; |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 896 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 897 | + ) { |
|
| 898 | + $stream = 'fakeinput://data'; |
|
| 899 | + } else { |
|
| 900 | + $stream = 'php://input'; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + return new Request( |
|
| 904 | + [ |
|
| 905 | + 'get' => $_GET, |
|
| 906 | + 'post' => $_POST, |
|
| 907 | + 'files' => $_FILES, |
|
| 908 | + 'server' => $_SERVER, |
|
| 909 | + 'env' => $_ENV, |
|
| 910 | + 'cookies' => $_COOKIE, |
|
| 911 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 912 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 913 | + : '', |
|
| 914 | + 'urlParams' => $urlParams, |
|
| 915 | + ], |
|
| 916 | + $this->get(IRequestId::class), |
|
| 917 | + $this->get(\OCP\IConfig::class), |
|
| 918 | + $this->get(CsrfTokenManager::class), |
|
| 919 | + $stream |
|
| 920 | + ); |
|
| 921 | + }); |
|
| 922 | + |
|
| 923 | + $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 924 | + return new RequestId( |
|
| 925 | + $_SERVER['UNIQUE_ID'] ?? '', |
|
| 926 | + $this->get(ISecureRandom::class) |
|
| 927 | + ); |
|
| 928 | + }); |
|
| 929 | + |
|
| 930 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 931 | + return new Mailer( |
|
| 932 | + $c->get(\OCP\IConfig::class), |
|
| 933 | + $c->get(LoggerInterface::class), |
|
| 934 | + $c->get(Defaults::class), |
|
| 935 | + $c->get(IURLGenerator::class), |
|
| 936 | + $c->getL10N('lib'), |
|
| 937 | + $c->get(IEventDispatcher::class), |
|
| 938 | + $c->get(IFactory::class) |
|
| 939 | + ); |
|
| 940 | + }); |
|
| 941 | + |
|
| 942 | + /** @since 30.0.0 */ |
|
| 943 | + $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 944 | + |
|
| 945 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 946 | + $config = $c->get(\OCP\IConfig::class); |
|
| 947 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 948 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 949 | + return new NullLDAPProviderFactory($this); |
|
| 950 | + } |
|
| 951 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 952 | + return new $factoryClass($this); |
|
| 953 | + }); |
|
| 954 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 955 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
| 956 | + return $factory->getLDAPProvider(); |
|
| 957 | + }); |
|
| 958 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 959 | + $ini = $c->get(IniGetWrapper::class); |
|
| 960 | + $config = $c->get(\OCP\IConfig::class); |
|
| 961 | + $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 962 | + if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 963 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 964 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 965 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 966 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 967 | + $timeFactory = $c->get(ITimeFactory::class); |
|
| 968 | + return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 969 | + } |
|
| 970 | + return new DBLockingProvider( |
|
| 971 | + $c->get(IDBConnection::class), |
|
| 972 | + new TimeFactory(), |
|
| 973 | + $ttl, |
|
| 974 | + !\OC::$CLI |
|
| 975 | + ); |
|
| 976 | + } |
|
| 977 | + return new NoopLockingProvider(); |
|
| 978 | + }); |
|
| 979 | + |
|
| 980 | + $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 981 | + return new LockManager(); |
|
| 982 | + }); |
|
| 983 | + |
|
| 984 | + $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 985 | + $this->registerService(SetupManager::class, function ($c) { |
|
| 986 | + // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 987 | + return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 988 | + }); |
|
| 989 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 990 | + |
|
| 991 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 992 | + return new \OC\Files\Type\Detection( |
|
| 993 | + $c->get(IURLGenerator::class), |
|
| 994 | + $c->get(LoggerInterface::class), |
|
| 995 | + \OC::$configDir, |
|
| 996 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 997 | + ); |
|
| 998 | + }); |
|
| 999 | + |
|
| 1000 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1001 | + $this->registerService(BundleFetcher::class, function () { |
|
| 1002 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 1003 | + }); |
|
| 1004 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1005 | + |
|
| 1006 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1007 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1008 | + $manager->registerCapability(function () use ($c) { |
|
| 1009 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1010 | + }); |
|
| 1011 | + $manager->registerCapability(function () use ($c) { |
|
| 1012 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1013 | + }); |
|
| 1014 | + return $manager; |
|
| 1015 | + }); |
|
| 1016 | + |
|
| 1017 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1018 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1019 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1020 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1021 | + $factory = new $factoryClass($this); |
|
| 1022 | + $manager = $factory->getManager(); |
|
| 1023 | + |
|
| 1024 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1025 | + $manager = $c->get(IUserManager::class); |
|
| 1026 | + $userDisplayName = $manager->getDisplayName($id); |
|
| 1027 | + if ($userDisplayName === null) { |
|
| 1028 | + $l = $c->get(IFactory::class)->get('core'); |
|
| 1029 | + return $l->t('Unknown account'); |
|
| 1030 | + } |
|
| 1031 | + return $userDisplayName; |
|
| 1032 | + }); |
|
| 1033 | + |
|
| 1034 | + return $manager; |
|
| 1035 | + }); |
|
| 1036 | + |
|
| 1037 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1038 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1039 | + try { |
|
| 1040 | + $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1041 | + } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1042 | + // App disabled or in maintenance mode |
|
| 1043 | + $classExists = false; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1047 | + $backgroundService = new BackgroundService( |
|
| 1048 | + $c->get(IRootFolder::class), |
|
| 1049 | + $c->getAppDataDir('theming'), |
|
| 1050 | + $c->get(IAppConfig::class), |
|
| 1051 | + $c->get(\OCP\IConfig::class), |
|
| 1052 | + $c->get(ISession::class)->get('user_id'), |
|
| 1053 | + ); |
|
| 1054 | + $imageManager = new ImageManager( |
|
| 1055 | + $c->get(\OCP\IConfig::class), |
|
| 1056 | + $c->getAppDataDir('theming'), |
|
| 1057 | + $c->get(IURLGenerator::class), |
|
| 1058 | + $c->get(ICacheFactory::class), |
|
| 1059 | + $c->get(LoggerInterface::class), |
|
| 1060 | + $c->get(ITempManager::class), |
|
| 1061 | + $backgroundService, |
|
| 1062 | + ); |
|
| 1063 | + return new ThemingDefaults( |
|
| 1064 | + $c->get(\OCP\IConfig::class), |
|
| 1065 | + $c->get(\OCP\IAppConfig::class), |
|
| 1066 | + $c->getL10N('theming'), |
|
| 1067 | + $c->get(IUserSession::class), |
|
| 1068 | + $c->get(IURLGenerator::class), |
|
| 1069 | + $c->get(ICacheFactory::class), |
|
| 1070 | + new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1071 | + $imageManager, |
|
| 1072 | + $c->get(IAppManager::class), |
|
| 1073 | + $c->get(INavigationManager::class), |
|
| 1074 | + $backgroundService, |
|
| 1075 | + ); |
|
| 1076 | + } |
|
| 1077 | + return new \OC_Defaults(); |
|
| 1078 | + }); |
|
| 1079 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1080 | + return new JSCombiner( |
|
| 1081 | + $c->getAppDataDir('js'), |
|
| 1082 | + $c->get(IURLGenerator::class), |
|
| 1083 | + $this->get(ICacheFactory::class), |
|
| 1084 | + $c->get(SystemConfig::class), |
|
| 1085 | + $c->get(LoggerInterface::class) |
|
| 1086 | + ); |
|
| 1087 | + }); |
|
| 1088 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1089 | + |
|
| 1090 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1091 | + // FIXME: Instantiated here due to cyclic dependency |
|
| 1092 | + $request = new Request( |
|
| 1093 | + [ |
|
| 1094 | + 'get' => $_GET, |
|
| 1095 | + 'post' => $_POST, |
|
| 1096 | + 'files' => $_FILES, |
|
| 1097 | + 'server' => $_SERVER, |
|
| 1098 | + 'env' => $_ENV, |
|
| 1099 | + 'cookies' => $_COOKIE, |
|
| 1100 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1101 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1102 | + : null, |
|
| 1103 | + ], |
|
| 1104 | + $c->get(IRequestId::class), |
|
| 1105 | + $c->get(\OCP\IConfig::class) |
|
| 1106 | + ); |
|
| 1107 | + |
|
| 1108 | + return new CryptoWrapper( |
|
| 1109 | + $c->get(ICrypto::class), |
|
| 1110 | + $c->get(ISecureRandom::class), |
|
| 1111 | + $request |
|
| 1112 | + ); |
|
| 1113 | + }); |
|
| 1114 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1115 | + return new SessionStorage($c->get(ISession::class)); |
|
| 1116 | + }); |
|
| 1117 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1118 | + |
|
| 1119 | + $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1120 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1121 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1122 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1123 | + return $c->get($factoryClass); |
|
| 1124 | + }); |
|
| 1125 | + |
|
| 1126 | + $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1127 | + |
|
| 1128 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1129 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1130 | + |
|
| 1131 | + // register default plugins |
|
| 1132 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1133 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1134 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1135 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1136 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1137 | + |
|
| 1138 | + return $instance; |
|
| 1139 | + }); |
|
| 1140 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1141 | + |
|
| 1142 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1143 | + |
|
| 1144 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1145 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1146 | + |
|
| 1147 | + $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1148 | + $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1149 | + |
|
| 1150 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1151 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1152 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1153 | + return new \OC\Files\AppData\Factory( |
|
| 1154 | + $c->get(IRootFolder::class), |
|
| 1155 | + $c->get(SystemConfig::class) |
|
| 1156 | + ); |
|
| 1157 | + }); |
|
| 1158 | + |
|
| 1159 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1160 | + return new LockdownManager(function () use ($c) { |
|
| 1161 | + return $c->get(ISession::class); |
|
| 1162 | + }); |
|
| 1163 | + }); |
|
| 1164 | + |
|
| 1165 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1166 | + return new DiscoveryService( |
|
| 1167 | + $c->get(ICacheFactory::class), |
|
| 1168 | + $c->get(IClientService::class) |
|
| 1169 | + ); |
|
| 1170 | + }); |
|
| 1171 | + $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1172 | + |
|
| 1173 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1174 | + return new CloudIdManager( |
|
| 1175 | + $c->get(\OCP\Contacts\IManager::class), |
|
| 1176 | + $c->get(IURLGenerator::class), |
|
| 1177 | + $c->get(IUserManager::class), |
|
| 1178 | + $c->get(ICacheFactory::class), |
|
| 1179 | + $c->get(IEventDispatcher::class), |
|
| 1180 | + ); |
|
| 1181 | + }); |
|
| 1182 | + |
|
| 1183 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1184 | + $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1185 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1186 | + return new CloudFederationFactory(); |
|
| 1187 | + }); |
|
| 1188 | 1188 | |
| 1189 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1189 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1190 | 1190 | |
| 1191 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1192 | - $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1191 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1192 | + $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1193 | 1193 | |
| 1194 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1195 | - return new Defaults( |
|
| 1196 | - $c->get('ThemingDefaults') |
|
| 1197 | - ); |
|
| 1198 | - }); |
|
| 1194 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1195 | + return new Defaults( |
|
| 1196 | + $c->get('ThemingDefaults') |
|
| 1197 | + ); |
|
| 1198 | + }); |
|
| 1199 | 1199 | |
| 1200 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1201 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1202 | - }, false); |
|
| 1200 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1201 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1202 | + }, false); |
|
| 1203 | 1203 | |
| 1204 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1205 | - return new ShareHelper( |
|
| 1206 | - $c->get(\OCP\Share\IManager::class) |
|
| 1207 | - ); |
|
| 1208 | - }); |
|
| 1204 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1205 | + return new ShareHelper( |
|
| 1206 | + $c->get(\OCP\Share\IManager::class) |
|
| 1207 | + ); |
|
| 1208 | + }); |
|
| 1209 | 1209 | |
| 1210 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1211 | - return new Installer( |
|
| 1212 | - $c->get(AppFetcher::class), |
|
| 1213 | - $c->get(IClientService::class), |
|
| 1214 | - $c->get(ITempManager::class), |
|
| 1215 | - $c->get(LoggerInterface::class), |
|
| 1216 | - $c->get(\OCP\IConfig::class), |
|
| 1217 | - \OC::$CLI |
|
| 1218 | - ); |
|
| 1219 | - }); |
|
| 1210 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1211 | + return new Installer( |
|
| 1212 | + $c->get(AppFetcher::class), |
|
| 1213 | + $c->get(IClientService::class), |
|
| 1214 | + $c->get(ITempManager::class), |
|
| 1215 | + $c->get(LoggerInterface::class), |
|
| 1216 | + $c->get(\OCP\IConfig::class), |
|
| 1217 | + \OC::$CLI |
|
| 1218 | + ); |
|
| 1219 | + }); |
|
| 1220 | 1220 | |
| 1221 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1222 | - return new ApiFactory($c->get(IClientService::class)); |
|
| 1223 | - }); |
|
| 1221 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1222 | + return new ApiFactory($c->get(IClientService::class)); |
|
| 1223 | + }); |
|
| 1224 | 1224 | |
| 1225 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1226 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1227 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1228 | - }); |
|
| 1225 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1226 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1227 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1228 | + }); |
|
| 1229 | 1229 | |
| 1230 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1231 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1230 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1231 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1232 | 1232 | |
| 1233 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1233 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1234 | 1234 | |
| 1235 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1235 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1236 | 1236 | |
| 1237 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1238 | - $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1237 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1238 | + $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1239 | 1239 | |
| 1240 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1240 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1241 | 1241 | |
| 1242 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1242 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1243 | 1243 | |
| 1244 | - $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1244 | + $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1245 | 1245 | |
| 1246 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1246 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1247 | 1247 | |
| 1248 | - $this->registerAlias(IBroker::class, Broker::class); |
|
| 1248 | + $this->registerAlias(IBroker::class, Broker::class); |
|
| 1249 | 1249 | |
| 1250 | - $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1250 | + $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1251 | 1251 | |
| 1252 | - $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1252 | + $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1253 | 1253 | |
| 1254 | - $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1254 | + $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1255 | 1255 | |
| 1256 | - $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1256 | + $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1257 | 1257 | |
| 1258 | - $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1258 | + $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1259 | 1259 | |
| 1260 | - $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1260 | + $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1261 | 1261 | |
| 1262 | - $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1262 | + $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1263 | 1263 | |
| 1264 | - $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1264 | + $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1265 | 1265 | |
| 1266 | - $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1266 | + $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1267 | 1267 | |
| 1268 | - $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1268 | + $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1269 | 1269 | |
| 1270 | - $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1270 | + $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1271 | 1271 | |
| 1272 | - $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1272 | + $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1273 | 1273 | |
| 1274 | - $this->registerAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1274 | + $this->registerAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1275 | 1275 | |
| 1276 | - $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1276 | + $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1277 | 1277 | |
| 1278 | - $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1278 | + $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1279 | 1279 | |
| 1280 | - $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1280 | + $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1281 | 1281 | |
| 1282 | - $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1282 | + $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1283 | 1283 | |
| 1284 | - $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1284 | + $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1285 | 1285 | |
| 1286 | - $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1286 | + $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1287 | 1287 | |
| 1288 | - $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1289 | - |
|
| 1290 | - $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1291 | - |
|
| 1292 | - $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1293 | - |
|
| 1294 | - $this->connectDispatcher(); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - public function boot() { |
|
| 1298 | - /** @var HookConnector $hookConnector */ |
|
| 1299 | - $hookConnector = $this->get(HookConnector::class); |
|
| 1300 | - $hookConnector->viewToNode(); |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - private function connectDispatcher(): void { |
|
| 1304 | - /** @var IEventDispatcher $eventDispatcher */ |
|
| 1305 | - $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1306 | - $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1307 | - $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1308 | - $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1309 | - $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1310 | - |
|
| 1311 | - FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1312 | - GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * @return \OCP\Contacts\IManager |
|
| 1317 | - * @deprecated 20.0.0 |
|
| 1318 | - */ |
|
| 1319 | - public function getContactsManager() { |
|
| 1320 | - return $this->get(\OCP\Contacts\IManager::class); |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - /** |
|
| 1324 | - * @return \OC\Encryption\Manager |
|
| 1325 | - * @deprecated 20.0.0 |
|
| 1326 | - */ |
|
| 1327 | - public function getEncryptionManager() { |
|
| 1328 | - return $this->get(\OCP\Encryption\IManager::class); |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - /** |
|
| 1332 | - * @return \OC\Encryption\File |
|
| 1333 | - * @deprecated 20.0.0 |
|
| 1334 | - */ |
|
| 1335 | - public function getEncryptionFilesHelper() { |
|
| 1336 | - return $this->get(IFile::class); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * The current request object holding all information about the request |
|
| 1341 | - * currently being processed is returned from this method. |
|
| 1342 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1343 | - * |
|
| 1344 | - * @return \OCP\IRequest |
|
| 1345 | - * @deprecated 20.0.0 |
|
| 1346 | - */ |
|
| 1347 | - public function getRequest() { |
|
| 1348 | - return $this->get(IRequest::class); |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * Returns the root folder of ownCloud's data directory |
|
| 1353 | - * |
|
| 1354 | - * @return IRootFolder |
|
| 1355 | - * @deprecated 20.0.0 |
|
| 1356 | - */ |
|
| 1357 | - public function getRootFolder() { |
|
| 1358 | - return $this->get(IRootFolder::class); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * Returns the root folder of ownCloud's data directory |
|
| 1363 | - * This is the lazy variant so this gets only initialized once it |
|
| 1364 | - * is actually used. |
|
| 1365 | - * |
|
| 1366 | - * @return IRootFolder |
|
| 1367 | - * @deprecated 20.0.0 |
|
| 1368 | - */ |
|
| 1369 | - public function getLazyRootFolder() { |
|
| 1370 | - return $this->get(IRootFolder::class); |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * Returns a view to ownCloud's files folder |
|
| 1375 | - * |
|
| 1376 | - * @param string $userId user ID |
|
| 1377 | - * @return \OCP\Files\Folder|null |
|
| 1378 | - * @deprecated 20.0.0 |
|
| 1379 | - */ |
|
| 1380 | - public function getUserFolder($userId = null) { |
|
| 1381 | - if ($userId === null) { |
|
| 1382 | - $user = $this->get(IUserSession::class)->getUser(); |
|
| 1383 | - if (!$user) { |
|
| 1384 | - return null; |
|
| 1385 | - } |
|
| 1386 | - $userId = $user->getUID(); |
|
| 1387 | - } |
|
| 1388 | - $root = $this->get(IRootFolder::class); |
|
| 1389 | - return $root->getUserFolder($userId); |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - /** |
|
| 1393 | - * @return \OC\User\Manager |
|
| 1394 | - * @deprecated 20.0.0 |
|
| 1395 | - */ |
|
| 1396 | - public function getUserManager() { |
|
| 1397 | - return $this->get(IUserManager::class); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - /** |
|
| 1401 | - * @return \OC\Group\Manager |
|
| 1402 | - * @deprecated 20.0.0 |
|
| 1403 | - */ |
|
| 1404 | - public function getGroupManager() { |
|
| 1405 | - return $this->get(IGroupManager::class); |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - /** |
|
| 1409 | - * @return \OC\User\Session |
|
| 1410 | - * @deprecated 20.0.0 |
|
| 1411 | - */ |
|
| 1412 | - public function getUserSession() { |
|
| 1413 | - return $this->get(IUserSession::class); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * @return \OCP\ISession |
|
| 1418 | - * @deprecated 20.0.0 |
|
| 1419 | - */ |
|
| 1420 | - public function getSession() { |
|
| 1421 | - return $this->get(Session::class)->getSession(); |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - /** |
|
| 1425 | - * @param \OCP\ISession $session |
|
| 1426 | - * @return void |
|
| 1427 | - */ |
|
| 1428 | - public function setSession(\OCP\ISession $session) { |
|
| 1429 | - $this->get(SessionStorage::class)->setSession($session); |
|
| 1430 | - $this->get(Session::class)->setSession($session); |
|
| 1431 | - $this->get(Store::class)->setSession($session); |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * @return \OCP\IConfig |
|
| 1436 | - * @deprecated 20.0.0 |
|
| 1437 | - */ |
|
| 1438 | - public function getConfig() { |
|
| 1439 | - return $this->get(AllConfig::class); |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - /** |
|
| 1443 | - * @return \OC\SystemConfig |
|
| 1444 | - * @deprecated 20.0.0 |
|
| 1445 | - */ |
|
| 1446 | - public function getSystemConfig() { |
|
| 1447 | - return $this->get(SystemConfig::class); |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - /** |
|
| 1451 | - * @return IFactory |
|
| 1452 | - * @deprecated 20.0.0 |
|
| 1453 | - */ |
|
| 1454 | - public function getL10NFactory() { |
|
| 1455 | - return $this->get(IFactory::class); |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - /** |
|
| 1459 | - * get an L10N instance |
|
| 1460 | - * |
|
| 1461 | - * @param string $app appid |
|
| 1462 | - * @param string $lang |
|
| 1463 | - * @return IL10N |
|
| 1464 | - * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1465 | - */ |
|
| 1466 | - public function getL10N($app, $lang = null) { |
|
| 1467 | - return $this->get(IFactory::class)->get($app, $lang); |
|
| 1468 | - } |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * @return IURLGenerator |
|
| 1472 | - * @deprecated 20.0.0 |
|
| 1473 | - */ |
|
| 1474 | - public function getURLGenerator() { |
|
| 1475 | - return $this->get(IURLGenerator::class); |
|
| 1476 | - } |
|
| 1477 | - |
|
| 1478 | - /** |
|
| 1479 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1480 | - * getMemCacheFactory() instead. |
|
| 1481 | - * |
|
| 1482 | - * @return ICache |
|
| 1483 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1484 | - */ |
|
| 1485 | - public function getCache() { |
|
| 1486 | - return $this->get(ICache::class); |
|
| 1487 | - } |
|
| 1488 | - |
|
| 1489 | - /** |
|
| 1490 | - * Returns an \OCP\CacheFactory instance |
|
| 1491 | - * |
|
| 1492 | - * @return \OCP\ICacheFactory |
|
| 1493 | - * @deprecated 20.0.0 |
|
| 1494 | - */ |
|
| 1495 | - public function getMemCacheFactory() { |
|
| 1496 | - return $this->get(ICacheFactory::class); |
|
| 1497 | - } |
|
| 1498 | - |
|
| 1499 | - /** |
|
| 1500 | - * Returns the current session |
|
| 1501 | - * |
|
| 1502 | - * @return \OCP\IDBConnection |
|
| 1503 | - * @deprecated 20.0.0 |
|
| 1504 | - */ |
|
| 1505 | - public function getDatabaseConnection() { |
|
| 1506 | - return $this->get(IDBConnection::class); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - /** |
|
| 1510 | - * Returns the activity manager |
|
| 1511 | - * |
|
| 1512 | - * @return \OCP\Activity\IManager |
|
| 1513 | - * @deprecated 20.0.0 |
|
| 1514 | - */ |
|
| 1515 | - public function getActivityManager() { |
|
| 1516 | - return $this->get(\OCP\Activity\IManager::class); |
|
| 1517 | - } |
|
| 1518 | - |
|
| 1519 | - /** |
|
| 1520 | - * Returns an job list for controlling background jobs |
|
| 1521 | - * |
|
| 1522 | - * @return IJobList |
|
| 1523 | - * @deprecated 20.0.0 |
|
| 1524 | - */ |
|
| 1525 | - public function getJobList() { |
|
| 1526 | - return $this->get(IJobList::class); |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - /** |
|
| 1530 | - * Returns a SecureRandom instance |
|
| 1531 | - * |
|
| 1532 | - * @return \OCP\Security\ISecureRandom |
|
| 1533 | - * @deprecated 20.0.0 |
|
| 1534 | - */ |
|
| 1535 | - public function getSecureRandom() { |
|
| 1536 | - return $this->get(ISecureRandom::class); |
|
| 1537 | - } |
|
| 1538 | - |
|
| 1539 | - /** |
|
| 1540 | - * Returns a Crypto instance |
|
| 1541 | - * |
|
| 1542 | - * @return ICrypto |
|
| 1543 | - * @deprecated 20.0.0 |
|
| 1544 | - */ |
|
| 1545 | - public function getCrypto() { |
|
| 1546 | - return $this->get(ICrypto::class); |
|
| 1547 | - } |
|
| 1548 | - |
|
| 1549 | - /** |
|
| 1550 | - * Returns a Hasher instance |
|
| 1551 | - * |
|
| 1552 | - * @return IHasher |
|
| 1553 | - * @deprecated 20.0.0 |
|
| 1554 | - */ |
|
| 1555 | - public function getHasher() { |
|
| 1556 | - return $this->get(IHasher::class); |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - /** |
|
| 1560 | - * Get the certificate manager |
|
| 1561 | - * |
|
| 1562 | - * @return \OCP\ICertificateManager |
|
| 1563 | - */ |
|
| 1564 | - public function getCertificateManager() { |
|
| 1565 | - return $this->get(ICertificateManager::class); |
|
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * Get the manager for temporary files and folders |
|
| 1570 | - * |
|
| 1571 | - * @return \OCP\ITempManager |
|
| 1572 | - * @deprecated 20.0.0 |
|
| 1573 | - */ |
|
| 1574 | - public function getTempManager() { |
|
| 1575 | - return $this->get(ITempManager::class); |
|
| 1576 | - } |
|
| 1577 | - |
|
| 1578 | - /** |
|
| 1579 | - * Get the app manager |
|
| 1580 | - * |
|
| 1581 | - * @return \OCP\App\IAppManager |
|
| 1582 | - * @deprecated 20.0.0 |
|
| 1583 | - */ |
|
| 1584 | - public function getAppManager() { |
|
| 1585 | - return $this->get(IAppManager::class); |
|
| 1586 | - } |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * Creates a new mailer |
|
| 1590 | - * |
|
| 1591 | - * @return IMailer |
|
| 1592 | - * @deprecated 20.0.0 |
|
| 1593 | - */ |
|
| 1594 | - public function getMailer() { |
|
| 1595 | - return $this->get(IMailer::class); |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - /** |
|
| 1599 | - * Get the webroot |
|
| 1600 | - * |
|
| 1601 | - * @return string |
|
| 1602 | - * @deprecated 20.0.0 |
|
| 1603 | - */ |
|
| 1604 | - public function getWebRoot() { |
|
| 1605 | - return $this->webRoot; |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * Get the locking provider |
|
| 1610 | - * |
|
| 1611 | - * @return ILockingProvider |
|
| 1612 | - * @since 8.1.0 |
|
| 1613 | - * @deprecated 20.0.0 |
|
| 1614 | - */ |
|
| 1615 | - public function getLockingProvider() { |
|
| 1616 | - return $this->get(ILockingProvider::class); |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - /** |
|
| 1620 | - * Get the MimeTypeDetector |
|
| 1621 | - * |
|
| 1622 | - * @return IMimeTypeDetector |
|
| 1623 | - * @deprecated 20.0.0 |
|
| 1624 | - */ |
|
| 1625 | - public function getMimeTypeDetector() { |
|
| 1626 | - return $this->get(IMimeTypeDetector::class); |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - /** |
|
| 1630 | - * Get the MimeTypeLoader |
|
| 1631 | - * |
|
| 1632 | - * @return IMimeTypeLoader |
|
| 1633 | - * @deprecated 20.0.0 |
|
| 1634 | - */ |
|
| 1635 | - public function getMimeTypeLoader() { |
|
| 1636 | - return $this->get(IMimeTypeLoader::class); |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - /** |
|
| 1640 | - * Get the Notification Manager |
|
| 1641 | - * |
|
| 1642 | - * @return \OCP\Notification\IManager |
|
| 1643 | - * @since 8.2.0 |
|
| 1644 | - * @deprecated 20.0.0 |
|
| 1645 | - */ |
|
| 1646 | - public function getNotificationManager() { |
|
| 1647 | - return $this->get(\OCP\Notification\IManager::class); |
|
| 1648 | - } |
|
| 1649 | - |
|
| 1650 | - /** |
|
| 1651 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1652 | - * @deprecated 20.0.0 |
|
| 1653 | - */ |
|
| 1654 | - public function getThemingDefaults() { |
|
| 1655 | - return $this->get('ThemingDefaults'); |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - /** |
|
| 1659 | - * @return \OC\IntegrityCheck\Checker |
|
| 1660 | - * @deprecated 20.0.0 |
|
| 1661 | - */ |
|
| 1662 | - public function getIntegrityCodeChecker() { |
|
| 1663 | - return $this->get('IntegrityCodeChecker'); |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * @return CsrfTokenManager |
|
| 1668 | - * @deprecated 20.0.0 |
|
| 1669 | - */ |
|
| 1670 | - public function getCsrfTokenManager() { |
|
| 1671 | - return $this->get(CsrfTokenManager::class); |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - /** |
|
| 1675 | - * @return ContentSecurityPolicyNonceManager |
|
| 1676 | - * @deprecated 20.0.0 |
|
| 1677 | - */ |
|
| 1678 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1679 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1680 | - } |
|
| 1681 | - |
|
| 1682 | - /** |
|
| 1683 | - * @return \OCP\Settings\IManager |
|
| 1684 | - * @deprecated 20.0.0 |
|
| 1685 | - */ |
|
| 1686 | - public function getSettingsManager() { |
|
| 1687 | - return $this->get(\OC\Settings\Manager::class); |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - /** |
|
| 1691 | - * @return \OCP\Files\IAppData |
|
| 1692 | - * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1693 | - */ |
|
| 1694 | - public function getAppDataDir($app) { |
|
| 1695 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1696 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1697 | - return $factory->get($app); |
|
| 1698 | - } |
|
| 1699 | - |
|
| 1700 | - /** |
|
| 1701 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1702 | - * @deprecated 20.0.0 |
|
| 1703 | - */ |
|
| 1704 | - public function getCloudIdManager() { |
|
| 1705 | - return $this->get(ICloudIdManager::class); |
|
| 1706 | - } |
|
| 1707 | - |
|
| 1708 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 1709 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 1710 | - try { |
|
| 1711 | - /** @var LoggerInterface $logger */ |
|
| 1712 | - $logger = $container->get(LoggerInterface::class); |
|
| 1713 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 1714 | - } catch (ContainerExceptionInterface $e) { |
|
| 1715 | - // Could not get logger. Continue |
|
| 1716 | - } |
|
| 1717 | - |
|
| 1718 | - return $container->get($target); |
|
| 1719 | - }, false); |
|
| 1720 | - } |
|
| 1288 | + $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1289 | + |
|
| 1290 | + $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1291 | + |
|
| 1292 | + $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1293 | + |
|
| 1294 | + $this->connectDispatcher(); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + public function boot() { |
|
| 1298 | + /** @var HookConnector $hookConnector */ |
|
| 1299 | + $hookConnector = $this->get(HookConnector::class); |
|
| 1300 | + $hookConnector->viewToNode(); |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + private function connectDispatcher(): void { |
|
| 1304 | + /** @var IEventDispatcher $eventDispatcher */ |
|
| 1305 | + $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1306 | + $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1307 | + $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1308 | + $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1309 | + $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1310 | + |
|
| 1311 | + FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1312 | + GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * @return \OCP\Contacts\IManager |
|
| 1317 | + * @deprecated 20.0.0 |
|
| 1318 | + */ |
|
| 1319 | + public function getContactsManager() { |
|
| 1320 | + return $this->get(\OCP\Contacts\IManager::class); |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * @return \OC\Encryption\Manager |
|
| 1325 | + * @deprecated 20.0.0 |
|
| 1326 | + */ |
|
| 1327 | + public function getEncryptionManager() { |
|
| 1328 | + return $this->get(\OCP\Encryption\IManager::class); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + /** |
|
| 1332 | + * @return \OC\Encryption\File |
|
| 1333 | + * @deprecated 20.0.0 |
|
| 1334 | + */ |
|
| 1335 | + public function getEncryptionFilesHelper() { |
|
| 1336 | + return $this->get(IFile::class); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * The current request object holding all information about the request |
|
| 1341 | + * currently being processed is returned from this method. |
|
| 1342 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1343 | + * |
|
| 1344 | + * @return \OCP\IRequest |
|
| 1345 | + * @deprecated 20.0.0 |
|
| 1346 | + */ |
|
| 1347 | + public function getRequest() { |
|
| 1348 | + return $this->get(IRequest::class); |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * Returns the root folder of ownCloud's data directory |
|
| 1353 | + * |
|
| 1354 | + * @return IRootFolder |
|
| 1355 | + * @deprecated 20.0.0 |
|
| 1356 | + */ |
|
| 1357 | + public function getRootFolder() { |
|
| 1358 | + return $this->get(IRootFolder::class); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + /** |
|
| 1362 | + * Returns the root folder of ownCloud's data directory |
|
| 1363 | + * This is the lazy variant so this gets only initialized once it |
|
| 1364 | + * is actually used. |
|
| 1365 | + * |
|
| 1366 | + * @return IRootFolder |
|
| 1367 | + * @deprecated 20.0.0 |
|
| 1368 | + */ |
|
| 1369 | + public function getLazyRootFolder() { |
|
| 1370 | + return $this->get(IRootFolder::class); |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * Returns a view to ownCloud's files folder |
|
| 1375 | + * |
|
| 1376 | + * @param string $userId user ID |
|
| 1377 | + * @return \OCP\Files\Folder|null |
|
| 1378 | + * @deprecated 20.0.0 |
|
| 1379 | + */ |
|
| 1380 | + public function getUserFolder($userId = null) { |
|
| 1381 | + if ($userId === null) { |
|
| 1382 | + $user = $this->get(IUserSession::class)->getUser(); |
|
| 1383 | + if (!$user) { |
|
| 1384 | + return null; |
|
| 1385 | + } |
|
| 1386 | + $userId = $user->getUID(); |
|
| 1387 | + } |
|
| 1388 | + $root = $this->get(IRootFolder::class); |
|
| 1389 | + return $root->getUserFolder($userId); |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + /** |
|
| 1393 | + * @return \OC\User\Manager |
|
| 1394 | + * @deprecated 20.0.0 |
|
| 1395 | + */ |
|
| 1396 | + public function getUserManager() { |
|
| 1397 | + return $this->get(IUserManager::class); |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + /** |
|
| 1401 | + * @return \OC\Group\Manager |
|
| 1402 | + * @deprecated 20.0.0 |
|
| 1403 | + */ |
|
| 1404 | + public function getGroupManager() { |
|
| 1405 | + return $this->get(IGroupManager::class); |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + /** |
|
| 1409 | + * @return \OC\User\Session |
|
| 1410 | + * @deprecated 20.0.0 |
|
| 1411 | + */ |
|
| 1412 | + public function getUserSession() { |
|
| 1413 | + return $this->get(IUserSession::class); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * @return \OCP\ISession |
|
| 1418 | + * @deprecated 20.0.0 |
|
| 1419 | + */ |
|
| 1420 | + public function getSession() { |
|
| 1421 | + return $this->get(Session::class)->getSession(); |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + /** |
|
| 1425 | + * @param \OCP\ISession $session |
|
| 1426 | + * @return void |
|
| 1427 | + */ |
|
| 1428 | + public function setSession(\OCP\ISession $session) { |
|
| 1429 | + $this->get(SessionStorage::class)->setSession($session); |
|
| 1430 | + $this->get(Session::class)->setSession($session); |
|
| 1431 | + $this->get(Store::class)->setSession($session); |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * @return \OCP\IConfig |
|
| 1436 | + * @deprecated 20.0.0 |
|
| 1437 | + */ |
|
| 1438 | + public function getConfig() { |
|
| 1439 | + return $this->get(AllConfig::class); |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + /** |
|
| 1443 | + * @return \OC\SystemConfig |
|
| 1444 | + * @deprecated 20.0.0 |
|
| 1445 | + */ |
|
| 1446 | + public function getSystemConfig() { |
|
| 1447 | + return $this->get(SystemConfig::class); |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + /** |
|
| 1451 | + * @return IFactory |
|
| 1452 | + * @deprecated 20.0.0 |
|
| 1453 | + */ |
|
| 1454 | + public function getL10NFactory() { |
|
| 1455 | + return $this->get(IFactory::class); |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + /** |
|
| 1459 | + * get an L10N instance |
|
| 1460 | + * |
|
| 1461 | + * @param string $app appid |
|
| 1462 | + * @param string $lang |
|
| 1463 | + * @return IL10N |
|
| 1464 | + * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1465 | + */ |
|
| 1466 | + public function getL10N($app, $lang = null) { |
|
| 1467 | + return $this->get(IFactory::class)->get($app, $lang); |
|
| 1468 | + } |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * @return IURLGenerator |
|
| 1472 | + * @deprecated 20.0.0 |
|
| 1473 | + */ |
|
| 1474 | + public function getURLGenerator() { |
|
| 1475 | + return $this->get(IURLGenerator::class); |
|
| 1476 | + } |
|
| 1477 | + |
|
| 1478 | + /** |
|
| 1479 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1480 | + * getMemCacheFactory() instead. |
|
| 1481 | + * |
|
| 1482 | + * @return ICache |
|
| 1483 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1484 | + */ |
|
| 1485 | + public function getCache() { |
|
| 1486 | + return $this->get(ICache::class); |
|
| 1487 | + } |
|
| 1488 | + |
|
| 1489 | + /** |
|
| 1490 | + * Returns an \OCP\CacheFactory instance |
|
| 1491 | + * |
|
| 1492 | + * @return \OCP\ICacheFactory |
|
| 1493 | + * @deprecated 20.0.0 |
|
| 1494 | + */ |
|
| 1495 | + public function getMemCacheFactory() { |
|
| 1496 | + return $this->get(ICacheFactory::class); |
|
| 1497 | + } |
|
| 1498 | + |
|
| 1499 | + /** |
|
| 1500 | + * Returns the current session |
|
| 1501 | + * |
|
| 1502 | + * @return \OCP\IDBConnection |
|
| 1503 | + * @deprecated 20.0.0 |
|
| 1504 | + */ |
|
| 1505 | + public function getDatabaseConnection() { |
|
| 1506 | + return $this->get(IDBConnection::class); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + /** |
|
| 1510 | + * Returns the activity manager |
|
| 1511 | + * |
|
| 1512 | + * @return \OCP\Activity\IManager |
|
| 1513 | + * @deprecated 20.0.0 |
|
| 1514 | + */ |
|
| 1515 | + public function getActivityManager() { |
|
| 1516 | + return $this->get(\OCP\Activity\IManager::class); |
|
| 1517 | + } |
|
| 1518 | + |
|
| 1519 | + /** |
|
| 1520 | + * Returns an job list for controlling background jobs |
|
| 1521 | + * |
|
| 1522 | + * @return IJobList |
|
| 1523 | + * @deprecated 20.0.0 |
|
| 1524 | + */ |
|
| 1525 | + public function getJobList() { |
|
| 1526 | + return $this->get(IJobList::class); |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + /** |
|
| 1530 | + * Returns a SecureRandom instance |
|
| 1531 | + * |
|
| 1532 | + * @return \OCP\Security\ISecureRandom |
|
| 1533 | + * @deprecated 20.0.0 |
|
| 1534 | + */ |
|
| 1535 | + public function getSecureRandom() { |
|
| 1536 | + return $this->get(ISecureRandom::class); |
|
| 1537 | + } |
|
| 1538 | + |
|
| 1539 | + /** |
|
| 1540 | + * Returns a Crypto instance |
|
| 1541 | + * |
|
| 1542 | + * @return ICrypto |
|
| 1543 | + * @deprecated 20.0.0 |
|
| 1544 | + */ |
|
| 1545 | + public function getCrypto() { |
|
| 1546 | + return $this->get(ICrypto::class); |
|
| 1547 | + } |
|
| 1548 | + |
|
| 1549 | + /** |
|
| 1550 | + * Returns a Hasher instance |
|
| 1551 | + * |
|
| 1552 | + * @return IHasher |
|
| 1553 | + * @deprecated 20.0.0 |
|
| 1554 | + */ |
|
| 1555 | + public function getHasher() { |
|
| 1556 | + return $this->get(IHasher::class); |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + /** |
|
| 1560 | + * Get the certificate manager |
|
| 1561 | + * |
|
| 1562 | + * @return \OCP\ICertificateManager |
|
| 1563 | + */ |
|
| 1564 | + public function getCertificateManager() { |
|
| 1565 | + return $this->get(ICertificateManager::class); |
|
| 1566 | + } |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * Get the manager for temporary files and folders |
|
| 1570 | + * |
|
| 1571 | + * @return \OCP\ITempManager |
|
| 1572 | + * @deprecated 20.0.0 |
|
| 1573 | + */ |
|
| 1574 | + public function getTempManager() { |
|
| 1575 | + return $this->get(ITempManager::class); |
|
| 1576 | + } |
|
| 1577 | + |
|
| 1578 | + /** |
|
| 1579 | + * Get the app manager |
|
| 1580 | + * |
|
| 1581 | + * @return \OCP\App\IAppManager |
|
| 1582 | + * @deprecated 20.0.0 |
|
| 1583 | + */ |
|
| 1584 | + public function getAppManager() { |
|
| 1585 | + return $this->get(IAppManager::class); |
|
| 1586 | + } |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * Creates a new mailer |
|
| 1590 | + * |
|
| 1591 | + * @return IMailer |
|
| 1592 | + * @deprecated 20.0.0 |
|
| 1593 | + */ |
|
| 1594 | + public function getMailer() { |
|
| 1595 | + return $this->get(IMailer::class); |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + /** |
|
| 1599 | + * Get the webroot |
|
| 1600 | + * |
|
| 1601 | + * @return string |
|
| 1602 | + * @deprecated 20.0.0 |
|
| 1603 | + */ |
|
| 1604 | + public function getWebRoot() { |
|
| 1605 | + return $this->webRoot; |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * Get the locking provider |
|
| 1610 | + * |
|
| 1611 | + * @return ILockingProvider |
|
| 1612 | + * @since 8.1.0 |
|
| 1613 | + * @deprecated 20.0.0 |
|
| 1614 | + */ |
|
| 1615 | + public function getLockingProvider() { |
|
| 1616 | + return $this->get(ILockingProvider::class); |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + /** |
|
| 1620 | + * Get the MimeTypeDetector |
|
| 1621 | + * |
|
| 1622 | + * @return IMimeTypeDetector |
|
| 1623 | + * @deprecated 20.0.0 |
|
| 1624 | + */ |
|
| 1625 | + public function getMimeTypeDetector() { |
|
| 1626 | + return $this->get(IMimeTypeDetector::class); |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + /** |
|
| 1630 | + * Get the MimeTypeLoader |
|
| 1631 | + * |
|
| 1632 | + * @return IMimeTypeLoader |
|
| 1633 | + * @deprecated 20.0.0 |
|
| 1634 | + */ |
|
| 1635 | + public function getMimeTypeLoader() { |
|
| 1636 | + return $this->get(IMimeTypeLoader::class); |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + /** |
|
| 1640 | + * Get the Notification Manager |
|
| 1641 | + * |
|
| 1642 | + * @return \OCP\Notification\IManager |
|
| 1643 | + * @since 8.2.0 |
|
| 1644 | + * @deprecated 20.0.0 |
|
| 1645 | + */ |
|
| 1646 | + public function getNotificationManager() { |
|
| 1647 | + return $this->get(\OCP\Notification\IManager::class); |
|
| 1648 | + } |
|
| 1649 | + |
|
| 1650 | + /** |
|
| 1651 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1652 | + * @deprecated 20.0.0 |
|
| 1653 | + */ |
|
| 1654 | + public function getThemingDefaults() { |
|
| 1655 | + return $this->get('ThemingDefaults'); |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + /** |
|
| 1659 | + * @return \OC\IntegrityCheck\Checker |
|
| 1660 | + * @deprecated 20.0.0 |
|
| 1661 | + */ |
|
| 1662 | + public function getIntegrityCodeChecker() { |
|
| 1663 | + return $this->get('IntegrityCodeChecker'); |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * @return CsrfTokenManager |
|
| 1668 | + * @deprecated 20.0.0 |
|
| 1669 | + */ |
|
| 1670 | + public function getCsrfTokenManager() { |
|
| 1671 | + return $this->get(CsrfTokenManager::class); |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + /** |
|
| 1675 | + * @return ContentSecurityPolicyNonceManager |
|
| 1676 | + * @deprecated 20.0.0 |
|
| 1677 | + */ |
|
| 1678 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1679 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1680 | + } |
|
| 1681 | + |
|
| 1682 | + /** |
|
| 1683 | + * @return \OCP\Settings\IManager |
|
| 1684 | + * @deprecated 20.0.0 |
|
| 1685 | + */ |
|
| 1686 | + public function getSettingsManager() { |
|
| 1687 | + return $this->get(\OC\Settings\Manager::class); |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + /** |
|
| 1691 | + * @return \OCP\Files\IAppData |
|
| 1692 | + * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1693 | + */ |
|
| 1694 | + public function getAppDataDir($app) { |
|
| 1695 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1696 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1697 | + return $factory->get($app); |
|
| 1698 | + } |
|
| 1699 | + |
|
| 1700 | + /** |
|
| 1701 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1702 | + * @deprecated 20.0.0 |
|
| 1703 | + */ |
|
| 1704 | + public function getCloudIdManager() { |
|
| 1705 | + return $this->get(ICloudIdManager::class); |
|
| 1706 | + } |
|
| 1707 | + |
|
| 1708 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 1709 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 1710 | + try { |
|
| 1711 | + /** @var LoggerInterface $logger */ |
|
| 1712 | + $logger = $container->get(LoggerInterface::class); |
|
| 1713 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 1714 | + } catch (ContainerExceptionInterface $e) { |
|
| 1715 | + // Could not get logger. Continue |
|
| 1716 | + } |
|
| 1717 | + |
|
| 1718 | + return $container->get($target); |
|
| 1719 | + }, false); |
|
| 1720 | + } |
|
| 1721 | 1721 | } |
@@ -17,124 +17,124 @@ |
||
| 17 | 17 | * @psalm-type ObjectStoreConfig array{class: class-string<IObjectStore>, arguments: array{multibucket: bool, ...}} |
| 18 | 18 | */ |
| 19 | 19 | class PrimaryObjectStoreConfig { |
| 20 | - public function __construct( |
|
| 21 | - private readonly IConfig $config, |
|
| 22 | - private readonly IAppManager $appManager, |
|
| 23 | - ) { |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param ObjectStoreConfig $config |
|
| 28 | - */ |
|
| 29 | - public function buildObjectStore(array $config): IObjectStore { |
|
| 30 | - return new $config['class']($config['arguments']); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return ?ObjectStoreConfig |
|
| 35 | - */ |
|
| 36 | - public function getObjectStoreConfigForRoot(): ?array { |
|
| 37 | - $config = $this->getObjectStoreConfig(); |
|
| 38 | - |
|
| 39 | - if ($config && $config['arguments']['multibucket']) { |
|
| 40 | - if (!isset($config['arguments']['bucket'])) { |
|
| 41 | - $config['arguments']['bucket'] = ''; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - // put the root FS always in first bucket for multibucket configuration |
|
| 45 | - $config['arguments']['bucket'] .= '0'; |
|
| 46 | - } |
|
| 47 | - return $config; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return ?ObjectStoreConfig |
|
| 52 | - */ |
|
| 53 | - public function getObjectStoreConfigForUser(IUser $user): ?array { |
|
| 54 | - $config = $this->getObjectStoreConfig(); |
|
| 55 | - |
|
| 56 | - if ($config && $config['arguments']['multibucket']) { |
|
| 57 | - $config['arguments']['bucket'] = $this->getBucketForUser($user, $config); |
|
| 58 | - } |
|
| 59 | - return $config; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return ?ObjectStoreConfig |
|
| 64 | - */ |
|
| 65 | - private function getObjectStoreConfig(): ?array { |
|
| 66 | - $objectStore = $this->config->getSystemValue('objectstore', null); |
|
| 67 | - $objectStoreMultiBucket = $this->config->getSystemValue('objectstore_multibucket', null); |
|
| 68 | - |
|
| 69 | - // new-style multibucket config uses the same 'objectstore' key but sets `'multibucket' => true`, transparently upgrade older style config |
|
| 70 | - if ($objectStoreMultiBucket) { |
|
| 71 | - $objectStoreMultiBucket['arguments']['multibucket'] = true; |
|
| 72 | - return $this->validateObjectStoreConfig($objectStoreMultiBucket); |
|
| 73 | - } elseif ($objectStore) { |
|
| 74 | - return $this->validateObjectStoreConfig($objectStore); |
|
| 75 | - } else { |
|
| 76 | - return null; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return ObjectStoreConfig |
|
| 82 | - */ |
|
| 83 | - private function validateObjectStoreConfig(array $config) { |
|
| 84 | - if (!isset($config['class'])) { |
|
| 85 | - throw new \Exception('No class configured for object store'); |
|
| 86 | - } |
|
| 87 | - if (!isset($config['arguments'])) { |
|
| 88 | - $config['arguments'] = []; |
|
| 89 | - } |
|
| 90 | - $class = $config['class']; |
|
| 91 | - $arguments = $config['arguments']; |
|
| 92 | - if (!is_array($arguments)) { |
|
| 93 | - throw new \Exception('Configured object store arguments are not an array'); |
|
| 94 | - } |
|
| 95 | - if (!isset($arguments['multibucket'])) { |
|
| 96 | - $arguments['multibucket'] = false; |
|
| 97 | - } |
|
| 98 | - if (!is_bool($arguments['multibucket'])) { |
|
| 99 | - throw new \Exception('arguments.multibucket must be a boolean in object store configuration'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if (!is_string($class)) { |
|
| 103 | - throw new \Exception('Configured class for object store is not a string'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if (str_starts_with($class, 'OCA\\') && substr_count($class, '\\') >= 2) { |
|
| 107 | - [$appId] = explode('\\', $class); |
|
| 108 | - $this->appManager->loadApp(strtolower($appId)); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if (!is_a($class, IObjectStore::class, true)) { |
|
| 112 | - throw new \Exception('Configured class for object store is not an object store'); |
|
| 113 | - } |
|
| 114 | - return [ |
|
| 115 | - 'class' => $class, |
|
| 116 | - 'arguments' => $arguments, |
|
| 117 | - ]; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - private function getBucketForUser(IUser $user, array $config): string { |
|
| 121 | - $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null); |
|
| 122 | - |
|
| 123 | - if ($bucket === null) { |
|
| 124 | - /* |
|
| 20 | + public function __construct( |
|
| 21 | + private readonly IConfig $config, |
|
| 22 | + private readonly IAppManager $appManager, |
|
| 23 | + ) { |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param ObjectStoreConfig $config |
|
| 28 | + */ |
|
| 29 | + public function buildObjectStore(array $config): IObjectStore { |
|
| 30 | + return new $config['class']($config['arguments']); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return ?ObjectStoreConfig |
|
| 35 | + */ |
|
| 36 | + public function getObjectStoreConfigForRoot(): ?array { |
|
| 37 | + $config = $this->getObjectStoreConfig(); |
|
| 38 | + |
|
| 39 | + if ($config && $config['arguments']['multibucket']) { |
|
| 40 | + if (!isset($config['arguments']['bucket'])) { |
|
| 41 | + $config['arguments']['bucket'] = ''; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + // put the root FS always in first bucket for multibucket configuration |
|
| 45 | + $config['arguments']['bucket'] .= '0'; |
|
| 46 | + } |
|
| 47 | + return $config; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return ?ObjectStoreConfig |
|
| 52 | + */ |
|
| 53 | + public function getObjectStoreConfigForUser(IUser $user): ?array { |
|
| 54 | + $config = $this->getObjectStoreConfig(); |
|
| 55 | + |
|
| 56 | + if ($config && $config['arguments']['multibucket']) { |
|
| 57 | + $config['arguments']['bucket'] = $this->getBucketForUser($user, $config); |
|
| 58 | + } |
|
| 59 | + return $config; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return ?ObjectStoreConfig |
|
| 64 | + */ |
|
| 65 | + private function getObjectStoreConfig(): ?array { |
|
| 66 | + $objectStore = $this->config->getSystemValue('objectstore', null); |
|
| 67 | + $objectStoreMultiBucket = $this->config->getSystemValue('objectstore_multibucket', null); |
|
| 68 | + |
|
| 69 | + // new-style multibucket config uses the same 'objectstore' key but sets `'multibucket' => true`, transparently upgrade older style config |
|
| 70 | + if ($objectStoreMultiBucket) { |
|
| 71 | + $objectStoreMultiBucket['arguments']['multibucket'] = true; |
|
| 72 | + return $this->validateObjectStoreConfig($objectStoreMultiBucket); |
|
| 73 | + } elseif ($objectStore) { |
|
| 74 | + return $this->validateObjectStoreConfig($objectStore); |
|
| 75 | + } else { |
|
| 76 | + return null; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return ObjectStoreConfig |
|
| 82 | + */ |
|
| 83 | + private function validateObjectStoreConfig(array $config) { |
|
| 84 | + if (!isset($config['class'])) { |
|
| 85 | + throw new \Exception('No class configured for object store'); |
|
| 86 | + } |
|
| 87 | + if (!isset($config['arguments'])) { |
|
| 88 | + $config['arguments'] = []; |
|
| 89 | + } |
|
| 90 | + $class = $config['class']; |
|
| 91 | + $arguments = $config['arguments']; |
|
| 92 | + if (!is_array($arguments)) { |
|
| 93 | + throw new \Exception('Configured object store arguments are not an array'); |
|
| 94 | + } |
|
| 95 | + if (!isset($arguments['multibucket'])) { |
|
| 96 | + $arguments['multibucket'] = false; |
|
| 97 | + } |
|
| 98 | + if (!is_bool($arguments['multibucket'])) { |
|
| 99 | + throw new \Exception('arguments.multibucket must be a boolean in object store configuration'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if (!is_string($class)) { |
|
| 103 | + throw new \Exception('Configured class for object store is not a string'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if (str_starts_with($class, 'OCA\\') && substr_count($class, '\\') >= 2) { |
|
| 107 | + [$appId] = explode('\\', $class); |
|
| 108 | + $this->appManager->loadApp(strtolower($appId)); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if (!is_a($class, IObjectStore::class, true)) { |
|
| 112 | + throw new \Exception('Configured class for object store is not an object store'); |
|
| 113 | + } |
|
| 114 | + return [ |
|
| 115 | + 'class' => $class, |
|
| 116 | + 'arguments' => $arguments, |
|
| 117 | + ]; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + private function getBucketForUser(IUser $user, array $config): string { |
|
| 121 | + $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null); |
|
| 122 | + |
|
| 123 | + if ($bucket === null) { |
|
| 124 | + /* |
|
| 125 | 125 | * Use any provided bucket argument as prefix |
| 126 | 126 | * and add the mapping from username => bucket |
| 127 | 127 | */ |
| 128 | - if (!isset($config['arguments']['bucket'])) { |
|
| 129 | - $config['arguments']['bucket'] = ''; |
|
| 130 | - } |
|
| 131 | - $mapper = new Mapper($user, $this->config); |
|
| 132 | - $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; |
|
| 133 | - $bucket = $config['arguments']['bucket'] . $mapper->getBucket($numBuckets); |
|
| 134 | - |
|
| 135 | - $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $bucket); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $bucket; |
|
| 139 | - } |
|
| 128 | + if (!isset($config['arguments']['bucket'])) { |
|
| 129 | + $config['arguments']['bucket'] = ''; |
|
| 130 | + } |
|
| 131 | + $mapper = new Mapper($user, $this->config); |
|
| 132 | + $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; |
|
| 133 | + $bucket = $config['arguments']['bucket'] . $mapper->getBucket($numBuckets); |
|
| 134 | + |
|
| 135 | + $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $bucket); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $bucket; |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -17,34 +17,34 @@ |
||
| 17 | 17 | use OCP\IConfig; |
| 18 | 18 | |
| 19 | 19 | class RootMountProvider implements IRootMountProvider { |
| 20 | - private PrimaryObjectStoreConfig $objectStoreConfig; |
|
| 21 | - private IConfig $config; |
|
| 22 | - |
|
| 23 | - public function __construct(PrimaryObjectStoreConfig $objectStoreConfig, IConfig $config) { |
|
| 24 | - $this->objectStoreConfig = $objectStoreConfig; |
|
| 25 | - $this->config = $config; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function getRootMounts(IStorageFactory $loader): array { |
|
| 29 | - $objectStoreConfig = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 30 | - |
|
| 31 | - if ($objectStoreConfig) { |
|
| 32 | - return [$this->getObjectStoreRootMount($loader, $objectStoreConfig)]; |
|
| 33 | - } else { |
|
| 34 | - return [$this->getLocalRootMount($loader)]; |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - private function getLocalRootMount(IStorageFactory $loader): MountPoint { |
|
| 39 | - $configDataDirectory = $this->config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 40 | - return new MountPoint(LocalRootStorage::class, '/', ['datadir' => $configDataDirectory], $loader, null, null, self::class); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - private function getObjectStoreRootMount(IStorageFactory $loader, array $objectStoreConfig): MountPoint { |
|
| 44 | - $arguments = array_merge($objectStoreConfig['arguments'], [ |
|
| 45 | - 'objectstore' => $this->objectStoreConfig->buildObjectStore($objectStoreConfig), |
|
| 46 | - ]); |
|
| 47 | - |
|
| 48 | - return new MountPoint(ObjectStoreStorage::class, '/', $arguments, $loader, null, null, self::class); |
|
| 49 | - } |
|
| 20 | + private PrimaryObjectStoreConfig $objectStoreConfig; |
|
| 21 | + private IConfig $config; |
|
| 22 | + |
|
| 23 | + public function __construct(PrimaryObjectStoreConfig $objectStoreConfig, IConfig $config) { |
|
| 24 | + $this->objectStoreConfig = $objectStoreConfig; |
|
| 25 | + $this->config = $config; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function getRootMounts(IStorageFactory $loader): array { |
|
| 29 | + $objectStoreConfig = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 30 | + |
|
| 31 | + if ($objectStoreConfig) { |
|
| 32 | + return [$this->getObjectStoreRootMount($loader, $objectStoreConfig)]; |
|
| 33 | + } else { |
|
| 34 | + return [$this->getLocalRootMount($loader)]; |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + private function getLocalRootMount(IStorageFactory $loader): MountPoint { |
|
| 39 | + $configDataDirectory = $this->config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 40 | + return new MountPoint(LocalRootStorage::class, '/', ['datadir' => $configDataDirectory], $loader, null, null, self::class); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + private function getObjectStoreRootMount(IStorageFactory $loader, array $objectStoreConfig): MountPoint { |
|
| 44 | + $arguments = array_merge($objectStoreConfig['arguments'], [ |
|
| 45 | + 'objectstore' => $this->objectStoreConfig->buildObjectStore($objectStoreConfig), |
|
| 46 | + ]); |
|
| 47 | + |
|
| 48 | + return new MountPoint(ObjectStoreStorage::class, '/', $arguments, $loader, null, null, self::class); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -18,28 +18,28 @@ |
||
| 18 | 18 | * Mount provider for object store home storages |
| 19 | 19 | */ |
| 20 | 20 | class ObjectHomeMountProvider implements IHomeMountProvider { |
| 21 | - public function __construct( |
|
| 22 | - private PrimaryObjectStoreConfig $objectStoreConfig, |
|
| 23 | - ) { |
|
| 24 | - } |
|
| 21 | + public function __construct( |
|
| 22 | + private PrimaryObjectStoreConfig $objectStoreConfig, |
|
| 23 | + ) { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Get the home mount for a user |
|
| 28 | - * |
|
| 29 | - * @param IUser $user |
|
| 30 | - * @param IStorageFactory $loader |
|
| 31 | - * @return ?IMountPoint |
|
| 32 | - */ |
|
| 33 | - public function getHomeMountForUser(IUser $user, IStorageFactory $loader): ?IMountPoint { |
|
| 34 | - $objectStoreConfig = $this->objectStoreConfig->getObjectStoreConfigForUser($user); |
|
| 35 | - if ($objectStoreConfig === null) { |
|
| 36 | - return null; |
|
| 37 | - } |
|
| 38 | - $arguments = array_merge($objectStoreConfig['arguments'], [ |
|
| 39 | - 'objectstore' => $this->objectStoreConfig->buildObjectStore($objectStoreConfig), |
|
| 40 | - 'user' => $user, |
|
| 41 | - ]); |
|
| 26 | + /** |
|
| 27 | + * Get the home mount for a user |
|
| 28 | + * |
|
| 29 | + * @param IUser $user |
|
| 30 | + * @param IStorageFactory $loader |
|
| 31 | + * @return ?IMountPoint |
|
| 32 | + */ |
|
| 33 | + public function getHomeMountForUser(IUser $user, IStorageFactory $loader): ?IMountPoint { |
|
| 34 | + $objectStoreConfig = $this->objectStoreConfig->getObjectStoreConfigForUser($user); |
|
| 35 | + if ($objectStoreConfig === null) { |
|
| 36 | + return null; |
|
| 37 | + } |
|
| 38 | + $arguments = array_merge($objectStoreConfig['arguments'], [ |
|
| 39 | + 'objectstore' => $this->objectStoreConfig->buildObjectStore($objectStoreConfig), |
|
| 40 | + 'user' => $user, |
|
| 41 | + ]); |
|
| 42 | 42 | |
| 43 | - return new HomeMountPoint($user, HomeObjectStoreStorage::class, '/' . $user->getUID(), $arguments, $loader, null, null, self::class); |
|
| 44 | - } |
|
| 43 | + return new HomeMountPoint($user, HomeObjectStoreStorage::class, '/' . $user->getUID(), $arguments, $loader, null, null, self::class); |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -22,106 +22,106 @@ |
||
| 22 | 22 | * @group DB |
| 23 | 23 | */ |
| 24 | 24 | class RootMountProviderTest extends TestCase { |
| 25 | - private StorageFactory $loader; |
|
| 25 | + private StorageFactory $loader; |
|
| 26 | 26 | |
| 27 | - protected function setUp(): void { |
|
| 28 | - parent::setUp(); |
|
| 27 | + protected function setUp(): void { |
|
| 28 | + parent::setUp(); |
|
| 29 | 29 | |
| 30 | - $this->loader = new StorageFactory(); |
|
| 31 | - } |
|
| 30 | + $this->loader = new StorageFactory(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - private function getConfig(array $systemConfig): IConfig { |
|
| 34 | - $config = $this->createMock(IConfig::class); |
|
| 35 | - $config->method('getSystemValue') |
|
| 36 | - ->willReturnCallback(function (string $key, $default) use ($systemConfig) { |
|
| 37 | - return $systemConfig[$key] ?? $default; |
|
| 38 | - }); |
|
| 39 | - return $config; |
|
| 40 | - } |
|
| 33 | + private function getConfig(array $systemConfig): IConfig { |
|
| 34 | + $config = $this->createMock(IConfig::class); |
|
| 35 | + $config->method('getSystemValue') |
|
| 36 | + ->willReturnCallback(function (string $key, $default) use ($systemConfig) { |
|
| 37 | + return $systemConfig[$key] ?? $default; |
|
| 38 | + }); |
|
| 39 | + return $config; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - private function getProvider(array $systemConfig): RootMountProvider { |
|
| 43 | - $config = $this->getConfig($systemConfig); |
|
| 44 | - $objectStoreConfig = new PrimaryObjectStoreConfig($config, $this->createMock(IAppManager::class)); |
|
| 45 | - return new RootMountProvider($objectStoreConfig, $config); |
|
| 46 | - } |
|
| 42 | + private function getProvider(array $systemConfig): RootMountProvider { |
|
| 43 | + $config = $this->getConfig($systemConfig); |
|
| 44 | + $objectStoreConfig = new PrimaryObjectStoreConfig($config, $this->createMock(IAppManager::class)); |
|
| 45 | + return new RootMountProvider($objectStoreConfig, $config); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function testLocal(): void { |
|
| 49 | - $provider = $this->getProvider([ |
|
| 50 | - 'datadirectory' => '/data', |
|
| 51 | - ]); |
|
| 52 | - $mounts = $provider->getRootMounts($this->loader); |
|
| 53 | - $this->assertCount(1, $mounts); |
|
| 54 | - $mount = $mounts[0]; |
|
| 55 | - $this->assertEquals('/', $mount->getMountPoint()); |
|
| 56 | - /** @var LocalRootStorage $storage */ |
|
| 57 | - $storage = $mount->getStorage(); |
|
| 58 | - $this->assertInstanceOf(LocalRootStorage::class, $storage); |
|
| 59 | - $this->assertEquals('/data/', $storage->getSourcePath('')); |
|
| 60 | - } |
|
| 48 | + public function testLocal(): void { |
|
| 49 | + $provider = $this->getProvider([ |
|
| 50 | + 'datadirectory' => '/data', |
|
| 51 | + ]); |
|
| 52 | + $mounts = $provider->getRootMounts($this->loader); |
|
| 53 | + $this->assertCount(1, $mounts); |
|
| 54 | + $mount = $mounts[0]; |
|
| 55 | + $this->assertEquals('/', $mount->getMountPoint()); |
|
| 56 | + /** @var LocalRootStorage $storage */ |
|
| 57 | + $storage = $mount->getStorage(); |
|
| 58 | + $this->assertInstanceOf(LocalRootStorage::class, $storage); |
|
| 59 | + $this->assertEquals('/data/', $storage->getSourcePath('')); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function testObjectStore(): void { |
|
| 63 | - $provider = $this->getProvider([ |
|
| 64 | - 'objectstore' => [ |
|
| 65 | - 'class' => "OC\Files\ObjectStore\S3", |
|
| 66 | - 'arguments' => [ |
|
| 67 | - 'bucket' => 'nextcloud', |
|
| 68 | - 'autocreate' => true, |
|
| 69 | - 'key' => 'minio', |
|
| 70 | - 'secret' => 'minio123', |
|
| 71 | - 'hostname' => 'localhost', |
|
| 72 | - 'port' => 9000, |
|
| 73 | - 'use_ssl' => false, |
|
| 74 | - 'use_path_style' => true, |
|
| 75 | - 'uploadPartSize' => 52428800, |
|
| 76 | - ], |
|
| 77 | - ], |
|
| 78 | - ]); |
|
| 79 | - $mounts = $provider->getRootMounts($this->loader); |
|
| 80 | - $this->assertCount(1, $mounts); |
|
| 81 | - $mount = $mounts[0]; |
|
| 82 | - $this->assertEquals('/', $mount->getMountPoint()); |
|
| 83 | - /** @var ObjectStoreStorage $storage */ |
|
| 84 | - $storage = $mount->getStorage(); |
|
| 85 | - $this->assertInstanceOf(ObjectStoreStorage::class, $storage); |
|
| 62 | + public function testObjectStore(): void { |
|
| 63 | + $provider = $this->getProvider([ |
|
| 64 | + 'objectstore' => [ |
|
| 65 | + 'class' => "OC\Files\ObjectStore\S3", |
|
| 66 | + 'arguments' => [ |
|
| 67 | + 'bucket' => 'nextcloud', |
|
| 68 | + 'autocreate' => true, |
|
| 69 | + 'key' => 'minio', |
|
| 70 | + 'secret' => 'minio123', |
|
| 71 | + 'hostname' => 'localhost', |
|
| 72 | + 'port' => 9000, |
|
| 73 | + 'use_ssl' => false, |
|
| 74 | + 'use_path_style' => true, |
|
| 75 | + 'uploadPartSize' => 52428800, |
|
| 76 | + ], |
|
| 77 | + ], |
|
| 78 | + ]); |
|
| 79 | + $mounts = $provider->getRootMounts($this->loader); |
|
| 80 | + $this->assertCount(1, $mounts); |
|
| 81 | + $mount = $mounts[0]; |
|
| 82 | + $this->assertEquals('/', $mount->getMountPoint()); |
|
| 83 | + /** @var ObjectStoreStorage $storage */ |
|
| 84 | + $storage = $mount->getStorage(); |
|
| 85 | + $this->assertInstanceOf(ObjectStoreStorage::class, $storage); |
|
| 86 | 86 | |
| 87 | - $class = new \ReflectionClass($storage); |
|
| 88 | - $prop = $class->getProperty('objectStore'); |
|
| 89 | - $prop->setAccessible(true); |
|
| 90 | - /** @var S3 $objectStore */ |
|
| 91 | - $objectStore = $prop->getValue($storage); |
|
| 92 | - $this->assertEquals('nextcloud', $objectStore->getBucket()); |
|
| 93 | - } |
|
| 87 | + $class = new \ReflectionClass($storage); |
|
| 88 | + $prop = $class->getProperty('objectStore'); |
|
| 89 | + $prop->setAccessible(true); |
|
| 90 | + /** @var S3 $objectStore */ |
|
| 91 | + $objectStore = $prop->getValue($storage); |
|
| 92 | + $this->assertEquals('nextcloud', $objectStore->getBucket()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function testObjectStoreMultiBucket(): void { |
|
| 96 | - $provider = $this->getProvider([ |
|
| 97 | - 'objectstore_multibucket' => [ |
|
| 98 | - 'class' => "OC\Files\ObjectStore\S3", |
|
| 99 | - 'arguments' => [ |
|
| 100 | - 'bucket' => 'nextcloud', |
|
| 101 | - 'autocreate' => true, |
|
| 102 | - 'key' => 'minio', |
|
| 103 | - 'secret' => 'minio123', |
|
| 104 | - 'hostname' => 'localhost', |
|
| 105 | - 'port' => 9000, |
|
| 106 | - 'use_ssl' => false, |
|
| 107 | - 'use_path_style' => true, |
|
| 108 | - 'uploadPartSize' => 52428800, |
|
| 109 | - ], |
|
| 110 | - ], |
|
| 111 | - ]); |
|
| 112 | - $mounts = $provider->getRootMounts($this->loader); |
|
| 113 | - $this->assertCount(1, $mounts); |
|
| 114 | - $mount = $mounts[0]; |
|
| 115 | - $this->assertEquals('/', $mount->getMountPoint()); |
|
| 116 | - /** @var ObjectStoreStorage $storage */ |
|
| 117 | - $storage = $mount->getStorage(); |
|
| 118 | - $this->assertInstanceOf(ObjectStoreStorage::class, $storage); |
|
| 95 | + public function testObjectStoreMultiBucket(): void { |
|
| 96 | + $provider = $this->getProvider([ |
|
| 97 | + 'objectstore_multibucket' => [ |
|
| 98 | + 'class' => "OC\Files\ObjectStore\S3", |
|
| 99 | + 'arguments' => [ |
|
| 100 | + 'bucket' => 'nextcloud', |
|
| 101 | + 'autocreate' => true, |
|
| 102 | + 'key' => 'minio', |
|
| 103 | + 'secret' => 'minio123', |
|
| 104 | + 'hostname' => 'localhost', |
|
| 105 | + 'port' => 9000, |
|
| 106 | + 'use_ssl' => false, |
|
| 107 | + 'use_path_style' => true, |
|
| 108 | + 'uploadPartSize' => 52428800, |
|
| 109 | + ], |
|
| 110 | + ], |
|
| 111 | + ]); |
|
| 112 | + $mounts = $provider->getRootMounts($this->loader); |
|
| 113 | + $this->assertCount(1, $mounts); |
|
| 114 | + $mount = $mounts[0]; |
|
| 115 | + $this->assertEquals('/', $mount->getMountPoint()); |
|
| 116 | + /** @var ObjectStoreStorage $storage */ |
|
| 117 | + $storage = $mount->getStorage(); |
|
| 118 | + $this->assertInstanceOf(ObjectStoreStorage::class, $storage); |
|
| 119 | 119 | |
| 120 | - $class = new \ReflectionClass($storage); |
|
| 121 | - $prop = $class->getProperty('objectStore'); |
|
| 122 | - $prop->setAccessible(true); |
|
| 123 | - /** @var S3 $objectStore */ |
|
| 124 | - $objectStore = $prop->getValue($storage); |
|
| 125 | - $this->assertEquals('nextcloud0', $objectStore->getBucket()); |
|
| 126 | - } |
|
| 120 | + $class = new \ReflectionClass($storage); |
|
| 121 | + $prop = $class->getProperty('objectStore'); |
|
| 122 | + $prop->setAccessible(true); |
|
| 123 | + /** @var S3 $objectStore */ |
|
| 124 | + $objectStore = $prop->getValue($storage); |
|
| 125 | + $this->assertEquals('nextcloud0', $objectStore->getBucket()); |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -15,257 +15,257 @@ |
||
| 15 | 15 | use OCP\IUser; |
| 16 | 16 | |
| 17 | 17 | class ObjectHomeMountProviderTest extends \Test\TestCase { |
| 18 | - /** @var ObjectHomeMountProvider */ |
|
| 19 | - protected $provider; |
|
| 20 | - |
|
| 21 | - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ |
|
| 22 | - protected $config; |
|
| 23 | - |
|
| 24 | - /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ |
|
| 25 | - protected $user; |
|
| 26 | - |
|
| 27 | - /** @var IStorageFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
| 28 | - protected $loader; |
|
| 29 | - |
|
| 30 | - protected function setUp(): void { |
|
| 31 | - parent::setUp(); |
|
| 32 | - |
|
| 33 | - $this->config = $this->createMock(IConfig::class); |
|
| 34 | - $this->user = $this->createMock(IUser::class); |
|
| 35 | - $this->loader = $this->createMock(IStorageFactory::class); |
|
| 36 | - |
|
| 37 | - $objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->createMock(IAppManager::class)); |
|
| 38 | - $this->provider = new ObjectHomeMountProvider($objectStoreConfig); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function testSingleBucket(): void { |
|
| 42 | - $this->config->method('getSystemValue') |
|
| 43 | - ->willReturnCallback(function ($key, $default) { |
|
| 44 | - if ($key === 'objectstore') { |
|
| 45 | - return [ |
|
| 46 | - 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 47 | - 'arguments' => [ |
|
| 48 | - 'foo' => 'bar' |
|
| 49 | - ], |
|
| 50 | - ]; |
|
| 51 | - } else { |
|
| 52 | - return $default; |
|
| 53 | - } |
|
| 54 | - }); |
|
| 55 | - |
|
| 56 | - $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 57 | - $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 58 | - |
|
| 59 | - $objectStore = $arguments['objectstore']; |
|
| 60 | - $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 61 | - $this->assertEquals(['foo' => 'bar', 'multibucket' => false], $objectStore->getArguments()); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function testMultiBucket(): void { |
|
| 65 | - $this->config->method('getSystemValue') |
|
| 66 | - ->willReturnCallback(function ($key, $default) { |
|
| 67 | - if ($key === 'objectstore_multibucket') { |
|
| 68 | - return [ |
|
| 69 | - 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 70 | - 'arguments' => [ |
|
| 71 | - 'foo' => 'bar' |
|
| 72 | - ], |
|
| 73 | - ]; |
|
| 74 | - } else { |
|
| 75 | - return $default; |
|
| 76 | - } |
|
| 77 | - }); |
|
| 78 | - |
|
| 79 | - $this->user->method('getUID') |
|
| 80 | - ->willReturn('uid'); |
|
| 81 | - $this->loader->expects($this->never())->method($this->anything()); |
|
| 82 | - |
|
| 83 | - $this->config->method('getUserValue') |
|
| 84 | - ->willReturn(null); |
|
| 85 | - |
|
| 86 | - $this->config->expects($this->once()) |
|
| 87 | - ->method('setUserValue') |
|
| 88 | - ->with( |
|
| 89 | - $this->equalTo('uid'), |
|
| 90 | - $this->equalTo('homeobjectstore'), |
|
| 91 | - $this->equalTo('bucket'), |
|
| 92 | - $this->equalTo('49'), |
|
| 93 | - $this->equalTo(null) |
|
| 94 | - ); |
|
| 95 | - |
|
| 96 | - $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 97 | - $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 98 | - |
|
| 99 | - $objectStore = $arguments['objectstore']; |
|
| 100 | - $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 101 | - $this->assertEquals(['foo' => 'bar', 'bucket' => 49, 'multibucket' => true], $objectStore->getArguments()); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function testMultiBucketWithPrefix(): void { |
|
| 105 | - $this->config->method('getSystemValue') |
|
| 106 | - ->willReturnCallback(function ($key, $default) { |
|
| 107 | - if ($key === 'objectstore_multibucket') { |
|
| 108 | - return [ |
|
| 109 | - 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 110 | - 'arguments' => [ |
|
| 111 | - 'foo' => 'bar', |
|
| 112 | - 'bucket' => 'myBucketPrefix', |
|
| 113 | - ], |
|
| 114 | - ]; |
|
| 115 | - } else { |
|
| 116 | - return $default; |
|
| 117 | - } |
|
| 118 | - }); |
|
| 119 | - |
|
| 120 | - $this->user->method('getUID') |
|
| 121 | - ->willReturn('uid'); |
|
| 122 | - $this->loader->expects($this->never())->method($this->anything()); |
|
| 123 | - |
|
| 124 | - $this->config |
|
| 125 | - ->method('getUserValue') |
|
| 126 | - ->willReturn(null); |
|
| 127 | - |
|
| 128 | - $this->config->expects($this->once()) |
|
| 129 | - ->method('setUserValue') |
|
| 130 | - ->with( |
|
| 131 | - $this->equalTo('uid'), |
|
| 132 | - $this->equalTo('homeobjectstore'), |
|
| 133 | - $this->equalTo('bucket'), |
|
| 134 | - $this->equalTo('myBucketPrefix49'), |
|
| 135 | - $this->equalTo(null) |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 139 | - $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 140 | - |
|
| 141 | - $objectStore = $arguments['objectstore']; |
|
| 142 | - $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 143 | - $this->assertEquals(['foo' => 'bar', 'bucket' => 'myBucketPrefix49', 'multibucket' => true], $objectStore->getArguments()); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - public function testMultiBucketBucketAlreadySet(): void { |
|
| 147 | - $this->config->method('getSystemValue') |
|
| 148 | - ->willReturnCallback(function ($key, $default) { |
|
| 149 | - if ($key === 'objectstore_multibucket') { |
|
| 150 | - return [ |
|
| 151 | - 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 152 | - 'arguments' => [ |
|
| 153 | - 'foo' => 'bar', |
|
| 154 | - 'bucket' => 'myBucketPrefix', |
|
| 155 | - ], |
|
| 156 | - ]; |
|
| 157 | - } else { |
|
| 158 | - return $default; |
|
| 159 | - } |
|
| 160 | - }); |
|
| 161 | - |
|
| 162 | - $this->user->method('getUID') |
|
| 163 | - ->willReturn('uid'); |
|
| 164 | - $this->loader->expects($this->never())->method($this->anything()); |
|
| 165 | - |
|
| 166 | - $this->config |
|
| 167 | - ->method('getUserValue') |
|
| 168 | - ->willReturnCallback(function ($uid, $app, $key, $default) { |
|
| 169 | - if ($uid === 'uid' && $app === 'homeobjectstore' && $key === 'bucket') { |
|
| 170 | - return 'awesomeBucket1'; |
|
| 171 | - } else { |
|
| 172 | - return $default; |
|
| 173 | - } |
|
| 174 | - }); |
|
| 175 | - |
|
| 176 | - $this->config->expects($this->never()) |
|
| 177 | - ->method('setUserValue'); |
|
| 178 | - |
|
| 179 | - $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 180 | - $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 181 | - |
|
| 182 | - $objectStore = $arguments['objectstore']; |
|
| 183 | - $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 184 | - $this->assertEquals(['foo' => 'bar', 'bucket' => 'awesomeBucket1', 'multibucket' => true], $objectStore->getArguments()); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - public function testMultiBucketConfigFirst(): void { |
|
| 188 | - $this->config->method('getSystemValue') |
|
| 189 | - ->willReturnCallback(function ($key, $default) { |
|
| 190 | - if ($key === 'objectstore_multibucket') { |
|
| 191 | - return [ |
|
| 192 | - 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 193 | - 'arguments' => [ |
|
| 194 | - 'foo' => 'bar', |
|
| 195 | - 'bucket' => 'myBucketPrefix', |
|
| 196 | - ], |
|
| 197 | - ]; |
|
| 198 | - } else { |
|
| 199 | - return $default; |
|
| 200 | - } |
|
| 201 | - }); |
|
| 202 | - |
|
| 203 | - $this->user->method('getUID') |
|
| 204 | - ->willReturn('uid'); |
|
| 205 | - $this->loader->expects($this->never())->method($this->anything()); |
|
| 206 | - |
|
| 207 | - $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 208 | - $this->assertInstanceOf('OC\Files\Mount\MountPoint', $mount); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - public function testMultiBucketConfigFirstFallBackSingle(): void { |
|
| 212 | - $this->config |
|
| 213 | - ->method('getSystemValue')->willReturnMap([ |
|
| 214 | - ['objectstore_multibucket', null, null], |
|
| 215 | - ['objectstore', null, [ |
|
| 216 | - 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 217 | - 'arguments' => [ |
|
| 218 | - 'foo' => 'bar', |
|
| 219 | - 'bucket' => 'myBucketPrefix', |
|
| 220 | - ], |
|
| 221 | - ]], |
|
| 222 | - ]); |
|
| 223 | - |
|
| 224 | - $this->user->method('getUID') |
|
| 225 | - ->willReturn('uid'); |
|
| 226 | - $this->loader->expects($this->never())->method($this->anything()); |
|
| 227 | - |
|
| 228 | - $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 229 | - $this->assertInstanceOf('OC\Files\Mount\MountPoint', $mount); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - public function testNoObjectStore(): void { |
|
| 233 | - $this->config->method('getSystemValue') |
|
| 234 | - ->willReturnCallback(function ($key, $default) { |
|
| 235 | - return $default; |
|
| 236 | - }); |
|
| 237 | - |
|
| 238 | - $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 239 | - $this->assertNull($mount); |
|
| 240 | - } |
|
| 18 | + /** @var ObjectHomeMountProvider */ |
|
| 19 | + protected $provider; |
|
| 20 | + |
|
| 21 | + /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ |
|
| 22 | + protected $config; |
|
| 23 | + |
|
| 24 | + /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ |
|
| 25 | + protected $user; |
|
| 26 | + |
|
| 27 | + /** @var IStorageFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
| 28 | + protected $loader; |
|
| 29 | + |
|
| 30 | + protected function setUp(): void { |
|
| 31 | + parent::setUp(); |
|
| 32 | + |
|
| 33 | + $this->config = $this->createMock(IConfig::class); |
|
| 34 | + $this->user = $this->createMock(IUser::class); |
|
| 35 | + $this->loader = $this->createMock(IStorageFactory::class); |
|
| 36 | + |
|
| 37 | + $objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->createMock(IAppManager::class)); |
|
| 38 | + $this->provider = new ObjectHomeMountProvider($objectStoreConfig); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function testSingleBucket(): void { |
|
| 42 | + $this->config->method('getSystemValue') |
|
| 43 | + ->willReturnCallback(function ($key, $default) { |
|
| 44 | + if ($key === 'objectstore') { |
|
| 45 | + return [ |
|
| 46 | + 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 47 | + 'arguments' => [ |
|
| 48 | + 'foo' => 'bar' |
|
| 49 | + ], |
|
| 50 | + ]; |
|
| 51 | + } else { |
|
| 52 | + return $default; |
|
| 53 | + } |
|
| 54 | + }); |
|
| 55 | + |
|
| 56 | + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 57 | + $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 58 | + |
|
| 59 | + $objectStore = $arguments['objectstore']; |
|
| 60 | + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 61 | + $this->assertEquals(['foo' => 'bar', 'multibucket' => false], $objectStore->getArguments()); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function testMultiBucket(): void { |
|
| 65 | + $this->config->method('getSystemValue') |
|
| 66 | + ->willReturnCallback(function ($key, $default) { |
|
| 67 | + if ($key === 'objectstore_multibucket') { |
|
| 68 | + return [ |
|
| 69 | + 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 70 | + 'arguments' => [ |
|
| 71 | + 'foo' => 'bar' |
|
| 72 | + ], |
|
| 73 | + ]; |
|
| 74 | + } else { |
|
| 75 | + return $default; |
|
| 76 | + } |
|
| 77 | + }); |
|
| 78 | + |
|
| 79 | + $this->user->method('getUID') |
|
| 80 | + ->willReturn('uid'); |
|
| 81 | + $this->loader->expects($this->never())->method($this->anything()); |
|
| 82 | + |
|
| 83 | + $this->config->method('getUserValue') |
|
| 84 | + ->willReturn(null); |
|
| 85 | + |
|
| 86 | + $this->config->expects($this->once()) |
|
| 87 | + ->method('setUserValue') |
|
| 88 | + ->with( |
|
| 89 | + $this->equalTo('uid'), |
|
| 90 | + $this->equalTo('homeobjectstore'), |
|
| 91 | + $this->equalTo('bucket'), |
|
| 92 | + $this->equalTo('49'), |
|
| 93 | + $this->equalTo(null) |
|
| 94 | + ); |
|
| 95 | + |
|
| 96 | + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 97 | + $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 98 | + |
|
| 99 | + $objectStore = $arguments['objectstore']; |
|
| 100 | + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 101 | + $this->assertEquals(['foo' => 'bar', 'bucket' => 49, 'multibucket' => true], $objectStore->getArguments()); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function testMultiBucketWithPrefix(): void { |
|
| 105 | + $this->config->method('getSystemValue') |
|
| 106 | + ->willReturnCallback(function ($key, $default) { |
|
| 107 | + if ($key === 'objectstore_multibucket') { |
|
| 108 | + return [ |
|
| 109 | + 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 110 | + 'arguments' => [ |
|
| 111 | + 'foo' => 'bar', |
|
| 112 | + 'bucket' => 'myBucketPrefix', |
|
| 113 | + ], |
|
| 114 | + ]; |
|
| 115 | + } else { |
|
| 116 | + return $default; |
|
| 117 | + } |
|
| 118 | + }); |
|
| 119 | + |
|
| 120 | + $this->user->method('getUID') |
|
| 121 | + ->willReturn('uid'); |
|
| 122 | + $this->loader->expects($this->never())->method($this->anything()); |
|
| 123 | + |
|
| 124 | + $this->config |
|
| 125 | + ->method('getUserValue') |
|
| 126 | + ->willReturn(null); |
|
| 127 | + |
|
| 128 | + $this->config->expects($this->once()) |
|
| 129 | + ->method('setUserValue') |
|
| 130 | + ->with( |
|
| 131 | + $this->equalTo('uid'), |
|
| 132 | + $this->equalTo('homeobjectstore'), |
|
| 133 | + $this->equalTo('bucket'), |
|
| 134 | + $this->equalTo('myBucketPrefix49'), |
|
| 135 | + $this->equalTo(null) |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 139 | + $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 140 | + |
|
| 141 | + $objectStore = $arguments['objectstore']; |
|
| 142 | + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 143 | + $this->assertEquals(['foo' => 'bar', 'bucket' => 'myBucketPrefix49', 'multibucket' => true], $objectStore->getArguments()); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + public function testMultiBucketBucketAlreadySet(): void { |
|
| 147 | + $this->config->method('getSystemValue') |
|
| 148 | + ->willReturnCallback(function ($key, $default) { |
|
| 149 | + if ($key === 'objectstore_multibucket') { |
|
| 150 | + return [ |
|
| 151 | + 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 152 | + 'arguments' => [ |
|
| 153 | + 'foo' => 'bar', |
|
| 154 | + 'bucket' => 'myBucketPrefix', |
|
| 155 | + ], |
|
| 156 | + ]; |
|
| 157 | + } else { |
|
| 158 | + return $default; |
|
| 159 | + } |
|
| 160 | + }); |
|
| 161 | + |
|
| 162 | + $this->user->method('getUID') |
|
| 163 | + ->willReturn('uid'); |
|
| 164 | + $this->loader->expects($this->never())->method($this->anything()); |
|
| 165 | + |
|
| 166 | + $this->config |
|
| 167 | + ->method('getUserValue') |
|
| 168 | + ->willReturnCallback(function ($uid, $app, $key, $default) { |
|
| 169 | + if ($uid === 'uid' && $app === 'homeobjectstore' && $key === 'bucket') { |
|
| 170 | + return 'awesomeBucket1'; |
|
| 171 | + } else { |
|
| 172 | + return $default; |
|
| 173 | + } |
|
| 174 | + }); |
|
| 175 | + |
|
| 176 | + $this->config->expects($this->never()) |
|
| 177 | + ->method('setUserValue'); |
|
| 178 | + |
|
| 179 | + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 180 | + $arguments = $this->invokePrivate($mount, 'arguments'); |
|
| 181 | + |
|
| 182 | + $objectStore = $arguments['objectstore']; |
|
| 183 | + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); |
|
| 184 | + $this->assertEquals(['foo' => 'bar', 'bucket' => 'awesomeBucket1', 'multibucket' => true], $objectStore->getArguments()); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + public function testMultiBucketConfigFirst(): void { |
|
| 188 | + $this->config->method('getSystemValue') |
|
| 189 | + ->willReturnCallback(function ($key, $default) { |
|
| 190 | + if ($key === 'objectstore_multibucket') { |
|
| 191 | + return [ |
|
| 192 | + 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 193 | + 'arguments' => [ |
|
| 194 | + 'foo' => 'bar', |
|
| 195 | + 'bucket' => 'myBucketPrefix', |
|
| 196 | + ], |
|
| 197 | + ]; |
|
| 198 | + } else { |
|
| 199 | + return $default; |
|
| 200 | + } |
|
| 201 | + }); |
|
| 202 | + |
|
| 203 | + $this->user->method('getUID') |
|
| 204 | + ->willReturn('uid'); |
|
| 205 | + $this->loader->expects($this->never())->method($this->anything()); |
|
| 206 | + |
|
| 207 | + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 208 | + $this->assertInstanceOf('OC\Files\Mount\MountPoint', $mount); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + public function testMultiBucketConfigFirstFallBackSingle(): void { |
|
| 212 | + $this->config |
|
| 213 | + ->method('getSystemValue')->willReturnMap([ |
|
| 214 | + ['objectstore_multibucket', null, null], |
|
| 215 | + ['objectstore', null, [ |
|
| 216 | + 'class' => 'Test\Files\Mount\FakeObjectStore', |
|
| 217 | + 'arguments' => [ |
|
| 218 | + 'foo' => 'bar', |
|
| 219 | + 'bucket' => 'myBucketPrefix', |
|
| 220 | + ], |
|
| 221 | + ]], |
|
| 222 | + ]); |
|
| 223 | + |
|
| 224 | + $this->user->method('getUID') |
|
| 225 | + ->willReturn('uid'); |
|
| 226 | + $this->loader->expects($this->never())->method($this->anything()); |
|
| 227 | + |
|
| 228 | + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 229 | + $this->assertInstanceOf('OC\Files\Mount\MountPoint', $mount); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + public function testNoObjectStore(): void { |
|
| 233 | + $this->config->method('getSystemValue') |
|
| 234 | + ->willReturnCallback(function ($key, $default) { |
|
| 235 | + return $default; |
|
| 236 | + }); |
|
| 237 | + |
|
| 238 | + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); |
|
| 239 | + $this->assertNull($mount); |
|
| 240 | + } |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | class FakeObjectStore implements IObjectStore { |
| 244 | - private $arguments; |
|
| 244 | + private $arguments; |
|
| 245 | 245 | |
| 246 | - public function __construct(array $arguments) { |
|
| 247 | - $this->arguments = $arguments; |
|
| 248 | - } |
|
| 246 | + public function __construct(array $arguments) { |
|
| 247 | + $this->arguments = $arguments; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - public function getArguments() { |
|
| 251 | - return $this->arguments; |
|
| 252 | - } |
|
| 250 | + public function getArguments() { |
|
| 251 | + return $this->arguments; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - public function getStorageId() { |
|
| 255 | - } |
|
| 254 | + public function getStorageId() { |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - public function readObject($urn) { |
|
| 258 | - } |
|
| 257 | + public function readObject($urn) { |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - public function writeObject($urn, $stream, ?string $mimetype = null) { |
|
| 261 | - } |
|
| 260 | + public function writeObject($urn, $stream, ?string $mimetype = null) { |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - public function deleteObject($urn) { |
|
| 264 | - } |
|
| 263 | + public function deleteObject($urn) { |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - public function objectExists($urn) { |
|
| 267 | - } |
|
| 266 | + public function objectExists($urn) { |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - public function copyObject($from, $to) { |
|
| 270 | - } |
|
| 269 | + public function copyObject($from, $to) { |
|
| 270 | + } |
|
| 271 | 271 | } |
@@ -28,582 +28,582 @@ |
||
| 28 | 28 | use OCP\Security\ISecureRandom; |
| 29 | 29 | |
| 30 | 30 | if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) { |
| 31 | - trait OnNotSuccessfulTestTrait { |
|
| 32 | - protected function onNotSuccessfulTest(\Throwable $t): never { |
|
| 33 | - $this->restoreAllServices(); |
|
| 34 | - |
|
| 35 | - // restore database connection |
|
| 36 | - if (!$this->IsDatabaseAccessAllowed()) { |
|
| 37 | - \OC::$server->registerService(IDBConnection::class, function () { |
|
| 38 | - return self::$realDatabase; |
|
| 39 | - }); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - parent::onNotSuccessfulTest($t); |
|
| 43 | - } |
|
| 44 | - } |
|
| 31 | + trait OnNotSuccessfulTestTrait { |
|
| 32 | + protected function onNotSuccessfulTest(\Throwable $t): never { |
|
| 33 | + $this->restoreAllServices(); |
|
| 34 | + |
|
| 35 | + // restore database connection |
|
| 36 | + if (!$this->IsDatabaseAccessAllowed()) { |
|
| 37 | + \OC::$server->registerService(IDBConnection::class, function () { |
|
| 38 | + return self::$realDatabase; |
|
| 39 | + }); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + parent::onNotSuccessfulTest($t); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | } else { |
| 46 | - trait OnNotSuccessfulTestTrait { |
|
| 47 | - protected function onNotSuccessfulTest(\Throwable $t): void { |
|
| 48 | - $this->restoreAllServices(); |
|
| 49 | - |
|
| 50 | - // restore database connection |
|
| 51 | - if (!$this->IsDatabaseAccessAllowed()) { |
|
| 52 | - \OC::$server->registerService(IDBConnection::class, function () { |
|
| 53 | - return self::$realDatabase; |
|
| 54 | - }); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - parent::onNotSuccessfulTest($t); |
|
| 58 | - } |
|
| 59 | - } |
|
| 46 | + trait OnNotSuccessfulTestTrait { |
|
| 47 | + protected function onNotSuccessfulTest(\Throwable $t): void { |
|
| 48 | + $this->restoreAllServices(); |
|
| 49 | + |
|
| 50 | + // restore database connection |
|
| 51 | + if (!$this->IsDatabaseAccessAllowed()) { |
|
| 52 | + \OC::$server->registerService(IDBConnection::class, function () { |
|
| 53 | + return self::$realDatabase; |
|
| 54 | + }); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + parent::onNotSuccessfulTest($t); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | abstract class TestCase extends \PHPUnit\Framework\TestCase { |
| 63 | - /** @var \OC\Command\QueueBus */ |
|
| 64 | - private $commandBus; |
|
| 65 | - |
|
| 66 | - /** @var IDBConnection */ |
|
| 67 | - protected static $realDatabase = null; |
|
| 68 | - |
|
| 69 | - /** @var bool */ |
|
| 70 | - private static $wasDatabaseAllowed = false; |
|
| 71 | - |
|
| 72 | - /** @var array */ |
|
| 73 | - protected $services = []; |
|
| 74 | - |
|
| 75 | - use OnNotSuccessfulTestTrait; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $name |
|
| 79 | - * @param mixed $newService |
|
| 80 | - * @return bool |
|
| 81 | - */ |
|
| 82 | - public function overwriteService(string $name, $newService): bool { |
|
| 83 | - if (isset($this->services[$name])) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $this->services[$name] = \OC::$server->query($name); |
|
| 88 | - $container = \OC::$server->getAppContainerForService($name); |
|
| 89 | - $container = $container ?? \OC::$server; |
|
| 90 | - |
|
| 91 | - $container->registerService($name, function () use ($newService) { |
|
| 92 | - return $newService; |
|
| 93 | - }); |
|
| 94 | - |
|
| 95 | - return true; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param string $name |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - public function restoreService(string $name): bool { |
|
| 103 | - if (isset($this->services[$name])) { |
|
| 104 | - $oldService = $this->services[$name]; |
|
| 105 | - |
|
| 106 | - $container = \OC::$server->getAppContainerForService($name); |
|
| 107 | - $container = $container ?? \OC::$server; |
|
| 108 | - |
|
| 109 | - $container->registerService($name, function () use ($oldService) { |
|
| 110 | - return $oldService; |
|
| 111 | - }); |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - unset($this->services[$name]); |
|
| 115 | - return true; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return false; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function restoreAllServices() { |
|
| 122 | - if (!empty($this->services)) { |
|
| 123 | - if (!empty($this->services)) { |
|
| 124 | - foreach ($this->services as $name => $service) { |
|
| 125 | - $this->restoreService($name); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - protected function getTestTraits() { |
|
| 132 | - $traits = []; |
|
| 133 | - $class = $this; |
|
| 134 | - do { |
|
| 135 | - $traits = array_merge(class_uses($class), $traits); |
|
| 136 | - } while ($class = get_parent_class($class)); |
|
| 137 | - foreach ($traits as $trait => $same) { |
|
| 138 | - $traits = array_merge(class_uses($trait), $traits); |
|
| 139 | - } |
|
| 140 | - $traits = array_unique($traits); |
|
| 141 | - return array_filter($traits, function ($trait) { |
|
| 142 | - return substr($trait, 0, 5) === 'Test\\'; |
|
| 143 | - }); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - protected function setUp(): void { |
|
| 147 | - // overwrite the command bus with one we can run ourselves |
|
| 148 | - $this->commandBus = new QueueBus(); |
|
| 149 | - $this->overwriteService('AsyncCommandBus', $this->commandBus); |
|
| 150 | - $this->overwriteService(IBus::class, $this->commandBus); |
|
| 151 | - |
|
| 152 | - // detect database access |
|
| 153 | - self::$wasDatabaseAllowed = true; |
|
| 154 | - if (!$this->IsDatabaseAccessAllowed()) { |
|
| 155 | - self::$wasDatabaseAllowed = false; |
|
| 156 | - if (is_null(self::$realDatabase)) { |
|
| 157 | - self::$realDatabase = \OC::$server->getDatabaseConnection(); |
|
| 158 | - } |
|
| 159 | - \OC::$server->registerService(IDBConnection::class, function () { |
|
| 160 | - $this->fail('Your test case is not allowed to access the database.'); |
|
| 161 | - }); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $traits = $this->getTestTraits(); |
|
| 165 | - foreach ($traits as $trait) { |
|
| 166 | - $methodName = 'setUp' . basename(str_replace('\\', '/', $trait)); |
|
| 167 | - if (method_exists($this, $methodName)) { |
|
| 168 | - call_user_func([$this, $methodName]); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - protected function tearDown(): void { |
|
| 174 | - $this->restoreAllServices(); |
|
| 175 | - |
|
| 176 | - // restore database connection |
|
| 177 | - if (!$this->IsDatabaseAccessAllowed()) { |
|
| 178 | - \OC::$server->registerService(IDBConnection::class, function () { |
|
| 179 | - return self::$realDatabase; |
|
| 180 | - }); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // further cleanup |
|
| 184 | - $hookExceptions = \OC_Hook::$thrownExceptions; |
|
| 185 | - \OC_Hook::$thrownExceptions = []; |
|
| 186 | - \OC::$server->get(ILockingProvider::class)->releaseAll(); |
|
| 187 | - if (!empty($hookExceptions)) { |
|
| 188 | - throw $hookExceptions[0]; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // fail hard if xml errors have not been cleaned up |
|
| 192 | - $errors = libxml_get_errors(); |
|
| 193 | - libxml_clear_errors(); |
|
| 194 | - if (!empty($errors)) { |
|
| 195 | - self::assertEquals([], $errors, 'There have been xml parsing errors'); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if ($this->IsDatabaseAccessAllowed()) { |
|
| 199 | - \OC\Files\Cache\Storage::getGlobalCache()->clearCache(); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // tearDown the traits |
|
| 203 | - $traits = $this->getTestTraits(); |
|
| 204 | - foreach ($traits as $trait) { |
|
| 205 | - $methodName = 'tearDown' . basename(str_replace('\\', '/', $trait)); |
|
| 206 | - if (method_exists($this, $methodName)) { |
|
| 207 | - call_user_func([$this, $methodName]); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Allows us to test private methods/properties |
|
| 214 | - * |
|
| 215 | - * @param $object |
|
| 216 | - * @param $methodName |
|
| 217 | - * @param array $parameters |
|
| 218 | - * @return mixed |
|
| 219 | - */ |
|
| 220 | - protected static function invokePrivate($object, $methodName, array $parameters = []) { |
|
| 221 | - if (is_string($object)) { |
|
| 222 | - $className = $object; |
|
| 223 | - } else { |
|
| 224 | - $className = get_class($object); |
|
| 225 | - } |
|
| 226 | - $reflection = new \ReflectionClass($className); |
|
| 227 | - |
|
| 228 | - if ($reflection->hasMethod($methodName)) { |
|
| 229 | - $method = $reflection->getMethod($methodName); |
|
| 230 | - |
|
| 231 | - $method->setAccessible(true); |
|
| 232 | - |
|
| 233 | - return $method->invokeArgs($object, $parameters); |
|
| 234 | - } elseif ($reflection->hasProperty($methodName)) { |
|
| 235 | - $property = $reflection->getProperty($methodName); |
|
| 236 | - |
|
| 237 | - $property->setAccessible(true); |
|
| 238 | - |
|
| 239 | - if (!empty($parameters)) { |
|
| 240 | - if ($property->isStatic()) { |
|
| 241 | - $property->setValue(null, array_pop($parameters)); |
|
| 242 | - } else { |
|
| 243 | - $property->setValue($object, array_pop($parameters)); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if (is_object($object)) { |
|
| 248 | - return $property->getValue($object); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return $property->getValue(); |
|
| 252 | - } elseif ($reflection->hasConstant($methodName)) { |
|
| 253 | - return $reflection->getConstant($methodName); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - return false; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Returns a unique identifier as uniqid() is not reliable sometimes |
|
| 261 | - * |
|
| 262 | - * @param string $prefix |
|
| 263 | - * @param int $length |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - protected static function getUniqueID($prefix = '', $length = 13) { |
|
| 267 | - return $prefix . \OC::$server->get(ISecureRandom::class)->generate( |
|
| 268 | - $length, |
|
| 269 | - // Do not use dots and slashes as we use the value for file names |
|
| 270 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Filter methods |
|
| 276 | - * |
|
| 277 | - * Returns all methods of the given class, |
|
| 278 | - * that are public or abstract and not in the ignoreMethods list, |
|
| 279 | - * to be able to fill onlyMethods() with an inverted list. |
|
| 280 | - * |
|
| 281 | - * @param string $className |
|
| 282 | - * @param string[] $filterMethods |
|
| 283 | - * @return string[] |
|
| 284 | - */ |
|
| 285 | - public function filterClassMethods(string $className, array $filterMethods): array { |
|
| 286 | - $class = new \ReflectionClass($className); |
|
| 287 | - |
|
| 288 | - $methods = []; |
|
| 289 | - foreach ($class->getMethods() as $method) { |
|
| 290 | - if (($method->isPublic() || $method->isAbstract()) && !in_array($method->getName(), $filterMethods, true)) { |
|
| 291 | - $methods[] = $method->getName(); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - return $methods; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - public static function tearDownAfterClass(): void { |
|
| 299 | - if (!self::$wasDatabaseAllowed && self::$realDatabase !== null) { |
|
| 300 | - // in case an error is thrown in a test, PHPUnit jumps straight to tearDownAfterClass, |
|
| 301 | - // so we need the database again |
|
| 302 | - \OC::$server->registerService(IDBConnection::class, function () { |
|
| 303 | - return self::$realDatabase; |
|
| 304 | - }); |
|
| 305 | - } |
|
| 306 | - $dataDir = \OC::$server->getConfig()->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data-autotest'); |
|
| 307 | - if (self::$wasDatabaseAllowed && \OC::$server->getDatabaseConnection()) { |
|
| 308 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 309 | - if ($db->inTransaction()) { |
|
| 310 | - $db->rollBack(); |
|
| 311 | - throw new \Exception('There was a transaction still in progress and needed to be rolled back. Please fix this in your test.'); |
|
| 312 | - } |
|
| 313 | - $queryBuilder = $db->getQueryBuilder(); |
|
| 314 | - |
|
| 315 | - self::tearDownAfterClassCleanShares($queryBuilder); |
|
| 316 | - self::tearDownAfterClassCleanStorages($queryBuilder); |
|
| 317 | - self::tearDownAfterClassCleanFileCache($queryBuilder); |
|
| 318 | - } |
|
| 319 | - self::tearDownAfterClassCleanStrayDataFiles($dataDir); |
|
| 320 | - self::tearDownAfterClassCleanStrayHooks(); |
|
| 321 | - self::tearDownAfterClassCleanStrayLocks(); |
|
| 322 | - |
|
| 323 | - /** @var SetupManager $setupManager */ |
|
| 324 | - $setupManager = \OC::$server->get(SetupManager::class); |
|
| 325 | - $setupManager->tearDown(); |
|
| 326 | - |
|
| 327 | - /** @var MountProviderCollection $mountProviderCollection */ |
|
| 328 | - $mountProviderCollection = \OC::$server->get(MountProviderCollection::class); |
|
| 329 | - $mountProviderCollection->clearProviders(); |
|
| 330 | - |
|
| 331 | - /** @var IConfig $config */ |
|
| 332 | - $config = \OC::$server->get(IConfig::class); |
|
| 333 | - $mountProviderCollection->registerProvider(new CacheMountProvider($config)); |
|
| 334 | - $mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 335 | - $objectStoreConfig = \OC::$server->get(PrimaryObjectStoreConfig::class); |
|
| 336 | - $mountProviderCollection->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 337 | - |
|
| 338 | - $setupManager->setupRoot(); |
|
| 339 | - |
|
| 340 | - parent::tearDownAfterClass(); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Remove all entries from the share table |
|
| 345 | - * |
|
| 346 | - * @param IQueryBuilder $queryBuilder |
|
| 347 | - */ |
|
| 348 | - protected static function tearDownAfterClassCleanShares(IQueryBuilder $queryBuilder) { |
|
| 349 | - $queryBuilder->delete('share') |
|
| 350 | - ->execute(); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Remove all entries from the storages table |
|
| 355 | - * |
|
| 356 | - * @param IQueryBuilder $queryBuilder |
|
| 357 | - */ |
|
| 358 | - protected static function tearDownAfterClassCleanStorages(IQueryBuilder $queryBuilder) { |
|
| 359 | - $queryBuilder->delete('storages') |
|
| 360 | - ->execute(); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Remove all entries from the filecache table |
|
| 365 | - * |
|
| 366 | - * @param IQueryBuilder $queryBuilder |
|
| 367 | - */ |
|
| 368 | - protected static function tearDownAfterClassCleanFileCache(IQueryBuilder $queryBuilder) { |
|
| 369 | - $queryBuilder->delete('filecache') |
|
| 370 | - ->runAcrossAllShards() |
|
| 371 | - ->execute(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Remove all unused files from the data dir |
|
| 376 | - * |
|
| 377 | - * @param string $dataDir |
|
| 378 | - */ |
|
| 379 | - protected static function tearDownAfterClassCleanStrayDataFiles($dataDir) { |
|
| 380 | - $knownEntries = [ |
|
| 381 | - 'nextcloud.log' => true, |
|
| 382 | - 'audit.log' => true, |
|
| 383 | - 'owncloud.db' => true, |
|
| 384 | - '.ocdata' => true, |
|
| 385 | - '..' => true, |
|
| 386 | - '.' => true, |
|
| 387 | - ]; |
|
| 388 | - |
|
| 389 | - if ($dh = opendir($dataDir)) { |
|
| 390 | - while (($file = readdir($dh)) !== false) { |
|
| 391 | - if (!isset($knownEntries[$file])) { |
|
| 392 | - self::tearDownAfterClassCleanStrayDataUnlinkDir($dataDir . '/' . $file); |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - closedir($dh); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Recursive delete files and folders from a given directory |
|
| 401 | - * |
|
| 402 | - * @param string $dir |
|
| 403 | - */ |
|
| 404 | - protected static function tearDownAfterClassCleanStrayDataUnlinkDir($dir) { |
|
| 405 | - if ($dh = @opendir($dir)) { |
|
| 406 | - while (($file = readdir($dh)) !== false) { |
|
| 407 | - if (\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 408 | - continue; |
|
| 409 | - } |
|
| 410 | - $path = $dir . '/' . $file; |
|
| 411 | - if (is_dir($path)) { |
|
| 412 | - self::tearDownAfterClassCleanStrayDataUnlinkDir($path); |
|
| 413 | - } else { |
|
| 414 | - @unlink($path); |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - closedir($dh); |
|
| 418 | - } |
|
| 419 | - @rmdir($dir); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Clean up the list of hooks |
|
| 424 | - */ |
|
| 425 | - protected static function tearDownAfterClassCleanStrayHooks() { |
|
| 426 | - \OC_Hook::clear(); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Clean up the list of locks |
|
| 431 | - */ |
|
| 432 | - protected static function tearDownAfterClassCleanStrayLocks() { |
|
| 433 | - \OC::$server->get(ILockingProvider::class)->releaseAll(); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Login and setup FS as a given user, |
|
| 438 | - * sets the given user as the current user. |
|
| 439 | - * |
|
| 440 | - * @param string $user user id or empty for a generic FS |
|
| 441 | - */ |
|
| 442 | - protected static function loginAsUser($user = '') { |
|
| 443 | - self::logout(); |
|
| 444 | - \OC\Files\Filesystem::tearDown(); |
|
| 445 | - \OC_User::setUserId($user); |
|
| 446 | - $userObject = \OC::$server->getUserManager()->get($user); |
|
| 447 | - if (!is_null($userObject)) { |
|
| 448 | - $userObject->updateLastLoginTimestamp(); |
|
| 449 | - } |
|
| 450 | - \OC_Util::setupFS($user); |
|
| 451 | - if (\OC::$server->getUserManager()->userExists($user)) { |
|
| 452 | - \OC::$server->getUserFolder($user); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Logout the current user and tear down the filesystem. |
|
| 458 | - */ |
|
| 459 | - protected static function logout() { |
|
| 460 | - \OC_Util::tearDownFS(); |
|
| 461 | - \OC_User::setUserId(''); |
|
| 462 | - // needed for fully logout |
|
| 463 | - \OC::$server->getUserSession()->setUser(null); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Run all commands pushed to the bus |
|
| 468 | - */ |
|
| 469 | - protected function runCommands() { |
|
| 470 | - // get the user for which the fs is setup |
|
| 471 | - $view = Filesystem::getView(); |
|
| 472 | - if ($view) { |
|
| 473 | - [, $user] = explode('/', $view->getRoot()); |
|
| 474 | - } else { |
|
| 475 | - $user = null; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - \OC_Util::tearDownFS(); // command can't reply on the fs being setup |
|
| 479 | - $this->commandBus->run(); |
|
| 480 | - \OC_Util::tearDownFS(); |
|
| 481 | - |
|
| 482 | - if ($user) { |
|
| 483 | - \OC_Util::setupFS($user); |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Check if the given path is locked with a given type |
|
| 489 | - * |
|
| 490 | - * @param \OC\Files\View $view view |
|
| 491 | - * @param string $path path to check |
|
| 492 | - * @param int $type lock type |
|
| 493 | - * @param bool $onMountPoint true to check the mount point instead of the |
|
| 494 | - * mounted storage |
|
| 495 | - * |
|
| 496 | - * @return boolean true if the file is locked with the |
|
| 497 | - * given type, false otherwise |
|
| 498 | - */ |
|
| 499 | - protected function isFileLocked($view, $path, $type, $onMountPoint = false) { |
|
| 500 | - // Note: this seems convoluted but is necessary because |
|
| 501 | - // the format of the lock key depends on the storage implementation |
|
| 502 | - // (in our case mostly md5) |
|
| 503 | - |
|
| 504 | - if ($type === \OCP\Lock\ILockingProvider::LOCK_SHARED) { |
|
| 505 | - // to check if the file has a shared lock, try acquiring an exclusive lock |
|
| 506 | - $checkType = \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE; |
|
| 507 | - } else { |
|
| 508 | - // a shared lock cannot be set if exclusive lock is in place |
|
| 509 | - $checkType = \OCP\Lock\ILockingProvider::LOCK_SHARED; |
|
| 510 | - } |
|
| 511 | - try { |
|
| 512 | - $view->lockFile($path, $checkType, $onMountPoint); |
|
| 513 | - // no exception, which means the lock of $type is not set |
|
| 514 | - // clean up |
|
| 515 | - $view->unlockFile($path, $checkType, $onMountPoint); |
|
| 516 | - return false; |
|
| 517 | - } catch (\OCP\Lock\LockedException $e) { |
|
| 518 | - // we could not acquire the counter-lock, which means |
|
| 519 | - // the lock of $type was in place |
|
| 520 | - return true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - protected function getGroupAnnotations(): array { |
|
| 525 | - if (method_exists($this, 'getAnnotations')) { |
|
| 526 | - $annotations = $this->getAnnotations(); |
|
| 527 | - return $annotations['class']['group'] ?? []; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - $r = new \ReflectionClass($this); |
|
| 531 | - $doc = $r->getDocComment(); |
|
| 532 | - preg_match_all('#@group\s+(.*?)\n#s', $doc, $annotations); |
|
| 533 | - return $annotations[1] ?? []; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - protected function IsDatabaseAccessAllowed() { |
|
| 537 | - $annotations = $this->getGroupAnnotations(); |
|
| 538 | - if (isset($annotations)) { |
|
| 539 | - if (in_array('DB', $annotations) || in_array('SLOWDB', $annotations)) { |
|
| 540 | - return true; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return false; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * @param string $expectedHtml |
|
| 549 | - * @param string $template |
|
| 550 | - * @param array $vars |
|
| 551 | - */ |
|
| 552 | - protected function assertTemplate($expectedHtml, $template, $vars = []) { |
|
| 553 | - $requestToken = 12345; |
|
| 554 | - /** @var Defaults|\PHPUnit\Framework\MockObject\MockObject $l10n */ |
|
| 555 | - $theme = $this->getMockBuilder('\OCP\Defaults') |
|
| 556 | - ->disableOriginalConstructor()->getMock(); |
|
| 557 | - $theme->expects($this->any()) |
|
| 558 | - ->method('getName') |
|
| 559 | - ->willReturn('Nextcloud'); |
|
| 560 | - /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */ |
|
| 561 | - $l10n = $this->getMockBuilder(IL10N::class) |
|
| 562 | - ->disableOriginalConstructor()->getMock(); |
|
| 563 | - $l10n |
|
| 564 | - ->expects($this->any()) |
|
| 565 | - ->method('t') |
|
| 566 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
| 567 | - return vsprintf($text, $parameters); |
|
| 568 | - }); |
|
| 569 | - |
|
| 570 | - $t = new Base($template, $requestToken, $l10n, $theme); |
|
| 571 | - $buf = $t->fetchPage($vars); |
|
| 572 | - $this->assertHtmlStringEqualsHtmlString($expectedHtml, $buf); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * @param string $expectedHtml |
|
| 577 | - * @param string $actualHtml |
|
| 578 | - * @param string $message |
|
| 579 | - */ |
|
| 580 | - protected function assertHtmlStringEqualsHtmlString($expectedHtml, $actualHtml, $message = '') { |
|
| 581 | - $expected = new DOMDocument(); |
|
| 582 | - $expected->preserveWhiteSpace = false; |
|
| 583 | - $expected->formatOutput = true; |
|
| 584 | - $expected->loadHTML($expectedHtml); |
|
| 585 | - |
|
| 586 | - $actual = new DOMDocument(); |
|
| 587 | - $actual->preserveWhiteSpace = false; |
|
| 588 | - $actual->formatOutput = true; |
|
| 589 | - $actual->loadHTML($actualHtml); |
|
| 590 | - $this->removeWhitespaces($actual); |
|
| 591 | - |
|
| 592 | - $expectedHtml1 = $expected->saveHTML(); |
|
| 593 | - $actualHtml1 = $actual->saveHTML(); |
|
| 594 | - self::assertEquals($expectedHtml1, $actualHtml1, $message); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - private function removeWhitespaces(DOMNode $domNode) { |
|
| 599 | - foreach ($domNode->childNodes as $node) { |
|
| 600 | - if ($node->hasChildNodes()) { |
|
| 601 | - $this->removeWhitespaces($node); |
|
| 602 | - } else { |
|
| 603 | - if ($node instanceof \DOMText && $node->isWhitespaceInElementContent()) { |
|
| 604 | - $domNode->removeChild($node); |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - } |
|
| 63 | + /** @var \OC\Command\QueueBus */ |
|
| 64 | + private $commandBus; |
|
| 65 | + |
|
| 66 | + /** @var IDBConnection */ |
|
| 67 | + protected static $realDatabase = null; |
|
| 68 | + |
|
| 69 | + /** @var bool */ |
|
| 70 | + private static $wasDatabaseAllowed = false; |
|
| 71 | + |
|
| 72 | + /** @var array */ |
|
| 73 | + protected $services = []; |
|
| 74 | + |
|
| 75 | + use OnNotSuccessfulTestTrait; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $name |
|
| 79 | + * @param mixed $newService |
|
| 80 | + * @return bool |
|
| 81 | + */ |
|
| 82 | + public function overwriteService(string $name, $newService): bool { |
|
| 83 | + if (isset($this->services[$name])) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $this->services[$name] = \OC::$server->query($name); |
|
| 88 | + $container = \OC::$server->getAppContainerForService($name); |
|
| 89 | + $container = $container ?? \OC::$server; |
|
| 90 | + |
|
| 91 | + $container->registerService($name, function () use ($newService) { |
|
| 92 | + return $newService; |
|
| 93 | + }); |
|
| 94 | + |
|
| 95 | + return true; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param string $name |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + public function restoreService(string $name): bool { |
|
| 103 | + if (isset($this->services[$name])) { |
|
| 104 | + $oldService = $this->services[$name]; |
|
| 105 | + |
|
| 106 | + $container = \OC::$server->getAppContainerForService($name); |
|
| 107 | + $container = $container ?? \OC::$server; |
|
| 108 | + |
|
| 109 | + $container->registerService($name, function () use ($oldService) { |
|
| 110 | + return $oldService; |
|
| 111 | + }); |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + unset($this->services[$name]); |
|
| 115 | + return true; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return false; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function restoreAllServices() { |
|
| 122 | + if (!empty($this->services)) { |
|
| 123 | + if (!empty($this->services)) { |
|
| 124 | + foreach ($this->services as $name => $service) { |
|
| 125 | + $this->restoreService($name); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + protected function getTestTraits() { |
|
| 132 | + $traits = []; |
|
| 133 | + $class = $this; |
|
| 134 | + do { |
|
| 135 | + $traits = array_merge(class_uses($class), $traits); |
|
| 136 | + } while ($class = get_parent_class($class)); |
|
| 137 | + foreach ($traits as $trait => $same) { |
|
| 138 | + $traits = array_merge(class_uses($trait), $traits); |
|
| 139 | + } |
|
| 140 | + $traits = array_unique($traits); |
|
| 141 | + return array_filter($traits, function ($trait) { |
|
| 142 | + return substr($trait, 0, 5) === 'Test\\'; |
|
| 143 | + }); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + protected function setUp(): void { |
|
| 147 | + // overwrite the command bus with one we can run ourselves |
|
| 148 | + $this->commandBus = new QueueBus(); |
|
| 149 | + $this->overwriteService('AsyncCommandBus', $this->commandBus); |
|
| 150 | + $this->overwriteService(IBus::class, $this->commandBus); |
|
| 151 | + |
|
| 152 | + // detect database access |
|
| 153 | + self::$wasDatabaseAllowed = true; |
|
| 154 | + if (!$this->IsDatabaseAccessAllowed()) { |
|
| 155 | + self::$wasDatabaseAllowed = false; |
|
| 156 | + if (is_null(self::$realDatabase)) { |
|
| 157 | + self::$realDatabase = \OC::$server->getDatabaseConnection(); |
|
| 158 | + } |
|
| 159 | + \OC::$server->registerService(IDBConnection::class, function () { |
|
| 160 | + $this->fail('Your test case is not allowed to access the database.'); |
|
| 161 | + }); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $traits = $this->getTestTraits(); |
|
| 165 | + foreach ($traits as $trait) { |
|
| 166 | + $methodName = 'setUp' . basename(str_replace('\\', '/', $trait)); |
|
| 167 | + if (method_exists($this, $methodName)) { |
|
| 168 | + call_user_func([$this, $methodName]); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + protected function tearDown(): void { |
|
| 174 | + $this->restoreAllServices(); |
|
| 175 | + |
|
| 176 | + // restore database connection |
|
| 177 | + if (!$this->IsDatabaseAccessAllowed()) { |
|
| 178 | + \OC::$server->registerService(IDBConnection::class, function () { |
|
| 179 | + return self::$realDatabase; |
|
| 180 | + }); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // further cleanup |
|
| 184 | + $hookExceptions = \OC_Hook::$thrownExceptions; |
|
| 185 | + \OC_Hook::$thrownExceptions = []; |
|
| 186 | + \OC::$server->get(ILockingProvider::class)->releaseAll(); |
|
| 187 | + if (!empty($hookExceptions)) { |
|
| 188 | + throw $hookExceptions[0]; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // fail hard if xml errors have not been cleaned up |
|
| 192 | + $errors = libxml_get_errors(); |
|
| 193 | + libxml_clear_errors(); |
|
| 194 | + if (!empty($errors)) { |
|
| 195 | + self::assertEquals([], $errors, 'There have been xml parsing errors'); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if ($this->IsDatabaseAccessAllowed()) { |
|
| 199 | + \OC\Files\Cache\Storage::getGlobalCache()->clearCache(); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // tearDown the traits |
|
| 203 | + $traits = $this->getTestTraits(); |
|
| 204 | + foreach ($traits as $trait) { |
|
| 205 | + $methodName = 'tearDown' . basename(str_replace('\\', '/', $trait)); |
|
| 206 | + if (method_exists($this, $methodName)) { |
|
| 207 | + call_user_func([$this, $methodName]); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Allows us to test private methods/properties |
|
| 214 | + * |
|
| 215 | + * @param $object |
|
| 216 | + * @param $methodName |
|
| 217 | + * @param array $parameters |
|
| 218 | + * @return mixed |
|
| 219 | + */ |
|
| 220 | + protected static function invokePrivate($object, $methodName, array $parameters = []) { |
|
| 221 | + if (is_string($object)) { |
|
| 222 | + $className = $object; |
|
| 223 | + } else { |
|
| 224 | + $className = get_class($object); |
|
| 225 | + } |
|
| 226 | + $reflection = new \ReflectionClass($className); |
|
| 227 | + |
|
| 228 | + if ($reflection->hasMethod($methodName)) { |
|
| 229 | + $method = $reflection->getMethod($methodName); |
|
| 230 | + |
|
| 231 | + $method->setAccessible(true); |
|
| 232 | + |
|
| 233 | + return $method->invokeArgs($object, $parameters); |
|
| 234 | + } elseif ($reflection->hasProperty($methodName)) { |
|
| 235 | + $property = $reflection->getProperty($methodName); |
|
| 236 | + |
|
| 237 | + $property->setAccessible(true); |
|
| 238 | + |
|
| 239 | + if (!empty($parameters)) { |
|
| 240 | + if ($property->isStatic()) { |
|
| 241 | + $property->setValue(null, array_pop($parameters)); |
|
| 242 | + } else { |
|
| 243 | + $property->setValue($object, array_pop($parameters)); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if (is_object($object)) { |
|
| 248 | + return $property->getValue($object); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + return $property->getValue(); |
|
| 252 | + } elseif ($reflection->hasConstant($methodName)) { |
|
| 253 | + return $reflection->getConstant($methodName); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + return false; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Returns a unique identifier as uniqid() is not reliable sometimes |
|
| 261 | + * |
|
| 262 | + * @param string $prefix |
|
| 263 | + * @param int $length |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + protected static function getUniqueID($prefix = '', $length = 13) { |
|
| 267 | + return $prefix . \OC::$server->get(ISecureRandom::class)->generate( |
|
| 268 | + $length, |
|
| 269 | + // Do not use dots and slashes as we use the value for file names |
|
| 270 | + ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Filter methods |
|
| 276 | + * |
|
| 277 | + * Returns all methods of the given class, |
|
| 278 | + * that are public or abstract and not in the ignoreMethods list, |
|
| 279 | + * to be able to fill onlyMethods() with an inverted list. |
|
| 280 | + * |
|
| 281 | + * @param string $className |
|
| 282 | + * @param string[] $filterMethods |
|
| 283 | + * @return string[] |
|
| 284 | + */ |
|
| 285 | + public function filterClassMethods(string $className, array $filterMethods): array { |
|
| 286 | + $class = new \ReflectionClass($className); |
|
| 287 | + |
|
| 288 | + $methods = []; |
|
| 289 | + foreach ($class->getMethods() as $method) { |
|
| 290 | + if (($method->isPublic() || $method->isAbstract()) && !in_array($method->getName(), $filterMethods, true)) { |
|
| 291 | + $methods[] = $method->getName(); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + return $methods; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + public static function tearDownAfterClass(): void { |
|
| 299 | + if (!self::$wasDatabaseAllowed && self::$realDatabase !== null) { |
|
| 300 | + // in case an error is thrown in a test, PHPUnit jumps straight to tearDownAfterClass, |
|
| 301 | + // so we need the database again |
|
| 302 | + \OC::$server->registerService(IDBConnection::class, function () { |
|
| 303 | + return self::$realDatabase; |
|
| 304 | + }); |
|
| 305 | + } |
|
| 306 | + $dataDir = \OC::$server->getConfig()->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data-autotest'); |
|
| 307 | + if (self::$wasDatabaseAllowed && \OC::$server->getDatabaseConnection()) { |
|
| 308 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 309 | + if ($db->inTransaction()) { |
|
| 310 | + $db->rollBack(); |
|
| 311 | + throw new \Exception('There was a transaction still in progress and needed to be rolled back. Please fix this in your test.'); |
|
| 312 | + } |
|
| 313 | + $queryBuilder = $db->getQueryBuilder(); |
|
| 314 | + |
|
| 315 | + self::tearDownAfterClassCleanShares($queryBuilder); |
|
| 316 | + self::tearDownAfterClassCleanStorages($queryBuilder); |
|
| 317 | + self::tearDownAfterClassCleanFileCache($queryBuilder); |
|
| 318 | + } |
|
| 319 | + self::tearDownAfterClassCleanStrayDataFiles($dataDir); |
|
| 320 | + self::tearDownAfterClassCleanStrayHooks(); |
|
| 321 | + self::tearDownAfterClassCleanStrayLocks(); |
|
| 322 | + |
|
| 323 | + /** @var SetupManager $setupManager */ |
|
| 324 | + $setupManager = \OC::$server->get(SetupManager::class); |
|
| 325 | + $setupManager->tearDown(); |
|
| 326 | + |
|
| 327 | + /** @var MountProviderCollection $mountProviderCollection */ |
|
| 328 | + $mountProviderCollection = \OC::$server->get(MountProviderCollection::class); |
|
| 329 | + $mountProviderCollection->clearProviders(); |
|
| 330 | + |
|
| 331 | + /** @var IConfig $config */ |
|
| 332 | + $config = \OC::$server->get(IConfig::class); |
|
| 333 | + $mountProviderCollection->registerProvider(new CacheMountProvider($config)); |
|
| 334 | + $mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 335 | + $objectStoreConfig = \OC::$server->get(PrimaryObjectStoreConfig::class); |
|
| 336 | + $mountProviderCollection->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 337 | + |
|
| 338 | + $setupManager->setupRoot(); |
|
| 339 | + |
|
| 340 | + parent::tearDownAfterClass(); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Remove all entries from the share table |
|
| 345 | + * |
|
| 346 | + * @param IQueryBuilder $queryBuilder |
|
| 347 | + */ |
|
| 348 | + protected static function tearDownAfterClassCleanShares(IQueryBuilder $queryBuilder) { |
|
| 349 | + $queryBuilder->delete('share') |
|
| 350 | + ->execute(); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Remove all entries from the storages table |
|
| 355 | + * |
|
| 356 | + * @param IQueryBuilder $queryBuilder |
|
| 357 | + */ |
|
| 358 | + protected static function tearDownAfterClassCleanStorages(IQueryBuilder $queryBuilder) { |
|
| 359 | + $queryBuilder->delete('storages') |
|
| 360 | + ->execute(); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Remove all entries from the filecache table |
|
| 365 | + * |
|
| 366 | + * @param IQueryBuilder $queryBuilder |
|
| 367 | + */ |
|
| 368 | + protected static function tearDownAfterClassCleanFileCache(IQueryBuilder $queryBuilder) { |
|
| 369 | + $queryBuilder->delete('filecache') |
|
| 370 | + ->runAcrossAllShards() |
|
| 371 | + ->execute(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Remove all unused files from the data dir |
|
| 376 | + * |
|
| 377 | + * @param string $dataDir |
|
| 378 | + */ |
|
| 379 | + protected static function tearDownAfterClassCleanStrayDataFiles($dataDir) { |
|
| 380 | + $knownEntries = [ |
|
| 381 | + 'nextcloud.log' => true, |
|
| 382 | + 'audit.log' => true, |
|
| 383 | + 'owncloud.db' => true, |
|
| 384 | + '.ocdata' => true, |
|
| 385 | + '..' => true, |
|
| 386 | + '.' => true, |
|
| 387 | + ]; |
|
| 388 | + |
|
| 389 | + if ($dh = opendir($dataDir)) { |
|
| 390 | + while (($file = readdir($dh)) !== false) { |
|
| 391 | + if (!isset($knownEntries[$file])) { |
|
| 392 | + self::tearDownAfterClassCleanStrayDataUnlinkDir($dataDir . '/' . $file); |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + closedir($dh); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Recursive delete files and folders from a given directory |
|
| 401 | + * |
|
| 402 | + * @param string $dir |
|
| 403 | + */ |
|
| 404 | + protected static function tearDownAfterClassCleanStrayDataUnlinkDir($dir) { |
|
| 405 | + if ($dh = @opendir($dir)) { |
|
| 406 | + while (($file = readdir($dh)) !== false) { |
|
| 407 | + if (\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 408 | + continue; |
|
| 409 | + } |
|
| 410 | + $path = $dir . '/' . $file; |
|
| 411 | + if (is_dir($path)) { |
|
| 412 | + self::tearDownAfterClassCleanStrayDataUnlinkDir($path); |
|
| 413 | + } else { |
|
| 414 | + @unlink($path); |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + closedir($dh); |
|
| 418 | + } |
|
| 419 | + @rmdir($dir); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Clean up the list of hooks |
|
| 424 | + */ |
|
| 425 | + protected static function tearDownAfterClassCleanStrayHooks() { |
|
| 426 | + \OC_Hook::clear(); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Clean up the list of locks |
|
| 431 | + */ |
|
| 432 | + protected static function tearDownAfterClassCleanStrayLocks() { |
|
| 433 | + \OC::$server->get(ILockingProvider::class)->releaseAll(); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Login and setup FS as a given user, |
|
| 438 | + * sets the given user as the current user. |
|
| 439 | + * |
|
| 440 | + * @param string $user user id or empty for a generic FS |
|
| 441 | + */ |
|
| 442 | + protected static function loginAsUser($user = '') { |
|
| 443 | + self::logout(); |
|
| 444 | + \OC\Files\Filesystem::tearDown(); |
|
| 445 | + \OC_User::setUserId($user); |
|
| 446 | + $userObject = \OC::$server->getUserManager()->get($user); |
|
| 447 | + if (!is_null($userObject)) { |
|
| 448 | + $userObject->updateLastLoginTimestamp(); |
|
| 449 | + } |
|
| 450 | + \OC_Util::setupFS($user); |
|
| 451 | + if (\OC::$server->getUserManager()->userExists($user)) { |
|
| 452 | + \OC::$server->getUserFolder($user); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Logout the current user and tear down the filesystem. |
|
| 458 | + */ |
|
| 459 | + protected static function logout() { |
|
| 460 | + \OC_Util::tearDownFS(); |
|
| 461 | + \OC_User::setUserId(''); |
|
| 462 | + // needed for fully logout |
|
| 463 | + \OC::$server->getUserSession()->setUser(null); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Run all commands pushed to the bus |
|
| 468 | + */ |
|
| 469 | + protected function runCommands() { |
|
| 470 | + // get the user for which the fs is setup |
|
| 471 | + $view = Filesystem::getView(); |
|
| 472 | + if ($view) { |
|
| 473 | + [, $user] = explode('/', $view->getRoot()); |
|
| 474 | + } else { |
|
| 475 | + $user = null; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + \OC_Util::tearDownFS(); // command can't reply on the fs being setup |
|
| 479 | + $this->commandBus->run(); |
|
| 480 | + \OC_Util::tearDownFS(); |
|
| 481 | + |
|
| 482 | + if ($user) { |
|
| 483 | + \OC_Util::setupFS($user); |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Check if the given path is locked with a given type |
|
| 489 | + * |
|
| 490 | + * @param \OC\Files\View $view view |
|
| 491 | + * @param string $path path to check |
|
| 492 | + * @param int $type lock type |
|
| 493 | + * @param bool $onMountPoint true to check the mount point instead of the |
|
| 494 | + * mounted storage |
|
| 495 | + * |
|
| 496 | + * @return boolean true if the file is locked with the |
|
| 497 | + * given type, false otherwise |
|
| 498 | + */ |
|
| 499 | + protected function isFileLocked($view, $path, $type, $onMountPoint = false) { |
|
| 500 | + // Note: this seems convoluted but is necessary because |
|
| 501 | + // the format of the lock key depends on the storage implementation |
|
| 502 | + // (in our case mostly md5) |
|
| 503 | + |
|
| 504 | + if ($type === \OCP\Lock\ILockingProvider::LOCK_SHARED) { |
|
| 505 | + // to check if the file has a shared lock, try acquiring an exclusive lock |
|
| 506 | + $checkType = \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE; |
|
| 507 | + } else { |
|
| 508 | + // a shared lock cannot be set if exclusive lock is in place |
|
| 509 | + $checkType = \OCP\Lock\ILockingProvider::LOCK_SHARED; |
|
| 510 | + } |
|
| 511 | + try { |
|
| 512 | + $view->lockFile($path, $checkType, $onMountPoint); |
|
| 513 | + // no exception, which means the lock of $type is not set |
|
| 514 | + // clean up |
|
| 515 | + $view->unlockFile($path, $checkType, $onMountPoint); |
|
| 516 | + return false; |
|
| 517 | + } catch (\OCP\Lock\LockedException $e) { |
|
| 518 | + // we could not acquire the counter-lock, which means |
|
| 519 | + // the lock of $type was in place |
|
| 520 | + return true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + protected function getGroupAnnotations(): array { |
|
| 525 | + if (method_exists($this, 'getAnnotations')) { |
|
| 526 | + $annotations = $this->getAnnotations(); |
|
| 527 | + return $annotations['class']['group'] ?? []; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + $r = new \ReflectionClass($this); |
|
| 531 | + $doc = $r->getDocComment(); |
|
| 532 | + preg_match_all('#@group\s+(.*?)\n#s', $doc, $annotations); |
|
| 533 | + return $annotations[1] ?? []; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + protected function IsDatabaseAccessAllowed() { |
|
| 537 | + $annotations = $this->getGroupAnnotations(); |
|
| 538 | + if (isset($annotations)) { |
|
| 539 | + if (in_array('DB', $annotations) || in_array('SLOWDB', $annotations)) { |
|
| 540 | + return true; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return false; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * @param string $expectedHtml |
|
| 549 | + * @param string $template |
|
| 550 | + * @param array $vars |
|
| 551 | + */ |
|
| 552 | + protected function assertTemplate($expectedHtml, $template, $vars = []) { |
|
| 553 | + $requestToken = 12345; |
|
| 554 | + /** @var Defaults|\PHPUnit\Framework\MockObject\MockObject $l10n */ |
|
| 555 | + $theme = $this->getMockBuilder('\OCP\Defaults') |
|
| 556 | + ->disableOriginalConstructor()->getMock(); |
|
| 557 | + $theme->expects($this->any()) |
|
| 558 | + ->method('getName') |
|
| 559 | + ->willReturn('Nextcloud'); |
|
| 560 | + /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */ |
|
| 561 | + $l10n = $this->getMockBuilder(IL10N::class) |
|
| 562 | + ->disableOriginalConstructor()->getMock(); |
|
| 563 | + $l10n |
|
| 564 | + ->expects($this->any()) |
|
| 565 | + ->method('t') |
|
| 566 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
| 567 | + return vsprintf($text, $parameters); |
|
| 568 | + }); |
|
| 569 | + |
|
| 570 | + $t = new Base($template, $requestToken, $l10n, $theme); |
|
| 571 | + $buf = $t->fetchPage($vars); |
|
| 572 | + $this->assertHtmlStringEqualsHtmlString($expectedHtml, $buf); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * @param string $expectedHtml |
|
| 577 | + * @param string $actualHtml |
|
| 578 | + * @param string $message |
|
| 579 | + */ |
|
| 580 | + protected function assertHtmlStringEqualsHtmlString($expectedHtml, $actualHtml, $message = '') { |
|
| 581 | + $expected = new DOMDocument(); |
|
| 582 | + $expected->preserveWhiteSpace = false; |
|
| 583 | + $expected->formatOutput = true; |
|
| 584 | + $expected->loadHTML($expectedHtml); |
|
| 585 | + |
|
| 586 | + $actual = new DOMDocument(); |
|
| 587 | + $actual->preserveWhiteSpace = false; |
|
| 588 | + $actual->formatOutput = true; |
|
| 589 | + $actual->loadHTML($actualHtml); |
|
| 590 | + $this->removeWhitespaces($actual); |
|
| 591 | + |
|
| 592 | + $expectedHtml1 = $expected->saveHTML(); |
|
| 593 | + $actualHtml1 = $actual->saveHTML(); |
|
| 594 | + self::assertEquals($expectedHtml1, $actualHtml1, $message); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + private function removeWhitespaces(DOMNode $domNode) { |
|
| 599 | + foreach ($domNode->childNodes as $node) { |
|
| 600 | + if ($node->hasChildNodes()) { |
|
| 601 | + $this->removeWhitespaces($node); |
|
| 602 | + } else { |
|
| 603 | + if ($node instanceof \DOMText && $node->isWhitespaceInElementContent()) { |
|
| 604 | + $domNode->removeChild($node); |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | 609 | } |