|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|