@@ -254,1927 +254,1927 @@ |
||
| 254 | 254 | * TODO: hookup all manager classes |
| 255 | 255 | */ |
| 256 | 256 | class Server extends ServerContainer implements IServerContainer { |
| 257 | - /** @var string */ |
|
| 258 | - private $webRoot; |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @param string $webRoot |
|
| 262 | - * @param \OC\Config $config |
|
| 263 | - */ |
|
| 264 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 265 | - parent::__construct(); |
|
| 266 | - $this->webRoot = $webRoot; |
|
| 267 | - |
|
| 268 | - // To find out if we are running from CLI or not |
|
| 269 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 270 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 271 | - |
|
| 272 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 273 | - return $c; |
|
| 274 | - }); |
|
| 275 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 276 | - return $c; |
|
| 277 | - }); |
|
| 278 | - |
|
| 279 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 280 | - |
|
| 281 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 282 | - |
|
| 283 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 284 | - |
|
| 285 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 286 | - |
|
| 287 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 288 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 289 | - $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 290 | - |
|
| 291 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 292 | - |
|
| 293 | - $this->registerService(View::class, function (Server $c) { |
|
| 294 | - return new View(); |
|
| 295 | - }, false); |
|
| 296 | - |
|
| 297 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 298 | - return new PreviewManager( |
|
| 299 | - $c->get(\OCP\IConfig::class), |
|
| 300 | - $c->get(IRootFolder::class), |
|
| 301 | - new \OC\Preview\Storage\Root( |
|
| 302 | - $c->get(IRootFolder::class), |
|
| 303 | - $c->get(SystemConfig::class) |
|
| 304 | - ), |
|
| 305 | - $c->get(IEventDispatcher::class), |
|
| 306 | - $c->get(GeneratorHelper::class), |
|
| 307 | - $c->get(ISession::class)->get('user_id'), |
|
| 308 | - $c->get(Coordinator::class), |
|
| 309 | - $c->get(IServerContainer::class), |
|
| 310 | - $c->get(IBinaryFinder::class), |
|
| 311 | - $c->get(IMagickSupport::class) |
|
| 312 | - ); |
|
| 313 | - }); |
|
| 314 | - $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 315 | - |
|
| 316 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 317 | - return new \OC\Preview\Watcher( |
|
| 318 | - new \OC\Preview\Storage\Root( |
|
| 319 | - $c->get(IRootFolder::class), |
|
| 320 | - $c->get(SystemConfig::class) |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - }); |
|
| 324 | - |
|
| 325 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
| 326 | - return new Profiler($c->get(SystemConfig::class)); |
|
| 327 | - }); |
|
| 328 | - |
|
| 329 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager { |
|
| 330 | - $view = new View(); |
|
| 331 | - $util = new Encryption\Util( |
|
| 332 | - $view, |
|
| 333 | - $c->get(IUserManager::class), |
|
| 334 | - $c->get(IGroupManager::class), |
|
| 335 | - $c->get(\OCP\IConfig::class) |
|
| 336 | - ); |
|
| 337 | - return new Encryption\Manager( |
|
| 338 | - $c->get(\OCP\IConfig::class), |
|
| 339 | - $c->get(LoggerInterface::class), |
|
| 340 | - $c->getL10N('core'), |
|
| 341 | - new View(), |
|
| 342 | - $util, |
|
| 343 | - new ArrayCache() |
|
| 344 | - ); |
|
| 345 | - }); |
|
| 346 | - |
|
| 347 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 348 | - $util = new Encryption\Util( |
|
| 349 | - new View(), |
|
| 350 | - $c->get(IUserManager::class), |
|
| 351 | - $c->get(IGroupManager::class), |
|
| 352 | - $c->get(\OCP\IConfig::class) |
|
| 353 | - ); |
|
| 354 | - return new Encryption\File( |
|
| 355 | - $util, |
|
| 356 | - $c->get(IRootFolder::class), |
|
| 357 | - $c->get(\OCP\Share\IManager::class) |
|
| 358 | - ); |
|
| 359 | - }); |
|
| 360 | - |
|
| 361 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 362 | - $view = new View(); |
|
| 363 | - $util = new Encryption\Util( |
|
| 364 | - $view, |
|
| 365 | - $c->get(IUserManager::class), |
|
| 366 | - $c->get(IGroupManager::class), |
|
| 367 | - $c->get(\OCP\IConfig::class) |
|
| 368 | - ); |
|
| 369 | - |
|
| 370 | - return new Encryption\Keys\Storage( |
|
| 371 | - $view, |
|
| 372 | - $util, |
|
| 373 | - $c->get(ICrypto::class), |
|
| 374 | - $c->get(\OCP\IConfig::class) |
|
| 375 | - ); |
|
| 376 | - }); |
|
| 377 | - |
|
| 378 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 379 | - |
|
| 380 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 381 | - /** @var \OCP\IConfig $config */ |
|
| 382 | - $config = $c->get(\OCP\IConfig::class); |
|
| 383 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 384 | - return new $factoryClass($this); |
|
| 385 | - }); |
|
| 386 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 387 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 388 | - }); |
|
| 389 | - /** @deprecated 19.0.0 */ |
|
| 390 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 391 | - |
|
| 392 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 393 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 394 | - }); |
|
| 395 | - $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 396 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 397 | - $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 398 | - $view = new View(); |
|
| 399 | - /** @var IUserSession $userSession */ |
|
| 400 | - $userSession = $c->get(IUserSession::class); |
|
| 401 | - $root = new Root( |
|
| 402 | - $manager, |
|
| 403 | - $view, |
|
| 404 | - $userSession->getUser(), |
|
| 405 | - $c->get(IUserMountCache::class), |
|
| 406 | - $this->get(LoggerInterface::class), |
|
| 407 | - $this->get(IUserManager::class), |
|
| 408 | - $this->get(IEventDispatcher::class), |
|
| 409 | - $this->get(ICacheFactory::class), |
|
| 410 | - ); |
|
| 411 | - |
|
| 412 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 413 | - $root, |
|
| 414 | - $c->get(SystemConfig::class), |
|
| 415 | - $this->get(IEventDispatcher::class) |
|
| 416 | - ); |
|
| 417 | - $previewConnector->connectWatcher(); |
|
| 418 | - |
|
| 419 | - return $root; |
|
| 420 | - }); |
|
| 421 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 422 | - return new HookConnector( |
|
| 423 | - $c->get(IRootFolder::class), |
|
| 424 | - new View(), |
|
| 425 | - $c->get(IEventDispatcher::class), |
|
| 426 | - $c->get(LoggerInterface::class) |
|
| 427 | - ); |
|
| 428 | - }); |
|
| 429 | - |
|
| 430 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 431 | - return new LazyRoot(function () use ($c) { |
|
| 432 | - return $c->get('RootFolder'); |
|
| 433 | - }); |
|
| 434 | - }); |
|
| 435 | - |
|
| 436 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 437 | - |
|
| 438 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 439 | - return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 440 | - }); |
|
| 441 | - |
|
| 442 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 443 | - $groupManager = new \OC\Group\Manager( |
|
| 444 | - $this->get(IUserManager::class), |
|
| 445 | - $this->get(IEventDispatcher::class), |
|
| 446 | - $this->get(LoggerInterface::class), |
|
| 447 | - $this->get(ICacheFactory::class), |
|
| 448 | - $this->get(IRemoteAddress::class), |
|
| 449 | - ); |
|
| 450 | - return $groupManager; |
|
| 451 | - }); |
|
| 452 | - |
|
| 453 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 454 | - $session = $c->get(ISession::class); |
|
| 455 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 456 | - $tokenProvider = $c->get(IProvider::class); |
|
| 457 | - } else { |
|
| 458 | - $tokenProvider = null; |
|
| 459 | - } |
|
| 460 | - $logger = $c->get(LoggerInterface::class); |
|
| 461 | - $crypto = $c->get(ICrypto::class); |
|
| 462 | - return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 463 | - }); |
|
| 464 | - $this->registerAlias(IStore::class, Store::class); |
|
| 465 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 466 | - $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 467 | - |
|
| 468 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 469 | - $manager = $c->get(IUserManager::class); |
|
| 470 | - $session = new \OC\Session\Memory(); |
|
| 471 | - $timeFactory = new TimeFactory(); |
|
| 472 | - // Token providers might require a working database. This code |
|
| 473 | - // might however be called when Nextcloud is not yet setup. |
|
| 474 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 475 | - $provider = $c->get(IProvider::class); |
|
| 476 | - } else { |
|
| 477 | - $provider = null; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - $userSession = new \OC\User\Session( |
|
| 481 | - $manager, |
|
| 482 | - $session, |
|
| 483 | - $timeFactory, |
|
| 484 | - $provider, |
|
| 485 | - $c->get(\OCP\IConfig::class), |
|
| 486 | - $c->get(ISecureRandom::class), |
|
| 487 | - $c->get('LockdownManager'), |
|
| 488 | - $c->get(LoggerInterface::class), |
|
| 489 | - $c->get(IEventDispatcher::class), |
|
| 490 | - ); |
|
| 491 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 492 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 493 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 494 | - }); |
|
| 495 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 496 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 497 | - /** @var \OC\User\User $user */ |
|
| 498 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 499 | - }); |
|
| 500 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 501 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 502 | - /** @var \OC\User\User $user */ |
|
| 503 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 504 | - }); |
|
| 505 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 506 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 507 | - /** @var \OC\User\User $user */ |
|
| 508 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 509 | - }); |
|
| 510 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 511 | - /** @var \OC\User\User $user */ |
|
| 512 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 513 | - }); |
|
| 514 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 515 | - /** @var \OC\User\User $user */ |
|
| 516 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 517 | - }); |
|
| 518 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 519 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 520 | - |
|
| 521 | - /** @var IEventDispatcher $dispatcher */ |
|
| 522 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 523 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 524 | - }); |
|
| 525 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 526 | - /** @var \OC\User\User $user */ |
|
| 527 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 528 | - |
|
| 529 | - /** @var IEventDispatcher $dispatcher */ |
|
| 530 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 531 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 532 | - }); |
|
| 533 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 534 | - /** @var IEventDispatcher $dispatcher */ |
|
| 535 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 536 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 537 | - }); |
|
| 538 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 539 | - /** @var \OC\User\User $user */ |
|
| 540 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 541 | - |
|
| 542 | - /** @var IEventDispatcher $dispatcher */ |
|
| 543 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 544 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 545 | - }); |
|
| 546 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 547 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 548 | - |
|
| 549 | - /** @var IEventDispatcher $dispatcher */ |
|
| 550 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 551 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 552 | - }); |
|
| 553 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 554 | - /** @var IEventDispatcher $dispatcher */ |
|
| 555 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 556 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 557 | - }); |
|
| 558 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 559 | - /** @var \OC\User\User $user */ |
|
| 560 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 561 | - }); |
|
| 562 | - return $userSession; |
|
| 563 | - }); |
|
| 564 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 565 | - |
|
| 566 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 567 | - |
|
| 568 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 569 | - |
|
| 570 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 571 | - |
|
| 572 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 573 | - return new \OC\SystemConfig($config); |
|
| 574 | - }); |
|
| 575 | - |
|
| 576 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 577 | - $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 578 | - |
|
| 579 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 580 | - return new \OC\L10N\Factory( |
|
| 581 | - $c->get(\OCP\IConfig::class), |
|
| 582 | - $c->getRequest(), |
|
| 583 | - $c->get(IUserSession::class), |
|
| 584 | - $c->get(ICacheFactory::class), |
|
| 585 | - \OC::$SERVERROOT, |
|
| 586 | - $c->get(IAppManager::class), |
|
| 587 | - ); |
|
| 588 | - }); |
|
| 589 | - |
|
| 590 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 591 | - |
|
| 592 | - $this->registerService(ICache::class, function ($c) { |
|
| 593 | - return new Cache\File(); |
|
| 594 | - }); |
|
| 595 | - |
|
| 596 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 597 | - $profiler = $c->get(IProfiler::class); |
|
| 598 | - $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 599 | - $profiler, |
|
| 600 | - ArrayCache::class, |
|
| 601 | - ArrayCache::class, |
|
| 602 | - ArrayCache::class |
|
| 603 | - ); |
|
| 604 | - /** @var SystemConfig $config */ |
|
| 605 | - $config = $c->get(SystemConfig::class); |
|
| 606 | - /** @var ServerVersion $serverVersion */ |
|
| 607 | - $serverVersion = $c->get(ServerVersion::class); |
|
| 608 | - |
|
| 609 | - if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 610 | - $logQuery = $config->getValue('log_query'); |
|
| 611 | - $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 612 | - if (!$logQuery) { |
|
| 613 | - try { |
|
| 614 | - $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(); |
|
| 615 | - } catch (\Doctrine\DBAL\Exception $e) { |
|
| 616 | - // Database service probably unavailable |
|
| 617 | - // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 618 | - return null; |
|
| 619 | - } |
|
| 620 | - } else { |
|
| 621 | - // If the log_query is enabled, we can not get the app versions |
|
| 622 | - // as that does a query, which will be logged and the logging |
|
| 623 | - // depends on redis and here we are back again in the same function. |
|
| 624 | - $v = [ |
|
| 625 | - 'log_query' => 'enabled', |
|
| 626 | - ]; |
|
| 627 | - } |
|
| 628 | - $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 629 | - $version = implode(',', $v); |
|
| 630 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 631 | - $path = \OC::$SERVERROOT; |
|
| 632 | - return md5($instanceId . '-' . $version . '-' . $path); |
|
| 633 | - }; |
|
| 634 | - return new \OC\Memcache\Factory($prefixClosure, |
|
| 635 | - $c->get(LoggerInterface::class), |
|
| 636 | - $profiler, |
|
| 637 | - /** @psalm-taint-escape callable */ |
|
| 638 | - $config->getValue('memcache.local', null), |
|
| 639 | - /** @psalm-taint-escape callable */ |
|
| 640 | - $config->getValue('memcache.distributed', null), |
|
| 641 | - /** @psalm-taint-escape callable */ |
|
| 642 | - $config->getValue('memcache.locking', null), |
|
| 643 | - /** @psalm-taint-escape callable */ |
|
| 644 | - $config->getValue('redis_log_file') |
|
| 645 | - ); |
|
| 646 | - } |
|
| 647 | - return $arrayCacheFactory; |
|
| 648 | - }); |
|
| 649 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 650 | - |
|
| 651 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 652 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 653 | - return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 654 | - }); |
|
| 655 | - |
|
| 656 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 657 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 658 | - return new \OC\Activity\Manager( |
|
| 659 | - $c->getRequest(), |
|
| 660 | - $c->get(IUserSession::class), |
|
| 661 | - $c->get(\OCP\IConfig::class), |
|
| 662 | - $c->get(IValidator::class), |
|
| 663 | - $c->get(IRichTextFormatter::class), |
|
| 664 | - $l10n |
|
| 665 | - ); |
|
| 666 | - }); |
|
| 667 | - |
|
| 668 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 669 | - return new \OC\Activity\EventMerger( |
|
| 670 | - $c->getL10N('lib') |
|
| 671 | - ); |
|
| 672 | - }); |
|
| 673 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 674 | - |
|
| 675 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 676 | - return new AvatarManager( |
|
| 677 | - $c->get(IUserSession::class), |
|
| 678 | - $c->get(\OC\User\Manager::class), |
|
| 679 | - $c->getAppDataDir('avatar'), |
|
| 680 | - $c->getL10N('lib'), |
|
| 681 | - $c->get(LoggerInterface::class), |
|
| 682 | - $c->get(\OCP\IConfig::class), |
|
| 683 | - $c->get(IAccountManager::class), |
|
| 684 | - $c->get(KnownUserService::class) |
|
| 685 | - ); |
|
| 686 | - }); |
|
| 687 | - |
|
| 688 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 689 | - |
|
| 690 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 691 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 692 | - $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 693 | - |
|
| 694 | - /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 695 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 696 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 697 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 698 | - $logger = $factory->get($logType); |
|
| 699 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 700 | - |
|
| 701 | - return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 702 | - }); |
|
| 703 | - // PSR-3 logger |
|
| 704 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 705 | - |
|
| 706 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 707 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 708 | - }); |
|
| 709 | - |
|
| 710 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 711 | - |
|
| 712 | - $this->registerService(Router::class, function (Server $c) { |
|
| 713 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 714 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 715 | - $router = $c->resolve(CachingRouter::class); |
|
| 716 | - } else { |
|
| 717 | - $router = $c->resolve(Router::class); |
|
| 718 | - } |
|
| 719 | - return $router; |
|
| 720 | - }); |
|
| 721 | - $this->registerAlias(IRouter::class, Router::class); |
|
| 722 | - |
|
| 723 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 724 | - $config = $c->get(\OCP\IConfig::class); |
|
| 725 | - if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 726 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 727 | - $c->get(AllConfig::class), |
|
| 728 | - $this->get(ICacheFactory::class), |
|
| 729 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 730 | - ); |
|
| 731 | - } else { |
|
| 732 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 733 | - $c->get(AllConfig::class), |
|
| 734 | - $c->get(IDBConnection::class), |
|
| 735 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 736 | - ); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - return $backend; |
|
| 740 | - }); |
|
| 741 | - |
|
| 742 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 743 | - $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 744 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 745 | - |
|
| 746 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 747 | - |
|
| 748 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 749 | - |
|
| 750 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 751 | - |
|
| 752 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 753 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 754 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 755 | - $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 756 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 757 | - if (!$factory->isValidType($type)) { |
|
| 758 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 759 | - } |
|
| 760 | - $connection = $factory->getConnection($type, []); |
|
| 761 | - return $connection; |
|
| 762 | - }); |
|
| 763 | - |
|
| 764 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 765 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
| 766 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 767 | - return new NegativeDnsCache( |
|
| 768 | - $c->get(ICacheFactory::class), |
|
| 769 | - ); |
|
| 770 | - }); |
|
| 771 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 772 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 773 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 774 | - }); |
|
| 775 | - |
|
| 776 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 777 | - $queryLogger = new QueryLogger(); |
|
| 778 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 779 | - // In debug mode, module is being activated by default |
|
| 780 | - $queryLogger->activate(); |
|
| 781 | - } |
|
| 782 | - return $queryLogger; |
|
| 783 | - }); |
|
| 784 | - |
|
| 785 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 786 | - |
|
| 787 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 788 | - // TODO: use auto-wiring |
|
| 789 | - return new \OC\App\AppManager( |
|
| 790 | - $c->get(IUserSession::class), |
|
| 791 | - $c->get(\OCP\IConfig::class), |
|
| 792 | - $c->get(IGroupManager::class), |
|
| 793 | - $c->get(ICacheFactory::class), |
|
| 794 | - $c->get(IEventDispatcher::class), |
|
| 795 | - $c->get(LoggerInterface::class), |
|
| 796 | - $c->get(ServerVersion::class), |
|
| 797 | - ); |
|
| 798 | - }); |
|
| 799 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 800 | - |
|
| 801 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 802 | - |
|
| 803 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 804 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 805 | - |
|
| 806 | - return new DateTimeFormatter( |
|
| 807 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 808 | - $c->getL10N('lib', $language) |
|
| 809 | - ); |
|
| 810 | - }); |
|
| 811 | - |
|
| 812 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 813 | - $mountCache = $c->get(UserMountCache::class); |
|
| 814 | - $listener = new UserMountCacheListener($mountCache); |
|
| 815 | - $listener->listen($c->get(IUserManager::class)); |
|
| 816 | - return $mountCache; |
|
| 817 | - }); |
|
| 818 | - |
|
| 819 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 820 | - $loader = $c->get(IStorageFactory::class); |
|
| 821 | - $mountCache = $c->get(IUserMountCache::class); |
|
| 822 | - $eventLogger = $c->get(IEventLogger::class); |
|
| 823 | - $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 824 | - |
|
| 825 | - // builtin providers |
|
| 826 | - |
|
| 827 | - $config = $c->get(\OCP\IConfig::class); |
|
| 828 | - $logger = $c->get(LoggerInterface::class); |
|
| 829 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 830 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 831 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 832 | - $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class))); |
|
| 833 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 834 | - |
|
| 835 | - return $manager; |
|
| 836 | - }); |
|
| 837 | - |
|
| 838 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 839 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 840 | - if ($busClass) { |
|
| 841 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 842 | - if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 843 | - $c->get(IAppManager::class)->loadApp($app); |
|
| 844 | - return $c->get($class); |
|
| 845 | - } else { |
|
| 846 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 847 | - } |
|
| 848 | - } else { |
|
| 849 | - $jobList = $c->get(IJobList::class); |
|
| 850 | - return new CronBus($jobList); |
|
| 851 | - } |
|
| 852 | - }); |
|
| 853 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 854 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 855 | - $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 856 | - |
|
| 857 | - $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 858 | - $config = $c->get(\OCP\IConfig::class); |
|
| 859 | - if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 860 | - && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 861 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 862 | - } else { |
|
| 863 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - return $backend; |
|
| 867 | - }); |
|
| 868 | - |
|
| 869 | - $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 870 | - $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 871 | - // IConfig requires a working database. This code |
|
| 872 | - // might however be called when Nextcloud is not yet setup. |
|
| 873 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 874 | - $config = $c->get(\OCP\IConfig::class); |
|
| 875 | - $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 876 | - } else { |
|
| 877 | - $config = null; |
|
| 878 | - $appConfig = null; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - return new Checker( |
|
| 882 | - $c->get(ServerVersion::class), |
|
| 883 | - $c->get(EnvironmentHelper::class), |
|
| 884 | - new FileAccessHelper(), |
|
| 885 | - new AppLocator(), |
|
| 886 | - $config, |
|
| 887 | - $appConfig, |
|
| 888 | - $c->get(ICacheFactory::class), |
|
| 889 | - $c->get(IAppManager::class), |
|
| 890 | - $c->get(IMimeTypeDetector::class) |
|
| 891 | - ); |
|
| 892 | - }); |
|
| 893 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 894 | - if (isset($this['urlParams'])) { |
|
| 895 | - $urlParams = $this['urlParams']; |
|
| 896 | - } else { |
|
| 897 | - $urlParams = []; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 901 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 902 | - ) { |
|
| 903 | - $stream = 'fakeinput://data'; |
|
| 904 | - } else { |
|
| 905 | - $stream = 'php://input'; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - return new Request( |
|
| 909 | - [ |
|
| 910 | - 'get' => $_GET, |
|
| 911 | - 'post' => $_POST, |
|
| 912 | - 'files' => $_FILES, |
|
| 913 | - 'server' => $_SERVER, |
|
| 914 | - 'env' => $_ENV, |
|
| 915 | - 'cookies' => $_COOKIE, |
|
| 916 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 917 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 918 | - : '', |
|
| 919 | - 'urlParams' => $urlParams, |
|
| 920 | - ], |
|
| 921 | - $this->get(IRequestId::class), |
|
| 922 | - $this->get(\OCP\IConfig::class), |
|
| 923 | - $this->get(CsrfTokenManager::class), |
|
| 924 | - $stream |
|
| 925 | - ); |
|
| 926 | - }); |
|
| 927 | - |
|
| 928 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 929 | - return new RequestId( |
|
| 930 | - $_SERVER['UNIQUE_ID'] ?? '', |
|
| 931 | - $this->get(ISecureRandom::class) |
|
| 932 | - ); |
|
| 933 | - }); |
|
| 934 | - |
|
| 935 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 936 | - return new Mailer( |
|
| 937 | - $c->get(\OCP\IConfig::class), |
|
| 938 | - $c->get(LoggerInterface::class), |
|
| 939 | - $c->get(Defaults::class), |
|
| 940 | - $c->get(IURLGenerator::class), |
|
| 941 | - $c->getL10N('lib'), |
|
| 942 | - $c->get(IEventDispatcher::class), |
|
| 943 | - $c->get(IFactory::class) |
|
| 944 | - ); |
|
| 945 | - }); |
|
| 946 | - |
|
| 947 | - /** @since 30.0.0 */ |
|
| 948 | - $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 949 | - |
|
| 950 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 951 | - $config = $c->get(\OCP\IConfig::class); |
|
| 952 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 953 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 954 | - return new NullLDAPProviderFactory($this); |
|
| 955 | - } |
|
| 956 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 957 | - return new $factoryClass($this); |
|
| 958 | - }); |
|
| 959 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 960 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
| 961 | - return $factory->getLDAPProvider(); |
|
| 962 | - }); |
|
| 963 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 964 | - $ini = $c->get(IniGetWrapper::class); |
|
| 965 | - $config = $c->get(\OCP\IConfig::class); |
|
| 966 | - $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 967 | - if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 968 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 969 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 970 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 971 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 972 | - $timeFactory = $c->get(ITimeFactory::class); |
|
| 973 | - return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 974 | - } |
|
| 975 | - return new DBLockingProvider( |
|
| 976 | - $c->get(IDBConnection::class), |
|
| 977 | - new TimeFactory(), |
|
| 978 | - $ttl, |
|
| 979 | - !\OC::$CLI |
|
| 980 | - ); |
|
| 981 | - } |
|
| 982 | - return new NoopLockingProvider(); |
|
| 983 | - }); |
|
| 984 | - |
|
| 985 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 986 | - return new LockManager(); |
|
| 987 | - }); |
|
| 988 | - |
|
| 989 | - $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 990 | - $this->registerService(SetupManager::class, function ($c) { |
|
| 991 | - // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 992 | - return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 993 | - }); |
|
| 994 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 995 | - |
|
| 996 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 997 | - return new \OC\Files\Type\Detection( |
|
| 998 | - $c->get(IURLGenerator::class), |
|
| 999 | - $c->get(LoggerInterface::class), |
|
| 1000 | - \OC::$configDir, |
|
| 1001 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 1002 | - ); |
|
| 1003 | - }); |
|
| 1004 | - |
|
| 1005 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1006 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1007 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 1008 | - }); |
|
| 1009 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1010 | - |
|
| 1011 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1012 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1013 | - $manager->registerCapability(function () use ($c) { |
|
| 1014 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1015 | - }); |
|
| 1016 | - $manager->registerCapability(function () use ($c) { |
|
| 1017 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1018 | - }); |
|
| 1019 | - return $manager; |
|
| 1020 | - }); |
|
| 1021 | - |
|
| 1022 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1023 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1024 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1025 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1026 | - $factory = new $factoryClass($this); |
|
| 1027 | - $manager = $factory->getManager(); |
|
| 1028 | - |
|
| 1029 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1030 | - $manager = $c->get(IUserManager::class); |
|
| 1031 | - $userDisplayName = $manager->getDisplayName($id); |
|
| 1032 | - if ($userDisplayName === null) { |
|
| 1033 | - $l = $c->get(IFactory::class)->get('core'); |
|
| 1034 | - return $l->t('Unknown account'); |
|
| 1035 | - } |
|
| 1036 | - return $userDisplayName; |
|
| 1037 | - }); |
|
| 1038 | - |
|
| 1039 | - return $manager; |
|
| 1040 | - }); |
|
| 1041 | - |
|
| 1042 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1043 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1044 | - try { |
|
| 1045 | - $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1046 | - } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1047 | - // App disabled or in maintenance mode |
|
| 1048 | - $classExists = false; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1052 | - $backgroundService = new BackgroundService( |
|
| 1053 | - $c->get(IRootFolder::class), |
|
| 1054 | - $c->getAppDataDir('theming'), |
|
| 1055 | - $c->get(IAppConfig::class), |
|
| 1056 | - $c->get(\OCP\IConfig::class), |
|
| 1057 | - $c->get(ISession::class)->get('user_id'), |
|
| 1058 | - ); |
|
| 1059 | - $imageManager = new ImageManager( |
|
| 1060 | - $c->get(\OCP\IConfig::class), |
|
| 1061 | - $c->getAppDataDir('theming'), |
|
| 1062 | - $c->get(IURLGenerator::class), |
|
| 1063 | - $c->get(ICacheFactory::class), |
|
| 1064 | - $c->get(LoggerInterface::class), |
|
| 1065 | - $c->get(ITempManager::class), |
|
| 1066 | - $backgroundService, |
|
| 1067 | - ); |
|
| 1068 | - return new ThemingDefaults( |
|
| 1069 | - $c->get(\OCP\IConfig::class), |
|
| 1070 | - $c->get(\OCP\IAppConfig::class), |
|
| 1071 | - $c->getL10N('theming'), |
|
| 1072 | - $c->get(IUserSession::class), |
|
| 1073 | - $c->get(IURLGenerator::class), |
|
| 1074 | - $c->get(ICacheFactory::class), |
|
| 1075 | - new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1076 | - $imageManager, |
|
| 1077 | - $c->get(IAppManager::class), |
|
| 1078 | - $c->get(INavigationManager::class), |
|
| 1079 | - $backgroundService, |
|
| 1080 | - ); |
|
| 1081 | - } |
|
| 1082 | - return new \OC_Defaults(); |
|
| 1083 | - }); |
|
| 1084 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1085 | - return new JSCombiner( |
|
| 1086 | - $c->getAppDataDir('js'), |
|
| 1087 | - $c->get(IURLGenerator::class), |
|
| 1088 | - $this->get(ICacheFactory::class), |
|
| 1089 | - $c->get(SystemConfig::class), |
|
| 1090 | - $c->get(LoggerInterface::class) |
|
| 1091 | - ); |
|
| 1092 | - }); |
|
| 1093 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1094 | - |
|
| 1095 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1096 | - // FIXME: Instantiated here due to cyclic dependency |
|
| 1097 | - $request = new Request( |
|
| 1098 | - [ |
|
| 1099 | - 'get' => $_GET, |
|
| 1100 | - 'post' => $_POST, |
|
| 1101 | - 'files' => $_FILES, |
|
| 1102 | - 'server' => $_SERVER, |
|
| 1103 | - 'env' => $_ENV, |
|
| 1104 | - 'cookies' => $_COOKIE, |
|
| 1105 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1106 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1107 | - : null, |
|
| 1108 | - ], |
|
| 1109 | - $c->get(IRequestId::class), |
|
| 1110 | - $c->get(\OCP\IConfig::class) |
|
| 1111 | - ); |
|
| 1112 | - |
|
| 1113 | - return new CryptoWrapper( |
|
| 1114 | - $c->get(ICrypto::class), |
|
| 1115 | - $c->get(ISecureRandom::class), |
|
| 1116 | - $request |
|
| 1117 | - ); |
|
| 1118 | - }); |
|
| 1119 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1120 | - return new SessionStorage($c->get(ISession::class)); |
|
| 1121 | - }); |
|
| 1122 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1123 | - |
|
| 1124 | - $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1125 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1126 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1127 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1128 | - return new $factoryClass($this); |
|
| 1129 | - }); |
|
| 1130 | - |
|
| 1131 | - $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1132 | - |
|
| 1133 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1134 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1135 | - |
|
| 1136 | - // register default plugins |
|
| 1137 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1138 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1139 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1140 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1141 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1142 | - |
|
| 1143 | - return $instance; |
|
| 1144 | - }); |
|
| 1145 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1146 | - |
|
| 1147 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1148 | - |
|
| 1149 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1150 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1151 | - |
|
| 1152 | - $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1153 | - $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1154 | - |
|
| 1155 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1156 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1157 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1158 | - return new \OC\Files\AppData\Factory( |
|
| 1159 | - $c->get(IRootFolder::class), |
|
| 1160 | - $c->get(SystemConfig::class) |
|
| 1161 | - ); |
|
| 1162 | - }); |
|
| 1163 | - |
|
| 1164 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1165 | - return new LockdownManager(function () use ($c) { |
|
| 1166 | - return $c->get(ISession::class); |
|
| 1167 | - }); |
|
| 1168 | - }); |
|
| 1169 | - |
|
| 1170 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1171 | - return new DiscoveryService( |
|
| 1172 | - $c->get(ICacheFactory::class), |
|
| 1173 | - $c->get(IClientService::class) |
|
| 1174 | - ); |
|
| 1175 | - }); |
|
| 1176 | - $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1177 | - |
|
| 1178 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1179 | - return new CloudIdManager( |
|
| 1180 | - $c->get(\OCP\Contacts\IManager::class), |
|
| 1181 | - $c->get(IURLGenerator::class), |
|
| 1182 | - $c->get(IUserManager::class), |
|
| 1183 | - $c->get(ICacheFactory::class), |
|
| 1184 | - $c->get(IEventDispatcher::class), |
|
| 1185 | - ); |
|
| 1186 | - }); |
|
| 1187 | - |
|
| 1188 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1189 | - $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1190 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1191 | - return new CloudFederationFactory(); |
|
| 1192 | - }); |
|
| 257 | + /** @var string */ |
|
| 258 | + private $webRoot; |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @param string $webRoot |
|
| 262 | + * @param \OC\Config $config |
|
| 263 | + */ |
|
| 264 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 265 | + parent::__construct(); |
|
| 266 | + $this->webRoot = $webRoot; |
|
| 267 | + |
|
| 268 | + // To find out if we are running from CLI or not |
|
| 269 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 270 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 271 | + |
|
| 272 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 273 | + return $c; |
|
| 274 | + }); |
|
| 275 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 276 | + return $c; |
|
| 277 | + }); |
|
| 278 | + |
|
| 279 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 280 | + |
|
| 281 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 282 | + |
|
| 283 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 284 | + |
|
| 285 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 286 | + |
|
| 287 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 288 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 289 | + $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 290 | + |
|
| 291 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 292 | + |
|
| 293 | + $this->registerService(View::class, function (Server $c) { |
|
| 294 | + return new View(); |
|
| 295 | + }, false); |
|
| 296 | + |
|
| 297 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 298 | + return new PreviewManager( |
|
| 299 | + $c->get(\OCP\IConfig::class), |
|
| 300 | + $c->get(IRootFolder::class), |
|
| 301 | + new \OC\Preview\Storage\Root( |
|
| 302 | + $c->get(IRootFolder::class), |
|
| 303 | + $c->get(SystemConfig::class) |
|
| 304 | + ), |
|
| 305 | + $c->get(IEventDispatcher::class), |
|
| 306 | + $c->get(GeneratorHelper::class), |
|
| 307 | + $c->get(ISession::class)->get('user_id'), |
|
| 308 | + $c->get(Coordinator::class), |
|
| 309 | + $c->get(IServerContainer::class), |
|
| 310 | + $c->get(IBinaryFinder::class), |
|
| 311 | + $c->get(IMagickSupport::class) |
|
| 312 | + ); |
|
| 313 | + }); |
|
| 314 | + $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 315 | + |
|
| 316 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 317 | + return new \OC\Preview\Watcher( |
|
| 318 | + new \OC\Preview\Storage\Root( |
|
| 319 | + $c->get(IRootFolder::class), |
|
| 320 | + $c->get(SystemConfig::class) |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + }); |
|
| 324 | + |
|
| 325 | + $this->registerService(IProfiler::class, function (Server $c) { |
|
| 326 | + return new Profiler($c->get(SystemConfig::class)); |
|
| 327 | + }); |
|
| 328 | + |
|
| 329 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager { |
|
| 330 | + $view = new View(); |
|
| 331 | + $util = new Encryption\Util( |
|
| 332 | + $view, |
|
| 333 | + $c->get(IUserManager::class), |
|
| 334 | + $c->get(IGroupManager::class), |
|
| 335 | + $c->get(\OCP\IConfig::class) |
|
| 336 | + ); |
|
| 337 | + return new Encryption\Manager( |
|
| 338 | + $c->get(\OCP\IConfig::class), |
|
| 339 | + $c->get(LoggerInterface::class), |
|
| 340 | + $c->getL10N('core'), |
|
| 341 | + new View(), |
|
| 342 | + $util, |
|
| 343 | + new ArrayCache() |
|
| 344 | + ); |
|
| 345 | + }); |
|
| 346 | + |
|
| 347 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 348 | + $util = new Encryption\Util( |
|
| 349 | + new View(), |
|
| 350 | + $c->get(IUserManager::class), |
|
| 351 | + $c->get(IGroupManager::class), |
|
| 352 | + $c->get(\OCP\IConfig::class) |
|
| 353 | + ); |
|
| 354 | + return new Encryption\File( |
|
| 355 | + $util, |
|
| 356 | + $c->get(IRootFolder::class), |
|
| 357 | + $c->get(\OCP\Share\IManager::class) |
|
| 358 | + ); |
|
| 359 | + }); |
|
| 360 | + |
|
| 361 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 362 | + $view = new View(); |
|
| 363 | + $util = new Encryption\Util( |
|
| 364 | + $view, |
|
| 365 | + $c->get(IUserManager::class), |
|
| 366 | + $c->get(IGroupManager::class), |
|
| 367 | + $c->get(\OCP\IConfig::class) |
|
| 368 | + ); |
|
| 369 | + |
|
| 370 | + return new Encryption\Keys\Storage( |
|
| 371 | + $view, |
|
| 372 | + $util, |
|
| 373 | + $c->get(ICrypto::class), |
|
| 374 | + $c->get(\OCP\IConfig::class) |
|
| 375 | + ); |
|
| 376 | + }); |
|
| 377 | + |
|
| 378 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 379 | + |
|
| 380 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 381 | + /** @var \OCP\IConfig $config */ |
|
| 382 | + $config = $c->get(\OCP\IConfig::class); |
|
| 383 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 384 | + return new $factoryClass($this); |
|
| 385 | + }); |
|
| 386 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 387 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 388 | + }); |
|
| 389 | + /** @deprecated 19.0.0 */ |
|
| 390 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 391 | + |
|
| 392 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 393 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 394 | + }); |
|
| 395 | + $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 396 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 397 | + $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 398 | + $view = new View(); |
|
| 399 | + /** @var IUserSession $userSession */ |
|
| 400 | + $userSession = $c->get(IUserSession::class); |
|
| 401 | + $root = new Root( |
|
| 402 | + $manager, |
|
| 403 | + $view, |
|
| 404 | + $userSession->getUser(), |
|
| 405 | + $c->get(IUserMountCache::class), |
|
| 406 | + $this->get(LoggerInterface::class), |
|
| 407 | + $this->get(IUserManager::class), |
|
| 408 | + $this->get(IEventDispatcher::class), |
|
| 409 | + $this->get(ICacheFactory::class), |
|
| 410 | + ); |
|
| 411 | + |
|
| 412 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 413 | + $root, |
|
| 414 | + $c->get(SystemConfig::class), |
|
| 415 | + $this->get(IEventDispatcher::class) |
|
| 416 | + ); |
|
| 417 | + $previewConnector->connectWatcher(); |
|
| 418 | + |
|
| 419 | + return $root; |
|
| 420 | + }); |
|
| 421 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 422 | + return new HookConnector( |
|
| 423 | + $c->get(IRootFolder::class), |
|
| 424 | + new View(), |
|
| 425 | + $c->get(IEventDispatcher::class), |
|
| 426 | + $c->get(LoggerInterface::class) |
|
| 427 | + ); |
|
| 428 | + }); |
|
| 429 | + |
|
| 430 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 431 | + return new LazyRoot(function () use ($c) { |
|
| 432 | + return $c->get('RootFolder'); |
|
| 433 | + }); |
|
| 434 | + }); |
|
| 435 | + |
|
| 436 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 437 | + |
|
| 438 | + $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 439 | + return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 440 | + }); |
|
| 441 | + |
|
| 442 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 443 | + $groupManager = new \OC\Group\Manager( |
|
| 444 | + $this->get(IUserManager::class), |
|
| 445 | + $this->get(IEventDispatcher::class), |
|
| 446 | + $this->get(LoggerInterface::class), |
|
| 447 | + $this->get(ICacheFactory::class), |
|
| 448 | + $this->get(IRemoteAddress::class), |
|
| 449 | + ); |
|
| 450 | + return $groupManager; |
|
| 451 | + }); |
|
| 452 | + |
|
| 453 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 454 | + $session = $c->get(ISession::class); |
|
| 455 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 456 | + $tokenProvider = $c->get(IProvider::class); |
|
| 457 | + } else { |
|
| 458 | + $tokenProvider = null; |
|
| 459 | + } |
|
| 460 | + $logger = $c->get(LoggerInterface::class); |
|
| 461 | + $crypto = $c->get(ICrypto::class); |
|
| 462 | + return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 463 | + }); |
|
| 464 | + $this->registerAlias(IStore::class, Store::class); |
|
| 465 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 466 | + $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 467 | + |
|
| 468 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 469 | + $manager = $c->get(IUserManager::class); |
|
| 470 | + $session = new \OC\Session\Memory(); |
|
| 471 | + $timeFactory = new TimeFactory(); |
|
| 472 | + // Token providers might require a working database. This code |
|
| 473 | + // might however be called when Nextcloud is not yet setup. |
|
| 474 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 475 | + $provider = $c->get(IProvider::class); |
|
| 476 | + } else { |
|
| 477 | + $provider = null; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + $userSession = new \OC\User\Session( |
|
| 481 | + $manager, |
|
| 482 | + $session, |
|
| 483 | + $timeFactory, |
|
| 484 | + $provider, |
|
| 485 | + $c->get(\OCP\IConfig::class), |
|
| 486 | + $c->get(ISecureRandom::class), |
|
| 487 | + $c->get('LockdownManager'), |
|
| 488 | + $c->get(LoggerInterface::class), |
|
| 489 | + $c->get(IEventDispatcher::class), |
|
| 490 | + ); |
|
| 491 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 492 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 493 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 494 | + }); |
|
| 495 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 496 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 497 | + /** @var \OC\User\User $user */ |
|
| 498 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 499 | + }); |
|
| 500 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 501 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 502 | + /** @var \OC\User\User $user */ |
|
| 503 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 504 | + }); |
|
| 505 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 506 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 507 | + /** @var \OC\User\User $user */ |
|
| 508 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 509 | + }); |
|
| 510 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 511 | + /** @var \OC\User\User $user */ |
|
| 512 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 513 | + }); |
|
| 514 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 515 | + /** @var \OC\User\User $user */ |
|
| 516 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 517 | + }); |
|
| 518 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 519 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 520 | + |
|
| 521 | + /** @var IEventDispatcher $dispatcher */ |
|
| 522 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 523 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 524 | + }); |
|
| 525 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 526 | + /** @var \OC\User\User $user */ |
|
| 527 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 528 | + |
|
| 529 | + /** @var IEventDispatcher $dispatcher */ |
|
| 530 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 531 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 532 | + }); |
|
| 533 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 534 | + /** @var IEventDispatcher $dispatcher */ |
|
| 535 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 536 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 537 | + }); |
|
| 538 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 539 | + /** @var \OC\User\User $user */ |
|
| 540 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 541 | + |
|
| 542 | + /** @var IEventDispatcher $dispatcher */ |
|
| 543 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 544 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 545 | + }); |
|
| 546 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 547 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 548 | + |
|
| 549 | + /** @var IEventDispatcher $dispatcher */ |
|
| 550 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 551 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 552 | + }); |
|
| 553 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 554 | + /** @var IEventDispatcher $dispatcher */ |
|
| 555 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 556 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 557 | + }); |
|
| 558 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 559 | + /** @var \OC\User\User $user */ |
|
| 560 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 561 | + }); |
|
| 562 | + return $userSession; |
|
| 563 | + }); |
|
| 564 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 565 | + |
|
| 566 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 567 | + |
|
| 568 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 569 | + |
|
| 570 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 571 | + |
|
| 572 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 573 | + return new \OC\SystemConfig($config); |
|
| 574 | + }); |
|
| 575 | + |
|
| 576 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 577 | + $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 578 | + |
|
| 579 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 580 | + return new \OC\L10N\Factory( |
|
| 581 | + $c->get(\OCP\IConfig::class), |
|
| 582 | + $c->getRequest(), |
|
| 583 | + $c->get(IUserSession::class), |
|
| 584 | + $c->get(ICacheFactory::class), |
|
| 585 | + \OC::$SERVERROOT, |
|
| 586 | + $c->get(IAppManager::class), |
|
| 587 | + ); |
|
| 588 | + }); |
|
| 589 | + |
|
| 590 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 591 | + |
|
| 592 | + $this->registerService(ICache::class, function ($c) { |
|
| 593 | + return new Cache\File(); |
|
| 594 | + }); |
|
| 595 | + |
|
| 596 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 597 | + $profiler = $c->get(IProfiler::class); |
|
| 598 | + $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 599 | + $profiler, |
|
| 600 | + ArrayCache::class, |
|
| 601 | + ArrayCache::class, |
|
| 602 | + ArrayCache::class |
|
| 603 | + ); |
|
| 604 | + /** @var SystemConfig $config */ |
|
| 605 | + $config = $c->get(SystemConfig::class); |
|
| 606 | + /** @var ServerVersion $serverVersion */ |
|
| 607 | + $serverVersion = $c->get(ServerVersion::class); |
|
| 608 | + |
|
| 609 | + if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 610 | + $logQuery = $config->getValue('log_query'); |
|
| 611 | + $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 612 | + if (!$logQuery) { |
|
| 613 | + try { |
|
| 614 | + $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(); |
|
| 615 | + } catch (\Doctrine\DBAL\Exception $e) { |
|
| 616 | + // Database service probably unavailable |
|
| 617 | + // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 618 | + return null; |
|
| 619 | + } |
|
| 620 | + } else { |
|
| 621 | + // If the log_query is enabled, we can not get the app versions |
|
| 622 | + // as that does a query, which will be logged and the logging |
|
| 623 | + // depends on redis and here we are back again in the same function. |
|
| 624 | + $v = [ |
|
| 625 | + 'log_query' => 'enabled', |
|
| 626 | + ]; |
|
| 627 | + } |
|
| 628 | + $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 629 | + $version = implode(',', $v); |
|
| 630 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 631 | + $path = \OC::$SERVERROOT; |
|
| 632 | + return md5($instanceId . '-' . $version . '-' . $path); |
|
| 633 | + }; |
|
| 634 | + return new \OC\Memcache\Factory($prefixClosure, |
|
| 635 | + $c->get(LoggerInterface::class), |
|
| 636 | + $profiler, |
|
| 637 | + /** @psalm-taint-escape callable */ |
|
| 638 | + $config->getValue('memcache.local', null), |
|
| 639 | + /** @psalm-taint-escape callable */ |
|
| 640 | + $config->getValue('memcache.distributed', null), |
|
| 641 | + /** @psalm-taint-escape callable */ |
|
| 642 | + $config->getValue('memcache.locking', null), |
|
| 643 | + /** @psalm-taint-escape callable */ |
|
| 644 | + $config->getValue('redis_log_file') |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | + return $arrayCacheFactory; |
|
| 648 | + }); |
|
| 649 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 650 | + |
|
| 651 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 652 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 653 | + return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 654 | + }); |
|
| 655 | + |
|
| 656 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 657 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 658 | + return new \OC\Activity\Manager( |
|
| 659 | + $c->getRequest(), |
|
| 660 | + $c->get(IUserSession::class), |
|
| 661 | + $c->get(\OCP\IConfig::class), |
|
| 662 | + $c->get(IValidator::class), |
|
| 663 | + $c->get(IRichTextFormatter::class), |
|
| 664 | + $l10n |
|
| 665 | + ); |
|
| 666 | + }); |
|
| 667 | + |
|
| 668 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 669 | + return new \OC\Activity\EventMerger( |
|
| 670 | + $c->getL10N('lib') |
|
| 671 | + ); |
|
| 672 | + }); |
|
| 673 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 674 | + |
|
| 675 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 676 | + return new AvatarManager( |
|
| 677 | + $c->get(IUserSession::class), |
|
| 678 | + $c->get(\OC\User\Manager::class), |
|
| 679 | + $c->getAppDataDir('avatar'), |
|
| 680 | + $c->getL10N('lib'), |
|
| 681 | + $c->get(LoggerInterface::class), |
|
| 682 | + $c->get(\OCP\IConfig::class), |
|
| 683 | + $c->get(IAccountManager::class), |
|
| 684 | + $c->get(KnownUserService::class) |
|
| 685 | + ); |
|
| 686 | + }); |
|
| 687 | + |
|
| 688 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 689 | + |
|
| 690 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 691 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 692 | + $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 693 | + |
|
| 694 | + /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 695 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 696 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 697 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 698 | + $logger = $factory->get($logType); |
|
| 699 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 700 | + |
|
| 701 | + return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 702 | + }); |
|
| 703 | + // PSR-3 logger |
|
| 704 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 705 | + |
|
| 706 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 707 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 708 | + }); |
|
| 709 | + |
|
| 710 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 711 | + |
|
| 712 | + $this->registerService(Router::class, function (Server $c) { |
|
| 713 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 714 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 715 | + $router = $c->resolve(CachingRouter::class); |
|
| 716 | + } else { |
|
| 717 | + $router = $c->resolve(Router::class); |
|
| 718 | + } |
|
| 719 | + return $router; |
|
| 720 | + }); |
|
| 721 | + $this->registerAlias(IRouter::class, Router::class); |
|
| 722 | + |
|
| 723 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 724 | + $config = $c->get(\OCP\IConfig::class); |
|
| 725 | + if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 726 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 727 | + $c->get(AllConfig::class), |
|
| 728 | + $this->get(ICacheFactory::class), |
|
| 729 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 730 | + ); |
|
| 731 | + } else { |
|
| 732 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 733 | + $c->get(AllConfig::class), |
|
| 734 | + $c->get(IDBConnection::class), |
|
| 735 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 736 | + ); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + return $backend; |
|
| 740 | + }); |
|
| 741 | + |
|
| 742 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 743 | + $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 744 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 745 | + |
|
| 746 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 747 | + |
|
| 748 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 749 | + |
|
| 750 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 751 | + |
|
| 752 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 753 | + $this->registerService(Connection::class, function (Server $c) { |
|
| 754 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 755 | + $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 756 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 757 | + if (!$factory->isValidType($type)) { |
|
| 758 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 759 | + } |
|
| 760 | + $connection = $factory->getConnection($type, []); |
|
| 761 | + return $connection; |
|
| 762 | + }); |
|
| 763 | + |
|
| 764 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 765 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
| 766 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 767 | + return new NegativeDnsCache( |
|
| 768 | + $c->get(ICacheFactory::class), |
|
| 769 | + ); |
|
| 770 | + }); |
|
| 771 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 772 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 773 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 774 | + }); |
|
| 775 | + |
|
| 776 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 777 | + $queryLogger = new QueryLogger(); |
|
| 778 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 779 | + // In debug mode, module is being activated by default |
|
| 780 | + $queryLogger->activate(); |
|
| 781 | + } |
|
| 782 | + return $queryLogger; |
|
| 783 | + }); |
|
| 784 | + |
|
| 785 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 786 | + |
|
| 787 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 788 | + // TODO: use auto-wiring |
|
| 789 | + return new \OC\App\AppManager( |
|
| 790 | + $c->get(IUserSession::class), |
|
| 791 | + $c->get(\OCP\IConfig::class), |
|
| 792 | + $c->get(IGroupManager::class), |
|
| 793 | + $c->get(ICacheFactory::class), |
|
| 794 | + $c->get(IEventDispatcher::class), |
|
| 795 | + $c->get(LoggerInterface::class), |
|
| 796 | + $c->get(ServerVersion::class), |
|
| 797 | + ); |
|
| 798 | + }); |
|
| 799 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 800 | + |
|
| 801 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 802 | + |
|
| 803 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 804 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 805 | + |
|
| 806 | + return new DateTimeFormatter( |
|
| 807 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 808 | + $c->getL10N('lib', $language) |
|
| 809 | + ); |
|
| 810 | + }); |
|
| 811 | + |
|
| 812 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 813 | + $mountCache = $c->get(UserMountCache::class); |
|
| 814 | + $listener = new UserMountCacheListener($mountCache); |
|
| 815 | + $listener->listen($c->get(IUserManager::class)); |
|
| 816 | + return $mountCache; |
|
| 817 | + }); |
|
| 818 | + |
|
| 819 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 820 | + $loader = $c->get(IStorageFactory::class); |
|
| 821 | + $mountCache = $c->get(IUserMountCache::class); |
|
| 822 | + $eventLogger = $c->get(IEventLogger::class); |
|
| 823 | + $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 824 | + |
|
| 825 | + // builtin providers |
|
| 826 | + |
|
| 827 | + $config = $c->get(\OCP\IConfig::class); |
|
| 828 | + $logger = $c->get(LoggerInterface::class); |
|
| 829 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 830 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 831 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 832 | + $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class))); |
|
| 833 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 834 | + |
|
| 835 | + return $manager; |
|
| 836 | + }); |
|
| 837 | + |
|
| 838 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 839 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 840 | + if ($busClass) { |
|
| 841 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 842 | + if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 843 | + $c->get(IAppManager::class)->loadApp($app); |
|
| 844 | + return $c->get($class); |
|
| 845 | + } else { |
|
| 846 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 847 | + } |
|
| 848 | + } else { |
|
| 849 | + $jobList = $c->get(IJobList::class); |
|
| 850 | + return new CronBus($jobList); |
|
| 851 | + } |
|
| 852 | + }); |
|
| 853 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 854 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 855 | + $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 856 | + |
|
| 857 | + $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 858 | + $config = $c->get(\OCP\IConfig::class); |
|
| 859 | + if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 860 | + && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 861 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 862 | + } else { |
|
| 863 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + return $backend; |
|
| 867 | + }); |
|
| 868 | + |
|
| 869 | + $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 870 | + $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 871 | + // IConfig requires a working database. This code |
|
| 872 | + // might however be called when Nextcloud is not yet setup. |
|
| 873 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 874 | + $config = $c->get(\OCP\IConfig::class); |
|
| 875 | + $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 876 | + } else { |
|
| 877 | + $config = null; |
|
| 878 | + $appConfig = null; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + return new Checker( |
|
| 882 | + $c->get(ServerVersion::class), |
|
| 883 | + $c->get(EnvironmentHelper::class), |
|
| 884 | + new FileAccessHelper(), |
|
| 885 | + new AppLocator(), |
|
| 886 | + $config, |
|
| 887 | + $appConfig, |
|
| 888 | + $c->get(ICacheFactory::class), |
|
| 889 | + $c->get(IAppManager::class), |
|
| 890 | + $c->get(IMimeTypeDetector::class) |
|
| 891 | + ); |
|
| 892 | + }); |
|
| 893 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 894 | + if (isset($this['urlParams'])) { |
|
| 895 | + $urlParams = $this['urlParams']; |
|
| 896 | + } else { |
|
| 897 | + $urlParams = []; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 901 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 902 | + ) { |
|
| 903 | + $stream = 'fakeinput://data'; |
|
| 904 | + } else { |
|
| 905 | + $stream = 'php://input'; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + return new Request( |
|
| 909 | + [ |
|
| 910 | + 'get' => $_GET, |
|
| 911 | + 'post' => $_POST, |
|
| 912 | + 'files' => $_FILES, |
|
| 913 | + 'server' => $_SERVER, |
|
| 914 | + 'env' => $_ENV, |
|
| 915 | + 'cookies' => $_COOKIE, |
|
| 916 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 917 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 918 | + : '', |
|
| 919 | + 'urlParams' => $urlParams, |
|
| 920 | + ], |
|
| 921 | + $this->get(IRequestId::class), |
|
| 922 | + $this->get(\OCP\IConfig::class), |
|
| 923 | + $this->get(CsrfTokenManager::class), |
|
| 924 | + $stream |
|
| 925 | + ); |
|
| 926 | + }); |
|
| 927 | + |
|
| 928 | + $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 929 | + return new RequestId( |
|
| 930 | + $_SERVER['UNIQUE_ID'] ?? '', |
|
| 931 | + $this->get(ISecureRandom::class) |
|
| 932 | + ); |
|
| 933 | + }); |
|
| 934 | + |
|
| 935 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 936 | + return new Mailer( |
|
| 937 | + $c->get(\OCP\IConfig::class), |
|
| 938 | + $c->get(LoggerInterface::class), |
|
| 939 | + $c->get(Defaults::class), |
|
| 940 | + $c->get(IURLGenerator::class), |
|
| 941 | + $c->getL10N('lib'), |
|
| 942 | + $c->get(IEventDispatcher::class), |
|
| 943 | + $c->get(IFactory::class) |
|
| 944 | + ); |
|
| 945 | + }); |
|
| 946 | + |
|
| 947 | + /** @since 30.0.0 */ |
|
| 948 | + $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 949 | + |
|
| 950 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 951 | + $config = $c->get(\OCP\IConfig::class); |
|
| 952 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 953 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 954 | + return new NullLDAPProviderFactory($this); |
|
| 955 | + } |
|
| 956 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 957 | + return new $factoryClass($this); |
|
| 958 | + }); |
|
| 959 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 960 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
| 961 | + return $factory->getLDAPProvider(); |
|
| 962 | + }); |
|
| 963 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 964 | + $ini = $c->get(IniGetWrapper::class); |
|
| 965 | + $config = $c->get(\OCP\IConfig::class); |
|
| 966 | + $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 967 | + if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 968 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 969 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 970 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 971 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 972 | + $timeFactory = $c->get(ITimeFactory::class); |
|
| 973 | + return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 974 | + } |
|
| 975 | + return new DBLockingProvider( |
|
| 976 | + $c->get(IDBConnection::class), |
|
| 977 | + new TimeFactory(), |
|
| 978 | + $ttl, |
|
| 979 | + !\OC::$CLI |
|
| 980 | + ); |
|
| 981 | + } |
|
| 982 | + return new NoopLockingProvider(); |
|
| 983 | + }); |
|
| 984 | + |
|
| 985 | + $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 986 | + return new LockManager(); |
|
| 987 | + }); |
|
| 988 | + |
|
| 989 | + $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 990 | + $this->registerService(SetupManager::class, function ($c) { |
|
| 991 | + // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 992 | + return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 993 | + }); |
|
| 994 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 995 | + |
|
| 996 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 997 | + return new \OC\Files\Type\Detection( |
|
| 998 | + $c->get(IURLGenerator::class), |
|
| 999 | + $c->get(LoggerInterface::class), |
|
| 1000 | + \OC::$configDir, |
|
| 1001 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 1002 | + ); |
|
| 1003 | + }); |
|
| 1004 | + |
|
| 1005 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1006 | + $this->registerService(BundleFetcher::class, function () { |
|
| 1007 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 1008 | + }); |
|
| 1009 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1010 | + |
|
| 1011 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1012 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1013 | + $manager->registerCapability(function () use ($c) { |
|
| 1014 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1015 | + }); |
|
| 1016 | + $manager->registerCapability(function () use ($c) { |
|
| 1017 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1018 | + }); |
|
| 1019 | + return $manager; |
|
| 1020 | + }); |
|
| 1021 | + |
|
| 1022 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1023 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1024 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1025 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1026 | + $factory = new $factoryClass($this); |
|
| 1027 | + $manager = $factory->getManager(); |
|
| 1028 | + |
|
| 1029 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1030 | + $manager = $c->get(IUserManager::class); |
|
| 1031 | + $userDisplayName = $manager->getDisplayName($id); |
|
| 1032 | + if ($userDisplayName === null) { |
|
| 1033 | + $l = $c->get(IFactory::class)->get('core'); |
|
| 1034 | + return $l->t('Unknown account'); |
|
| 1035 | + } |
|
| 1036 | + return $userDisplayName; |
|
| 1037 | + }); |
|
| 1038 | + |
|
| 1039 | + return $manager; |
|
| 1040 | + }); |
|
| 1041 | + |
|
| 1042 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1043 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1044 | + try { |
|
| 1045 | + $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1046 | + } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1047 | + // App disabled or in maintenance mode |
|
| 1048 | + $classExists = false; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1052 | + $backgroundService = new BackgroundService( |
|
| 1053 | + $c->get(IRootFolder::class), |
|
| 1054 | + $c->getAppDataDir('theming'), |
|
| 1055 | + $c->get(IAppConfig::class), |
|
| 1056 | + $c->get(\OCP\IConfig::class), |
|
| 1057 | + $c->get(ISession::class)->get('user_id'), |
|
| 1058 | + ); |
|
| 1059 | + $imageManager = new ImageManager( |
|
| 1060 | + $c->get(\OCP\IConfig::class), |
|
| 1061 | + $c->getAppDataDir('theming'), |
|
| 1062 | + $c->get(IURLGenerator::class), |
|
| 1063 | + $c->get(ICacheFactory::class), |
|
| 1064 | + $c->get(LoggerInterface::class), |
|
| 1065 | + $c->get(ITempManager::class), |
|
| 1066 | + $backgroundService, |
|
| 1067 | + ); |
|
| 1068 | + return new ThemingDefaults( |
|
| 1069 | + $c->get(\OCP\IConfig::class), |
|
| 1070 | + $c->get(\OCP\IAppConfig::class), |
|
| 1071 | + $c->getL10N('theming'), |
|
| 1072 | + $c->get(IUserSession::class), |
|
| 1073 | + $c->get(IURLGenerator::class), |
|
| 1074 | + $c->get(ICacheFactory::class), |
|
| 1075 | + new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1076 | + $imageManager, |
|
| 1077 | + $c->get(IAppManager::class), |
|
| 1078 | + $c->get(INavigationManager::class), |
|
| 1079 | + $backgroundService, |
|
| 1080 | + ); |
|
| 1081 | + } |
|
| 1082 | + return new \OC_Defaults(); |
|
| 1083 | + }); |
|
| 1084 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1085 | + return new JSCombiner( |
|
| 1086 | + $c->getAppDataDir('js'), |
|
| 1087 | + $c->get(IURLGenerator::class), |
|
| 1088 | + $this->get(ICacheFactory::class), |
|
| 1089 | + $c->get(SystemConfig::class), |
|
| 1090 | + $c->get(LoggerInterface::class) |
|
| 1091 | + ); |
|
| 1092 | + }); |
|
| 1093 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1094 | + |
|
| 1095 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1096 | + // FIXME: Instantiated here due to cyclic dependency |
|
| 1097 | + $request = new Request( |
|
| 1098 | + [ |
|
| 1099 | + 'get' => $_GET, |
|
| 1100 | + 'post' => $_POST, |
|
| 1101 | + 'files' => $_FILES, |
|
| 1102 | + 'server' => $_SERVER, |
|
| 1103 | + 'env' => $_ENV, |
|
| 1104 | + 'cookies' => $_COOKIE, |
|
| 1105 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1106 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1107 | + : null, |
|
| 1108 | + ], |
|
| 1109 | + $c->get(IRequestId::class), |
|
| 1110 | + $c->get(\OCP\IConfig::class) |
|
| 1111 | + ); |
|
| 1112 | + |
|
| 1113 | + return new CryptoWrapper( |
|
| 1114 | + $c->get(ICrypto::class), |
|
| 1115 | + $c->get(ISecureRandom::class), |
|
| 1116 | + $request |
|
| 1117 | + ); |
|
| 1118 | + }); |
|
| 1119 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1120 | + return new SessionStorage($c->get(ISession::class)); |
|
| 1121 | + }); |
|
| 1122 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1123 | + |
|
| 1124 | + $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1125 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1126 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1127 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1128 | + return new $factoryClass($this); |
|
| 1129 | + }); |
|
| 1130 | + |
|
| 1131 | + $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1132 | + |
|
| 1133 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1134 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1135 | + |
|
| 1136 | + // register default plugins |
|
| 1137 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1138 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1139 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1140 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1141 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1142 | + |
|
| 1143 | + return $instance; |
|
| 1144 | + }); |
|
| 1145 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1146 | + |
|
| 1147 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1148 | + |
|
| 1149 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1150 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1151 | + |
|
| 1152 | + $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1153 | + $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1154 | + |
|
| 1155 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1156 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1157 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1158 | + return new \OC\Files\AppData\Factory( |
|
| 1159 | + $c->get(IRootFolder::class), |
|
| 1160 | + $c->get(SystemConfig::class) |
|
| 1161 | + ); |
|
| 1162 | + }); |
|
| 1163 | + |
|
| 1164 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1165 | + return new LockdownManager(function () use ($c) { |
|
| 1166 | + return $c->get(ISession::class); |
|
| 1167 | + }); |
|
| 1168 | + }); |
|
| 1169 | + |
|
| 1170 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1171 | + return new DiscoveryService( |
|
| 1172 | + $c->get(ICacheFactory::class), |
|
| 1173 | + $c->get(IClientService::class) |
|
| 1174 | + ); |
|
| 1175 | + }); |
|
| 1176 | + $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1177 | + |
|
| 1178 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1179 | + return new CloudIdManager( |
|
| 1180 | + $c->get(\OCP\Contacts\IManager::class), |
|
| 1181 | + $c->get(IURLGenerator::class), |
|
| 1182 | + $c->get(IUserManager::class), |
|
| 1183 | + $c->get(ICacheFactory::class), |
|
| 1184 | + $c->get(IEventDispatcher::class), |
|
| 1185 | + ); |
|
| 1186 | + }); |
|
| 1187 | + |
|
| 1188 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1189 | + $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1190 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1191 | + return new CloudFederationFactory(); |
|
| 1192 | + }); |
|
| 1193 | 1193 | |
| 1194 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1194 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1195 | 1195 | |
| 1196 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1197 | - $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1196 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1197 | + $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1198 | 1198 | |
| 1199 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1200 | - return new Defaults( |
|
| 1201 | - $c->get('ThemingDefaults') |
|
| 1202 | - ); |
|
| 1203 | - }); |
|
| 1199 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1200 | + return new Defaults( |
|
| 1201 | + $c->get('ThemingDefaults') |
|
| 1202 | + ); |
|
| 1203 | + }); |
|
| 1204 | 1204 | |
| 1205 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1206 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1207 | - }, false); |
|
| 1205 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1206 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1207 | + }, false); |
|
| 1208 | 1208 | |
| 1209 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1210 | - return new ShareHelper( |
|
| 1211 | - $c->get(\OCP\Share\IManager::class) |
|
| 1212 | - ); |
|
| 1213 | - }); |
|
| 1209 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1210 | + return new ShareHelper( |
|
| 1211 | + $c->get(\OCP\Share\IManager::class) |
|
| 1212 | + ); |
|
| 1213 | + }); |
|
| 1214 | 1214 | |
| 1215 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1216 | - return new Installer( |
|
| 1217 | - $c->get(AppFetcher::class), |
|
| 1218 | - $c->get(IClientService::class), |
|
| 1219 | - $c->get(ITempManager::class), |
|
| 1220 | - $c->get(LoggerInterface::class), |
|
| 1221 | - $c->get(\OCP\IConfig::class), |
|
| 1222 | - \OC::$CLI |
|
| 1223 | - ); |
|
| 1224 | - }); |
|
| 1215 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1216 | + return new Installer( |
|
| 1217 | + $c->get(AppFetcher::class), |
|
| 1218 | + $c->get(IClientService::class), |
|
| 1219 | + $c->get(ITempManager::class), |
|
| 1220 | + $c->get(LoggerInterface::class), |
|
| 1221 | + $c->get(\OCP\IConfig::class), |
|
| 1222 | + \OC::$CLI |
|
| 1223 | + ); |
|
| 1224 | + }); |
|
| 1225 | 1225 | |
| 1226 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1227 | - return new ApiFactory($c->get(IClientService::class)); |
|
| 1228 | - }); |
|
| 1226 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1227 | + return new ApiFactory($c->get(IClientService::class)); |
|
| 1228 | + }); |
|
| 1229 | 1229 | |
| 1230 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1231 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1232 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1233 | - }); |
|
| 1230 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1231 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1232 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1233 | + }); |
|
| 1234 | 1234 | |
| 1235 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1236 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1235 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1236 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1237 | 1237 | |
| 1238 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1238 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1239 | 1239 | |
| 1240 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1240 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1241 | 1241 | |
| 1242 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1243 | - $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1242 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1243 | + $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1244 | 1244 | |
| 1245 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1245 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1246 | 1246 | |
| 1247 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1247 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1248 | 1248 | |
| 1249 | - $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1249 | + $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1250 | 1250 | |
| 1251 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1251 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1252 | 1252 | |
| 1253 | - $this->registerAlias(IBroker::class, Broker::class); |
|
| 1253 | + $this->registerAlias(IBroker::class, Broker::class); |
|
| 1254 | 1254 | |
| 1255 | - $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1255 | + $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1256 | 1256 | |
| 1257 | - $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1257 | + $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1258 | 1258 | |
| 1259 | - $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1259 | + $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1260 | 1260 | |
| 1261 | - $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1261 | + $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1262 | 1262 | |
| 1263 | - $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1263 | + $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1264 | 1264 | |
| 1265 | - $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1265 | + $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1266 | 1266 | |
| 1267 | - $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1267 | + $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1268 | 1268 | |
| 1269 | - $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1269 | + $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1270 | 1270 | |
| 1271 | - $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1271 | + $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1272 | 1272 | |
| 1273 | - $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1273 | + $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1274 | 1274 | |
| 1275 | - $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1275 | + $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1276 | 1276 | |
| 1277 | - $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1277 | + $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1278 | 1278 | |
| 1279 | - $this->registerAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1279 | + $this->registerAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1280 | 1280 | |
| 1281 | - $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1281 | + $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1282 | 1282 | |
| 1283 | - $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1283 | + $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1284 | 1284 | |
| 1285 | - $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1285 | + $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1286 | 1286 | |
| 1287 | - $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1287 | + $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1288 | 1288 | |
| 1289 | - $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1289 | + $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1290 | 1290 | |
| 1291 | - $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1291 | + $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1292 | 1292 | |
| 1293 | - $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1293 | + $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1294 | 1294 | |
| 1295 | - $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1295 | + $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1296 | 1296 | |
| 1297 | - $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1297 | + $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1298 | 1298 | |
| 1299 | - $this->connectDispatcher(); |
|
| 1300 | - } |
|
| 1299 | + $this->connectDispatcher(); |
|
| 1300 | + } |
|
| 1301 | 1301 | |
| 1302 | - public function boot() { |
|
| 1303 | - /** @var HookConnector $hookConnector */ |
|
| 1304 | - $hookConnector = $this->get(HookConnector::class); |
|
| 1305 | - $hookConnector->viewToNode(); |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - /** |
|
| 1309 | - * @return \OCP\Calendar\IManager |
|
| 1310 | - * @deprecated 20.0.0 |
|
| 1311 | - */ |
|
| 1312 | - public function getCalendarManager() { |
|
| 1313 | - return $this->get(\OC\Calendar\Manager::class); |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * @return \OCP\Calendar\Resource\IManager |
|
| 1318 | - * @deprecated 20.0.0 |
|
| 1319 | - */ |
|
| 1320 | - public function getCalendarResourceBackendManager() { |
|
| 1321 | - return $this->get(\OC\Calendar\Resource\Manager::class); |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - /** |
|
| 1325 | - * @return \OCP\Calendar\Room\IManager |
|
| 1326 | - * @deprecated 20.0.0 |
|
| 1327 | - */ |
|
| 1328 | - public function getCalendarRoomBackendManager() { |
|
| 1329 | - return $this->get(\OC\Calendar\Room\Manager::class); |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - private function connectDispatcher(): void { |
|
| 1333 | - /** @var IEventDispatcher $eventDispatcher */ |
|
| 1334 | - $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1335 | - $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1336 | - $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1337 | - $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1338 | - $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1339 | - |
|
| 1340 | - FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1341 | - GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1342 | - } |
|
| 1343 | - |
|
| 1344 | - /** |
|
| 1345 | - * @return \OCP\Contacts\IManager |
|
| 1346 | - * @deprecated 20.0.0 |
|
| 1347 | - */ |
|
| 1348 | - public function getContactsManager() { |
|
| 1349 | - return $this->get(\OCP\Contacts\IManager::class); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * @return \OC\Encryption\Manager |
|
| 1354 | - * @deprecated 20.0.0 |
|
| 1355 | - */ |
|
| 1356 | - public function getEncryptionManager() { |
|
| 1357 | - return $this->get(\OCP\Encryption\IManager::class); |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - /** |
|
| 1361 | - * @return \OC\Encryption\File |
|
| 1362 | - * @deprecated 20.0.0 |
|
| 1363 | - */ |
|
| 1364 | - public function getEncryptionFilesHelper() { |
|
| 1365 | - return $this->get(IFile::class); |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1370 | - * @deprecated 20.0.0 |
|
| 1371 | - */ |
|
| 1372 | - public function getEncryptionKeyStorage() { |
|
| 1373 | - return $this->get(IStorage::class); |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * The current request object holding all information about the request |
|
| 1378 | - * currently being processed is returned from this method. |
|
| 1379 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1380 | - * |
|
| 1381 | - * @return \OCP\IRequest |
|
| 1382 | - * @deprecated 20.0.0 |
|
| 1383 | - */ |
|
| 1384 | - public function getRequest() { |
|
| 1385 | - return $this->get(IRequest::class); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * Returns the preview manager which can create preview images for a given file |
|
| 1390 | - * |
|
| 1391 | - * @return IPreview |
|
| 1392 | - * @deprecated 20.0.0 |
|
| 1393 | - */ |
|
| 1394 | - public function getPreviewManager() { |
|
| 1395 | - return $this->get(IPreview::class); |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - /** |
|
| 1399 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1400 | - * |
|
| 1401 | - * @see \OCP\ITagManager::load() |
|
| 1402 | - * @return ITagManager |
|
| 1403 | - * @deprecated 20.0.0 |
|
| 1404 | - */ |
|
| 1405 | - public function getTagManager() { |
|
| 1406 | - return $this->get(ITagManager::class); |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - /** |
|
| 1410 | - * Returns the system-tag manager |
|
| 1411 | - * |
|
| 1412 | - * @return ISystemTagManager |
|
| 1413 | - * |
|
| 1414 | - * @since 9.0.0 |
|
| 1415 | - * @deprecated 20.0.0 |
|
| 1416 | - */ |
|
| 1417 | - public function getSystemTagManager() { |
|
| 1418 | - return $this->get(ISystemTagManager::class); |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * Returns the system-tag object mapper |
|
| 1423 | - * |
|
| 1424 | - * @return ISystemTagObjectMapper |
|
| 1425 | - * |
|
| 1426 | - * @since 9.0.0 |
|
| 1427 | - * @deprecated 20.0.0 |
|
| 1428 | - */ |
|
| 1429 | - public function getSystemTagObjectMapper() { |
|
| 1430 | - return $this->get(ISystemTagObjectMapper::class); |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - /** |
|
| 1434 | - * Returns the avatar manager, used for avatar functionality |
|
| 1435 | - * |
|
| 1436 | - * @return IAvatarManager |
|
| 1437 | - * @deprecated 20.0.0 |
|
| 1438 | - */ |
|
| 1439 | - public function getAvatarManager() { |
|
| 1440 | - return $this->get(IAvatarManager::class); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - /** |
|
| 1444 | - * Returns the root folder of ownCloud's data directory |
|
| 1445 | - * |
|
| 1446 | - * @return IRootFolder |
|
| 1447 | - * @deprecated 20.0.0 |
|
| 1448 | - */ |
|
| 1449 | - public function getRootFolder() { |
|
| 1450 | - return $this->get(IRootFolder::class); |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * Returns the root folder of ownCloud's data directory |
|
| 1455 | - * This is the lazy variant so this gets only initialized once it |
|
| 1456 | - * is actually used. |
|
| 1457 | - * |
|
| 1458 | - * @return IRootFolder |
|
| 1459 | - * @deprecated 20.0.0 |
|
| 1460 | - */ |
|
| 1461 | - public function getLazyRootFolder() { |
|
| 1462 | - return $this->get(IRootFolder::class); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - /** |
|
| 1466 | - * Returns a view to ownCloud's files folder |
|
| 1467 | - * |
|
| 1468 | - * @param string $userId user ID |
|
| 1469 | - * @return \OCP\Files\Folder|null |
|
| 1470 | - * @deprecated 20.0.0 |
|
| 1471 | - */ |
|
| 1472 | - public function getUserFolder($userId = null) { |
|
| 1473 | - if ($userId === null) { |
|
| 1474 | - $user = $this->get(IUserSession::class)->getUser(); |
|
| 1475 | - if (!$user) { |
|
| 1476 | - return null; |
|
| 1477 | - } |
|
| 1478 | - $userId = $user->getUID(); |
|
| 1479 | - } |
|
| 1480 | - $root = $this->get(IRootFolder::class); |
|
| 1481 | - return $root->getUserFolder($userId); |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - /** |
|
| 1485 | - * @return \OC\User\Manager |
|
| 1486 | - * @deprecated 20.0.0 |
|
| 1487 | - */ |
|
| 1488 | - public function getUserManager() { |
|
| 1489 | - return $this->get(IUserManager::class); |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - /** |
|
| 1493 | - * @return \OC\Group\Manager |
|
| 1494 | - * @deprecated 20.0.0 |
|
| 1495 | - */ |
|
| 1496 | - public function getGroupManager() { |
|
| 1497 | - return $this->get(IGroupManager::class); |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - /** |
|
| 1501 | - * @return \OC\User\Session |
|
| 1502 | - * @deprecated 20.0.0 |
|
| 1503 | - */ |
|
| 1504 | - public function getUserSession() { |
|
| 1505 | - return $this->get(IUserSession::class); |
|
| 1506 | - } |
|
| 1507 | - |
|
| 1508 | - /** |
|
| 1509 | - * @return \OCP\ISession |
|
| 1510 | - * @deprecated 20.0.0 |
|
| 1511 | - */ |
|
| 1512 | - public function getSession() { |
|
| 1513 | - return $this->get(Session::class)->getSession(); |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - /** |
|
| 1517 | - * @param \OCP\ISession $session |
|
| 1518 | - * @return void |
|
| 1519 | - */ |
|
| 1520 | - public function setSession(\OCP\ISession $session) { |
|
| 1521 | - $this->get(SessionStorage::class)->setSession($session); |
|
| 1522 | - $this->get(Session::class)->setSession($session); |
|
| 1523 | - $this->get(Store::class)->setSession($session); |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - /** |
|
| 1527 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1528 | - * @deprecated 20.0.0 |
|
| 1529 | - */ |
|
| 1530 | - public function getTwoFactorAuthManager() { |
|
| 1531 | - return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1532 | - } |
|
| 1533 | - |
|
| 1534 | - /** |
|
| 1535 | - * @return \OC\NavigationManager |
|
| 1536 | - * @deprecated 20.0.0 |
|
| 1537 | - */ |
|
| 1538 | - public function getNavigationManager() { |
|
| 1539 | - return $this->get(INavigationManager::class); |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - /** |
|
| 1543 | - * @return \OCP\IConfig |
|
| 1544 | - * @deprecated 20.0.0 |
|
| 1545 | - */ |
|
| 1546 | - public function getConfig() { |
|
| 1547 | - return $this->get(AllConfig::class); |
|
| 1548 | - } |
|
| 1549 | - |
|
| 1550 | - /** |
|
| 1551 | - * @return \OC\SystemConfig |
|
| 1552 | - * @deprecated 20.0.0 |
|
| 1553 | - */ |
|
| 1554 | - public function getSystemConfig() { |
|
| 1555 | - return $this->get(SystemConfig::class); |
|
| 1556 | - } |
|
| 1557 | - |
|
| 1558 | - /** |
|
| 1559 | - * Returns the app config manager |
|
| 1560 | - * |
|
| 1561 | - * @return IAppConfig |
|
| 1562 | - * @deprecated 20.0.0 |
|
| 1563 | - */ |
|
| 1564 | - public function getAppConfig() { |
|
| 1565 | - return $this->get(IAppConfig::class); |
|
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * @return IFactory |
|
| 1570 | - * @deprecated 20.0.0 |
|
| 1571 | - */ |
|
| 1572 | - public function getL10NFactory() { |
|
| 1573 | - return $this->get(IFactory::class); |
|
| 1574 | - } |
|
| 1575 | - |
|
| 1576 | - /** |
|
| 1577 | - * get an L10N instance |
|
| 1578 | - * |
|
| 1579 | - * @param string $app appid |
|
| 1580 | - * @param string $lang |
|
| 1581 | - * @return IL10N |
|
| 1582 | - * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1583 | - */ |
|
| 1584 | - public function getL10N($app, $lang = null) { |
|
| 1585 | - return $this->get(IFactory::class)->get($app, $lang); |
|
| 1586 | - } |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * @return IURLGenerator |
|
| 1590 | - * @deprecated 20.0.0 |
|
| 1591 | - */ |
|
| 1592 | - public function getURLGenerator() { |
|
| 1593 | - return $this->get(IURLGenerator::class); |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * @return AppFetcher |
|
| 1598 | - * @deprecated 20.0.0 |
|
| 1599 | - */ |
|
| 1600 | - public function getAppFetcher() { |
|
| 1601 | - return $this->get(AppFetcher::class); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1606 | - * getMemCacheFactory() instead. |
|
| 1607 | - * |
|
| 1608 | - * @return ICache |
|
| 1609 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1610 | - */ |
|
| 1611 | - public function getCache() { |
|
| 1612 | - return $this->get(ICache::class); |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - /** |
|
| 1616 | - * Returns an \OCP\CacheFactory instance |
|
| 1617 | - * |
|
| 1618 | - * @return \OCP\ICacheFactory |
|
| 1619 | - * @deprecated 20.0.0 |
|
| 1620 | - */ |
|
| 1621 | - public function getMemCacheFactory() { |
|
| 1622 | - return $this->get(ICacheFactory::class); |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - /** |
|
| 1626 | - * Returns an \OC\RedisFactory instance |
|
| 1627 | - * |
|
| 1628 | - * @return \OC\RedisFactory |
|
| 1629 | - * @deprecated 20.0.0 |
|
| 1630 | - */ |
|
| 1631 | - public function getGetRedisFactory() { |
|
| 1632 | - return $this->get('RedisFactory'); |
|
| 1633 | - } |
|
| 1634 | - |
|
| 1635 | - |
|
| 1636 | - /** |
|
| 1637 | - * Returns the current session |
|
| 1638 | - * |
|
| 1639 | - * @return \OCP\IDBConnection |
|
| 1640 | - * @deprecated 20.0.0 |
|
| 1641 | - */ |
|
| 1642 | - public function getDatabaseConnection() { |
|
| 1643 | - return $this->get(IDBConnection::class); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - /** |
|
| 1647 | - * Returns the activity manager |
|
| 1648 | - * |
|
| 1649 | - * @return \OCP\Activity\IManager |
|
| 1650 | - * @deprecated 20.0.0 |
|
| 1651 | - */ |
|
| 1652 | - public function getActivityManager() { |
|
| 1653 | - return $this->get(\OCP\Activity\IManager::class); |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - /** |
|
| 1657 | - * Returns an job list for controlling background jobs |
|
| 1658 | - * |
|
| 1659 | - * @return IJobList |
|
| 1660 | - * @deprecated 20.0.0 |
|
| 1661 | - */ |
|
| 1662 | - public function getJobList() { |
|
| 1663 | - return $this->get(IJobList::class); |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * @return ILogFactory |
|
| 1668 | - * @throws \OCP\AppFramework\QueryException |
|
| 1669 | - * @deprecated 20.0.0 |
|
| 1670 | - */ |
|
| 1671 | - public function getLogFactory() { |
|
| 1672 | - return $this->get(ILogFactory::class); |
|
| 1673 | - } |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * Returns a router for generating and matching urls |
|
| 1677 | - * |
|
| 1678 | - * @return IRouter |
|
| 1679 | - * @deprecated 20.0.0 |
|
| 1680 | - */ |
|
| 1681 | - public function getRouter() { |
|
| 1682 | - return $this->get(IRouter::class); |
|
| 1683 | - } |
|
| 1684 | - |
|
| 1685 | - /** |
|
| 1686 | - * Returns a SecureRandom instance |
|
| 1687 | - * |
|
| 1688 | - * @return \OCP\Security\ISecureRandom |
|
| 1689 | - * @deprecated 20.0.0 |
|
| 1690 | - */ |
|
| 1691 | - public function getSecureRandom() { |
|
| 1692 | - return $this->get(ISecureRandom::class); |
|
| 1693 | - } |
|
| 1694 | - |
|
| 1695 | - /** |
|
| 1696 | - * Returns a Crypto instance |
|
| 1697 | - * |
|
| 1698 | - * @return ICrypto |
|
| 1699 | - * @deprecated 20.0.0 |
|
| 1700 | - */ |
|
| 1701 | - public function getCrypto() { |
|
| 1702 | - return $this->get(ICrypto::class); |
|
| 1703 | - } |
|
| 1704 | - |
|
| 1705 | - /** |
|
| 1706 | - * Returns a Hasher instance |
|
| 1707 | - * |
|
| 1708 | - * @return IHasher |
|
| 1709 | - * @deprecated 20.0.0 |
|
| 1710 | - */ |
|
| 1711 | - public function getHasher() { |
|
| 1712 | - return $this->get(IHasher::class); |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - /** |
|
| 1716 | - * Returns a CredentialsManager instance |
|
| 1717 | - * |
|
| 1718 | - * @return ICredentialsManager |
|
| 1719 | - * @deprecated 20.0.0 |
|
| 1720 | - */ |
|
| 1721 | - public function getCredentialsManager() { |
|
| 1722 | - return $this->get(ICredentialsManager::class); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - /** |
|
| 1726 | - * Get the certificate manager |
|
| 1727 | - * |
|
| 1728 | - * @return \OCP\ICertificateManager |
|
| 1729 | - */ |
|
| 1730 | - public function getCertificateManager() { |
|
| 1731 | - return $this->get(ICertificateManager::class); |
|
| 1732 | - } |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * Returns an instance of the HTTP client service |
|
| 1736 | - * |
|
| 1737 | - * @return IClientService |
|
| 1738 | - * @deprecated 20.0.0 |
|
| 1739 | - */ |
|
| 1740 | - public function getHTTPClientService() { |
|
| 1741 | - return $this->get(IClientService::class); |
|
| 1742 | - } |
|
| 1743 | - |
|
| 1744 | - /** |
|
| 1745 | - * Get the active event logger |
|
| 1746 | - * |
|
| 1747 | - * The returned logger only logs data when debug mode is enabled |
|
| 1748 | - * |
|
| 1749 | - * @return IEventLogger |
|
| 1750 | - * @deprecated 20.0.0 |
|
| 1751 | - */ |
|
| 1752 | - public function getEventLogger() { |
|
| 1753 | - return $this->get(IEventLogger::class); |
|
| 1754 | - } |
|
| 1755 | - |
|
| 1756 | - /** |
|
| 1757 | - * Get the active query logger |
|
| 1758 | - * |
|
| 1759 | - * The returned logger only logs data when debug mode is enabled |
|
| 1760 | - * |
|
| 1761 | - * @return IQueryLogger |
|
| 1762 | - * @deprecated 20.0.0 |
|
| 1763 | - */ |
|
| 1764 | - public function getQueryLogger() { |
|
| 1765 | - return $this->get(IQueryLogger::class); |
|
| 1766 | - } |
|
| 1767 | - |
|
| 1768 | - /** |
|
| 1769 | - * Get the manager for temporary files and folders |
|
| 1770 | - * |
|
| 1771 | - * @return \OCP\ITempManager |
|
| 1772 | - * @deprecated 20.0.0 |
|
| 1773 | - */ |
|
| 1774 | - public function getTempManager() { |
|
| 1775 | - return $this->get(ITempManager::class); |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - /** |
|
| 1779 | - * Get the app manager |
|
| 1780 | - * |
|
| 1781 | - * @return \OCP\App\IAppManager |
|
| 1782 | - * @deprecated 20.0.0 |
|
| 1783 | - */ |
|
| 1784 | - public function getAppManager() { |
|
| 1785 | - return $this->get(IAppManager::class); |
|
| 1786 | - } |
|
| 1787 | - |
|
| 1788 | - /** |
|
| 1789 | - * Creates a new mailer |
|
| 1790 | - * |
|
| 1791 | - * @return IMailer |
|
| 1792 | - * @deprecated 20.0.0 |
|
| 1793 | - */ |
|
| 1794 | - public function getMailer() { |
|
| 1795 | - return $this->get(IMailer::class); |
|
| 1796 | - } |
|
| 1797 | - |
|
| 1798 | - /** |
|
| 1799 | - * Get the webroot |
|
| 1800 | - * |
|
| 1801 | - * @return string |
|
| 1802 | - * @deprecated 20.0.0 |
|
| 1803 | - */ |
|
| 1804 | - public function getWebRoot() { |
|
| 1805 | - return $this->webRoot; |
|
| 1806 | - } |
|
| 1807 | - |
|
| 1808 | - /** |
|
| 1809 | - * @return \OC\OCSClient |
|
| 1810 | - * @deprecated 20.0.0 |
|
| 1811 | - */ |
|
| 1812 | - public function getOcsClient() { |
|
| 1813 | - return $this->get('OcsClient'); |
|
| 1814 | - } |
|
| 1815 | - |
|
| 1816 | - /** |
|
| 1817 | - * @return IDateTimeZone |
|
| 1818 | - * @deprecated 20.0.0 |
|
| 1819 | - */ |
|
| 1820 | - public function getDateTimeZone() { |
|
| 1821 | - return $this->get(IDateTimeZone::class); |
|
| 1822 | - } |
|
| 1823 | - |
|
| 1824 | - /** |
|
| 1825 | - * @return IDateTimeFormatter |
|
| 1826 | - * @deprecated 20.0.0 |
|
| 1827 | - */ |
|
| 1828 | - public function getDateTimeFormatter() { |
|
| 1829 | - return $this->get(IDateTimeFormatter::class); |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - /** |
|
| 1833 | - * @return IMountProviderCollection |
|
| 1834 | - * @deprecated 20.0.0 |
|
| 1835 | - */ |
|
| 1836 | - public function getMountProviderCollection() { |
|
| 1837 | - return $this->get(IMountProviderCollection::class); |
|
| 1838 | - } |
|
| 1839 | - |
|
| 1840 | - /** |
|
| 1841 | - * Get the IniWrapper |
|
| 1842 | - * |
|
| 1843 | - * @return IniGetWrapper |
|
| 1844 | - * @deprecated 20.0.0 |
|
| 1845 | - */ |
|
| 1846 | - public function getIniWrapper() { |
|
| 1847 | - return $this->get(IniGetWrapper::class); |
|
| 1848 | - } |
|
| 1849 | - |
|
| 1850 | - /** |
|
| 1851 | - * @return \OCP\Command\IBus |
|
| 1852 | - * @deprecated 20.0.0 |
|
| 1853 | - */ |
|
| 1854 | - public function getCommandBus() { |
|
| 1855 | - return $this->get(IBus::class); |
|
| 1856 | - } |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * Get the trusted domain helper |
|
| 1860 | - * |
|
| 1861 | - * @return TrustedDomainHelper |
|
| 1862 | - * @deprecated 20.0.0 |
|
| 1863 | - */ |
|
| 1864 | - public function getTrustedDomainHelper() { |
|
| 1865 | - return $this->get(TrustedDomainHelper::class); |
|
| 1866 | - } |
|
| 1867 | - |
|
| 1868 | - /** |
|
| 1869 | - * Get the locking provider |
|
| 1870 | - * |
|
| 1871 | - * @return ILockingProvider |
|
| 1872 | - * @since 8.1.0 |
|
| 1873 | - * @deprecated 20.0.0 |
|
| 1874 | - */ |
|
| 1875 | - public function getLockingProvider() { |
|
| 1876 | - return $this->get(ILockingProvider::class); |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * @return IMountManager |
|
| 1881 | - * @deprecated 20.0.0 |
|
| 1882 | - **/ |
|
| 1883 | - public function getMountManager() { |
|
| 1884 | - return $this->get(IMountManager::class); |
|
| 1885 | - } |
|
| 1886 | - |
|
| 1887 | - /** |
|
| 1888 | - * @return IUserMountCache |
|
| 1889 | - * @deprecated 20.0.0 |
|
| 1890 | - */ |
|
| 1891 | - public function getUserMountCache() { |
|
| 1892 | - return $this->get(IUserMountCache::class); |
|
| 1893 | - } |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Get the MimeTypeDetector |
|
| 1897 | - * |
|
| 1898 | - * @return IMimeTypeDetector |
|
| 1899 | - * @deprecated 20.0.0 |
|
| 1900 | - */ |
|
| 1901 | - public function getMimeTypeDetector() { |
|
| 1902 | - return $this->get(IMimeTypeDetector::class); |
|
| 1903 | - } |
|
| 1904 | - |
|
| 1905 | - /** |
|
| 1906 | - * Get the MimeTypeLoader |
|
| 1907 | - * |
|
| 1908 | - * @return IMimeTypeLoader |
|
| 1909 | - * @deprecated 20.0.0 |
|
| 1910 | - */ |
|
| 1911 | - public function getMimeTypeLoader() { |
|
| 1912 | - return $this->get(IMimeTypeLoader::class); |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - /** |
|
| 1916 | - * Get the manager of all the capabilities |
|
| 1917 | - * |
|
| 1918 | - * @return CapabilitiesManager |
|
| 1919 | - * @deprecated 20.0.0 |
|
| 1920 | - */ |
|
| 1921 | - public function getCapabilitiesManager() { |
|
| 1922 | - return $this->get(CapabilitiesManager::class); |
|
| 1923 | - } |
|
| 1924 | - |
|
| 1925 | - /** |
|
| 1926 | - * Get the Notification Manager |
|
| 1927 | - * |
|
| 1928 | - * @return \OCP\Notification\IManager |
|
| 1929 | - * @since 8.2.0 |
|
| 1930 | - * @deprecated 20.0.0 |
|
| 1931 | - */ |
|
| 1932 | - public function getNotificationManager() { |
|
| 1933 | - return $this->get(\OCP\Notification\IManager::class); |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - /** |
|
| 1937 | - * @return ICommentsManager |
|
| 1938 | - * @deprecated 20.0.0 |
|
| 1939 | - */ |
|
| 1940 | - public function getCommentsManager() { |
|
| 1941 | - return $this->get(ICommentsManager::class); |
|
| 1942 | - } |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1946 | - * @deprecated 20.0.0 |
|
| 1947 | - */ |
|
| 1948 | - public function getThemingDefaults() { |
|
| 1949 | - return $this->get('ThemingDefaults'); |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * @return \OC\IntegrityCheck\Checker |
|
| 1954 | - * @deprecated 20.0.0 |
|
| 1955 | - */ |
|
| 1956 | - public function getIntegrityCodeChecker() { |
|
| 1957 | - return $this->get('IntegrityCodeChecker'); |
|
| 1958 | - } |
|
| 1959 | - |
|
| 1960 | - /** |
|
| 1961 | - * @return \OC\Session\CryptoWrapper |
|
| 1962 | - * @deprecated 20.0.0 |
|
| 1963 | - */ |
|
| 1964 | - public function getSessionCryptoWrapper() { |
|
| 1965 | - return $this->get('CryptoWrapper'); |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - /** |
|
| 1969 | - * @return CsrfTokenManager |
|
| 1970 | - * @deprecated 20.0.0 |
|
| 1971 | - */ |
|
| 1972 | - public function getCsrfTokenManager() { |
|
| 1973 | - return $this->get(CsrfTokenManager::class); |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * @return IThrottler |
|
| 1978 | - * @deprecated 20.0.0 |
|
| 1979 | - */ |
|
| 1980 | - public function getBruteForceThrottler() { |
|
| 1981 | - return $this->get(Throttler::class); |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - /** |
|
| 1985 | - * @return IContentSecurityPolicyManager |
|
| 1986 | - * @deprecated 20.0.0 |
|
| 1987 | - */ |
|
| 1988 | - public function getContentSecurityPolicyManager() { |
|
| 1989 | - return $this->get(ContentSecurityPolicyManager::class); |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * @return ContentSecurityPolicyNonceManager |
|
| 1994 | - * @deprecated 20.0.0 |
|
| 1995 | - */ |
|
| 1996 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1997 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1998 | - } |
|
| 1999 | - |
|
| 2000 | - /** |
|
| 2001 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2002 | - * |
|
| 2003 | - * @return \OCA\Files_External\Service\BackendService |
|
| 2004 | - * @deprecated 20.0.0 |
|
| 2005 | - */ |
|
| 2006 | - public function getStoragesBackendService() { |
|
| 2007 | - return $this->get(BackendService::class); |
|
| 2008 | - } |
|
| 2009 | - |
|
| 2010 | - /** |
|
| 2011 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2012 | - * |
|
| 2013 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2014 | - * @deprecated 20.0.0 |
|
| 2015 | - */ |
|
| 2016 | - public function getGlobalStoragesService() { |
|
| 2017 | - return $this->get(GlobalStoragesService::class); |
|
| 2018 | - } |
|
| 2019 | - |
|
| 2020 | - /** |
|
| 2021 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2022 | - * |
|
| 2023 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2024 | - * @deprecated 20.0.0 |
|
| 2025 | - */ |
|
| 2026 | - public function getUserGlobalStoragesService() { |
|
| 2027 | - return $this->get(UserGlobalStoragesService::class); |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2032 | - * |
|
| 2033 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2034 | - * @deprecated 20.0.0 |
|
| 2035 | - */ |
|
| 2036 | - public function getUserStoragesService() { |
|
| 2037 | - return $this->get(UserStoragesService::class); |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - /** |
|
| 2041 | - * @return \OCP\Share\IManager |
|
| 2042 | - * @deprecated 20.0.0 |
|
| 2043 | - */ |
|
| 2044 | - public function getShareManager() { |
|
| 2045 | - return $this->get(\OCP\Share\IManager::class); |
|
| 2046 | - } |
|
| 2047 | - |
|
| 2048 | - /** |
|
| 2049 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2050 | - * @deprecated 20.0.0 |
|
| 2051 | - */ |
|
| 2052 | - public function getCollaboratorSearch() { |
|
| 2053 | - return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2054 | - } |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2058 | - * @deprecated 20.0.0 |
|
| 2059 | - */ |
|
| 2060 | - public function getAutoCompleteManager() { |
|
| 2061 | - return $this->get(IManager::class); |
|
| 2062 | - } |
|
| 2063 | - |
|
| 2064 | - /** |
|
| 2065 | - * Returns the LDAP Provider |
|
| 2066 | - * |
|
| 2067 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 2068 | - * @deprecated 20.0.0 |
|
| 2069 | - */ |
|
| 2070 | - public function getLDAPProvider() { |
|
| 2071 | - return $this->get('LDAPProvider'); |
|
| 2072 | - } |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * @return \OCP\Settings\IManager |
|
| 2076 | - * @deprecated 20.0.0 |
|
| 2077 | - */ |
|
| 2078 | - public function getSettingsManager() { |
|
| 2079 | - return $this->get(\OC\Settings\Manager::class); |
|
| 2080 | - } |
|
| 2081 | - |
|
| 2082 | - /** |
|
| 2083 | - * @return \OCP\Files\IAppData |
|
| 2084 | - * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 2085 | - */ |
|
| 2086 | - public function getAppDataDir($app) { |
|
| 2087 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2088 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 2089 | - return $factory->get($app); |
|
| 2090 | - } |
|
| 2091 | - |
|
| 2092 | - /** |
|
| 2093 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 2094 | - * @deprecated 20.0.0 |
|
| 2095 | - */ |
|
| 2096 | - public function getLockdownManager() { |
|
| 2097 | - return $this->get('LockdownManager'); |
|
| 2098 | - } |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * @return \OCP\Federation\ICloudIdManager |
|
| 2102 | - * @deprecated 20.0.0 |
|
| 2103 | - */ |
|
| 2104 | - public function getCloudIdManager() { |
|
| 2105 | - return $this->get(ICloudIdManager::class); |
|
| 2106 | - } |
|
| 2107 | - |
|
| 2108 | - /** |
|
| 2109 | - * @return \OCP\GlobalScale\IConfig |
|
| 2110 | - * @deprecated 20.0.0 |
|
| 2111 | - */ |
|
| 2112 | - public function getGlobalScaleConfig() { |
|
| 2113 | - return $this->get(IConfig::class); |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - /** |
|
| 2117 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2118 | - * @deprecated 20.0.0 |
|
| 2119 | - */ |
|
| 2120 | - public function getCloudFederationProviderManager() { |
|
| 2121 | - return $this->get(ICloudFederationProviderManager::class); |
|
| 2122 | - } |
|
| 2123 | - |
|
| 2124 | - /** |
|
| 2125 | - * @return \OCP\Remote\Api\IApiFactory |
|
| 2126 | - * @deprecated 20.0.0 |
|
| 2127 | - */ |
|
| 2128 | - public function getRemoteApiFactory() { |
|
| 2129 | - return $this->get(IApiFactory::class); |
|
| 2130 | - } |
|
| 2131 | - |
|
| 2132 | - /** |
|
| 2133 | - * @return \OCP\Federation\ICloudFederationFactory |
|
| 2134 | - * @deprecated 20.0.0 |
|
| 2135 | - */ |
|
| 2136 | - public function getCloudFederationFactory() { |
|
| 2137 | - return $this->get(ICloudFederationFactory::class); |
|
| 2138 | - } |
|
| 2139 | - |
|
| 2140 | - /** |
|
| 2141 | - * @return \OCP\Remote\IInstanceFactory |
|
| 2142 | - * @deprecated 20.0.0 |
|
| 2143 | - */ |
|
| 2144 | - public function getRemoteInstanceFactory() { |
|
| 2145 | - return $this->get(IInstanceFactory::class); |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - /** |
|
| 2149 | - * @return IStorageFactory |
|
| 2150 | - * @deprecated 20.0.0 |
|
| 2151 | - */ |
|
| 2152 | - public function getStorageFactory() { |
|
| 2153 | - return $this->get(IStorageFactory::class); |
|
| 2154 | - } |
|
| 2155 | - |
|
| 2156 | - /** |
|
| 2157 | - * Get the Preview GeneratorHelper |
|
| 2158 | - * |
|
| 2159 | - * @return GeneratorHelper |
|
| 2160 | - * @since 17.0.0 |
|
| 2161 | - * @deprecated 20.0.0 |
|
| 2162 | - */ |
|
| 2163 | - public function getGeneratorHelper() { |
|
| 2164 | - return $this->get(\OC\Preview\GeneratorHelper::class); |
|
| 2165 | - } |
|
| 2166 | - |
|
| 2167 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2168 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2169 | - try { |
|
| 2170 | - /** @var LoggerInterface $logger */ |
|
| 2171 | - $logger = $container->get(LoggerInterface::class); |
|
| 2172 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2173 | - } catch (ContainerExceptionInterface $e) { |
|
| 2174 | - // Could not get logger. Continue |
|
| 2175 | - } |
|
| 2176 | - |
|
| 2177 | - return $container->get($target); |
|
| 2178 | - }, false); |
|
| 2179 | - } |
|
| 1302 | + public function boot() { |
|
| 1303 | + /** @var HookConnector $hookConnector */ |
|
| 1304 | + $hookConnector = $this->get(HookConnector::class); |
|
| 1305 | + $hookConnector->viewToNode(); |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + /** |
|
| 1309 | + * @return \OCP\Calendar\IManager |
|
| 1310 | + * @deprecated 20.0.0 |
|
| 1311 | + */ |
|
| 1312 | + public function getCalendarManager() { |
|
| 1313 | + return $this->get(\OC\Calendar\Manager::class); |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * @return \OCP\Calendar\Resource\IManager |
|
| 1318 | + * @deprecated 20.0.0 |
|
| 1319 | + */ |
|
| 1320 | + public function getCalendarResourceBackendManager() { |
|
| 1321 | + return $this->get(\OC\Calendar\Resource\Manager::class); |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + /** |
|
| 1325 | + * @return \OCP\Calendar\Room\IManager |
|
| 1326 | + * @deprecated 20.0.0 |
|
| 1327 | + */ |
|
| 1328 | + public function getCalendarRoomBackendManager() { |
|
| 1329 | + return $this->get(\OC\Calendar\Room\Manager::class); |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + private function connectDispatcher(): void { |
|
| 1333 | + /** @var IEventDispatcher $eventDispatcher */ |
|
| 1334 | + $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1335 | + $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1336 | + $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1337 | + $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1338 | + $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1339 | + |
|
| 1340 | + FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1341 | + GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1342 | + } |
|
| 1343 | + |
|
| 1344 | + /** |
|
| 1345 | + * @return \OCP\Contacts\IManager |
|
| 1346 | + * @deprecated 20.0.0 |
|
| 1347 | + */ |
|
| 1348 | + public function getContactsManager() { |
|
| 1349 | + return $this->get(\OCP\Contacts\IManager::class); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * @return \OC\Encryption\Manager |
|
| 1354 | + * @deprecated 20.0.0 |
|
| 1355 | + */ |
|
| 1356 | + public function getEncryptionManager() { |
|
| 1357 | + return $this->get(\OCP\Encryption\IManager::class); |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + /** |
|
| 1361 | + * @return \OC\Encryption\File |
|
| 1362 | + * @deprecated 20.0.0 |
|
| 1363 | + */ |
|
| 1364 | + public function getEncryptionFilesHelper() { |
|
| 1365 | + return $this->get(IFile::class); |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1370 | + * @deprecated 20.0.0 |
|
| 1371 | + */ |
|
| 1372 | + public function getEncryptionKeyStorage() { |
|
| 1373 | + return $this->get(IStorage::class); |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * The current request object holding all information about the request |
|
| 1378 | + * currently being processed is returned from this method. |
|
| 1379 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1380 | + * |
|
| 1381 | + * @return \OCP\IRequest |
|
| 1382 | + * @deprecated 20.0.0 |
|
| 1383 | + */ |
|
| 1384 | + public function getRequest() { |
|
| 1385 | + return $this->get(IRequest::class); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * Returns the preview manager which can create preview images for a given file |
|
| 1390 | + * |
|
| 1391 | + * @return IPreview |
|
| 1392 | + * @deprecated 20.0.0 |
|
| 1393 | + */ |
|
| 1394 | + public function getPreviewManager() { |
|
| 1395 | + return $this->get(IPreview::class); |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + /** |
|
| 1399 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1400 | + * |
|
| 1401 | + * @see \OCP\ITagManager::load() |
|
| 1402 | + * @return ITagManager |
|
| 1403 | + * @deprecated 20.0.0 |
|
| 1404 | + */ |
|
| 1405 | + public function getTagManager() { |
|
| 1406 | + return $this->get(ITagManager::class); |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + /** |
|
| 1410 | + * Returns the system-tag manager |
|
| 1411 | + * |
|
| 1412 | + * @return ISystemTagManager |
|
| 1413 | + * |
|
| 1414 | + * @since 9.0.0 |
|
| 1415 | + * @deprecated 20.0.0 |
|
| 1416 | + */ |
|
| 1417 | + public function getSystemTagManager() { |
|
| 1418 | + return $this->get(ISystemTagManager::class); |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * Returns the system-tag object mapper |
|
| 1423 | + * |
|
| 1424 | + * @return ISystemTagObjectMapper |
|
| 1425 | + * |
|
| 1426 | + * @since 9.0.0 |
|
| 1427 | + * @deprecated 20.0.0 |
|
| 1428 | + */ |
|
| 1429 | + public function getSystemTagObjectMapper() { |
|
| 1430 | + return $this->get(ISystemTagObjectMapper::class); |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + /** |
|
| 1434 | + * Returns the avatar manager, used for avatar functionality |
|
| 1435 | + * |
|
| 1436 | + * @return IAvatarManager |
|
| 1437 | + * @deprecated 20.0.0 |
|
| 1438 | + */ |
|
| 1439 | + public function getAvatarManager() { |
|
| 1440 | + return $this->get(IAvatarManager::class); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + /** |
|
| 1444 | + * Returns the root folder of ownCloud's data directory |
|
| 1445 | + * |
|
| 1446 | + * @return IRootFolder |
|
| 1447 | + * @deprecated 20.0.0 |
|
| 1448 | + */ |
|
| 1449 | + public function getRootFolder() { |
|
| 1450 | + return $this->get(IRootFolder::class); |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * Returns the root folder of ownCloud's data directory |
|
| 1455 | + * This is the lazy variant so this gets only initialized once it |
|
| 1456 | + * is actually used. |
|
| 1457 | + * |
|
| 1458 | + * @return IRootFolder |
|
| 1459 | + * @deprecated 20.0.0 |
|
| 1460 | + */ |
|
| 1461 | + public function getLazyRootFolder() { |
|
| 1462 | + return $this->get(IRootFolder::class); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + /** |
|
| 1466 | + * Returns a view to ownCloud's files folder |
|
| 1467 | + * |
|
| 1468 | + * @param string $userId user ID |
|
| 1469 | + * @return \OCP\Files\Folder|null |
|
| 1470 | + * @deprecated 20.0.0 |
|
| 1471 | + */ |
|
| 1472 | + public function getUserFolder($userId = null) { |
|
| 1473 | + if ($userId === null) { |
|
| 1474 | + $user = $this->get(IUserSession::class)->getUser(); |
|
| 1475 | + if (!$user) { |
|
| 1476 | + return null; |
|
| 1477 | + } |
|
| 1478 | + $userId = $user->getUID(); |
|
| 1479 | + } |
|
| 1480 | + $root = $this->get(IRootFolder::class); |
|
| 1481 | + return $root->getUserFolder($userId); |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + /** |
|
| 1485 | + * @return \OC\User\Manager |
|
| 1486 | + * @deprecated 20.0.0 |
|
| 1487 | + */ |
|
| 1488 | + public function getUserManager() { |
|
| 1489 | + return $this->get(IUserManager::class); |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + /** |
|
| 1493 | + * @return \OC\Group\Manager |
|
| 1494 | + * @deprecated 20.0.0 |
|
| 1495 | + */ |
|
| 1496 | + public function getGroupManager() { |
|
| 1497 | + return $this->get(IGroupManager::class); |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * @return \OC\User\Session |
|
| 1502 | + * @deprecated 20.0.0 |
|
| 1503 | + */ |
|
| 1504 | + public function getUserSession() { |
|
| 1505 | + return $this->get(IUserSession::class); |
|
| 1506 | + } |
|
| 1507 | + |
|
| 1508 | + /** |
|
| 1509 | + * @return \OCP\ISession |
|
| 1510 | + * @deprecated 20.0.0 |
|
| 1511 | + */ |
|
| 1512 | + public function getSession() { |
|
| 1513 | + return $this->get(Session::class)->getSession(); |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + /** |
|
| 1517 | + * @param \OCP\ISession $session |
|
| 1518 | + * @return void |
|
| 1519 | + */ |
|
| 1520 | + public function setSession(\OCP\ISession $session) { |
|
| 1521 | + $this->get(SessionStorage::class)->setSession($session); |
|
| 1522 | + $this->get(Session::class)->setSession($session); |
|
| 1523 | + $this->get(Store::class)->setSession($session); |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + /** |
|
| 1527 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1528 | + * @deprecated 20.0.0 |
|
| 1529 | + */ |
|
| 1530 | + public function getTwoFactorAuthManager() { |
|
| 1531 | + return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1532 | + } |
|
| 1533 | + |
|
| 1534 | + /** |
|
| 1535 | + * @return \OC\NavigationManager |
|
| 1536 | + * @deprecated 20.0.0 |
|
| 1537 | + */ |
|
| 1538 | + public function getNavigationManager() { |
|
| 1539 | + return $this->get(INavigationManager::class); |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + /** |
|
| 1543 | + * @return \OCP\IConfig |
|
| 1544 | + * @deprecated 20.0.0 |
|
| 1545 | + */ |
|
| 1546 | + public function getConfig() { |
|
| 1547 | + return $this->get(AllConfig::class); |
|
| 1548 | + } |
|
| 1549 | + |
|
| 1550 | + /** |
|
| 1551 | + * @return \OC\SystemConfig |
|
| 1552 | + * @deprecated 20.0.0 |
|
| 1553 | + */ |
|
| 1554 | + public function getSystemConfig() { |
|
| 1555 | + return $this->get(SystemConfig::class); |
|
| 1556 | + } |
|
| 1557 | + |
|
| 1558 | + /** |
|
| 1559 | + * Returns the app config manager |
|
| 1560 | + * |
|
| 1561 | + * @return IAppConfig |
|
| 1562 | + * @deprecated 20.0.0 |
|
| 1563 | + */ |
|
| 1564 | + public function getAppConfig() { |
|
| 1565 | + return $this->get(IAppConfig::class); |
|
| 1566 | + } |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * @return IFactory |
|
| 1570 | + * @deprecated 20.0.0 |
|
| 1571 | + */ |
|
| 1572 | + public function getL10NFactory() { |
|
| 1573 | + return $this->get(IFactory::class); |
|
| 1574 | + } |
|
| 1575 | + |
|
| 1576 | + /** |
|
| 1577 | + * get an L10N instance |
|
| 1578 | + * |
|
| 1579 | + * @param string $app appid |
|
| 1580 | + * @param string $lang |
|
| 1581 | + * @return IL10N |
|
| 1582 | + * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1583 | + */ |
|
| 1584 | + public function getL10N($app, $lang = null) { |
|
| 1585 | + return $this->get(IFactory::class)->get($app, $lang); |
|
| 1586 | + } |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * @return IURLGenerator |
|
| 1590 | + * @deprecated 20.0.0 |
|
| 1591 | + */ |
|
| 1592 | + public function getURLGenerator() { |
|
| 1593 | + return $this->get(IURLGenerator::class); |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * @return AppFetcher |
|
| 1598 | + * @deprecated 20.0.0 |
|
| 1599 | + */ |
|
| 1600 | + public function getAppFetcher() { |
|
| 1601 | + return $this->get(AppFetcher::class); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1606 | + * getMemCacheFactory() instead. |
|
| 1607 | + * |
|
| 1608 | + * @return ICache |
|
| 1609 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1610 | + */ |
|
| 1611 | + public function getCache() { |
|
| 1612 | + return $this->get(ICache::class); |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + /** |
|
| 1616 | + * Returns an \OCP\CacheFactory instance |
|
| 1617 | + * |
|
| 1618 | + * @return \OCP\ICacheFactory |
|
| 1619 | + * @deprecated 20.0.0 |
|
| 1620 | + */ |
|
| 1621 | + public function getMemCacheFactory() { |
|
| 1622 | + return $this->get(ICacheFactory::class); |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + /** |
|
| 1626 | + * Returns an \OC\RedisFactory instance |
|
| 1627 | + * |
|
| 1628 | + * @return \OC\RedisFactory |
|
| 1629 | + * @deprecated 20.0.0 |
|
| 1630 | + */ |
|
| 1631 | + public function getGetRedisFactory() { |
|
| 1632 | + return $this->get('RedisFactory'); |
|
| 1633 | + } |
|
| 1634 | + |
|
| 1635 | + |
|
| 1636 | + /** |
|
| 1637 | + * Returns the current session |
|
| 1638 | + * |
|
| 1639 | + * @return \OCP\IDBConnection |
|
| 1640 | + * @deprecated 20.0.0 |
|
| 1641 | + */ |
|
| 1642 | + public function getDatabaseConnection() { |
|
| 1643 | + return $this->get(IDBConnection::class); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + /** |
|
| 1647 | + * Returns the activity manager |
|
| 1648 | + * |
|
| 1649 | + * @return \OCP\Activity\IManager |
|
| 1650 | + * @deprecated 20.0.0 |
|
| 1651 | + */ |
|
| 1652 | + public function getActivityManager() { |
|
| 1653 | + return $this->get(\OCP\Activity\IManager::class); |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + /** |
|
| 1657 | + * Returns an job list for controlling background jobs |
|
| 1658 | + * |
|
| 1659 | + * @return IJobList |
|
| 1660 | + * @deprecated 20.0.0 |
|
| 1661 | + */ |
|
| 1662 | + public function getJobList() { |
|
| 1663 | + return $this->get(IJobList::class); |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * @return ILogFactory |
|
| 1668 | + * @throws \OCP\AppFramework\QueryException |
|
| 1669 | + * @deprecated 20.0.0 |
|
| 1670 | + */ |
|
| 1671 | + public function getLogFactory() { |
|
| 1672 | + return $this->get(ILogFactory::class); |
|
| 1673 | + } |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * Returns a router for generating and matching urls |
|
| 1677 | + * |
|
| 1678 | + * @return IRouter |
|
| 1679 | + * @deprecated 20.0.0 |
|
| 1680 | + */ |
|
| 1681 | + public function getRouter() { |
|
| 1682 | + return $this->get(IRouter::class); |
|
| 1683 | + } |
|
| 1684 | + |
|
| 1685 | + /** |
|
| 1686 | + * Returns a SecureRandom instance |
|
| 1687 | + * |
|
| 1688 | + * @return \OCP\Security\ISecureRandom |
|
| 1689 | + * @deprecated 20.0.0 |
|
| 1690 | + */ |
|
| 1691 | + public function getSecureRandom() { |
|
| 1692 | + return $this->get(ISecureRandom::class); |
|
| 1693 | + } |
|
| 1694 | + |
|
| 1695 | + /** |
|
| 1696 | + * Returns a Crypto instance |
|
| 1697 | + * |
|
| 1698 | + * @return ICrypto |
|
| 1699 | + * @deprecated 20.0.0 |
|
| 1700 | + */ |
|
| 1701 | + public function getCrypto() { |
|
| 1702 | + return $this->get(ICrypto::class); |
|
| 1703 | + } |
|
| 1704 | + |
|
| 1705 | + /** |
|
| 1706 | + * Returns a Hasher instance |
|
| 1707 | + * |
|
| 1708 | + * @return IHasher |
|
| 1709 | + * @deprecated 20.0.0 |
|
| 1710 | + */ |
|
| 1711 | + public function getHasher() { |
|
| 1712 | + return $this->get(IHasher::class); |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + /** |
|
| 1716 | + * Returns a CredentialsManager instance |
|
| 1717 | + * |
|
| 1718 | + * @return ICredentialsManager |
|
| 1719 | + * @deprecated 20.0.0 |
|
| 1720 | + */ |
|
| 1721 | + public function getCredentialsManager() { |
|
| 1722 | + return $this->get(ICredentialsManager::class); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + /** |
|
| 1726 | + * Get the certificate manager |
|
| 1727 | + * |
|
| 1728 | + * @return \OCP\ICertificateManager |
|
| 1729 | + */ |
|
| 1730 | + public function getCertificateManager() { |
|
| 1731 | + return $this->get(ICertificateManager::class); |
|
| 1732 | + } |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * Returns an instance of the HTTP client service |
|
| 1736 | + * |
|
| 1737 | + * @return IClientService |
|
| 1738 | + * @deprecated 20.0.0 |
|
| 1739 | + */ |
|
| 1740 | + public function getHTTPClientService() { |
|
| 1741 | + return $this->get(IClientService::class); |
|
| 1742 | + } |
|
| 1743 | + |
|
| 1744 | + /** |
|
| 1745 | + * Get the active event logger |
|
| 1746 | + * |
|
| 1747 | + * The returned logger only logs data when debug mode is enabled |
|
| 1748 | + * |
|
| 1749 | + * @return IEventLogger |
|
| 1750 | + * @deprecated 20.0.0 |
|
| 1751 | + */ |
|
| 1752 | + public function getEventLogger() { |
|
| 1753 | + return $this->get(IEventLogger::class); |
|
| 1754 | + } |
|
| 1755 | + |
|
| 1756 | + /** |
|
| 1757 | + * Get the active query logger |
|
| 1758 | + * |
|
| 1759 | + * The returned logger only logs data when debug mode is enabled |
|
| 1760 | + * |
|
| 1761 | + * @return IQueryLogger |
|
| 1762 | + * @deprecated 20.0.0 |
|
| 1763 | + */ |
|
| 1764 | + public function getQueryLogger() { |
|
| 1765 | + return $this->get(IQueryLogger::class); |
|
| 1766 | + } |
|
| 1767 | + |
|
| 1768 | + /** |
|
| 1769 | + * Get the manager for temporary files and folders |
|
| 1770 | + * |
|
| 1771 | + * @return \OCP\ITempManager |
|
| 1772 | + * @deprecated 20.0.0 |
|
| 1773 | + */ |
|
| 1774 | + public function getTempManager() { |
|
| 1775 | + return $this->get(ITempManager::class); |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + /** |
|
| 1779 | + * Get the app manager |
|
| 1780 | + * |
|
| 1781 | + * @return \OCP\App\IAppManager |
|
| 1782 | + * @deprecated 20.0.0 |
|
| 1783 | + */ |
|
| 1784 | + public function getAppManager() { |
|
| 1785 | + return $this->get(IAppManager::class); |
|
| 1786 | + } |
|
| 1787 | + |
|
| 1788 | + /** |
|
| 1789 | + * Creates a new mailer |
|
| 1790 | + * |
|
| 1791 | + * @return IMailer |
|
| 1792 | + * @deprecated 20.0.0 |
|
| 1793 | + */ |
|
| 1794 | + public function getMailer() { |
|
| 1795 | + return $this->get(IMailer::class); |
|
| 1796 | + } |
|
| 1797 | + |
|
| 1798 | + /** |
|
| 1799 | + * Get the webroot |
|
| 1800 | + * |
|
| 1801 | + * @return string |
|
| 1802 | + * @deprecated 20.0.0 |
|
| 1803 | + */ |
|
| 1804 | + public function getWebRoot() { |
|
| 1805 | + return $this->webRoot; |
|
| 1806 | + } |
|
| 1807 | + |
|
| 1808 | + /** |
|
| 1809 | + * @return \OC\OCSClient |
|
| 1810 | + * @deprecated 20.0.0 |
|
| 1811 | + */ |
|
| 1812 | + public function getOcsClient() { |
|
| 1813 | + return $this->get('OcsClient'); |
|
| 1814 | + } |
|
| 1815 | + |
|
| 1816 | + /** |
|
| 1817 | + * @return IDateTimeZone |
|
| 1818 | + * @deprecated 20.0.0 |
|
| 1819 | + */ |
|
| 1820 | + public function getDateTimeZone() { |
|
| 1821 | + return $this->get(IDateTimeZone::class); |
|
| 1822 | + } |
|
| 1823 | + |
|
| 1824 | + /** |
|
| 1825 | + * @return IDateTimeFormatter |
|
| 1826 | + * @deprecated 20.0.0 |
|
| 1827 | + */ |
|
| 1828 | + public function getDateTimeFormatter() { |
|
| 1829 | + return $this->get(IDateTimeFormatter::class); |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + /** |
|
| 1833 | + * @return IMountProviderCollection |
|
| 1834 | + * @deprecated 20.0.0 |
|
| 1835 | + */ |
|
| 1836 | + public function getMountProviderCollection() { |
|
| 1837 | + return $this->get(IMountProviderCollection::class); |
|
| 1838 | + } |
|
| 1839 | + |
|
| 1840 | + /** |
|
| 1841 | + * Get the IniWrapper |
|
| 1842 | + * |
|
| 1843 | + * @return IniGetWrapper |
|
| 1844 | + * @deprecated 20.0.0 |
|
| 1845 | + */ |
|
| 1846 | + public function getIniWrapper() { |
|
| 1847 | + return $this->get(IniGetWrapper::class); |
|
| 1848 | + } |
|
| 1849 | + |
|
| 1850 | + /** |
|
| 1851 | + * @return \OCP\Command\IBus |
|
| 1852 | + * @deprecated 20.0.0 |
|
| 1853 | + */ |
|
| 1854 | + public function getCommandBus() { |
|
| 1855 | + return $this->get(IBus::class); |
|
| 1856 | + } |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * Get the trusted domain helper |
|
| 1860 | + * |
|
| 1861 | + * @return TrustedDomainHelper |
|
| 1862 | + * @deprecated 20.0.0 |
|
| 1863 | + */ |
|
| 1864 | + public function getTrustedDomainHelper() { |
|
| 1865 | + return $this->get(TrustedDomainHelper::class); |
|
| 1866 | + } |
|
| 1867 | + |
|
| 1868 | + /** |
|
| 1869 | + * Get the locking provider |
|
| 1870 | + * |
|
| 1871 | + * @return ILockingProvider |
|
| 1872 | + * @since 8.1.0 |
|
| 1873 | + * @deprecated 20.0.0 |
|
| 1874 | + */ |
|
| 1875 | + public function getLockingProvider() { |
|
| 1876 | + return $this->get(ILockingProvider::class); |
|
| 1877 | + } |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * @return IMountManager |
|
| 1881 | + * @deprecated 20.0.0 |
|
| 1882 | + **/ |
|
| 1883 | + public function getMountManager() { |
|
| 1884 | + return $this->get(IMountManager::class); |
|
| 1885 | + } |
|
| 1886 | + |
|
| 1887 | + /** |
|
| 1888 | + * @return IUserMountCache |
|
| 1889 | + * @deprecated 20.0.0 |
|
| 1890 | + */ |
|
| 1891 | + public function getUserMountCache() { |
|
| 1892 | + return $this->get(IUserMountCache::class); |
|
| 1893 | + } |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Get the MimeTypeDetector |
|
| 1897 | + * |
|
| 1898 | + * @return IMimeTypeDetector |
|
| 1899 | + * @deprecated 20.0.0 |
|
| 1900 | + */ |
|
| 1901 | + public function getMimeTypeDetector() { |
|
| 1902 | + return $this->get(IMimeTypeDetector::class); |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + /** |
|
| 1906 | + * Get the MimeTypeLoader |
|
| 1907 | + * |
|
| 1908 | + * @return IMimeTypeLoader |
|
| 1909 | + * @deprecated 20.0.0 |
|
| 1910 | + */ |
|
| 1911 | + public function getMimeTypeLoader() { |
|
| 1912 | + return $this->get(IMimeTypeLoader::class); |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + /** |
|
| 1916 | + * Get the manager of all the capabilities |
|
| 1917 | + * |
|
| 1918 | + * @return CapabilitiesManager |
|
| 1919 | + * @deprecated 20.0.0 |
|
| 1920 | + */ |
|
| 1921 | + public function getCapabilitiesManager() { |
|
| 1922 | + return $this->get(CapabilitiesManager::class); |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * Get the Notification Manager |
|
| 1927 | + * |
|
| 1928 | + * @return \OCP\Notification\IManager |
|
| 1929 | + * @since 8.2.0 |
|
| 1930 | + * @deprecated 20.0.0 |
|
| 1931 | + */ |
|
| 1932 | + public function getNotificationManager() { |
|
| 1933 | + return $this->get(\OCP\Notification\IManager::class); |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + /** |
|
| 1937 | + * @return ICommentsManager |
|
| 1938 | + * @deprecated 20.0.0 |
|
| 1939 | + */ |
|
| 1940 | + public function getCommentsManager() { |
|
| 1941 | + return $this->get(ICommentsManager::class); |
|
| 1942 | + } |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1946 | + * @deprecated 20.0.0 |
|
| 1947 | + */ |
|
| 1948 | + public function getThemingDefaults() { |
|
| 1949 | + return $this->get('ThemingDefaults'); |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * @return \OC\IntegrityCheck\Checker |
|
| 1954 | + * @deprecated 20.0.0 |
|
| 1955 | + */ |
|
| 1956 | + public function getIntegrityCodeChecker() { |
|
| 1957 | + return $this->get('IntegrityCodeChecker'); |
|
| 1958 | + } |
|
| 1959 | + |
|
| 1960 | + /** |
|
| 1961 | + * @return \OC\Session\CryptoWrapper |
|
| 1962 | + * @deprecated 20.0.0 |
|
| 1963 | + */ |
|
| 1964 | + public function getSessionCryptoWrapper() { |
|
| 1965 | + return $this->get('CryptoWrapper'); |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + /** |
|
| 1969 | + * @return CsrfTokenManager |
|
| 1970 | + * @deprecated 20.0.0 |
|
| 1971 | + */ |
|
| 1972 | + public function getCsrfTokenManager() { |
|
| 1973 | + return $this->get(CsrfTokenManager::class); |
|
| 1974 | + } |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * @return IThrottler |
|
| 1978 | + * @deprecated 20.0.0 |
|
| 1979 | + */ |
|
| 1980 | + public function getBruteForceThrottler() { |
|
| 1981 | + return $this->get(Throttler::class); |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + /** |
|
| 1985 | + * @return IContentSecurityPolicyManager |
|
| 1986 | + * @deprecated 20.0.0 |
|
| 1987 | + */ |
|
| 1988 | + public function getContentSecurityPolicyManager() { |
|
| 1989 | + return $this->get(ContentSecurityPolicyManager::class); |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * @return ContentSecurityPolicyNonceManager |
|
| 1994 | + * @deprecated 20.0.0 |
|
| 1995 | + */ |
|
| 1996 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1997 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1998 | + } |
|
| 1999 | + |
|
| 2000 | + /** |
|
| 2001 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2002 | + * |
|
| 2003 | + * @return \OCA\Files_External\Service\BackendService |
|
| 2004 | + * @deprecated 20.0.0 |
|
| 2005 | + */ |
|
| 2006 | + public function getStoragesBackendService() { |
|
| 2007 | + return $this->get(BackendService::class); |
|
| 2008 | + } |
|
| 2009 | + |
|
| 2010 | + /** |
|
| 2011 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2012 | + * |
|
| 2013 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2014 | + * @deprecated 20.0.0 |
|
| 2015 | + */ |
|
| 2016 | + public function getGlobalStoragesService() { |
|
| 2017 | + return $this->get(GlobalStoragesService::class); |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + /** |
|
| 2021 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2022 | + * |
|
| 2023 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2024 | + * @deprecated 20.0.0 |
|
| 2025 | + */ |
|
| 2026 | + public function getUserGlobalStoragesService() { |
|
| 2027 | + return $this->get(UserGlobalStoragesService::class); |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2032 | + * |
|
| 2033 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2034 | + * @deprecated 20.0.0 |
|
| 2035 | + */ |
|
| 2036 | + public function getUserStoragesService() { |
|
| 2037 | + return $this->get(UserStoragesService::class); |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + /** |
|
| 2041 | + * @return \OCP\Share\IManager |
|
| 2042 | + * @deprecated 20.0.0 |
|
| 2043 | + */ |
|
| 2044 | + public function getShareManager() { |
|
| 2045 | + return $this->get(\OCP\Share\IManager::class); |
|
| 2046 | + } |
|
| 2047 | + |
|
| 2048 | + /** |
|
| 2049 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2050 | + * @deprecated 20.0.0 |
|
| 2051 | + */ |
|
| 2052 | + public function getCollaboratorSearch() { |
|
| 2053 | + return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2054 | + } |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2058 | + * @deprecated 20.0.0 |
|
| 2059 | + */ |
|
| 2060 | + public function getAutoCompleteManager() { |
|
| 2061 | + return $this->get(IManager::class); |
|
| 2062 | + } |
|
| 2063 | + |
|
| 2064 | + /** |
|
| 2065 | + * Returns the LDAP Provider |
|
| 2066 | + * |
|
| 2067 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 2068 | + * @deprecated 20.0.0 |
|
| 2069 | + */ |
|
| 2070 | + public function getLDAPProvider() { |
|
| 2071 | + return $this->get('LDAPProvider'); |
|
| 2072 | + } |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * @return \OCP\Settings\IManager |
|
| 2076 | + * @deprecated 20.0.0 |
|
| 2077 | + */ |
|
| 2078 | + public function getSettingsManager() { |
|
| 2079 | + return $this->get(\OC\Settings\Manager::class); |
|
| 2080 | + } |
|
| 2081 | + |
|
| 2082 | + /** |
|
| 2083 | + * @return \OCP\Files\IAppData |
|
| 2084 | + * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 2085 | + */ |
|
| 2086 | + public function getAppDataDir($app) { |
|
| 2087 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2088 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 2089 | + return $factory->get($app); |
|
| 2090 | + } |
|
| 2091 | + |
|
| 2092 | + /** |
|
| 2093 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 2094 | + * @deprecated 20.0.0 |
|
| 2095 | + */ |
|
| 2096 | + public function getLockdownManager() { |
|
| 2097 | + return $this->get('LockdownManager'); |
|
| 2098 | + } |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * @return \OCP\Federation\ICloudIdManager |
|
| 2102 | + * @deprecated 20.0.0 |
|
| 2103 | + */ |
|
| 2104 | + public function getCloudIdManager() { |
|
| 2105 | + return $this->get(ICloudIdManager::class); |
|
| 2106 | + } |
|
| 2107 | + |
|
| 2108 | + /** |
|
| 2109 | + * @return \OCP\GlobalScale\IConfig |
|
| 2110 | + * @deprecated 20.0.0 |
|
| 2111 | + */ |
|
| 2112 | + public function getGlobalScaleConfig() { |
|
| 2113 | + return $this->get(IConfig::class); |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + /** |
|
| 2117 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2118 | + * @deprecated 20.0.0 |
|
| 2119 | + */ |
|
| 2120 | + public function getCloudFederationProviderManager() { |
|
| 2121 | + return $this->get(ICloudFederationProviderManager::class); |
|
| 2122 | + } |
|
| 2123 | + |
|
| 2124 | + /** |
|
| 2125 | + * @return \OCP\Remote\Api\IApiFactory |
|
| 2126 | + * @deprecated 20.0.0 |
|
| 2127 | + */ |
|
| 2128 | + public function getRemoteApiFactory() { |
|
| 2129 | + return $this->get(IApiFactory::class); |
|
| 2130 | + } |
|
| 2131 | + |
|
| 2132 | + /** |
|
| 2133 | + * @return \OCP\Federation\ICloudFederationFactory |
|
| 2134 | + * @deprecated 20.0.0 |
|
| 2135 | + */ |
|
| 2136 | + public function getCloudFederationFactory() { |
|
| 2137 | + return $this->get(ICloudFederationFactory::class); |
|
| 2138 | + } |
|
| 2139 | + |
|
| 2140 | + /** |
|
| 2141 | + * @return \OCP\Remote\IInstanceFactory |
|
| 2142 | + * @deprecated 20.0.0 |
|
| 2143 | + */ |
|
| 2144 | + public function getRemoteInstanceFactory() { |
|
| 2145 | + return $this->get(IInstanceFactory::class); |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + /** |
|
| 2149 | + * @return IStorageFactory |
|
| 2150 | + * @deprecated 20.0.0 |
|
| 2151 | + */ |
|
| 2152 | + public function getStorageFactory() { |
|
| 2153 | + return $this->get(IStorageFactory::class); |
|
| 2154 | + } |
|
| 2155 | + |
|
| 2156 | + /** |
|
| 2157 | + * Get the Preview GeneratorHelper |
|
| 2158 | + * |
|
| 2159 | + * @return GeneratorHelper |
|
| 2160 | + * @since 17.0.0 |
|
| 2161 | + * @deprecated 20.0.0 |
|
| 2162 | + */ |
|
| 2163 | + public function getGeneratorHelper() { |
|
| 2164 | + return $this->get(\OC\Preview\GeneratorHelper::class); |
|
| 2165 | + } |
|
| 2166 | + |
|
| 2167 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2168 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2169 | + try { |
|
| 2170 | + /** @var LoggerInterface $logger */ |
|
| 2171 | + $logger = $container->get(LoggerInterface::class); |
|
| 2172 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2173 | + } catch (ContainerExceptionInterface $e) { |
|
| 2174 | + // Could not get logger. Continue |
|
| 2175 | + } |
|
| 2176 | + |
|
| 2177 | + return $container->get($target); |
|
| 2178 | + }, false); |
|
| 2179 | + } |
|
| 2180 | 2180 | } |
@@ -22,42 +22,42 @@ |
||
| 22 | 22 | * Class that will watch filesystem activity and remove previews as needed. |
| 23 | 23 | */ |
| 24 | 24 | class Watcher { |
| 25 | - /** @var IAppData */ |
|
| 26 | - private $appData; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Watcher constructor. |
|
| 30 | - * |
|
| 31 | - * @param IAppData $appData |
|
| 32 | - */ |
|
| 33 | - public function __construct(IAppData $appData) { |
|
| 34 | - $this->appData = $appData; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function postWrite(Node $node) { |
|
| 38 | - $this->deleteNode($node); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - protected function deleteNode(FileInfo $node) { |
|
| 42 | - // We only handle files |
|
| 43 | - if ($node instanceof Folder) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - try { |
|
| 48 | - if (is_null($node->getId())) { |
|
| 49 | - return; |
|
| 50 | - } |
|
| 51 | - $folder = $this->appData->getFolder((string)$node->getId()); |
|
| 52 | - $folder->delete(); |
|
| 53 | - } catch (NotFoundException $e) { |
|
| 54 | - //Nothing to do |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function versionRollback(array $data) { |
|
| 59 | - if (isset($data['node'])) { |
|
| 60 | - $this->deleteNode($data['node']); |
|
| 61 | - } |
|
| 62 | - } |
|
| 25 | + /** @var IAppData */ |
|
| 26 | + private $appData; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Watcher constructor. |
|
| 30 | + * |
|
| 31 | + * @param IAppData $appData |
|
| 32 | + */ |
|
| 33 | + public function __construct(IAppData $appData) { |
|
| 34 | + $this->appData = $appData; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function postWrite(Node $node) { |
|
| 38 | + $this->deleteNode($node); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + protected function deleteNode(FileInfo $node) { |
|
| 42 | + // We only handle files |
|
| 43 | + if ($node instanceof Folder) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + try { |
|
| 48 | + if (is_null($node->getId())) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | + $folder = $this->appData->getFolder((string)$node->getId()); |
|
| 52 | + $folder->delete(); |
|
| 53 | + } catch (NotFoundException $e) { |
|
| 54 | + //Nothing to do |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function versionRollback(array $data) { |
|
| 59 | + if (isset($data['node'])) { |
|
| 60 | + $this->deleteNode($data['node']); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -15,27 +15,27 @@ |
||
| 15 | 15 | use OCP\Files\Node; |
| 16 | 16 | |
| 17 | 17 | class WatcherConnector { |
| 18 | - public function __construct( |
|
| 19 | - private IRootFolder $root, |
|
| 20 | - private SystemConfig $config, |
|
| 21 | - private IEventDispatcher $dispatcher, |
|
| 22 | - ) { |
|
| 23 | - } |
|
| 18 | + public function __construct( |
|
| 19 | + private IRootFolder $root, |
|
| 20 | + private SystemConfig $config, |
|
| 21 | + private IEventDispatcher $dispatcher, |
|
| 22 | + ) { |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - private function getWatcher(): Watcher { |
|
| 26 | - return \OCP\Server::get(Watcher::class); |
|
| 27 | - } |
|
| 25 | + private function getWatcher(): Watcher { |
|
| 26 | + return \OCP\Server::get(Watcher::class); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function connectWatcher(): void { |
|
| 30 | - // Do not connect if we are not setup yet! |
|
| 31 | - if ($this->config->getValue('instanceid', null) !== null) { |
|
| 32 | - $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
| 33 | - $this->getWatcher()->postWrite($node); |
|
| 34 | - }); |
|
| 29 | + public function connectWatcher(): void { |
|
| 30 | + // Do not connect if we are not setup yet! |
|
| 31 | + if ($this->config->getValue('instanceid', null) !== null) { |
|
| 32 | + $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
| 33 | + $this->getWatcher()->postWrite($node); |
|
| 34 | + }); |
|
| 35 | 35 | |
| 36 | - $this->dispatcher->addListener(VersionRestoredEvent::class, function (VersionRestoredEvent $event) { |
|
| 37 | - $this->getWatcher()->versionRollback(['node' => $event->getVersion()->getSourceFile()]); |
|
| 38 | - }); |
|
| 39 | - } |
|
| 40 | - } |
|
| 36 | + $this->dispatcher->addListener(VersionRestoredEvent::class, function (VersionRestoredEvent $event) { |
|
| 37 | + $this->getWatcher()->versionRollback(['node' => $event->getVersion()->getSourceFile()]); |
|
| 38 | + }); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -29,11 +29,11 @@ |
||
| 29 | 29 | public function connectWatcher(): void { |
| 30 | 30 | // Do not connect if we are not setup yet! |
| 31 | 31 | if ($this->config->getValue('instanceid', null) !== null) { |
| 32 | - $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
| 32 | + $this->root->listen('\OC\Files', 'postWrite', function(Node $node) { |
|
| 33 | 33 | $this->getWatcher()->postWrite($node); |
| 34 | 34 | }); |
| 35 | 35 | |
| 36 | - $this->dispatcher->addListener(VersionRestoredEvent::class, function (VersionRestoredEvent $event) { |
|
| 36 | + $this->dispatcher->addListener(VersionRestoredEvent::class, function(VersionRestoredEvent $event) { |
|
| 37 | 37 | $this->getWatcher()->versionRollback(['node' => $event->getVersion()->getSourceFile()]); |
| 38 | 38 | }); |
| 39 | 39 | } |
@@ -36,960 +36,960 @@ |
||
| 36 | 36 | * @group DB |
| 37 | 37 | */ |
| 38 | 38 | class VersioningTest extends \Test\TestCase { |
| 39 | - public const TEST_VERSIONS_USER = 'test-versions-user'; |
|
| 40 | - public const TEST_VERSIONS_USER2 = 'test-versions-user2'; |
|
| 41 | - public const USERS_VERSIONS_ROOT = '/test-versions-user/files_versions'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var View |
|
| 45 | - */ |
|
| 46 | - private $rootView; |
|
| 47 | - /** |
|
| 48 | - * @var VersionsMapper |
|
| 49 | - */ |
|
| 50 | - private $versionsMapper; |
|
| 51 | - /** |
|
| 52 | - * @var IMimeTypeLoader |
|
| 53 | - */ |
|
| 54 | - private $mimeTypeLoader; |
|
| 55 | - private $user1; |
|
| 56 | - private $user2; |
|
| 57 | - |
|
| 58 | - public static function setUpBeforeClass(): void { |
|
| 59 | - parent::setUpBeforeClass(); |
|
| 60 | - |
|
| 61 | - $application = new Application(); |
|
| 62 | - |
|
| 63 | - // create test user |
|
| 64 | - self::loginHelper(self::TEST_VERSIONS_USER2, true); |
|
| 65 | - self::loginHelper(self::TEST_VERSIONS_USER, true); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public static function tearDownAfterClass(): void { |
|
| 69 | - // cleanup test user |
|
| 70 | - $user = Server::get(IUserManager::class)->get(self::TEST_VERSIONS_USER); |
|
| 71 | - if ($user !== null) { |
|
| 72 | - $user->delete(); |
|
| 73 | - } |
|
| 74 | - $user = Server::get(IUserManager::class)->get(self::TEST_VERSIONS_USER2); |
|
| 75 | - if ($user !== null) { |
|
| 76 | - $user->delete(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - parent::tearDownAfterClass(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - protected function setUp(): void { |
|
| 83 | - parent::setUp(); |
|
| 84 | - |
|
| 85 | - $config = Server::get(IConfig::class); |
|
| 86 | - $mockConfig = $this->createMock(IConfig::class); |
|
| 87 | - $mockConfig->expects($this->any()) |
|
| 88 | - ->method('getSystemValue') |
|
| 89 | - ->willReturnCallback(function ($key, $default) use ($config) { |
|
| 90 | - if ($key === 'filesystem_check_changes') { |
|
| 91 | - return Watcher::CHECK_ONCE; |
|
| 92 | - } else { |
|
| 93 | - return $config->getSystemValue($key, $default); |
|
| 94 | - } |
|
| 95 | - }); |
|
| 96 | - $this->overwriteService(AllConfig::class, $mockConfig); |
|
| 97 | - |
|
| 98 | - // clear hooks |
|
| 99 | - \OC_Hook::clear(); |
|
| 100 | - \OC::registerShareHooks(Server::get(SystemConfig::class)); |
|
| 101 | - \OC::$server->boot(); |
|
| 102 | - |
|
| 103 | - self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 104 | - $this->rootView = new View(); |
|
| 105 | - if (!$this->rootView->file_exists(self::USERS_VERSIONS_ROOT)) { |
|
| 106 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $this->versionsMapper = Server::get(VersionsMapper::class); |
|
| 110 | - $this->mimeTypeLoader = Server::get(IMimeTypeLoader::class); |
|
| 111 | - |
|
| 112 | - $this->user1 = $this->createMock(IUser::class); |
|
| 113 | - $this->user1->method('getUID') |
|
| 114 | - ->willReturn(self::TEST_VERSIONS_USER); |
|
| 115 | - $this->user2 = $this->createMock(IUser::class); |
|
| 116 | - $this->user2->method('getUID') |
|
| 117 | - ->willReturn(self::TEST_VERSIONS_USER2); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - protected function tearDown(): void { |
|
| 121 | - $this->restoreService(AllConfig::class); |
|
| 122 | - |
|
| 123 | - if ($this->rootView) { |
|
| 124 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files/'); |
|
| 125 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files/'); |
|
| 126 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files_versions/'); |
|
| 127 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files_versions/'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - \OC_Hook::clear(); |
|
| 131 | - |
|
| 132 | - parent::tearDown(); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @medium |
|
| 137 | - * test expire logic |
|
| 138 | - * @dataProvider versionsProvider |
|
| 139 | - */ |
|
| 140 | - public function testGetExpireList($versions, $sizeOfAllDeletedFiles): void { |
|
| 141 | - |
|
| 142 | - // last interval end at 2592000 |
|
| 143 | - $startTime = 5000000; |
|
| 144 | - |
|
| 145 | - $testClass = new VersionStorageToTest(); |
|
| 146 | - [$deleted, $size] = $testClass->callProtectedGetExpireList($startTime, $versions); |
|
| 147 | - |
|
| 148 | - // we should have deleted 16 files each of the size 1 |
|
| 149 | - $this->assertEquals($sizeOfAllDeletedFiles, $size); |
|
| 150 | - |
|
| 151 | - // the deleted array should only contain versions which should be deleted |
|
| 152 | - foreach ($deleted as $key => $path) { |
|
| 153 | - unset($versions[$key]); |
|
| 154 | - $this->assertEquals('delete', substr($path, 0, strlen('delete'))); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // the versions array should only contain versions which should be kept |
|
| 158 | - foreach ($versions as $version) { |
|
| 159 | - $this->assertEquals('keep', $version['path']); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - public function versionsProvider() { |
|
| 164 | - return [ |
|
| 165 | - // first set of versions uniformly distributed versions |
|
| 166 | - [ |
|
| 167 | - [ |
|
| 168 | - // first slice (10sec) keep one version every 2 seconds |
|
| 169 | - ['version' => 4999999, 'path' => 'keep', 'size' => 1], |
|
| 170 | - ['version' => 4999998, 'path' => 'delete', 'size' => 1], |
|
| 171 | - ['version' => 4999997, 'path' => 'keep', 'size' => 1], |
|
| 172 | - ['version' => 4999995, 'path' => 'keep', 'size' => 1], |
|
| 173 | - ['version' => 4999994, 'path' => 'delete', 'size' => 1], |
|
| 174 | - //next slice (60sec) starts at 4999990 keep one version every 10 secons |
|
| 175 | - ['version' => 4999988, 'path' => 'keep', 'size' => 1], |
|
| 176 | - ['version' => 4999978, 'path' => 'keep', 'size' => 1], |
|
| 177 | - ['version' => 4999975, 'path' => 'delete', 'size' => 1], |
|
| 178 | - ['version' => 4999972, 'path' => 'delete', 'size' => 1], |
|
| 179 | - ['version' => 4999967, 'path' => 'keep', 'size' => 1], |
|
| 180 | - ['version' => 4999958, 'path' => 'delete', 'size' => 1], |
|
| 181 | - ['version' => 4999957, 'path' => 'keep', 'size' => 1], |
|
| 182 | - //next slice (3600sec) start at 4999940 keep one version every 60 seconds |
|
| 183 | - ['version' => 4999900, 'path' => 'keep', 'size' => 1], |
|
| 184 | - ['version' => 4999841, 'path' => 'delete', 'size' => 1], |
|
| 185 | - ['version' => 4999840, 'path' => 'keep', 'size' => 1], |
|
| 186 | - ['version' => 4999780, 'path' => 'keep', 'size' => 1], |
|
| 187 | - ['version' => 4996401, 'path' => 'keep', 'size' => 1], |
|
| 188 | - // next slice (86400sec) start at 4996400 keep one version every 3600 seconds |
|
| 189 | - ['version' => 4996350, 'path' => 'delete', 'size' => 1], |
|
| 190 | - ['version' => 4992800, 'path' => 'keep', 'size' => 1], |
|
| 191 | - ['version' => 4989800, 'path' => 'delete', 'size' => 1], |
|
| 192 | - ['version' => 4989700, 'path' => 'delete', 'size' => 1], |
|
| 193 | - ['version' => 4989200, 'path' => 'keep', 'size' => 1], |
|
| 194 | - // next slice (2592000sec) start at 4913600 keep one version every 86400 seconds |
|
| 195 | - ['version' => 4913600, 'path' => 'keep', 'size' => 1], |
|
| 196 | - ['version' => 4852800, 'path' => 'delete', 'size' => 1], |
|
| 197 | - ['version' => 4827201, 'path' => 'delete', 'size' => 1], |
|
| 198 | - ['version' => 4827200, 'path' => 'keep', 'size' => 1], |
|
| 199 | - ['version' => 4777201, 'path' => 'delete', 'size' => 1], |
|
| 200 | - ['version' => 4777501, 'path' => 'delete', 'size' => 1], |
|
| 201 | - ['version' => 4740000, 'path' => 'keep', 'size' => 1], |
|
| 202 | - // final slice starts at 2408000 keep one version every 604800 secons |
|
| 203 | - ['version' => 2408000, 'path' => 'keep', 'size' => 1], |
|
| 204 | - ['version' => 1803201, 'path' => 'delete', 'size' => 1], |
|
| 205 | - ['version' => 1803200, 'path' => 'keep', 'size' => 1], |
|
| 206 | - ['version' => 1800199, 'path' => 'delete', 'size' => 1], |
|
| 207 | - ['version' => 1800100, 'path' => 'delete', 'size' => 1], |
|
| 208 | - ['version' => 1198300, 'path' => 'keep', 'size' => 1], |
|
| 209 | - ], |
|
| 210 | - 16 // size of all deleted files (every file has the size 1) |
|
| 211 | - ], |
|
| 212 | - // second set of versions, here we have only really old versions |
|
| 213 | - [ |
|
| 214 | - [ |
|
| 215 | - // first slice (10sec) keep one version every 2 seconds |
|
| 216 | - // next slice (60sec) starts at 4999990 keep one version every 10 secons |
|
| 217 | - // next slice (3600sec) start at 4999940 keep one version every 60 seconds |
|
| 218 | - // next slice (86400sec) start at 4996400 keep one version every 3600 seconds |
|
| 219 | - ['version' => 4996400, 'path' => 'keep', 'size' => 1], |
|
| 220 | - ['version' => 4996350, 'path' => 'delete', 'size' => 1], |
|
| 221 | - ['version' => 4996350, 'path' => 'delete', 'size' => 1], |
|
| 222 | - ['version' => 4992800, 'path' => 'keep', 'size' => 1], |
|
| 223 | - ['version' => 4989800, 'path' => 'delete', 'size' => 1], |
|
| 224 | - ['version' => 4989700, 'path' => 'delete', 'size' => 1], |
|
| 225 | - ['version' => 4989200, 'path' => 'keep', 'size' => 1], |
|
| 226 | - // next slice (2592000sec) start at 4913600 keep one version every 86400 seconds |
|
| 227 | - ['version' => 4913600, 'path' => 'keep', 'size' => 1], |
|
| 228 | - ['version' => 4852800, 'path' => 'delete', 'size' => 1], |
|
| 229 | - ['version' => 4827201, 'path' => 'delete', 'size' => 1], |
|
| 230 | - ['version' => 4827200, 'path' => 'keep', 'size' => 1], |
|
| 231 | - ['version' => 4777201, 'path' => 'delete', 'size' => 1], |
|
| 232 | - ['version' => 4777501, 'path' => 'delete', 'size' => 1], |
|
| 233 | - ['version' => 4740000, 'path' => 'keep', 'size' => 1], |
|
| 234 | - // final slice starts at 2408000 keep one version every 604800 secons |
|
| 235 | - ['version' => 2408000, 'path' => 'keep', 'size' => 1], |
|
| 236 | - ['version' => 1803201, 'path' => 'delete', 'size' => 1], |
|
| 237 | - ['version' => 1803200, 'path' => 'keep', 'size' => 1], |
|
| 238 | - ['version' => 1800199, 'path' => 'delete', 'size' => 1], |
|
| 239 | - ['version' => 1800100, 'path' => 'delete', 'size' => 1], |
|
| 240 | - ['version' => 1198300, 'path' => 'keep', 'size' => 1], |
|
| 241 | - ], |
|
| 242 | - 11 // size of all deleted files (every file has the size 1) |
|
| 243 | - ], |
|
| 244 | - // third set of versions, with some gaps between |
|
| 245 | - [ |
|
| 246 | - [ |
|
| 247 | - // first slice (10sec) keep one version every 2 seconds |
|
| 248 | - ['version' => 4999999, 'path' => 'keep', 'size' => 1], |
|
| 249 | - ['version' => 4999998, 'path' => 'delete', 'size' => 1], |
|
| 250 | - ['version' => 4999997, 'path' => 'keep', 'size' => 1], |
|
| 251 | - ['version' => 4999995, 'path' => 'keep', 'size' => 1], |
|
| 252 | - ['version' => 4999994, 'path' => 'delete', 'size' => 1], |
|
| 253 | - //next slice (60sec) starts at 4999990 keep one version every 10 secons |
|
| 254 | - ['version' => 4999988, 'path' => 'keep', 'size' => 1], |
|
| 255 | - ['version' => 4999978, 'path' => 'keep', 'size' => 1], |
|
| 256 | - //next slice (3600sec) start at 4999940 keep one version every 60 seconds |
|
| 257 | - // next slice (86400sec) start at 4996400 keep one version every 3600 seconds |
|
| 258 | - ['version' => 4989200, 'path' => 'keep', 'size' => 1], |
|
| 259 | - // next slice (2592000sec) start at 4913600 keep one version every 86400 seconds |
|
| 260 | - ['version' => 4913600, 'path' => 'keep', 'size' => 1], |
|
| 261 | - ['version' => 4852800, 'path' => 'delete', 'size' => 1], |
|
| 262 | - ['version' => 4827201, 'path' => 'delete', 'size' => 1], |
|
| 263 | - ['version' => 4827200, 'path' => 'keep', 'size' => 1], |
|
| 264 | - ['version' => 4777201, 'path' => 'delete', 'size' => 1], |
|
| 265 | - ['version' => 4777501, 'path' => 'delete', 'size' => 1], |
|
| 266 | - ['version' => 4740000, 'path' => 'keep', 'size' => 1], |
|
| 267 | - // final slice starts at 2408000 keep one version every 604800 secons |
|
| 268 | - ['version' => 2408000, 'path' => 'keep', 'size' => 1], |
|
| 269 | - ['version' => 1803201, 'path' => 'delete', 'size' => 1], |
|
| 270 | - ['version' => 1803200, 'path' => 'keep', 'size' => 1], |
|
| 271 | - ['version' => 1800199, 'path' => 'delete', 'size' => 1], |
|
| 272 | - ['version' => 1800100, 'path' => 'delete', 'size' => 1], |
|
| 273 | - ['version' => 1198300, 'path' => 'keep', 'size' => 1], |
|
| 274 | - ], |
|
| 275 | - 9 // size of all deleted files (every file has the size 1) |
|
| 276 | - ], |
|
| 277 | - // fourth set of versions: empty (see issue #19066) |
|
| 278 | - [ |
|
| 279 | - [], |
|
| 280 | - 0 |
|
| 281 | - ] |
|
| 282 | - |
|
| 283 | - ]; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - public function testRename(): void { |
|
| 287 | - Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 288 | - |
|
| 289 | - $t1 = time(); |
|
| 290 | - // second version is two weeks older, this way we make sure that no |
|
| 291 | - // version will be expired |
|
| 292 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 293 | - |
|
| 294 | - // create some versions |
|
| 295 | - $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 296 | - $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 297 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 298 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 299 | - |
|
| 300 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 301 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 302 | - |
|
| 303 | - // execute rename hook of versions app |
|
| 304 | - Filesystem::rename('test.txt', 'test2.txt'); |
|
| 305 | - |
|
| 306 | - $this->runCommands(); |
|
| 307 | - |
|
| 308 | - $this->assertFalse($this->rootView->file_exists($v1), 'version 1 of old file does not exist'); |
|
| 309 | - $this->assertFalse($this->rootView->file_exists($v2), 'version 2 of old file does not exist'); |
|
| 310 | - |
|
| 311 | - $this->assertTrue($this->rootView->file_exists($v1Renamed), 'version 1 of renamed file exists'); |
|
| 312 | - $this->assertTrue($this->rootView->file_exists($v2Renamed), 'version 2 of renamed file exists'); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - public function testRenameInSharedFolder(): void { |
|
| 316 | - Filesystem::mkdir('folder1'); |
|
| 317 | - Filesystem::mkdir('folder1/folder2'); |
|
| 318 | - Filesystem::file_put_contents('folder1/test.txt', 'test file'); |
|
| 319 | - |
|
| 320 | - $t1 = time(); |
|
| 321 | - // second version is two weeks older, this way we make sure that no |
|
| 322 | - // version will be expired |
|
| 323 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 324 | - |
|
| 325 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1'); |
|
| 326 | - // create some versions |
|
| 327 | - $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1; |
|
| 328 | - $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2; |
|
| 329 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t1; |
|
| 330 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t2; |
|
| 331 | - |
|
| 332 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 333 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 334 | - |
|
| 335 | - $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); |
|
| 336 | - $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 337 | - $share->setNode($node) |
|
| 338 | - ->setShareType(IShare::TYPE_USER) |
|
| 339 | - ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 340 | - ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 341 | - ->setPermissions(Constants::PERMISSION_ALL); |
|
| 342 | - $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 343 | - Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 344 | - |
|
| 345 | - self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 346 | - |
|
| 347 | - $this->assertTrue(Filesystem::file_exists('folder1/test.txt')); |
|
| 348 | - |
|
| 349 | - // execute rename hook of versions app |
|
| 350 | - Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt'); |
|
| 351 | - |
|
| 352 | - $this->runCommands(); |
|
| 353 | - |
|
| 354 | - self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 355 | - |
|
| 356 | - $this->assertFalse($this->rootView->file_exists($v1), 'version 1 of old file does not exist'); |
|
| 357 | - $this->assertFalse($this->rootView->file_exists($v2), 'version 2 of old file does not exist'); |
|
| 358 | - |
|
| 359 | - $this->assertTrue($this->rootView->file_exists($v1Renamed), 'version 1 of renamed file exists'); |
|
| 360 | - $this->assertTrue($this->rootView->file_exists($v2Renamed), 'version 2 of renamed file exists'); |
|
| 361 | - |
|
| 362 | - Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - public function testMoveFolder(): void { |
|
| 366 | - Filesystem::mkdir('folder1'); |
|
| 367 | - Filesystem::mkdir('folder2'); |
|
| 368 | - Filesystem::file_put_contents('folder1/test.txt', 'test file'); |
|
| 369 | - |
|
| 370 | - $t1 = time(); |
|
| 371 | - // second version is two weeks older, this way we make sure that no |
|
| 372 | - // version will be expired |
|
| 373 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 374 | - |
|
| 375 | - // create some versions |
|
| 376 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1'); |
|
| 377 | - $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1; |
|
| 378 | - $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2; |
|
| 379 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t1; |
|
| 380 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t2; |
|
| 39 | + public const TEST_VERSIONS_USER = 'test-versions-user'; |
|
| 40 | + public const TEST_VERSIONS_USER2 = 'test-versions-user2'; |
|
| 41 | + public const USERS_VERSIONS_ROOT = '/test-versions-user/files_versions'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var View |
|
| 45 | + */ |
|
| 46 | + private $rootView; |
|
| 47 | + /** |
|
| 48 | + * @var VersionsMapper |
|
| 49 | + */ |
|
| 50 | + private $versionsMapper; |
|
| 51 | + /** |
|
| 52 | + * @var IMimeTypeLoader |
|
| 53 | + */ |
|
| 54 | + private $mimeTypeLoader; |
|
| 55 | + private $user1; |
|
| 56 | + private $user2; |
|
| 57 | + |
|
| 58 | + public static function setUpBeforeClass(): void { |
|
| 59 | + parent::setUpBeforeClass(); |
|
| 60 | + |
|
| 61 | + $application = new Application(); |
|
| 62 | + |
|
| 63 | + // create test user |
|
| 64 | + self::loginHelper(self::TEST_VERSIONS_USER2, true); |
|
| 65 | + self::loginHelper(self::TEST_VERSIONS_USER, true); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public static function tearDownAfterClass(): void { |
|
| 69 | + // cleanup test user |
|
| 70 | + $user = Server::get(IUserManager::class)->get(self::TEST_VERSIONS_USER); |
|
| 71 | + if ($user !== null) { |
|
| 72 | + $user->delete(); |
|
| 73 | + } |
|
| 74 | + $user = Server::get(IUserManager::class)->get(self::TEST_VERSIONS_USER2); |
|
| 75 | + if ($user !== null) { |
|
| 76 | + $user->delete(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + parent::tearDownAfterClass(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + protected function setUp(): void { |
|
| 83 | + parent::setUp(); |
|
| 84 | + |
|
| 85 | + $config = Server::get(IConfig::class); |
|
| 86 | + $mockConfig = $this->createMock(IConfig::class); |
|
| 87 | + $mockConfig->expects($this->any()) |
|
| 88 | + ->method('getSystemValue') |
|
| 89 | + ->willReturnCallback(function ($key, $default) use ($config) { |
|
| 90 | + if ($key === 'filesystem_check_changes') { |
|
| 91 | + return Watcher::CHECK_ONCE; |
|
| 92 | + } else { |
|
| 93 | + return $config->getSystemValue($key, $default); |
|
| 94 | + } |
|
| 95 | + }); |
|
| 96 | + $this->overwriteService(AllConfig::class, $mockConfig); |
|
| 97 | + |
|
| 98 | + // clear hooks |
|
| 99 | + \OC_Hook::clear(); |
|
| 100 | + \OC::registerShareHooks(Server::get(SystemConfig::class)); |
|
| 101 | + \OC::$server->boot(); |
|
| 102 | + |
|
| 103 | + self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 104 | + $this->rootView = new View(); |
|
| 105 | + if (!$this->rootView->file_exists(self::USERS_VERSIONS_ROOT)) { |
|
| 106 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $this->versionsMapper = Server::get(VersionsMapper::class); |
|
| 110 | + $this->mimeTypeLoader = Server::get(IMimeTypeLoader::class); |
|
| 111 | + |
|
| 112 | + $this->user1 = $this->createMock(IUser::class); |
|
| 113 | + $this->user1->method('getUID') |
|
| 114 | + ->willReturn(self::TEST_VERSIONS_USER); |
|
| 115 | + $this->user2 = $this->createMock(IUser::class); |
|
| 116 | + $this->user2->method('getUID') |
|
| 117 | + ->willReturn(self::TEST_VERSIONS_USER2); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + protected function tearDown(): void { |
|
| 121 | + $this->restoreService(AllConfig::class); |
|
| 122 | + |
|
| 123 | + if ($this->rootView) { |
|
| 124 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files/'); |
|
| 125 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files/'); |
|
| 126 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files_versions/'); |
|
| 127 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files_versions/'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + \OC_Hook::clear(); |
|
| 131 | + |
|
| 132 | + parent::tearDown(); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @medium |
|
| 137 | + * test expire logic |
|
| 138 | + * @dataProvider versionsProvider |
|
| 139 | + */ |
|
| 140 | + public function testGetExpireList($versions, $sizeOfAllDeletedFiles): void { |
|
| 141 | + |
|
| 142 | + // last interval end at 2592000 |
|
| 143 | + $startTime = 5000000; |
|
| 144 | + |
|
| 145 | + $testClass = new VersionStorageToTest(); |
|
| 146 | + [$deleted, $size] = $testClass->callProtectedGetExpireList($startTime, $versions); |
|
| 147 | + |
|
| 148 | + // we should have deleted 16 files each of the size 1 |
|
| 149 | + $this->assertEquals($sizeOfAllDeletedFiles, $size); |
|
| 150 | + |
|
| 151 | + // the deleted array should only contain versions which should be deleted |
|
| 152 | + foreach ($deleted as $key => $path) { |
|
| 153 | + unset($versions[$key]); |
|
| 154 | + $this->assertEquals('delete', substr($path, 0, strlen('delete'))); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // the versions array should only contain versions which should be kept |
|
| 158 | + foreach ($versions as $version) { |
|
| 159 | + $this->assertEquals('keep', $version['path']); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + public function versionsProvider() { |
|
| 164 | + return [ |
|
| 165 | + // first set of versions uniformly distributed versions |
|
| 166 | + [ |
|
| 167 | + [ |
|
| 168 | + // first slice (10sec) keep one version every 2 seconds |
|
| 169 | + ['version' => 4999999, 'path' => 'keep', 'size' => 1], |
|
| 170 | + ['version' => 4999998, 'path' => 'delete', 'size' => 1], |
|
| 171 | + ['version' => 4999997, 'path' => 'keep', 'size' => 1], |
|
| 172 | + ['version' => 4999995, 'path' => 'keep', 'size' => 1], |
|
| 173 | + ['version' => 4999994, 'path' => 'delete', 'size' => 1], |
|
| 174 | + //next slice (60sec) starts at 4999990 keep one version every 10 secons |
|
| 175 | + ['version' => 4999988, 'path' => 'keep', 'size' => 1], |
|
| 176 | + ['version' => 4999978, 'path' => 'keep', 'size' => 1], |
|
| 177 | + ['version' => 4999975, 'path' => 'delete', 'size' => 1], |
|
| 178 | + ['version' => 4999972, 'path' => 'delete', 'size' => 1], |
|
| 179 | + ['version' => 4999967, 'path' => 'keep', 'size' => 1], |
|
| 180 | + ['version' => 4999958, 'path' => 'delete', 'size' => 1], |
|
| 181 | + ['version' => 4999957, 'path' => 'keep', 'size' => 1], |
|
| 182 | + //next slice (3600sec) start at 4999940 keep one version every 60 seconds |
|
| 183 | + ['version' => 4999900, 'path' => 'keep', 'size' => 1], |
|
| 184 | + ['version' => 4999841, 'path' => 'delete', 'size' => 1], |
|
| 185 | + ['version' => 4999840, 'path' => 'keep', 'size' => 1], |
|
| 186 | + ['version' => 4999780, 'path' => 'keep', 'size' => 1], |
|
| 187 | + ['version' => 4996401, 'path' => 'keep', 'size' => 1], |
|
| 188 | + // next slice (86400sec) start at 4996400 keep one version every 3600 seconds |
|
| 189 | + ['version' => 4996350, 'path' => 'delete', 'size' => 1], |
|
| 190 | + ['version' => 4992800, 'path' => 'keep', 'size' => 1], |
|
| 191 | + ['version' => 4989800, 'path' => 'delete', 'size' => 1], |
|
| 192 | + ['version' => 4989700, 'path' => 'delete', 'size' => 1], |
|
| 193 | + ['version' => 4989200, 'path' => 'keep', 'size' => 1], |
|
| 194 | + // next slice (2592000sec) start at 4913600 keep one version every 86400 seconds |
|
| 195 | + ['version' => 4913600, 'path' => 'keep', 'size' => 1], |
|
| 196 | + ['version' => 4852800, 'path' => 'delete', 'size' => 1], |
|
| 197 | + ['version' => 4827201, 'path' => 'delete', 'size' => 1], |
|
| 198 | + ['version' => 4827200, 'path' => 'keep', 'size' => 1], |
|
| 199 | + ['version' => 4777201, 'path' => 'delete', 'size' => 1], |
|
| 200 | + ['version' => 4777501, 'path' => 'delete', 'size' => 1], |
|
| 201 | + ['version' => 4740000, 'path' => 'keep', 'size' => 1], |
|
| 202 | + // final slice starts at 2408000 keep one version every 604800 secons |
|
| 203 | + ['version' => 2408000, 'path' => 'keep', 'size' => 1], |
|
| 204 | + ['version' => 1803201, 'path' => 'delete', 'size' => 1], |
|
| 205 | + ['version' => 1803200, 'path' => 'keep', 'size' => 1], |
|
| 206 | + ['version' => 1800199, 'path' => 'delete', 'size' => 1], |
|
| 207 | + ['version' => 1800100, 'path' => 'delete', 'size' => 1], |
|
| 208 | + ['version' => 1198300, 'path' => 'keep', 'size' => 1], |
|
| 209 | + ], |
|
| 210 | + 16 // size of all deleted files (every file has the size 1) |
|
| 211 | + ], |
|
| 212 | + // second set of versions, here we have only really old versions |
|
| 213 | + [ |
|
| 214 | + [ |
|
| 215 | + // first slice (10sec) keep one version every 2 seconds |
|
| 216 | + // next slice (60sec) starts at 4999990 keep one version every 10 secons |
|
| 217 | + // next slice (3600sec) start at 4999940 keep one version every 60 seconds |
|
| 218 | + // next slice (86400sec) start at 4996400 keep one version every 3600 seconds |
|
| 219 | + ['version' => 4996400, 'path' => 'keep', 'size' => 1], |
|
| 220 | + ['version' => 4996350, 'path' => 'delete', 'size' => 1], |
|
| 221 | + ['version' => 4996350, 'path' => 'delete', 'size' => 1], |
|
| 222 | + ['version' => 4992800, 'path' => 'keep', 'size' => 1], |
|
| 223 | + ['version' => 4989800, 'path' => 'delete', 'size' => 1], |
|
| 224 | + ['version' => 4989700, 'path' => 'delete', 'size' => 1], |
|
| 225 | + ['version' => 4989200, 'path' => 'keep', 'size' => 1], |
|
| 226 | + // next slice (2592000sec) start at 4913600 keep one version every 86400 seconds |
|
| 227 | + ['version' => 4913600, 'path' => 'keep', 'size' => 1], |
|
| 228 | + ['version' => 4852800, 'path' => 'delete', 'size' => 1], |
|
| 229 | + ['version' => 4827201, 'path' => 'delete', 'size' => 1], |
|
| 230 | + ['version' => 4827200, 'path' => 'keep', 'size' => 1], |
|
| 231 | + ['version' => 4777201, 'path' => 'delete', 'size' => 1], |
|
| 232 | + ['version' => 4777501, 'path' => 'delete', 'size' => 1], |
|
| 233 | + ['version' => 4740000, 'path' => 'keep', 'size' => 1], |
|
| 234 | + // final slice starts at 2408000 keep one version every 604800 secons |
|
| 235 | + ['version' => 2408000, 'path' => 'keep', 'size' => 1], |
|
| 236 | + ['version' => 1803201, 'path' => 'delete', 'size' => 1], |
|
| 237 | + ['version' => 1803200, 'path' => 'keep', 'size' => 1], |
|
| 238 | + ['version' => 1800199, 'path' => 'delete', 'size' => 1], |
|
| 239 | + ['version' => 1800100, 'path' => 'delete', 'size' => 1], |
|
| 240 | + ['version' => 1198300, 'path' => 'keep', 'size' => 1], |
|
| 241 | + ], |
|
| 242 | + 11 // size of all deleted files (every file has the size 1) |
|
| 243 | + ], |
|
| 244 | + // third set of versions, with some gaps between |
|
| 245 | + [ |
|
| 246 | + [ |
|
| 247 | + // first slice (10sec) keep one version every 2 seconds |
|
| 248 | + ['version' => 4999999, 'path' => 'keep', 'size' => 1], |
|
| 249 | + ['version' => 4999998, 'path' => 'delete', 'size' => 1], |
|
| 250 | + ['version' => 4999997, 'path' => 'keep', 'size' => 1], |
|
| 251 | + ['version' => 4999995, 'path' => 'keep', 'size' => 1], |
|
| 252 | + ['version' => 4999994, 'path' => 'delete', 'size' => 1], |
|
| 253 | + //next slice (60sec) starts at 4999990 keep one version every 10 secons |
|
| 254 | + ['version' => 4999988, 'path' => 'keep', 'size' => 1], |
|
| 255 | + ['version' => 4999978, 'path' => 'keep', 'size' => 1], |
|
| 256 | + //next slice (3600sec) start at 4999940 keep one version every 60 seconds |
|
| 257 | + // next slice (86400sec) start at 4996400 keep one version every 3600 seconds |
|
| 258 | + ['version' => 4989200, 'path' => 'keep', 'size' => 1], |
|
| 259 | + // next slice (2592000sec) start at 4913600 keep one version every 86400 seconds |
|
| 260 | + ['version' => 4913600, 'path' => 'keep', 'size' => 1], |
|
| 261 | + ['version' => 4852800, 'path' => 'delete', 'size' => 1], |
|
| 262 | + ['version' => 4827201, 'path' => 'delete', 'size' => 1], |
|
| 263 | + ['version' => 4827200, 'path' => 'keep', 'size' => 1], |
|
| 264 | + ['version' => 4777201, 'path' => 'delete', 'size' => 1], |
|
| 265 | + ['version' => 4777501, 'path' => 'delete', 'size' => 1], |
|
| 266 | + ['version' => 4740000, 'path' => 'keep', 'size' => 1], |
|
| 267 | + // final slice starts at 2408000 keep one version every 604800 secons |
|
| 268 | + ['version' => 2408000, 'path' => 'keep', 'size' => 1], |
|
| 269 | + ['version' => 1803201, 'path' => 'delete', 'size' => 1], |
|
| 270 | + ['version' => 1803200, 'path' => 'keep', 'size' => 1], |
|
| 271 | + ['version' => 1800199, 'path' => 'delete', 'size' => 1], |
|
| 272 | + ['version' => 1800100, 'path' => 'delete', 'size' => 1], |
|
| 273 | + ['version' => 1198300, 'path' => 'keep', 'size' => 1], |
|
| 274 | + ], |
|
| 275 | + 9 // size of all deleted files (every file has the size 1) |
|
| 276 | + ], |
|
| 277 | + // fourth set of versions: empty (see issue #19066) |
|
| 278 | + [ |
|
| 279 | + [], |
|
| 280 | + 0 |
|
| 281 | + ] |
|
| 282 | + |
|
| 283 | + ]; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + public function testRename(): void { |
|
| 287 | + Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 288 | + |
|
| 289 | + $t1 = time(); |
|
| 290 | + // second version is two weeks older, this way we make sure that no |
|
| 291 | + // version will be expired |
|
| 292 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 293 | + |
|
| 294 | + // create some versions |
|
| 295 | + $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 296 | + $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 297 | + $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 298 | + $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 299 | + |
|
| 300 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 301 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 302 | + |
|
| 303 | + // execute rename hook of versions app |
|
| 304 | + Filesystem::rename('test.txt', 'test2.txt'); |
|
| 305 | + |
|
| 306 | + $this->runCommands(); |
|
| 307 | + |
|
| 308 | + $this->assertFalse($this->rootView->file_exists($v1), 'version 1 of old file does not exist'); |
|
| 309 | + $this->assertFalse($this->rootView->file_exists($v2), 'version 2 of old file does not exist'); |
|
| 310 | + |
|
| 311 | + $this->assertTrue($this->rootView->file_exists($v1Renamed), 'version 1 of renamed file exists'); |
|
| 312 | + $this->assertTrue($this->rootView->file_exists($v2Renamed), 'version 2 of renamed file exists'); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + public function testRenameInSharedFolder(): void { |
|
| 316 | + Filesystem::mkdir('folder1'); |
|
| 317 | + Filesystem::mkdir('folder1/folder2'); |
|
| 318 | + Filesystem::file_put_contents('folder1/test.txt', 'test file'); |
|
| 319 | + |
|
| 320 | + $t1 = time(); |
|
| 321 | + // second version is two weeks older, this way we make sure that no |
|
| 322 | + // version will be expired |
|
| 323 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 324 | + |
|
| 325 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1'); |
|
| 326 | + // create some versions |
|
| 327 | + $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1; |
|
| 328 | + $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2; |
|
| 329 | + $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t1; |
|
| 330 | + $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t2; |
|
| 331 | + |
|
| 332 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 333 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 334 | + |
|
| 335 | + $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); |
|
| 336 | + $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 337 | + $share->setNode($node) |
|
| 338 | + ->setShareType(IShare::TYPE_USER) |
|
| 339 | + ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 340 | + ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 341 | + ->setPermissions(Constants::PERMISSION_ALL); |
|
| 342 | + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 343 | + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 344 | + |
|
| 345 | + self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 346 | + |
|
| 347 | + $this->assertTrue(Filesystem::file_exists('folder1/test.txt')); |
|
| 348 | + |
|
| 349 | + // execute rename hook of versions app |
|
| 350 | + Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt'); |
|
| 351 | + |
|
| 352 | + $this->runCommands(); |
|
| 353 | + |
|
| 354 | + self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 355 | + |
|
| 356 | + $this->assertFalse($this->rootView->file_exists($v1), 'version 1 of old file does not exist'); |
|
| 357 | + $this->assertFalse($this->rootView->file_exists($v2), 'version 2 of old file does not exist'); |
|
| 358 | + |
|
| 359 | + $this->assertTrue($this->rootView->file_exists($v1Renamed), 'version 1 of renamed file exists'); |
|
| 360 | + $this->assertTrue($this->rootView->file_exists($v2Renamed), 'version 2 of renamed file exists'); |
|
| 361 | + |
|
| 362 | + Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + public function testMoveFolder(): void { |
|
| 366 | + Filesystem::mkdir('folder1'); |
|
| 367 | + Filesystem::mkdir('folder2'); |
|
| 368 | + Filesystem::file_put_contents('folder1/test.txt', 'test file'); |
|
| 369 | + |
|
| 370 | + $t1 = time(); |
|
| 371 | + // second version is two weeks older, this way we make sure that no |
|
| 372 | + // version will be expired |
|
| 373 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 374 | + |
|
| 375 | + // create some versions |
|
| 376 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1'); |
|
| 377 | + $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1; |
|
| 378 | + $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2; |
|
| 379 | + $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t1; |
|
| 380 | + $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t2; |
|
| 381 | 381 | |
| 382 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 383 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 382 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 383 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 384 | 384 | |
| 385 | - // execute rename hook of versions app |
|
| 386 | - Filesystem::rename('folder1', 'folder2/folder1'); |
|
| 385 | + // execute rename hook of versions app |
|
| 386 | + Filesystem::rename('folder1', 'folder2/folder1'); |
|
| 387 | 387 | |
| 388 | - $this->runCommands(); |
|
| 388 | + $this->runCommands(); |
|
| 389 | 389 | |
| 390 | - $this->assertFalse($this->rootView->file_exists($v1)); |
|
| 391 | - $this->assertFalse($this->rootView->file_exists($v2)); |
|
| 390 | + $this->assertFalse($this->rootView->file_exists($v1)); |
|
| 391 | + $this->assertFalse($this->rootView->file_exists($v2)); |
|
| 392 | 392 | |
| 393 | - $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
|
| 394 | - $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
|
| 395 | - } |
|
| 393 | + $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
|
| 394 | + $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
|
| 395 | + } |
|
| 396 | 396 | |
| 397 | 397 | |
| 398 | - public function testMoveFileIntoSharedFolderAsRecipient(): void { |
|
| 399 | - Filesystem::mkdir('folder1'); |
|
| 400 | - $fileInfo = Filesystem::getFileInfo('folder1'); |
|
| 398 | + public function testMoveFileIntoSharedFolderAsRecipient(): void { |
|
| 399 | + Filesystem::mkdir('folder1'); |
|
| 400 | + $fileInfo = Filesystem::getFileInfo('folder1'); |
|
| 401 | 401 | |
| 402 | - $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); |
|
| 403 | - $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 404 | - $share->setNode($node) |
|
| 405 | - ->setShareType(IShare::TYPE_USER) |
|
| 406 | - ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 407 | - ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 408 | - ->setPermissions(Constants::PERMISSION_ALL); |
|
| 409 | - $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 410 | - Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 402 | + $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); |
|
| 403 | + $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 404 | + $share->setNode($node) |
|
| 405 | + ->setShareType(IShare::TYPE_USER) |
|
| 406 | + ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 407 | + ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 408 | + ->setPermissions(Constants::PERMISSION_ALL); |
|
| 409 | + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 410 | + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 411 | 411 | |
| 412 | - self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 413 | - $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; |
|
| 414 | - Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 412 | + self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 413 | + $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; |
|
| 414 | + Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 415 | 415 | |
| 416 | - $t1 = time(); |
|
| 417 | - // second version is two weeks older, this way we make sure that no |
|
| 418 | - // version will be expired |
|
| 419 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 416 | + $t1 = time(); |
|
| 417 | + // second version is two weeks older, this way we make sure that no |
|
| 418 | + // version will be expired |
|
| 419 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 420 | 420 | |
| 421 | - $this->rootView->mkdir($versionsFolder2); |
|
| 422 | - // create some versions |
|
| 423 | - $v1 = $versionsFolder2 . '/test.txt.v' . $t1; |
|
| 424 | - $v2 = $versionsFolder2 . '/test.txt.v' . $t2; |
|
| 421 | + $this->rootView->mkdir($versionsFolder2); |
|
| 422 | + // create some versions |
|
| 423 | + $v1 = $versionsFolder2 . '/test.txt.v' . $t1; |
|
| 424 | + $v2 = $versionsFolder2 . '/test.txt.v' . $t2; |
|
| 425 | 425 | |
| 426 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 427 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 426 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 427 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 428 | 428 | |
| 429 | - // move file into the shared folder as recipient |
|
| 430 | - Filesystem::rename('/test.txt', '/folder1/test.txt'); |
|
| 429 | + // move file into the shared folder as recipient |
|
| 430 | + Filesystem::rename('/test.txt', '/folder1/test.txt'); |
|
| 431 | 431 | |
| 432 | - $this->assertFalse($this->rootView->file_exists($v1)); |
|
| 433 | - $this->assertFalse($this->rootView->file_exists($v2)); |
|
| 432 | + $this->assertFalse($this->rootView->file_exists($v1)); |
|
| 433 | + $this->assertFalse($this->rootView->file_exists($v2)); |
|
| 434 | 434 | |
| 435 | - self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 435 | + self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 436 | 436 | |
| 437 | - $versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions'; |
|
| 437 | + $versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions'; |
|
| 438 | 438 | |
| 439 | - $v1Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t1; |
|
| 440 | - $v2Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t2; |
|
| 439 | + $v1Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t1; |
|
| 440 | + $v2Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t2; |
|
| 441 | 441 | |
| 442 | - $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
|
| 443 | - $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
|
| 442 | + $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
|
| 443 | + $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
|
| 444 | 444 | |
| 445 | - Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 446 | - } |
|
| 445 | + Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - public function testMoveFolderIntoSharedFolderAsRecipient(): void { |
|
| 449 | - Filesystem::mkdir('folder1'); |
|
| 448 | + public function testMoveFolderIntoSharedFolderAsRecipient(): void { |
|
| 449 | + Filesystem::mkdir('folder1'); |
|
| 450 | 450 | |
| 451 | - $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); |
|
| 452 | - $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 453 | - $share->setNode($node) |
|
| 454 | - ->setShareType(IShare::TYPE_USER) |
|
| 455 | - ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 456 | - ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 457 | - ->setPermissions(Constants::PERMISSION_ALL); |
|
| 458 | - $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 459 | - Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 451 | + $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); |
|
| 452 | + $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 453 | + $share->setNode($node) |
|
| 454 | + ->setShareType(IShare::TYPE_USER) |
|
| 455 | + ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 456 | + ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 457 | + ->setPermissions(Constants::PERMISSION_ALL); |
|
| 458 | + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 459 | + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 460 | 460 | |
| 461 | - self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 462 | - $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; |
|
| 463 | - Filesystem::mkdir('folder2'); |
|
| 464 | - Filesystem::file_put_contents('folder2/test.txt', 'test file'); |
|
| 461 | + self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 462 | + $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; |
|
| 463 | + Filesystem::mkdir('folder2'); |
|
| 464 | + Filesystem::file_put_contents('folder2/test.txt', 'test file'); |
|
| 465 | 465 | |
| 466 | - $t1 = time(); |
|
| 467 | - // second version is two weeks older, this way we make sure that no |
|
| 468 | - // version will be expired |
|
| 469 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 466 | + $t1 = time(); |
|
| 467 | + // second version is two weeks older, this way we make sure that no |
|
| 468 | + // version will be expired |
|
| 469 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 470 | 470 | |
| 471 | - $this->rootView->mkdir($versionsFolder2); |
|
| 472 | - $this->rootView->mkdir($versionsFolder2 . '/folder2'); |
|
| 473 | - // create some versions |
|
| 474 | - $v1 = $versionsFolder2 . '/folder2/test.txt.v' . $t1; |
|
| 475 | - $v2 = $versionsFolder2 . '/folder2/test.txt.v' . $t2; |
|
| 471 | + $this->rootView->mkdir($versionsFolder2); |
|
| 472 | + $this->rootView->mkdir($versionsFolder2 . '/folder2'); |
|
| 473 | + // create some versions |
|
| 474 | + $v1 = $versionsFolder2 . '/folder2/test.txt.v' . $t1; |
|
| 475 | + $v2 = $versionsFolder2 . '/folder2/test.txt.v' . $t2; |
|
| 476 | 476 | |
| 477 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 478 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 477 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 478 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 479 | 479 | |
| 480 | - // move file into the shared folder as recipient |
|
| 481 | - Filesystem::rename('/folder2', '/folder1/folder2'); |
|
| 480 | + // move file into the shared folder as recipient |
|
| 481 | + Filesystem::rename('/folder2', '/folder1/folder2'); |
|
| 482 | 482 | |
| 483 | - $this->assertFalse($this->rootView->file_exists($v1)); |
|
| 484 | - $this->assertFalse($this->rootView->file_exists($v2)); |
|
| 483 | + $this->assertFalse($this->rootView->file_exists($v1)); |
|
| 484 | + $this->assertFalse($this->rootView->file_exists($v2)); |
|
| 485 | 485 | |
| 486 | - self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 486 | + self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 487 | 487 | |
| 488 | - $versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions'; |
|
| 488 | + $versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions'; |
|
| 489 | 489 | |
| 490 | - $v1Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t1; |
|
| 491 | - $v2Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t2; |
|
| 490 | + $v1Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t1; |
|
| 491 | + $v2Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t2; |
|
| 492 | 492 | |
| 493 | - $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
|
| 494 | - $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
|
| 493 | + $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
|
| 494 | + $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
|
| 495 | 495 | |
| 496 | - Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 497 | - } |
|
| 496 | + Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - public function testRenameSharedFile(): void { |
|
| 500 | - Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 499 | + public function testRenameSharedFile(): void { |
|
| 500 | + Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 501 | 501 | |
| 502 | - $t1 = time(); |
|
| 503 | - // second version is two weeks older, this way we make sure that no |
|
| 504 | - // version will be expired |
|
| 505 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 502 | + $t1 = time(); |
|
| 503 | + // second version is two weeks older, this way we make sure that no |
|
| 504 | + // version will be expired |
|
| 505 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 506 | 506 | |
| 507 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT); |
|
| 508 | - // create some versions |
|
| 509 | - $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 510 | - $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 511 | - // the renamed versions should not exist! Because we only moved the mount point! |
|
| 512 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 513 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 507 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT); |
|
| 508 | + // create some versions |
|
| 509 | + $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 510 | + $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 511 | + // the renamed versions should not exist! Because we only moved the mount point! |
|
| 512 | + $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 513 | + $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 514 | 514 | |
| 515 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 516 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 515 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 516 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 517 | 517 | |
| 518 | - $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt'); |
|
| 519 | - $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 520 | - $share->setNode($node) |
|
| 521 | - ->setShareType(IShare::TYPE_USER) |
|
| 522 | - ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 523 | - ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 524 | - ->setPermissions(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE); |
|
| 525 | - $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 526 | - Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 518 | + $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt'); |
|
| 519 | + $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 520 | + $share->setNode($node) |
|
| 521 | + ->setShareType(IShare::TYPE_USER) |
|
| 522 | + ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 523 | + ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 524 | + ->setPermissions(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE); |
|
| 525 | + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 526 | + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 527 | 527 | |
| 528 | - self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 528 | + self::loginHelper(self::TEST_VERSIONS_USER2); |
|
| 529 | 529 | |
| 530 | - $this->assertTrue(Filesystem::file_exists('test.txt')); |
|
| 530 | + $this->assertTrue(Filesystem::file_exists('test.txt')); |
|
| 531 | 531 | |
| 532 | - // execute rename hook of versions app |
|
| 533 | - Filesystem::rename('test.txt', 'test2.txt'); |
|
| 532 | + // execute rename hook of versions app |
|
| 533 | + Filesystem::rename('test.txt', 'test2.txt'); |
|
| 534 | 534 | |
| 535 | - self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 535 | + self::loginHelper(self::TEST_VERSIONS_USER); |
|
| 536 | 536 | |
| 537 | - $this->runCommands(); |
|
| 537 | + $this->runCommands(); |
|
| 538 | 538 | |
| 539 | - $this->assertTrue($this->rootView->file_exists($v1)); |
|
| 540 | - $this->assertTrue($this->rootView->file_exists($v2)); |
|
| 539 | + $this->assertTrue($this->rootView->file_exists($v1)); |
|
| 540 | + $this->assertTrue($this->rootView->file_exists($v2)); |
|
| 541 | 541 | |
| 542 | - $this->assertFalse($this->rootView->file_exists($v1Renamed)); |
|
| 543 | - $this->assertFalse($this->rootView->file_exists($v2Renamed)); |
|
| 542 | + $this->assertFalse($this->rootView->file_exists($v1Renamed)); |
|
| 543 | + $this->assertFalse($this->rootView->file_exists($v2Renamed)); |
|
| 544 | 544 | |
| 545 | - Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 546 | - } |
|
| 545 | + Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 546 | + } |
|
| 547 | 547 | |
| 548 | - public function testCopy(): void { |
|
| 549 | - Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 548 | + public function testCopy(): void { |
|
| 549 | + Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 550 | 550 | |
| 551 | - $t1 = time(); |
|
| 552 | - // second version is two weeks older, this way we make sure that no |
|
| 553 | - // version will be expired |
|
| 554 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 551 | + $t1 = time(); |
|
| 552 | + // second version is two weeks older, this way we make sure that no |
|
| 553 | + // version will be expired |
|
| 554 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 555 | 555 | |
| 556 | - // create some versions |
|
| 557 | - $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 558 | - $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 559 | - $v1Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 560 | - $v2Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 556 | + // create some versions |
|
| 557 | + $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 558 | + $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 559 | + $v1Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 560 | + $v2Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 561 | 561 | |
| 562 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 563 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 562 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 563 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 564 | 564 | |
| 565 | - // execute copy hook of versions app |
|
| 566 | - Filesystem::copy('test.txt', 'test2.txt'); |
|
| 565 | + // execute copy hook of versions app |
|
| 566 | + Filesystem::copy('test.txt', 'test2.txt'); |
|
| 567 | 567 | |
| 568 | - $this->runCommands(); |
|
| 568 | + $this->runCommands(); |
|
| 569 | 569 | |
| 570 | - $this->assertTrue($this->rootView->file_exists($v1), 'version 1 of original file exists'); |
|
| 571 | - $this->assertTrue($this->rootView->file_exists($v2), 'version 2 of original file exists'); |
|
| 570 | + $this->assertTrue($this->rootView->file_exists($v1), 'version 1 of original file exists'); |
|
| 571 | + $this->assertTrue($this->rootView->file_exists($v2), 'version 2 of original file exists'); |
|
| 572 | 572 | |
| 573 | - $this->assertTrue($this->rootView->file_exists($v1Copied), 'version 1 of copied file exists'); |
|
| 574 | - $this->assertTrue($this->rootView->file_exists($v2Copied), 'version 2 of copied file exists'); |
|
| 575 | - } |
|
| 573 | + $this->assertTrue($this->rootView->file_exists($v1Copied), 'version 1 of copied file exists'); |
|
| 574 | + $this->assertTrue($this->rootView->file_exists($v2Copied), 'version 2 of copied file exists'); |
|
| 575 | + } |
|
| 576 | 576 | |
| 577 | - /** |
|
| 578 | - * test if we find all versions and if the versions array contain |
|
| 579 | - * the correct 'path' and 'name' |
|
| 580 | - */ |
|
| 581 | - public function testGetVersions(): void { |
|
| 582 | - $t1 = time(); |
|
| 583 | - // second version is two weeks older, this way we make sure that no |
|
| 584 | - // version will be expired |
|
| 585 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 577 | + /** |
|
| 578 | + * test if we find all versions and if the versions array contain |
|
| 579 | + * the correct 'path' and 'name' |
|
| 580 | + */ |
|
| 581 | + public function testGetVersions(): void { |
|
| 582 | + $t1 = time(); |
|
| 583 | + // second version is two weeks older, this way we make sure that no |
|
| 584 | + // version will be expired |
|
| 585 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 586 | 586 | |
| 587 | - // create some versions |
|
| 588 | - $v1 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t1; |
|
| 589 | - $v2 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t2; |
|
| 587 | + // create some versions |
|
| 588 | + $v1 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t1; |
|
| 589 | + $v2 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t2; |
|
| 590 | 590 | |
| 591 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/subfolder/'); |
|
| 591 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/subfolder/'); |
|
| 592 | 592 | |
| 593 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 594 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 593 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 594 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 595 | 595 | |
| 596 | - // execute copy hook of versions app |
|
| 597 | - $versions = Storage::getVersions(self::TEST_VERSIONS_USER, '/subfolder/test.txt'); |
|
| 596 | + // execute copy hook of versions app |
|
| 597 | + $versions = Storage::getVersions(self::TEST_VERSIONS_USER, '/subfolder/test.txt'); |
|
| 598 | 598 | |
| 599 | - $this->assertCount(2, $versions); |
|
| 599 | + $this->assertCount(2, $versions); |
|
| 600 | 600 | |
| 601 | - foreach ($versions as $version) { |
|
| 602 | - $this->assertSame('/subfolder/test.txt', $version['path']); |
|
| 603 | - $this->assertSame('test.txt', $version['name']); |
|
| 604 | - } |
|
| 601 | + foreach ($versions as $version) { |
|
| 602 | + $this->assertSame('/subfolder/test.txt', $version['path']); |
|
| 603 | + $this->assertSame('test.txt', $version['name']); |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - //cleanup |
|
| 607 | - $this->rootView->deleteAll(self::USERS_VERSIONS_ROOT . '/subfolder'); |
|
| 608 | - } |
|
| 606 | + //cleanup |
|
| 607 | + $this->rootView->deleteAll(self::USERS_VERSIONS_ROOT . '/subfolder'); |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | - /** |
|
| 611 | - * test if we find all versions and if the versions array contain |
|
| 612 | - * the correct 'path' and 'name' |
|
| 613 | - */ |
|
| 614 | - public function testGetVersionsEmptyFile(): void { |
|
| 615 | - // execute copy hook of versions app |
|
| 616 | - $versions = Storage::getVersions(self::TEST_VERSIONS_USER, ''); |
|
| 617 | - $this->assertCount(0, $versions); |
|
| 610 | + /** |
|
| 611 | + * test if we find all versions and if the versions array contain |
|
| 612 | + * the correct 'path' and 'name' |
|
| 613 | + */ |
|
| 614 | + public function testGetVersionsEmptyFile(): void { |
|
| 615 | + // execute copy hook of versions app |
|
| 616 | + $versions = Storage::getVersions(self::TEST_VERSIONS_USER, ''); |
|
| 617 | + $this->assertCount(0, $versions); |
|
| 618 | 618 | |
| 619 | - $versions = Storage::getVersions(self::TEST_VERSIONS_USER, null); |
|
| 620 | - $this->assertCount(0, $versions); |
|
| 621 | - } |
|
| 619 | + $versions = Storage::getVersions(self::TEST_VERSIONS_USER, null); |
|
| 620 | + $this->assertCount(0, $versions); |
|
| 621 | + } |
|
| 622 | 622 | |
| 623 | - public function testExpireNonexistingFile(): void { |
|
| 624 | - $this->logout(); |
|
| 625 | - // needed to have a FS setup (the background job does this) |
|
| 626 | - \OC_Util::setupFS(self::TEST_VERSIONS_USER); |
|
| 623 | + public function testExpireNonexistingFile(): void { |
|
| 624 | + $this->logout(); |
|
| 625 | + // needed to have a FS setup (the background job does this) |
|
| 626 | + \OC_Util::setupFS(self::TEST_VERSIONS_USER); |
|
| 627 | 627 | |
| 628 | - $this->assertFalse(Storage::expire('/void/unexist.txt', self::TEST_VERSIONS_USER)); |
|
| 629 | - } |
|
| 628 | + $this->assertFalse(Storage::expire('/void/unexist.txt', self::TEST_VERSIONS_USER)); |
|
| 629 | + } |
|
| 630 | 630 | |
| 631 | 631 | |
| 632 | - public function testExpireNonexistingUser(): void { |
|
| 633 | - $this->expectException(NoUserException::class); |
|
| 632 | + public function testExpireNonexistingUser(): void { |
|
| 633 | + $this->expectException(NoUserException::class); |
|
| 634 | 634 | |
| 635 | - $this->logout(); |
|
| 636 | - // needed to have a FS setup (the background job does this) |
|
| 637 | - \OC_Util::setupFS(self::TEST_VERSIONS_USER); |
|
| 638 | - Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 635 | + $this->logout(); |
|
| 636 | + // needed to have a FS setup (the background job does this) |
|
| 637 | + \OC_Util::setupFS(self::TEST_VERSIONS_USER); |
|
| 638 | + Filesystem::file_put_contents('test.txt', 'test file'); |
|
| 639 | 639 | |
| 640 | - $this->assertFalse(Storage::expire('test.txt', 'unexist')); |
|
| 641 | - } |
|
| 640 | + $this->assertFalse(Storage::expire('test.txt', 'unexist')); |
|
| 641 | + } |
|
| 642 | 642 | |
| 643 | - public function testRestoreSameStorage(): void { |
|
| 644 | - Filesystem::mkdir('sub'); |
|
| 645 | - $this->doTestRestore(); |
|
| 646 | - } |
|
| 643 | + public function testRestoreSameStorage(): void { |
|
| 644 | + Filesystem::mkdir('sub'); |
|
| 645 | + $this->doTestRestore(); |
|
| 646 | + } |
|
| 647 | 647 | |
| 648 | - public function testRestoreCrossStorage(): void { |
|
| 649 | - $storage2 = new Temporary([]); |
|
| 650 | - Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER . '/files/sub'); |
|
| 648 | + public function testRestoreCrossStorage(): void { |
|
| 649 | + $storage2 = new Temporary([]); |
|
| 650 | + Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER . '/files/sub'); |
|
| 651 | 651 | |
| 652 | - $this->doTestRestore(); |
|
| 653 | - } |
|
| 652 | + $this->doTestRestore(); |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | - public function testRestoreNoPermission(): void { |
|
| 656 | - $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 655 | + public function testRestoreNoPermission(): void { |
|
| 656 | + $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 657 | 657 | |
| 658 | - $userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER); |
|
| 659 | - $node = $userHome->newFolder('folder'); |
|
| 660 | - $file = $node->newFile('test.txt'); |
|
| 658 | + $userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER); |
|
| 659 | + $node = $userHome->newFolder('folder'); |
|
| 660 | + $file = $node->newFile('test.txt'); |
|
| 661 | 661 | |
| 662 | - $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 663 | - $share->setNode($node) |
|
| 664 | - ->setShareType(IShare::TYPE_USER) |
|
| 665 | - ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 666 | - ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 667 | - ->setPermissions(Constants::PERMISSION_READ); |
|
| 668 | - $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 669 | - Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 670 | - |
|
| 671 | - $versions = $this->createAndCheckVersions( |
|
| 672 | - Filesystem::getView(), |
|
| 673 | - 'folder/test.txt' |
|
| 674 | - ); |
|
| 675 | - |
|
| 676 | - $file->putContent('test file'); |
|
| 677 | - |
|
| 678 | - $this->loginAsUser(self::TEST_VERSIONS_USER2); |
|
| 662 | + $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 663 | + $share->setNode($node) |
|
| 664 | + ->setShareType(IShare::TYPE_USER) |
|
| 665 | + ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 666 | + ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 667 | + ->setPermissions(Constants::PERMISSION_READ); |
|
| 668 | + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 669 | + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 670 | + |
|
| 671 | + $versions = $this->createAndCheckVersions( |
|
| 672 | + Filesystem::getView(), |
|
| 673 | + 'folder/test.txt' |
|
| 674 | + ); |
|
| 675 | + |
|
| 676 | + $file->putContent('test file'); |
|
| 677 | + |
|
| 678 | + $this->loginAsUser(self::TEST_VERSIONS_USER2); |
|
| 679 | 679 | |
| 680 | - $firstVersion = current($versions); |
|
| 680 | + $firstVersion = current($versions); |
|
| 681 | 681 | |
| 682 | - $this->assertFalse(Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user2), 'Revert did not happen'); |
|
| 682 | + $this->assertFalse(Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user2), 'Revert did not happen'); |
|
| 683 | 683 | |
| 684 | - $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 684 | + $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 685 | 685 | |
| 686 | - Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 687 | - $this->assertEquals('test file', $file->getContent(), 'File content has not changed'); |
|
| 688 | - } |
|
| 686 | + Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 687 | + $this->assertEquals('test file', $file->getContent(), 'File content has not changed'); |
|
| 688 | + } |
|
| 689 | 689 | |
| 690 | - public function testRestoreMovedShare(): void { |
|
| 691 | - $this->markTestSkipped('Unreliable test'); |
|
| 692 | - $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 693 | - |
|
| 694 | - $userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER); |
|
| 695 | - $node = $userHome->newFolder('folder'); |
|
| 696 | - $file = $node->newFile('test.txt'); |
|
| 697 | - |
|
| 698 | - $userHome2 = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER2); |
|
| 699 | - $userHome2->newFolder('subfolder'); |
|
| 700 | - |
|
| 701 | - $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 702 | - $share->setNode($node) |
|
| 703 | - ->setShareType(IShare::TYPE_USER) |
|
| 704 | - ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 705 | - ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 706 | - ->setPermissions(Constants::PERMISSION_ALL); |
|
| 707 | - $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 708 | - $shareManager = Server::get(\OCP\Share\IManager::class); |
|
| 709 | - $shareManager->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 710 | - |
|
| 711 | - $share->setTarget('subfolder/folder'); |
|
| 712 | - $shareManager->moveShare($share, self::TEST_VERSIONS_USER2); |
|
| 713 | - |
|
| 714 | - $versions = $this->createAndCheckVersions( |
|
| 715 | - Filesystem::getView(), |
|
| 716 | - 'folder/test.txt' |
|
| 717 | - ); |
|
| 718 | - |
|
| 719 | - $file->putContent('test file'); |
|
| 720 | - |
|
| 721 | - $this->loginAsUser(self::TEST_VERSIONS_USER2); |
|
| 722 | - |
|
| 723 | - $firstVersion = current($versions); |
|
| 724 | - |
|
| 725 | - $this->assertTrue(Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user1)); |
|
| 726 | - |
|
| 727 | - $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 728 | - |
|
| 729 | - Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 730 | - $this->assertEquals('version 2', $file->getContent(), 'File content has not changed'); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * @param string $hookName name of hook called |
|
| 735 | - * @param string $params variable to receive parameters provided by hook |
|
| 736 | - */ |
|
| 737 | - private function connectMockHooks($hookName, &$params) { |
|
| 738 | - if ($hookName === null) { |
|
| 739 | - return; |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - $eventHandler = $this->getMockBuilder(\stdclass::class) |
|
| 743 | - ->setMethods(['callback']) |
|
| 744 | - ->getMock(); |
|
| 745 | - |
|
| 746 | - $eventHandler->expects($this->any()) |
|
| 747 | - ->method('callback') |
|
| 748 | - ->willReturnCallback( |
|
| 749 | - function ($p) use (&$params): void { |
|
| 750 | - $params = $p; |
|
| 751 | - } |
|
| 752 | - ); |
|
| 753 | - |
|
| 754 | - Util::connectHook( |
|
| 755 | - '\OCP\Versions', |
|
| 756 | - $hookName, |
|
| 757 | - $eventHandler, |
|
| 758 | - 'callback' |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - private function doTestRestore() { |
|
| 763 | - $filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt'; |
|
| 764 | - $this->rootView->file_put_contents($filePath, 'test file'); |
|
| 765 | - |
|
| 766 | - $fileInfo = $this->rootView->getFileInfo($filePath); |
|
| 767 | - $t0 = $this->rootView->filemtime($filePath); |
|
| 768 | - |
|
| 769 | - // not exactly the same timestamp as the file |
|
| 770 | - $t1 = time() - 60; |
|
| 771 | - // second version is two weeks older |
|
| 772 | - $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 773 | - |
|
| 774 | - // create some versions |
|
| 775 | - $v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1; |
|
| 776 | - $v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2; |
|
| 777 | - |
|
| 778 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub'); |
|
| 779 | - |
|
| 780 | - $this->rootView->file_put_contents($v1, 'version1'); |
|
| 781 | - $fileInfoV1 = $this->rootView->getFileInfo($v1); |
|
| 782 | - $versionEntity = new VersionEntity(); |
|
| 783 | - $versionEntity->setFileId($fileInfo->getId()); |
|
| 784 | - $versionEntity->setTimestamp($t1); |
|
| 785 | - $versionEntity->setSize($fileInfoV1->getSize()); |
|
| 786 | - $versionEntity->setMimetype($this->mimeTypeLoader->getId($fileInfoV1->getMimetype())); |
|
| 787 | - $versionEntity->setMetadata([]); |
|
| 788 | - $this->versionsMapper->insert($versionEntity); |
|
| 789 | - |
|
| 790 | - $this->rootView->file_put_contents($v2, 'version2'); |
|
| 791 | - $fileInfoV2 = $this->rootView->getFileInfo($v2); |
|
| 792 | - $versionEntity = new VersionEntity(); |
|
| 793 | - $versionEntity->setFileId($fileInfo->getId()); |
|
| 794 | - $versionEntity->setTimestamp($t2); |
|
| 795 | - $versionEntity->setSize($fileInfoV2->getSize()); |
|
| 796 | - $versionEntity->setMimetype($this->mimeTypeLoader->getId($fileInfoV2->getMimetype())); |
|
| 797 | - $versionEntity->setMetadata([]); |
|
| 798 | - $this->versionsMapper->insert($versionEntity); |
|
| 799 | - |
|
| 800 | - $oldVersions = Storage::getVersions( |
|
| 801 | - self::TEST_VERSIONS_USER, '/sub/test.txt' |
|
| 802 | - ); |
|
| 803 | - |
|
| 804 | - $this->assertCount(2, $oldVersions); |
|
| 805 | - |
|
| 806 | - $this->assertEquals('test file', $this->rootView->file_get_contents($filePath)); |
|
| 807 | - $info1 = $this->rootView->getFileInfo($filePath); |
|
| 808 | - |
|
| 809 | - $eventDispatcher = Server::get(IEventDispatcher::class); |
|
| 810 | - $eventFired = false; |
|
| 811 | - $eventDispatcher->addListener(VersionRestoredEvent::class, function ($event) use (&$eventFired, $t2) { |
|
| 812 | - $eventFired = true; |
|
| 813 | - $this->assertEquals('/sub/test.txt', $event->getVersion()->getVersionPath()); |
|
| 814 | - $this->assertTrue($event->getVersion()->getRevisionId() > 0); |
|
| 815 | - }); |
|
| 816 | - |
|
| 817 | - $versionManager = Server::get(IVersionManager::class); |
|
| 818 | - $versions = $versionManager->getVersionsForFile($this->user1, $info1); |
|
| 819 | - $version = array_filter($versions, function ($version) use ($t2) { |
|
| 820 | - return $version->getRevisionId() === $t2; |
|
| 821 | - }); |
|
| 822 | - $this->assertTrue($versionManager->rollback(current($version))); |
|
| 823 | - |
|
| 824 | - $this->assertTrue($eventFired, 'VersionRestoredEvent was not fired'); |
|
| 825 | - |
|
| 826 | - $this->assertEquals('version2', $this->rootView->file_get_contents($filePath)); |
|
| 827 | - $info2 = $this->rootView->getFileInfo($filePath); |
|
| 828 | - |
|
| 829 | - $this->assertNotEquals( |
|
| 830 | - $info2['etag'], |
|
| 831 | - $info1['etag'], |
|
| 832 | - 'Etag must change after rolling back version' |
|
| 833 | - ); |
|
| 834 | - $this->assertEquals( |
|
| 835 | - $info2['fileid'], |
|
| 836 | - $info1['fileid'], |
|
| 837 | - 'File id must not change after rolling back version' |
|
| 838 | - ); |
|
| 839 | - $this->assertEquals( |
|
| 840 | - $info2['mtime'], |
|
| 841 | - $t2, |
|
| 842 | - 'Restored file has mtime from version' |
|
| 843 | - ); |
|
| 844 | - |
|
| 845 | - $newVersions = Storage::getVersions( |
|
| 846 | - self::TEST_VERSIONS_USER, '/sub/test.txt' |
|
| 847 | - ); |
|
| 848 | - |
|
| 849 | - $this->assertTrue( |
|
| 850 | - $this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0), |
|
| 851 | - 'A version file was created for the file before restoration' |
|
| 852 | - ); |
|
| 853 | - $this->assertTrue( |
|
| 854 | - $this->rootView->file_exists($v1), |
|
| 855 | - 'Untouched version file is still there' |
|
| 856 | - ); |
|
| 857 | - $this->assertFalse( |
|
| 858 | - $this->rootView->file_exists($v2), |
|
| 859 | - 'Restored version file gone from files_version folder' |
|
| 860 | - ); |
|
| 861 | - |
|
| 862 | - $this->assertCount(2, $newVersions, 'Additional version created'); |
|
| 863 | - |
|
| 864 | - $this->assertTrue( |
|
| 865 | - isset($newVersions[$t0 . '#' . 'test.txt']), |
|
| 866 | - 'A version was created for the file before restoration' |
|
| 867 | - ); |
|
| 868 | - $this->assertTrue( |
|
| 869 | - isset($newVersions[$t1 . '#' . 'test.txt']), |
|
| 870 | - 'Untouched version is still there' |
|
| 871 | - ); |
|
| 872 | - $this->assertFalse( |
|
| 873 | - isset($newVersions[$t2 . '#' . 'test.txt']), |
|
| 874 | - 'Restored version is not in the list any more' |
|
| 875 | - ); |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * Test whether versions are created when overwriting as owner |
|
| 880 | - */ |
|
| 881 | - public function testStoreVersionAsOwner(): void { |
|
| 882 | - $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 883 | - |
|
| 884 | - $this->createAndCheckVersions( |
|
| 885 | - Filesystem::getView(), |
|
| 886 | - 'test.txt' |
|
| 887 | - ); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * Test whether versions are created when overwriting as share recipient |
|
| 892 | - */ |
|
| 893 | - public function testStoreVersionAsRecipient(): void { |
|
| 894 | - $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 895 | - |
|
| 896 | - Filesystem::mkdir('folder'); |
|
| 897 | - Filesystem::file_put_contents('folder/test.txt', 'test file'); |
|
| 898 | - |
|
| 899 | - $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder'); |
|
| 900 | - $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 901 | - $share->setNode($node) |
|
| 902 | - ->setShareType(IShare::TYPE_USER) |
|
| 903 | - ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 904 | - ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 905 | - ->setPermissions(Constants::PERMISSION_ALL); |
|
| 906 | - $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 907 | - Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 908 | - |
|
| 909 | - $this->loginAsUser(self::TEST_VERSIONS_USER2); |
|
| 910 | - |
|
| 911 | - $this->createAndCheckVersions( |
|
| 912 | - Filesystem::getView(), |
|
| 913 | - 'folder/test.txt' |
|
| 914 | - ); |
|
| 915 | - |
|
| 916 | - Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * Test whether versions are created when overwriting anonymously. |
|
| 921 | - * |
|
| 922 | - * When uploading through a public link or publicwebdav, no user |
|
| 923 | - * is logged in. File modification must still be able to find |
|
| 924 | - * the owner and create versions. |
|
| 925 | - */ |
|
| 926 | - public function testStoreVersionAsAnonymous(): void { |
|
| 927 | - $this->logout(); |
|
| 928 | - |
|
| 929 | - // note: public link upload does this, |
|
| 930 | - // needed to make the hooks fire |
|
| 931 | - \OC_Util::setupFS(self::TEST_VERSIONS_USER); |
|
| 932 | - |
|
| 933 | - $userView = new View('/' . self::TEST_VERSIONS_USER . '/files'); |
|
| 934 | - $this->createAndCheckVersions( |
|
| 935 | - $userView, |
|
| 936 | - 'test.txt' |
|
| 937 | - ); |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * @param View $view |
|
| 942 | - * @param string $path |
|
| 943 | - */ |
|
| 944 | - private function createAndCheckVersions(View $view, $path) { |
|
| 945 | - $view->file_put_contents($path, 'test file'); |
|
| 946 | - $view->file_put_contents($path, 'version 1'); |
|
| 947 | - $view->file_put_contents($path, 'version 2'); |
|
| 948 | - |
|
| 949 | - $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 950 | - |
|
| 951 | - // need to scan for the versions |
|
| 952 | - [$rootStorage,] = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions'); |
|
| 953 | - $rootStorage->getScanner()->scan('files_versions'); |
|
| 954 | - |
|
| 955 | - $versions = Storage::getVersions( |
|
| 956 | - self::TEST_VERSIONS_USER, '/' . $path |
|
| 957 | - ); |
|
| 958 | - |
|
| 959 | - // note: we cannot predict how many versions are created due to |
|
| 960 | - // test run timing |
|
| 961 | - $this->assertGreaterThan(0, count($versions)); |
|
| 962 | - |
|
| 963 | - return $versions; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * @param string $user |
|
| 968 | - * @param bool $create |
|
| 969 | - */ |
|
| 970 | - public static function loginHelper($user, $create = false) { |
|
| 971 | - if ($create) { |
|
| 972 | - $backend = new \Test\Util\User\Dummy(); |
|
| 973 | - $backend->createUser($user, $user); |
|
| 974 | - Server::get(IUserManager::class)->registerBackend($backend); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - \OC_Util::tearDownFS(); |
|
| 978 | - \OC_User::setUserId(''); |
|
| 979 | - Filesystem::tearDown(); |
|
| 980 | - \OC_User::setUserId($user); |
|
| 981 | - \OC_Util::setupFS($user); |
|
| 982 | - \OC::$server->getUserFolder($user); |
|
| 983 | - } |
|
| 690 | + public function testRestoreMovedShare(): void { |
|
| 691 | + $this->markTestSkipped('Unreliable test'); |
|
| 692 | + $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 693 | + |
|
| 694 | + $userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER); |
|
| 695 | + $node = $userHome->newFolder('folder'); |
|
| 696 | + $file = $node->newFile('test.txt'); |
|
| 697 | + |
|
| 698 | + $userHome2 = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER2); |
|
| 699 | + $userHome2->newFolder('subfolder'); |
|
| 700 | + |
|
| 701 | + $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 702 | + $share->setNode($node) |
|
| 703 | + ->setShareType(IShare::TYPE_USER) |
|
| 704 | + ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 705 | + ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 706 | + ->setPermissions(Constants::PERMISSION_ALL); |
|
| 707 | + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 708 | + $shareManager = Server::get(\OCP\Share\IManager::class); |
|
| 709 | + $shareManager->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 710 | + |
|
| 711 | + $share->setTarget('subfolder/folder'); |
|
| 712 | + $shareManager->moveShare($share, self::TEST_VERSIONS_USER2); |
|
| 713 | + |
|
| 714 | + $versions = $this->createAndCheckVersions( |
|
| 715 | + Filesystem::getView(), |
|
| 716 | + 'folder/test.txt' |
|
| 717 | + ); |
|
| 718 | + |
|
| 719 | + $file->putContent('test file'); |
|
| 720 | + |
|
| 721 | + $this->loginAsUser(self::TEST_VERSIONS_USER2); |
|
| 722 | + |
|
| 723 | + $firstVersion = current($versions); |
|
| 724 | + |
|
| 725 | + $this->assertTrue(Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user1)); |
|
| 726 | + |
|
| 727 | + $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 728 | + |
|
| 729 | + Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 730 | + $this->assertEquals('version 2', $file->getContent(), 'File content has not changed'); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * @param string $hookName name of hook called |
|
| 735 | + * @param string $params variable to receive parameters provided by hook |
|
| 736 | + */ |
|
| 737 | + private function connectMockHooks($hookName, &$params) { |
|
| 738 | + if ($hookName === null) { |
|
| 739 | + return; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + $eventHandler = $this->getMockBuilder(\stdclass::class) |
|
| 743 | + ->setMethods(['callback']) |
|
| 744 | + ->getMock(); |
|
| 745 | + |
|
| 746 | + $eventHandler->expects($this->any()) |
|
| 747 | + ->method('callback') |
|
| 748 | + ->willReturnCallback( |
|
| 749 | + function ($p) use (&$params): void { |
|
| 750 | + $params = $p; |
|
| 751 | + } |
|
| 752 | + ); |
|
| 753 | + |
|
| 754 | + Util::connectHook( |
|
| 755 | + '\OCP\Versions', |
|
| 756 | + $hookName, |
|
| 757 | + $eventHandler, |
|
| 758 | + 'callback' |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + private function doTestRestore() { |
|
| 763 | + $filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt'; |
|
| 764 | + $this->rootView->file_put_contents($filePath, 'test file'); |
|
| 765 | + |
|
| 766 | + $fileInfo = $this->rootView->getFileInfo($filePath); |
|
| 767 | + $t0 = $this->rootView->filemtime($filePath); |
|
| 768 | + |
|
| 769 | + // not exactly the same timestamp as the file |
|
| 770 | + $t1 = time() - 60; |
|
| 771 | + // second version is two weeks older |
|
| 772 | + $t2 = $t1 - 60 * 60 * 24 * 14; |
|
| 773 | + |
|
| 774 | + // create some versions |
|
| 775 | + $v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1; |
|
| 776 | + $v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2; |
|
| 777 | + |
|
| 778 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub'); |
|
| 779 | + |
|
| 780 | + $this->rootView->file_put_contents($v1, 'version1'); |
|
| 781 | + $fileInfoV1 = $this->rootView->getFileInfo($v1); |
|
| 782 | + $versionEntity = new VersionEntity(); |
|
| 783 | + $versionEntity->setFileId($fileInfo->getId()); |
|
| 784 | + $versionEntity->setTimestamp($t1); |
|
| 785 | + $versionEntity->setSize($fileInfoV1->getSize()); |
|
| 786 | + $versionEntity->setMimetype($this->mimeTypeLoader->getId($fileInfoV1->getMimetype())); |
|
| 787 | + $versionEntity->setMetadata([]); |
|
| 788 | + $this->versionsMapper->insert($versionEntity); |
|
| 789 | + |
|
| 790 | + $this->rootView->file_put_contents($v2, 'version2'); |
|
| 791 | + $fileInfoV2 = $this->rootView->getFileInfo($v2); |
|
| 792 | + $versionEntity = new VersionEntity(); |
|
| 793 | + $versionEntity->setFileId($fileInfo->getId()); |
|
| 794 | + $versionEntity->setTimestamp($t2); |
|
| 795 | + $versionEntity->setSize($fileInfoV2->getSize()); |
|
| 796 | + $versionEntity->setMimetype($this->mimeTypeLoader->getId($fileInfoV2->getMimetype())); |
|
| 797 | + $versionEntity->setMetadata([]); |
|
| 798 | + $this->versionsMapper->insert($versionEntity); |
|
| 799 | + |
|
| 800 | + $oldVersions = Storage::getVersions( |
|
| 801 | + self::TEST_VERSIONS_USER, '/sub/test.txt' |
|
| 802 | + ); |
|
| 803 | + |
|
| 804 | + $this->assertCount(2, $oldVersions); |
|
| 805 | + |
|
| 806 | + $this->assertEquals('test file', $this->rootView->file_get_contents($filePath)); |
|
| 807 | + $info1 = $this->rootView->getFileInfo($filePath); |
|
| 808 | + |
|
| 809 | + $eventDispatcher = Server::get(IEventDispatcher::class); |
|
| 810 | + $eventFired = false; |
|
| 811 | + $eventDispatcher->addListener(VersionRestoredEvent::class, function ($event) use (&$eventFired, $t2) { |
|
| 812 | + $eventFired = true; |
|
| 813 | + $this->assertEquals('/sub/test.txt', $event->getVersion()->getVersionPath()); |
|
| 814 | + $this->assertTrue($event->getVersion()->getRevisionId() > 0); |
|
| 815 | + }); |
|
| 816 | + |
|
| 817 | + $versionManager = Server::get(IVersionManager::class); |
|
| 818 | + $versions = $versionManager->getVersionsForFile($this->user1, $info1); |
|
| 819 | + $version = array_filter($versions, function ($version) use ($t2) { |
|
| 820 | + return $version->getRevisionId() === $t2; |
|
| 821 | + }); |
|
| 822 | + $this->assertTrue($versionManager->rollback(current($version))); |
|
| 823 | + |
|
| 824 | + $this->assertTrue($eventFired, 'VersionRestoredEvent was not fired'); |
|
| 825 | + |
|
| 826 | + $this->assertEquals('version2', $this->rootView->file_get_contents($filePath)); |
|
| 827 | + $info2 = $this->rootView->getFileInfo($filePath); |
|
| 828 | + |
|
| 829 | + $this->assertNotEquals( |
|
| 830 | + $info2['etag'], |
|
| 831 | + $info1['etag'], |
|
| 832 | + 'Etag must change after rolling back version' |
|
| 833 | + ); |
|
| 834 | + $this->assertEquals( |
|
| 835 | + $info2['fileid'], |
|
| 836 | + $info1['fileid'], |
|
| 837 | + 'File id must not change after rolling back version' |
|
| 838 | + ); |
|
| 839 | + $this->assertEquals( |
|
| 840 | + $info2['mtime'], |
|
| 841 | + $t2, |
|
| 842 | + 'Restored file has mtime from version' |
|
| 843 | + ); |
|
| 844 | + |
|
| 845 | + $newVersions = Storage::getVersions( |
|
| 846 | + self::TEST_VERSIONS_USER, '/sub/test.txt' |
|
| 847 | + ); |
|
| 848 | + |
|
| 849 | + $this->assertTrue( |
|
| 850 | + $this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0), |
|
| 851 | + 'A version file was created for the file before restoration' |
|
| 852 | + ); |
|
| 853 | + $this->assertTrue( |
|
| 854 | + $this->rootView->file_exists($v1), |
|
| 855 | + 'Untouched version file is still there' |
|
| 856 | + ); |
|
| 857 | + $this->assertFalse( |
|
| 858 | + $this->rootView->file_exists($v2), |
|
| 859 | + 'Restored version file gone from files_version folder' |
|
| 860 | + ); |
|
| 861 | + |
|
| 862 | + $this->assertCount(2, $newVersions, 'Additional version created'); |
|
| 863 | + |
|
| 864 | + $this->assertTrue( |
|
| 865 | + isset($newVersions[$t0 . '#' . 'test.txt']), |
|
| 866 | + 'A version was created for the file before restoration' |
|
| 867 | + ); |
|
| 868 | + $this->assertTrue( |
|
| 869 | + isset($newVersions[$t1 . '#' . 'test.txt']), |
|
| 870 | + 'Untouched version is still there' |
|
| 871 | + ); |
|
| 872 | + $this->assertFalse( |
|
| 873 | + isset($newVersions[$t2 . '#' . 'test.txt']), |
|
| 874 | + 'Restored version is not in the list any more' |
|
| 875 | + ); |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * Test whether versions are created when overwriting as owner |
|
| 880 | + */ |
|
| 881 | + public function testStoreVersionAsOwner(): void { |
|
| 882 | + $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 883 | + |
|
| 884 | + $this->createAndCheckVersions( |
|
| 885 | + Filesystem::getView(), |
|
| 886 | + 'test.txt' |
|
| 887 | + ); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * Test whether versions are created when overwriting as share recipient |
|
| 892 | + */ |
|
| 893 | + public function testStoreVersionAsRecipient(): void { |
|
| 894 | + $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 895 | + |
|
| 896 | + Filesystem::mkdir('folder'); |
|
| 897 | + Filesystem::file_put_contents('folder/test.txt', 'test file'); |
|
| 898 | + |
|
| 899 | + $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder'); |
|
| 900 | + $share = Server::get(\OCP\Share\IManager::class)->newShare(); |
|
| 901 | + $share->setNode($node) |
|
| 902 | + ->setShareType(IShare::TYPE_USER) |
|
| 903 | + ->setSharedBy(self::TEST_VERSIONS_USER) |
|
| 904 | + ->setSharedWith(self::TEST_VERSIONS_USER2) |
|
| 905 | + ->setPermissions(Constants::PERMISSION_ALL); |
|
| 906 | + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); |
|
| 907 | + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
|
| 908 | + |
|
| 909 | + $this->loginAsUser(self::TEST_VERSIONS_USER2); |
|
| 910 | + |
|
| 911 | + $this->createAndCheckVersions( |
|
| 912 | + Filesystem::getView(), |
|
| 913 | + 'folder/test.txt' |
|
| 914 | + ); |
|
| 915 | + |
|
| 916 | + Server::get(\OCP\Share\IManager::class)->deleteShare($share); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * Test whether versions are created when overwriting anonymously. |
|
| 921 | + * |
|
| 922 | + * When uploading through a public link or publicwebdav, no user |
|
| 923 | + * is logged in. File modification must still be able to find |
|
| 924 | + * the owner and create versions. |
|
| 925 | + */ |
|
| 926 | + public function testStoreVersionAsAnonymous(): void { |
|
| 927 | + $this->logout(); |
|
| 928 | + |
|
| 929 | + // note: public link upload does this, |
|
| 930 | + // needed to make the hooks fire |
|
| 931 | + \OC_Util::setupFS(self::TEST_VERSIONS_USER); |
|
| 932 | + |
|
| 933 | + $userView = new View('/' . self::TEST_VERSIONS_USER . '/files'); |
|
| 934 | + $this->createAndCheckVersions( |
|
| 935 | + $userView, |
|
| 936 | + 'test.txt' |
|
| 937 | + ); |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * @param View $view |
|
| 942 | + * @param string $path |
|
| 943 | + */ |
|
| 944 | + private function createAndCheckVersions(View $view, $path) { |
|
| 945 | + $view->file_put_contents($path, 'test file'); |
|
| 946 | + $view->file_put_contents($path, 'version 1'); |
|
| 947 | + $view->file_put_contents($path, 'version 2'); |
|
| 948 | + |
|
| 949 | + $this->loginAsUser(self::TEST_VERSIONS_USER); |
|
| 950 | + |
|
| 951 | + // need to scan for the versions |
|
| 952 | + [$rootStorage,] = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions'); |
|
| 953 | + $rootStorage->getScanner()->scan('files_versions'); |
|
| 954 | + |
|
| 955 | + $versions = Storage::getVersions( |
|
| 956 | + self::TEST_VERSIONS_USER, '/' . $path |
|
| 957 | + ); |
|
| 958 | + |
|
| 959 | + // note: we cannot predict how many versions are created due to |
|
| 960 | + // test run timing |
|
| 961 | + $this->assertGreaterThan(0, count($versions)); |
|
| 962 | + |
|
| 963 | + return $versions; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * @param string $user |
|
| 968 | + * @param bool $create |
|
| 969 | + */ |
|
| 970 | + public static function loginHelper($user, $create = false) { |
|
| 971 | + if ($create) { |
|
| 972 | + $backend = new \Test\Util\User\Dummy(); |
|
| 973 | + $backend->createUser($user, $user); |
|
| 974 | + Server::get(IUserManager::class)->registerBackend($backend); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + \OC_Util::tearDownFS(); |
|
| 978 | + \OC_User::setUserId(''); |
|
| 979 | + Filesystem::tearDown(); |
|
| 980 | + \OC_User::setUserId($user); |
|
| 981 | + \OC_Util::setupFS($user); |
|
| 982 | + \OC::$server->getUserFolder($user); |
|
| 983 | + } |
|
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | // extend the original class to make it possible to test protected methods |
| 987 | 987 | class VersionStorageToTest extends Storage { |
| 988 | 988 | |
| 989 | - /** |
|
| 990 | - * @param integer $time |
|
| 991 | - */ |
|
| 992 | - public function callProtectedGetExpireList($time, $versions) { |
|
| 993 | - return self::getExpireList($time, $versions); |
|
| 994 | - } |
|
| 989 | + /** |
|
| 990 | + * @param integer $time |
|
| 991 | + */ |
|
| 992 | + public function callProtectedGetExpireList($time, $versions) { |
|
| 993 | + return self::getExpireList($time, $versions); |
|
| 994 | + } |
|
| 995 | 995 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $mockConfig = $this->createMock(IConfig::class); |
| 87 | 87 | $mockConfig->expects($this->any()) |
| 88 | 88 | ->method('getSystemValue') |
| 89 | - ->willReturnCallback(function ($key, $default) use ($config) { |
|
| 89 | + ->willReturnCallback(function($key, $default) use ($config) { |
|
| 90 | 90 | if ($key === 'filesystem_check_changes') { |
| 91 | 91 | return Watcher::CHECK_ONCE; |
| 92 | 92 | } else { |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | $this->restoreService(AllConfig::class); |
| 122 | 122 | |
| 123 | 123 | if ($this->rootView) { |
| 124 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files/'); |
|
| 125 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files/'); |
|
| 126 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files_versions/'); |
|
| 127 | - $this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files_versions/'); |
|
| 124 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER.'/files/'); |
|
| 125 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER2.'/files/'); |
|
| 126 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER.'/files_versions/'); |
|
| 127 | + $this->rootView->deleteAll(self::TEST_VERSIONS_USER2.'/files_versions/'); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | \OC_Hook::clear(); |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | $t2 = $t1 - 60 * 60 * 24 * 14; |
| 293 | 293 | |
| 294 | 294 | // create some versions |
| 295 | - $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 296 | - $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 297 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 298 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 295 | + $v1 = self::USERS_VERSIONS_ROOT.'/test.txt.v'.$t1; |
|
| 296 | + $v2 = self::USERS_VERSIONS_ROOT.'/test.txt.v'.$t2; |
|
| 297 | + $v1Renamed = self::USERS_VERSIONS_ROOT.'/test2.txt.v'.$t1; |
|
| 298 | + $v2Renamed = self::USERS_VERSIONS_ROOT.'/test2.txt.v'.$t2; |
|
| 299 | 299 | |
| 300 | 300 | $this->rootView->file_put_contents($v1, 'version1'); |
| 301 | 301 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -322,12 +322,12 @@ discard block |
||
| 322 | 322 | // version will be expired |
| 323 | 323 | $t2 = $t1 - 60 * 60 * 24 * 14; |
| 324 | 324 | |
| 325 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1'); |
|
| 325 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT.'/folder1'); |
|
| 326 | 326 | // create some versions |
| 327 | - $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1; |
|
| 328 | - $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2; |
|
| 329 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t1; |
|
| 330 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t2; |
|
| 327 | + $v1 = self::USERS_VERSIONS_ROOT.'/folder1/test.txt.v'.$t1; |
|
| 328 | + $v2 = self::USERS_VERSIONS_ROOT.'/folder1/test.txt.v'.$t2; |
|
| 329 | + $v1Renamed = self::USERS_VERSIONS_ROOT.'/folder1/folder2/test.txt.v'.$t1; |
|
| 330 | + $v2Renamed = self::USERS_VERSIONS_ROOT.'/folder1/folder2/test.txt.v'.$t2; |
|
| 331 | 331 | |
| 332 | 332 | $this->rootView->file_put_contents($v1, 'version1'); |
| 333 | 333 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -373,11 +373,11 @@ discard block |
||
| 373 | 373 | $t2 = $t1 - 60 * 60 * 24 * 14; |
| 374 | 374 | |
| 375 | 375 | // create some versions |
| 376 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1'); |
|
| 377 | - $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1; |
|
| 378 | - $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2; |
|
| 379 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t1; |
|
| 380 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t2; |
|
| 376 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT.'/folder1'); |
|
| 377 | + $v1 = self::USERS_VERSIONS_ROOT.'/folder1/test.txt.v'.$t1; |
|
| 378 | + $v2 = self::USERS_VERSIONS_ROOT.'/folder1/test.txt.v'.$t2; |
|
| 379 | + $v1Renamed = self::USERS_VERSIONS_ROOT.'/folder2/folder1/test.txt.v'.$t1; |
|
| 380 | + $v2Renamed = self::USERS_VERSIONS_ROOT.'/folder2/folder1/test.txt.v'.$t2; |
|
| 381 | 381 | |
| 382 | 382 | $this->rootView->file_put_contents($v1, 'version1'); |
| 383 | 383 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
| 411 | 411 | |
| 412 | 412 | self::loginHelper(self::TEST_VERSIONS_USER2); |
| 413 | - $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; |
|
| 413 | + $versionsFolder2 = '/'.self::TEST_VERSIONS_USER2.'/files_versions'; |
|
| 414 | 414 | Filesystem::file_put_contents('test.txt', 'test file'); |
| 415 | 415 | |
| 416 | 416 | $t1 = time(); |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | $this->rootView->mkdir($versionsFolder2); |
| 422 | 422 | // create some versions |
| 423 | - $v1 = $versionsFolder2 . '/test.txt.v' . $t1; |
|
| 424 | - $v2 = $versionsFolder2 . '/test.txt.v' . $t2; |
|
| 423 | + $v1 = $versionsFolder2.'/test.txt.v'.$t1; |
|
| 424 | + $v2 = $versionsFolder2.'/test.txt.v'.$t2; |
|
| 425 | 425 | |
| 426 | 426 | $this->rootView->file_put_contents($v1, 'version1'); |
| 427 | 427 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -434,10 +434,10 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | self::loginHelper(self::TEST_VERSIONS_USER); |
| 436 | 436 | |
| 437 | - $versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions'; |
|
| 437 | + $versionsFolder1 = '/'.self::TEST_VERSIONS_USER.'/files_versions'; |
|
| 438 | 438 | |
| 439 | - $v1Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t1; |
|
| 440 | - $v2Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t2; |
|
| 439 | + $v1Renamed = $versionsFolder1.'/folder1/test.txt.v'.$t1; |
|
| 440 | + $v2Renamed = $versionsFolder1.'/folder1/test.txt.v'.$t2; |
|
| 441 | 441 | |
| 442 | 442 | $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
| 443 | 443 | $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); |
| 460 | 460 | |
| 461 | 461 | self::loginHelper(self::TEST_VERSIONS_USER2); |
| 462 | - $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; |
|
| 462 | + $versionsFolder2 = '/'.self::TEST_VERSIONS_USER2.'/files_versions'; |
|
| 463 | 463 | Filesystem::mkdir('folder2'); |
| 464 | 464 | Filesystem::file_put_contents('folder2/test.txt', 'test file'); |
| 465 | 465 | |
@@ -469,10 +469,10 @@ discard block |
||
| 469 | 469 | $t2 = $t1 - 60 * 60 * 24 * 14; |
| 470 | 470 | |
| 471 | 471 | $this->rootView->mkdir($versionsFolder2); |
| 472 | - $this->rootView->mkdir($versionsFolder2 . '/folder2'); |
|
| 472 | + $this->rootView->mkdir($versionsFolder2.'/folder2'); |
|
| 473 | 473 | // create some versions |
| 474 | - $v1 = $versionsFolder2 . '/folder2/test.txt.v' . $t1; |
|
| 475 | - $v2 = $versionsFolder2 . '/folder2/test.txt.v' . $t2; |
|
| 474 | + $v1 = $versionsFolder2.'/folder2/test.txt.v'.$t1; |
|
| 475 | + $v2 = $versionsFolder2.'/folder2/test.txt.v'.$t2; |
|
| 476 | 476 | |
| 477 | 477 | $this->rootView->file_put_contents($v1, 'version1'); |
| 478 | 478 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -485,10 +485,10 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | self::loginHelper(self::TEST_VERSIONS_USER); |
| 487 | 487 | |
| 488 | - $versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions'; |
|
| 488 | + $versionsFolder1 = '/'.self::TEST_VERSIONS_USER.'/files_versions'; |
|
| 489 | 489 | |
| 490 | - $v1Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t1; |
|
| 491 | - $v2Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t2; |
|
| 490 | + $v1Renamed = $versionsFolder1.'/folder1/folder2/test.txt.v'.$t1; |
|
| 491 | + $v2Renamed = $versionsFolder1.'/folder1/folder2/test.txt.v'.$t2; |
|
| 492 | 492 | |
| 493 | 493 | $this->assertTrue($this->rootView->file_exists($v1Renamed)); |
| 494 | 494 | $this->assertTrue($this->rootView->file_exists($v2Renamed)); |
@@ -506,11 +506,11 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | $this->rootView->mkdir(self::USERS_VERSIONS_ROOT); |
| 508 | 508 | // create some versions |
| 509 | - $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 510 | - $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 509 | + $v1 = self::USERS_VERSIONS_ROOT.'/test.txt.v'.$t1; |
|
| 510 | + $v2 = self::USERS_VERSIONS_ROOT.'/test.txt.v'.$t2; |
|
| 511 | 511 | // the renamed versions should not exist! Because we only moved the mount point! |
| 512 | - $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 513 | - $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 512 | + $v1Renamed = self::USERS_VERSIONS_ROOT.'/test2.txt.v'.$t1; |
|
| 513 | + $v2Renamed = self::USERS_VERSIONS_ROOT.'/test2.txt.v'.$t2; |
|
| 514 | 514 | |
| 515 | 515 | $this->rootView->file_put_contents($v1, 'version1'); |
| 516 | 516 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -554,10 +554,10 @@ discard block |
||
| 554 | 554 | $t2 = $t1 - 60 * 60 * 24 * 14; |
| 555 | 555 | |
| 556 | 556 | // create some versions |
| 557 | - $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; |
|
| 558 | - $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; |
|
| 559 | - $v1Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; |
|
| 560 | - $v2Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; |
|
| 557 | + $v1 = self::USERS_VERSIONS_ROOT.'/test.txt.v'.$t1; |
|
| 558 | + $v2 = self::USERS_VERSIONS_ROOT.'/test.txt.v'.$t2; |
|
| 559 | + $v1Copied = self::USERS_VERSIONS_ROOT.'/test2.txt.v'.$t1; |
|
| 560 | + $v2Copied = self::USERS_VERSIONS_ROOT.'/test2.txt.v'.$t2; |
|
| 561 | 561 | |
| 562 | 562 | $this->rootView->file_put_contents($v1, 'version1'); |
| 563 | 563 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -585,10 +585,10 @@ discard block |
||
| 585 | 585 | $t2 = $t1 - 60 * 60 * 24 * 14; |
| 586 | 586 | |
| 587 | 587 | // create some versions |
| 588 | - $v1 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t1; |
|
| 589 | - $v2 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t2; |
|
| 588 | + $v1 = self::USERS_VERSIONS_ROOT.'/subfolder/test.txt.v'.$t1; |
|
| 589 | + $v2 = self::USERS_VERSIONS_ROOT.'/subfolder/test.txt.v'.$t2; |
|
| 590 | 590 | |
| 591 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/subfolder/'); |
|
| 591 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT.'/subfolder/'); |
|
| 592 | 592 | |
| 593 | 593 | $this->rootView->file_put_contents($v1, 'version1'); |
| 594 | 594 | $this->rootView->file_put_contents($v2, 'version2'); |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | //cleanup |
| 607 | - $this->rootView->deleteAll(self::USERS_VERSIONS_ROOT . '/subfolder'); |
|
| 607 | + $this->rootView->deleteAll(self::USERS_VERSIONS_ROOT.'/subfolder'); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | |
| 648 | 648 | public function testRestoreCrossStorage(): void { |
| 649 | 649 | $storage2 = new Temporary([]); |
| 650 | - Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER . '/files/sub'); |
|
| 650 | + Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER.'/files/sub'); |
|
| 651 | 651 | |
| 652 | 652 | $this->doTestRestore(); |
| 653 | 653 | } |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | $eventHandler->expects($this->any()) |
| 747 | 747 | ->method('callback') |
| 748 | 748 | ->willReturnCallback( |
| 749 | - function ($p) use (&$params): void { |
|
| 749 | + function($p) use (&$params): void { |
|
| 750 | 750 | $params = $p; |
| 751 | 751 | } |
| 752 | 752 | ); |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | private function doTestRestore() { |
| 763 | - $filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt'; |
|
| 763 | + $filePath = self::TEST_VERSIONS_USER.'/files/sub/test.txt'; |
|
| 764 | 764 | $this->rootView->file_put_contents($filePath, 'test file'); |
| 765 | 765 | |
| 766 | 766 | $fileInfo = $this->rootView->getFileInfo($filePath); |
@@ -772,10 +772,10 @@ discard block |
||
| 772 | 772 | $t2 = $t1 - 60 * 60 * 24 * 14; |
| 773 | 773 | |
| 774 | 774 | // create some versions |
| 775 | - $v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1; |
|
| 776 | - $v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2; |
|
| 775 | + $v1 = self::USERS_VERSIONS_ROOT.'/sub/test.txt.v'.$t1; |
|
| 776 | + $v2 = self::USERS_VERSIONS_ROOT.'/sub/test.txt.v'.$t2; |
|
| 777 | 777 | |
| 778 | - $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub'); |
|
| 778 | + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT.'/sub'); |
|
| 779 | 779 | |
| 780 | 780 | $this->rootView->file_put_contents($v1, 'version1'); |
| 781 | 781 | $fileInfoV1 = $this->rootView->getFileInfo($v1); |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | |
| 809 | 809 | $eventDispatcher = Server::get(IEventDispatcher::class); |
| 810 | 810 | $eventFired = false; |
| 811 | - $eventDispatcher->addListener(VersionRestoredEvent::class, function ($event) use (&$eventFired, $t2) { |
|
| 811 | + $eventDispatcher->addListener(VersionRestoredEvent::class, function($event) use (&$eventFired, $t2) { |
|
| 812 | 812 | $eventFired = true; |
| 813 | 813 | $this->assertEquals('/sub/test.txt', $event->getVersion()->getVersionPath()); |
| 814 | 814 | $this->assertTrue($event->getVersion()->getRevisionId() > 0); |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | |
| 817 | 817 | $versionManager = Server::get(IVersionManager::class); |
| 818 | 818 | $versions = $versionManager->getVersionsForFile($this->user1, $info1); |
| 819 | - $version = array_filter($versions, function ($version) use ($t2) { |
|
| 819 | + $version = array_filter($versions, function($version) use ($t2) { |
|
| 820 | 820 | return $version->getRevisionId() === $t2; |
| 821 | 821 | }); |
| 822 | 822 | $this->assertTrue($versionManager->rollback(current($version))); |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | ); |
| 848 | 848 | |
| 849 | 849 | $this->assertTrue( |
| 850 | - $this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0), |
|
| 850 | + $this->rootView->file_exists(self::USERS_VERSIONS_ROOT.'/sub/test.txt.v'.$t0), |
|
| 851 | 851 | 'A version file was created for the file before restoration' |
| 852 | 852 | ); |
| 853 | 853 | $this->assertTrue( |
@@ -862,15 +862,15 @@ discard block |
||
| 862 | 862 | $this->assertCount(2, $newVersions, 'Additional version created'); |
| 863 | 863 | |
| 864 | 864 | $this->assertTrue( |
| 865 | - isset($newVersions[$t0 . '#' . 'test.txt']), |
|
| 865 | + isset($newVersions[$t0.'#'.'test.txt']), |
|
| 866 | 866 | 'A version was created for the file before restoration' |
| 867 | 867 | ); |
| 868 | 868 | $this->assertTrue( |
| 869 | - isset($newVersions[$t1 . '#' . 'test.txt']), |
|
| 869 | + isset($newVersions[$t1.'#'.'test.txt']), |
|
| 870 | 870 | 'Untouched version is still there' |
| 871 | 871 | ); |
| 872 | 872 | $this->assertFalse( |
| 873 | - isset($newVersions[$t2 . '#' . 'test.txt']), |
|
| 873 | + isset($newVersions[$t2.'#'.'test.txt']), |
|
| 874 | 874 | 'Restored version is not in the list any more' |
| 875 | 875 | ); |
| 876 | 876 | } |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | // needed to make the hooks fire |
| 931 | 931 | \OC_Util::setupFS(self::TEST_VERSIONS_USER); |
| 932 | 932 | |
| 933 | - $userView = new View('/' . self::TEST_VERSIONS_USER . '/files'); |
|
| 933 | + $userView = new View('/'.self::TEST_VERSIONS_USER.'/files'); |
|
| 934 | 934 | $this->createAndCheckVersions( |
| 935 | 935 | $userView, |
| 936 | 936 | 'test.txt' |
@@ -949,11 +949,11 @@ discard block |
||
| 949 | 949 | $this->loginAsUser(self::TEST_VERSIONS_USER); |
| 950 | 950 | |
| 951 | 951 | // need to scan for the versions |
| 952 | - [$rootStorage,] = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions'); |
|
| 952 | + [$rootStorage, ] = $this->rootView->resolvePath(self::TEST_VERSIONS_USER.'/files_versions'); |
|
| 953 | 953 | $rootStorage->getScanner()->scan('files_versions'); |
| 954 | 954 | |
| 955 | 955 | $versions = Storage::getVersions( |
| 956 | - self::TEST_VERSIONS_USER, '/' . $path |
|
| 956 | + self::TEST_VERSIONS_USER, '/'.$path |
|
| 957 | 957 | ); |
| 958 | 958 | |
| 959 | 959 | // note: we cannot predict how many versions are created due to |
@@ -73,161 +73,161 @@ |
||
| 73 | 73 | use Psr\Container\ContainerInterface; |
| 74 | 74 | |
| 75 | 75 | class Application extends App implements IBootstrap { |
| 76 | - public function __construct() { |
|
| 77 | - parent::__construct('admin_audit'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function register(IRegistrationContext $context): void { |
|
| 81 | - $context->registerService(IAuditLogger::class, function (ContainerInterface $c) { |
|
| 82 | - return new AuditLogger($c->get(ILogFactory::class), $c->get(IConfig::class)); |
|
| 83 | - }); |
|
| 84 | - |
|
| 85 | - $context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class); |
|
| 86 | - |
|
| 87 | - // User management events |
|
| 88 | - $context->registerEventListener(UserCreatedEvent::class, UserManagementEventListener::class); |
|
| 89 | - $context->registerEventListener(UserDeletedEvent::class, UserManagementEventListener::class); |
|
| 90 | - $context->registerEventListener(UserChangedEvent::class, UserManagementEventListener::class); |
|
| 91 | - $context->registerEventListener(PasswordUpdatedEvent::class, UserManagementEventListener::class); |
|
| 92 | - $context->registerEventListener(UserIdAssignedEvent::class, UserManagementEventListener::class); |
|
| 93 | - $context->registerEventListener(UserIdUnassignedEvent::class, UserManagementEventListener::class); |
|
| 94 | - |
|
| 95 | - // Group management events |
|
| 96 | - $context->registerEventListener(UserAddedEvent::class, GroupManagementEventListener::class); |
|
| 97 | - $context->registerEventListener(UserRemovedEvent::class, GroupManagementEventListener::class); |
|
| 98 | - $context->registerEventListener(GroupCreatedEvent::class, GroupManagementEventListener::class); |
|
| 99 | - $context->registerEventListener(GroupDeletedEvent::class, GroupManagementEventListener::class); |
|
| 100 | - |
|
| 101 | - // Sharing events |
|
| 102 | - $context->registerEventListener(ShareCreatedEvent::class, SharingEventListener::class); |
|
| 103 | - $context->registerEventListener(ShareDeletedEvent::class, SharingEventListener::class); |
|
| 104 | - |
|
| 105 | - // Auth events |
|
| 106 | - $context->registerEventListener(BeforeUserLoggedInEvent::class, AuthEventListener::class); |
|
| 107 | - $context->registerEventListener(UserLoggedInWithCookieEvent::class, AuthEventListener::class); |
|
| 108 | - $context->registerEventListener(UserLoggedInEvent::class, AuthEventListener::class); |
|
| 109 | - $context->registerEventListener(BeforeUserLoggedOutEvent::class, AuthEventListener::class); |
|
| 110 | - $context->registerEventListener(AnyLoginFailedEvent::class, AuthEventListener::class); |
|
| 111 | - |
|
| 112 | - // File events |
|
| 113 | - $context->registerEventListener(BeforePreviewFetchedEvent::class, FileEventListener::class); |
|
| 114 | - $context->registerEventListener(VersionRestoredEvent::class, FileEventListener::class); |
|
| 115 | - |
|
| 116 | - // Security events |
|
| 117 | - $context->registerEventListener(TwoFactorProviderChallengePassed::class, SecurityEventListener::class); |
|
| 118 | - $context->registerEventListener(TwoFactorProviderChallengeFailed::class, SecurityEventListener::class); |
|
| 119 | - |
|
| 120 | - // App management events |
|
| 121 | - $context->registerEventListener(AppEnableEvent::class, AppManagementEventListener::class); |
|
| 122 | - $context->registerEventListener(AppDisableEvent::class, AppManagementEventListener::class); |
|
| 123 | - $context->registerEventListener(AppUpdateEvent::class, AppManagementEventListener::class); |
|
| 124 | - |
|
| 125 | - // Console events |
|
| 126 | - $context->registerEventListener(ConsoleEvent::class, ConsoleEventListener::class); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function boot(IBootContext $context): void { |
|
| 130 | - /** @var IAuditLogger $logger */ |
|
| 131 | - $logger = $context->getAppContainer()->get(IAuditLogger::class); |
|
| 132 | - |
|
| 133 | - /* |
|
| 76 | + public function __construct() { |
|
| 77 | + parent::__construct('admin_audit'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function register(IRegistrationContext $context): void { |
|
| 81 | + $context->registerService(IAuditLogger::class, function (ContainerInterface $c) { |
|
| 82 | + return new AuditLogger($c->get(ILogFactory::class), $c->get(IConfig::class)); |
|
| 83 | + }); |
|
| 84 | + |
|
| 85 | + $context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class); |
|
| 86 | + |
|
| 87 | + // User management events |
|
| 88 | + $context->registerEventListener(UserCreatedEvent::class, UserManagementEventListener::class); |
|
| 89 | + $context->registerEventListener(UserDeletedEvent::class, UserManagementEventListener::class); |
|
| 90 | + $context->registerEventListener(UserChangedEvent::class, UserManagementEventListener::class); |
|
| 91 | + $context->registerEventListener(PasswordUpdatedEvent::class, UserManagementEventListener::class); |
|
| 92 | + $context->registerEventListener(UserIdAssignedEvent::class, UserManagementEventListener::class); |
|
| 93 | + $context->registerEventListener(UserIdUnassignedEvent::class, UserManagementEventListener::class); |
|
| 94 | + |
|
| 95 | + // Group management events |
|
| 96 | + $context->registerEventListener(UserAddedEvent::class, GroupManagementEventListener::class); |
|
| 97 | + $context->registerEventListener(UserRemovedEvent::class, GroupManagementEventListener::class); |
|
| 98 | + $context->registerEventListener(GroupCreatedEvent::class, GroupManagementEventListener::class); |
|
| 99 | + $context->registerEventListener(GroupDeletedEvent::class, GroupManagementEventListener::class); |
|
| 100 | + |
|
| 101 | + // Sharing events |
|
| 102 | + $context->registerEventListener(ShareCreatedEvent::class, SharingEventListener::class); |
|
| 103 | + $context->registerEventListener(ShareDeletedEvent::class, SharingEventListener::class); |
|
| 104 | + |
|
| 105 | + // Auth events |
|
| 106 | + $context->registerEventListener(BeforeUserLoggedInEvent::class, AuthEventListener::class); |
|
| 107 | + $context->registerEventListener(UserLoggedInWithCookieEvent::class, AuthEventListener::class); |
|
| 108 | + $context->registerEventListener(UserLoggedInEvent::class, AuthEventListener::class); |
|
| 109 | + $context->registerEventListener(BeforeUserLoggedOutEvent::class, AuthEventListener::class); |
|
| 110 | + $context->registerEventListener(AnyLoginFailedEvent::class, AuthEventListener::class); |
|
| 111 | + |
|
| 112 | + // File events |
|
| 113 | + $context->registerEventListener(BeforePreviewFetchedEvent::class, FileEventListener::class); |
|
| 114 | + $context->registerEventListener(VersionRestoredEvent::class, FileEventListener::class); |
|
| 115 | + |
|
| 116 | + // Security events |
|
| 117 | + $context->registerEventListener(TwoFactorProviderChallengePassed::class, SecurityEventListener::class); |
|
| 118 | + $context->registerEventListener(TwoFactorProviderChallengeFailed::class, SecurityEventListener::class); |
|
| 119 | + |
|
| 120 | + // App management events |
|
| 121 | + $context->registerEventListener(AppEnableEvent::class, AppManagementEventListener::class); |
|
| 122 | + $context->registerEventListener(AppDisableEvent::class, AppManagementEventListener::class); |
|
| 123 | + $context->registerEventListener(AppUpdateEvent::class, AppManagementEventListener::class); |
|
| 124 | + |
|
| 125 | + // Console events |
|
| 126 | + $context->registerEventListener(ConsoleEvent::class, ConsoleEventListener::class); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function boot(IBootContext $context): void { |
|
| 130 | + /** @var IAuditLogger $logger */ |
|
| 131 | + $logger = $context->getAppContainer()->get(IAuditLogger::class); |
|
| 132 | + |
|
| 133 | + /* |
|
| 134 | 134 | * TODO: once the hooks are migrated to lazy events, this should be done |
| 135 | 135 | * in \OCA\AdminAudit\AppInfo\Application::register |
| 136 | 136 | */ |
| 137 | - $this->registerLegacyHooks($logger, $context->getServerContainer()); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Register hooks in order to log them |
|
| 142 | - */ |
|
| 143 | - private function registerLegacyHooks(IAuditLogger $logger, ContainerInterface $serverContainer): void { |
|
| 144 | - /** @var IEventDispatcher $eventDispatcher */ |
|
| 145 | - $eventDispatcher = $serverContainer->get(IEventDispatcher::class); |
|
| 146 | - $this->sharingLegacyHooks($logger); |
|
| 147 | - $this->fileHooks($logger, $eventDispatcher); |
|
| 148 | - $this->trashbinHooks($logger); |
|
| 149 | - $this->versionsHooks($logger); |
|
| 150 | - $this->tagHooks($logger, $eventDispatcher); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - private function sharingLegacyHooks(IAuditLogger $logger): void { |
|
| 154 | - $shareActions = new Sharing($logger); |
|
| 155 | - |
|
| 156 | - Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 157 | - Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
| 158 | - Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 159 | - Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - private function tagHooks(IAuditLogger $logger, |
|
| 163 | - IEventDispatcher $eventDispatcher): void { |
|
| 164 | - $eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, function (ManagerEvent $event) use ($logger): void { |
|
| 165 | - $tagActions = new TagManagement($logger); |
|
| 166 | - $tagActions->createTag($event->getTag()); |
|
| 167 | - }); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - private function fileHooks(IAuditLogger $logger, IEventDispatcher $eventDispatcher): void { |
|
| 171 | - $fileActions = new Files($logger); |
|
| 172 | - |
|
| 173 | - $eventDispatcher->addListener( |
|
| 174 | - BeforeNodeRenamedEvent::class, |
|
| 175 | - function (BeforeNodeRenamedEvent $event) use ($fileActions): void { |
|
| 176 | - $fileActions->beforeRename($event); |
|
| 177 | - } |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - $eventDispatcher->addListener( |
|
| 181 | - NodeRenamedEvent::class, |
|
| 182 | - function (NodeRenamedEvent $event) use ($fileActions): void { |
|
| 183 | - $fileActions->afterRename($event); |
|
| 184 | - } |
|
| 185 | - ); |
|
| 186 | - |
|
| 187 | - $eventDispatcher->addListener( |
|
| 188 | - NodeCreatedEvent::class, |
|
| 189 | - function (NodeCreatedEvent $event) use ($fileActions): void { |
|
| 190 | - $fileActions->create($event); |
|
| 191 | - } |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - $eventDispatcher->addListener( |
|
| 195 | - NodeCopiedEvent::class, |
|
| 196 | - function (NodeCopiedEvent $event) use ($fileActions): void { |
|
| 197 | - $fileActions->copy($event); |
|
| 198 | - } |
|
| 199 | - ); |
|
| 200 | - |
|
| 201 | - $eventDispatcher->addListener( |
|
| 202 | - NodeWrittenEvent::class, |
|
| 203 | - function (NodeWrittenEvent $event) use ($fileActions): void { |
|
| 204 | - $fileActions->write($event); |
|
| 205 | - } |
|
| 206 | - ); |
|
| 207 | - |
|
| 208 | - $eventDispatcher->addListener( |
|
| 209 | - BeforeNodeReadEvent::class, |
|
| 210 | - function (BeforeNodeReadEvent $event) use ($fileActions): void { |
|
| 211 | - $fileActions->read($event); |
|
| 212 | - } |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - $eventDispatcher->addListener( |
|
| 216 | - BeforeNodeDeletedEvent::class, |
|
| 217 | - function (BeforeNodeDeletedEvent $event) use ($fileActions): void { |
|
| 218 | - $fileActions->delete($event); |
|
| 219 | - } |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - private function versionsHooks(IAuditLogger $logger): void { |
|
| 224 | - $versionsActions = new Versions($logger); |
|
| 225 | - Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - private function trashbinHooks(IAuditLogger $logger): void { |
|
| 229 | - $trashActions = new Trashbin($logger); |
|
| 230 | - Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 231 | - Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 232 | - } |
|
| 137 | + $this->registerLegacyHooks($logger, $context->getServerContainer()); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Register hooks in order to log them |
|
| 142 | + */ |
|
| 143 | + private function registerLegacyHooks(IAuditLogger $logger, ContainerInterface $serverContainer): void { |
|
| 144 | + /** @var IEventDispatcher $eventDispatcher */ |
|
| 145 | + $eventDispatcher = $serverContainer->get(IEventDispatcher::class); |
|
| 146 | + $this->sharingLegacyHooks($logger); |
|
| 147 | + $this->fileHooks($logger, $eventDispatcher); |
|
| 148 | + $this->trashbinHooks($logger); |
|
| 149 | + $this->versionsHooks($logger); |
|
| 150 | + $this->tagHooks($logger, $eventDispatcher); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + private function sharingLegacyHooks(IAuditLogger $logger): void { |
|
| 154 | + $shareActions = new Sharing($logger); |
|
| 155 | + |
|
| 156 | + Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 157 | + Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
| 158 | + Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 159 | + Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + private function tagHooks(IAuditLogger $logger, |
|
| 163 | + IEventDispatcher $eventDispatcher): void { |
|
| 164 | + $eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, function (ManagerEvent $event) use ($logger): void { |
|
| 165 | + $tagActions = new TagManagement($logger); |
|
| 166 | + $tagActions->createTag($event->getTag()); |
|
| 167 | + }); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + private function fileHooks(IAuditLogger $logger, IEventDispatcher $eventDispatcher): void { |
|
| 171 | + $fileActions = new Files($logger); |
|
| 172 | + |
|
| 173 | + $eventDispatcher->addListener( |
|
| 174 | + BeforeNodeRenamedEvent::class, |
|
| 175 | + function (BeforeNodeRenamedEvent $event) use ($fileActions): void { |
|
| 176 | + $fileActions->beforeRename($event); |
|
| 177 | + } |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + $eventDispatcher->addListener( |
|
| 181 | + NodeRenamedEvent::class, |
|
| 182 | + function (NodeRenamedEvent $event) use ($fileActions): void { |
|
| 183 | + $fileActions->afterRename($event); |
|
| 184 | + } |
|
| 185 | + ); |
|
| 186 | + |
|
| 187 | + $eventDispatcher->addListener( |
|
| 188 | + NodeCreatedEvent::class, |
|
| 189 | + function (NodeCreatedEvent $event) use ($fileActions): void { |
|
| 190 | + $fileActions->create($event); |
|
| 191 | + } |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + $eventDispatcher->addListener( |
|
| 195 | + NodeCopiedEvent::class, |
|
| 196 | + function (NodeCopiedEvent $event) use ($fileActions): void { |
|
| 197 | + $fileActions->copy($event); |
|
| 198 | + } |
|
| 199 | + ); |
|
| 200 | + |
|
| 201 | + $eventDispatcher->addListener( |
|
| 202 | + NodeWrittenEvent::class, |
|
| 203 | + function (NodeWrittenEvent $event) use ($fileActions): void { |
|
| 204 | + $fileActions->write($event); |
|
| 205 | + } |
|
| 206 | + ); |
|
| 207 | + |
|
| 208 | + $eventDispatcher->addListener( |
|
| 209 | + BeforeNodeReadEvent::class, |
|
| 210 | + function (BeforeNodeReadEvent $event) use ($fileActions): void { |
|
| 211 | + $fileActions->read($event); |
|
| 212 | + } |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + $eventDispatcher->addListener( |
|
| 216 | + BeforeNodeDeletedEvent::class, |
|
| 217 | + function (BeforeNodeDeletedEvent $event) use ($fileActions): void { |
|
| 218 | + $fileActions->delete($event); |
|
| 219 | + } |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + private function versionsHooks(IAuditLogger $logger): void { |
|
| 224 | + $versionsActions = new Versions($logger); |
|
| 225 | + Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + private function trashbinHooks(IAuditLogger $logger): void { |
|
| 229 | + $trashActions = new Trashbin($logger); |
|
| 230 | + Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 231 | + Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 232 | + } |
|
| 233 | 233 | } |
@@ -8,10 +8,10 @@ |
||
| 8 | 8 | namespace OCA\AdminAudit\Actions; |
| 9 | 9 | |
| 10 | 10 | class Versions extends Action { |
| 11 | - public function delete(array $params): void { |
|
| 12 | - $this->log('Version "%s" was deleted.', |
|
| 13 | - ['path' => $params['path']], |
|
| 14 | - ['path'] |
|
| 15 | - ); |
|
| 16 | - } |
|
| 11 | + public function delete(array $params): void { |
|
| 12 | + $this->log('Version "%s" was deleted.', |
|
| 13 | + ['path' => $params['path']], |
|
| 14 | + ['path'] |
|
| 15 | + ); |
|
| 16 | + } |
|
| 17 | 17 | } |
@@ -23,52 +23,52 @@ |
||
| 23 | 23 | * @template-implements IEventListener<BeforePreviewFetchedEvent|VersionRestoredEvent> |
| 24 | 24 | */ |
| 25 | 25 | class FileEventListener extends Action implements IEventListener { |
| 26 | - public function handle(Event $event): void { |
|
| 27 | - if ($event instanceof BeforePreviewFetchedEvent) { |
|
| 28 | - $this->beforePreviewFetched($event); |
|
| 29 | - } elseif ($event instanceof VersionRestoredEvent) { |
|
| 30 | - $this->versionRestored($event); |
|
| 31 | - } |
|
| 32 | - } |
|
| 26 | + public function handle(Event $event): void { |
|
| 27 | + if ($event instanceof BeforePreviewFetchedEvent) { |
|
| 28 | + $this->beforePreviewFetched($event); |
|
| 29 | + } elseif ($event instanceof VersionRestoredEvent) { |
|
| 30 | + $this->versionRestored($event); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Logs preview access to a file |
|
| 36 | - */ |
|
| 37 | - private function beforePreviewFetched(BeforePreviewFetchedEvent $event): void { |
|
| 38 | - try { |
|
| 39 | - $file = $event->getNode(); |
|
| 40 | - $params = [ |
|
| 41 | - 'id' => $file->getId(), |
|
| 42 | - 'width' => $event->getWidth(), |
|
| 43 | - 'height' => $event->getHeight(), |
|
| 44 | - 'crop' => $event->isCrop(), |
|
| 45 | - 'mode' => $event->getMode(), |
|
| 46 | - 'path' => $file->getPath(), |
|
| 47 | - ]; |
|
| 48 | - $this->log( |
|
| 49 | - 'Preview accessed: (id: "%s", width: "%s", height: "%s" crop: "%s", mode: "%s", path: "%s")', |
|
| 50 | - $params, |
|
| 51 | - array_keys($params) |
|
| 52 | - ); |
|
| 53 | - } catch (InvalidPathException|NotFoundException $e) { |
|
| 54 | - Server::get(LoggerInterface::class)->error( |
|
| 55 | - 'Exception thrown in file preview: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e] |
|
| 56 | - ); |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - } |
|
| 34 | + /** |
|
| 35 | + * Logs preview access to a file |
|
| 36 | + */ |
|
| 37 | + private function beforePreviewFetched(BeforePreviewFetchedEvent $event): void { |
|
| 38 | + try { |
|
| 39 | + $file = $event->getNode(); |
|
| 40 | + $params = [ |
|
| 41 | + 'id' => $file->getId(), |
|
| 42 | + 'width' => $event->getWidth(), |
|
| 43 | + 'height' => $event->getHeight(), |
|
| 44 | + 'crop' => $event->isCrop(), |
|
| 45 | + 'mode' => $event->getMode(), |
|
| 46 | + 'path' => $file->getPath(), |
|
| 47 | + ]; |
|
| 48 | + $this->log( |
|
| 49 | + 'Preview accessed: (id: "%s", width: "%s", height: "%s" crop: "%s", mode: "%s", path: "%s")', |
|
| 50 | + $params, |
|
| 51 | + array_keys($params) |
|
| 52 | + ); |
|
| 53 | + } catch (InvalidPathException|NotFoundException $e) { |
|
| 54 | + Server::get(LoggerInterface::class)->error( |
|
| 55 | + 'Exception thrown in file preview: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e] |
|
| 56 | + ); |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Logs when a version is restored |
|
| 63 | - */ |
|
| 64 | - private function versionRestored(VersionRestoredEvent $event): void { |
|
| 65 | - $version = $event->getVersion(); |
|
| 66 | - $this->log('Version "%s" of "%s" was restored.', |
|
| 67 | - [ |
|
| 68 | - 'version' => $version->getRevisionId(), |
|
| 69 | - 'path' => $version->getVersionPath() |
|
| 70 | - ], |
|
| 71 | - ['version', 'path'] |
|
| 72 | - ); |
|
| 73 | - } |
|
| 61 | + /** |
|
| 62 | + * Logs when a version is restored |
|
| 63 | + */ |
|
| 64 | + private function versionRestored(VersionRestoredEvent $event): void { |
|
| 65 | + $version = $event->getVersion(); |
|
| 66 | + $this->log('Version "%s" of "%s" was restored.', |
|
| 67 | + [ |
|
| 68 | + 'version' => $version->getRevisionId(), |
|
| 69 | + 'path' => $version->getVersionPath() |
|
| 70 | + ], |
|
| 71 | + ['version', 'path'] |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | } |