registerCapability(Capabilities::class); /** * Register $principalBackend for the DAV collection */ $context->registerService('principalBackend', function (ContainerInterface $c) { /** @var IServerContainer $server */ $server = $c->get(IServerContainer::class); return new Principal( $server->get(IUserManager::class), $server->get(IGroupManager::class), \OC::$server->get(IAccountManager::class), $server->get(IShareManager::class), $server->get(IUserSession::class), $server->get(IAppManager::class), $server->get(ProxyMapper::class), $server->get(KnownUserService::class), $server->get(IConfig::class), $server->get(IFactory::class), ); }); $context->registerService(IVersionManager::class, function () { return new VersionManager(); }); /** * Register Events */ $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); $context->registerEventListener(BeforeNodeRenamedEvent::class, VersionStorageMoveListener::class); $context->registerEventListener(NodeRenamedEvent::class, VersionStorageMoveListener::class); $context->registerEventListener(BeforeNodeCopiedEvent::class, VersionStorageMoveListener::class); $context->registerEventListener(NodeCopiedEvent::class, VersionStorageMoveListener::class); $context->registerEventListener(NodeCreatedEvent::class, FileEventsListener::class); $context->registerEventListener(BeforeNodeTouchedEvent::class, FileEventsListener::class); $context->registerEventListener(NodeTouchedEvent::class, FileEventsListener::class); $context->registerEventListener(BeforeNodeWrittenEvent::class, FileEventsListener::class); $context->registerEventListener(NodeWrittenEvent::class, FileEventsListener::class); $context->registerEventListener(BeforeNodeDeletedEvent::class, FileEventsListener::class); $context->registerEventListener(NodeDeletedEvent::class, FileEventsListener::class); $context->registerEventListener(NodeRenamedEvent::class, FileEventsListener::class); $context->registerEventListener(NodeCopiedEvent::class, FileEventsListener::class); $context->registerEventListener(BeforeNodeRenamedEvent::class, FileEventsListener::class); $context->registerEventListener(BeforeNodeCopiedEvent::class, FileEventsListener::class); $context->registerEventListener(NodeWrittenEvent::class, VersionAuthorListener::class); } public function boot(IBootContext $context): void { $context->injectFn(\Closure::fromCallable([$this, 'registerVersionBackends'])); } public function registerVersionBackends(ContainerInterface $container, IAppManager $appManager, LoggerInterface $logger): void { foreach ($appManager->getInstalledApps() as $app) { $appInfo = $appManager->getAppInfo($app); if (isset($appInfo['versions'])) { $backends = $appInfo['versions']; foreach ($backends as $backend) { if (isset($backend['@value'])) { $this->loadBackend($backend, $container, $logger); } else { foreach ($backend as $singleBackend) { $this->loadBackend($singleBackend, $container, $logger); } } } } } } private function loadBackend(array $backend, ContainerInterface $container, LoggerInterface $logger): void { /** @var IVersionManager $versionManager */ $versionManager = $container->get(IVersionManager::class); $class = $backend['@value']; $for = $backend['@attributes']['for']; try { $backendObject = $container->get($class); $versionManager->registerBackend($for, $backendObject); } catch (\Exception $e) { $logger->error($e->getMessage(), ['exception' => $e]); } } }