Merge pull request #21750 from nextcloud/techdebt/noid/files_versions-bootstrap
Move files_versions to bootstrap mechanism
This commit is contained in:
commit
a4cf136706
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
||||
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
\OC::$server->query(\OCA\Files_Versions\AppInfo\Application::class);
|
|
@ -38,31 +38,32 @@ use OCA\Files_Versions\Listener\LoadAdditionalListener;
|
|||
use OCA\Files_Versions\Listener\LoadSidebarListener;
|
||||
use OCA\Files_Versions\Versions\IVersionManager;
|
||||
use OCA\Files_Versions\Versions\VersionManager;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\ILogger;
|
||||
use OCP\IServerContainer;
|
||||
|
||||
class Application extends App {
|
||||
class Application extends App implements IBootstrap {
|
||||
public const APP_ID = 'files_versions';
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
}
|
||||
|
||||
$container = $this->getContainer();
|
||||
$server = $container->getServer();
|
||||
|
||||
/** @var IEventDispatcher $newDispatcher */
|
||||
$dispatcher = $server->query(IEventDispatcher::class);
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
/**
|
||||
* Register capabilities
|
||||
*/
|
||||
$container->registerCapability(Capabilities::class);
|
||||
$context->registerCapability(Capabilities::class);
|
||||
|
||||
/**
|
||||
* Register $principalBackend for the DAV collection
|
||||
*/
|
||||
$container->registerService('principalBackend', function (IAppContainer $c) {
|
||||
$context->registerService('principalBackend', function (IAppContainer $c) {
|
||||
$server = $c->getServer();
|
||||
return new Principal(
|
||||
$server->getUserManager(),
|
||||
|
@ -71,20 +72,23 @@ class Application extends App {
|
|||
$server->getUserSession(),
|
||||
$server->getAppManager(),
|
||||
$server->query(ProxyMapper::class),
|
||||
\OC::$server->getConfig()
|
||||
$server->getConfig()
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService(IVersionManager::class, function (IAppContainer $c) {
|
||||
$context->registerService(IVersionManager::class, function (IAppContainer $c) {
|
||||
return new VersionManager();
|
||||
});
|
||||
|
||||
$this->registerVersionBackends();
|
||||
|
||||
/**
|
||||
* Register Events
|
||||
*/
|
||||
$this->registerEvents($dispatcher);
|
||||
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
|
||||
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
$context->injectFn(\Closure::fromCallable([$this, 'registerVersionBackends']));
|
||||
|
||||
/**
|
||||
* Register hooks
|
||||
|
@ -92,19 +96,17 @@ class Application extends App {
|
|||
Hooks::connectHooks();
|
||||
}
|
||||
|
||||
public function registerVersionBackends() {
|
||||
$server = $this->getContainer()->getServer();
|
||||
$appManager = $server->getAppManager();
|
||||
public function registerVersionBackends(IServerContainer $server, IAppManager $appManager, ILogger $logger) {
|
||||
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);
|
||||
$this->loadBackend($backend, $server, $logger);
|
||||
} else {
|
||||
foreach ($backend as $singleBackend) {
|
||||
$this->loadBackend($singleBackend);
|
||||
$this->loadBackend($singleBackend, $server, $logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,11 +114,9 @@ class Application extends App {
|
|||
}
|
||||
}
|
||||
|
||||
private function loadBackend(array $backend) {
|
||||
$server = $this->getContainer()->getServer();
|
||||
$logger = $server->getLogger();
|
||||
private function loadBackend(array $backend, IServerContainer $server, ILogger $logger) {
|
||||
/** @var IVersionManager $versionManager */
|
||||
$versionManager = $this->getContainer()->getServer()->query(IVersionManager::class);
|
||||
$versionManager = $server->query(IVersionManager::class);
|
||||
$class = $backend['@value'];
|
||||
$for = $backend['@attributes']['for'];
|
||||
try {
|
||||
|
@ -126,9 +126,4 @@ class Application extends App {
|
|||
$logger->logException($e);
|
||||
}
|
||||
}
|
||||
|
||||
protected function registerEvents(IEventDispatcher $dispatcher) {
|
||||
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
|
||||
$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@
|
|||
|
||||
namespace OCA\Files_Versions\Tests;
|
||||
|
||||
require_once __DIR__ . '/../appinfo/app.php';
|
||||
|
||||
use OC\Files\Storage\Temporary;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUser;
|
||||
|
|
Loading…
Reference in New Issue