diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-11 22:03:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-11 22:03:01 +0200 |
commit | 8a700d7b44814d1eccbed3a0990dc51c90df576a (patch) | |
tree | 0af4d42477ec5d084fd0008fa626efcfd0823948 /lib | |
parent | bf56b8c620cd2fc18b6e37a54737fb1dd5430ee5 (diff) | |
parent | 7eba1d806b6d0034ba399ad3aeedc336e600ab62 (diff) | |
download | nextcloud-server-8a700d7b44814d1eccbed3a0990dc51c90df576a.tar.gz nextcloud-server-8a700d7b44814d1eccbed3a0990dc51c90df576a.zip |
Merge pull request #1705 from nextcloud/us_register-commands-in-info.xml
[oc] Register commands in info.xml
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/App/InfoParser.php | 6 | ||||
-rw-r--r-- | lib/private/AppFramework/DependencyInjection/DIContainer.php | 5 | ||||
-rw-r--r-- | lib/private/Console/Application.php | 25 |
3 files changed, 33 insertions, 3 deletions
diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index fbeb932763e..44f495534c9 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -107,6 +107,9 @@ class InfoParser { if (!array_key_exists('two-factor-providers', $array)) { $array['two-factor-providers'] = []; } + if (!array_key_exists('commands', $array)) { + $array['commands'] = []; + } if (array_key_exists('types', $array)) { if (is_array($array['types'])) { @@ -138,6 +141,9 @@ class InfoParser { if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { $array['background-jobs'] = $array['background-jobs']['job']; } + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { + $array['commands'] = $array['commands']['command']; + } if(!is_null($this->cache)) { $this->cache->set($fileCacheKey, json_encode($array)); diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index b6f8d8f458d..5fc200a1bce 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -47,7 +47,7 @@ use OC\Core\Middleware\TwoFactorMiddleware; use OCP\AppFramework\IApi; use OCP\AppFramework\IAppContainer; use OCP\Files\IAppData; - +use OCP\Files\Mount\IMountManager; class DIContainer extends SimpleContainer implements IAppContainer { @@ -309,6 +309,9 @@ class DIContainer extends SimpleContainer implements IAppContainer { $this->registerService('OCP\\AppFramework\\IAppContainer', function ($c) { return $c; }); + $this->registerService(IMountManager::class, function () { + return $this->getServer()->getMountManager(); + }); // commonly used attributes $this->registerService('UserId', function ($c) { diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 3033d7beb86..299b23714b6 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -27,12 +27,11 @@ namespace OC\Console; use OC_App; +use OCP\AppFramework\QueryException; use OCP\Console\ConsoleEvent; -use OCP\Defaults; use OCP\IConfig; use OCP\IRequest; use Symfony\Component\Console\Application as SymfonyApplication; -use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -103,6 +102,12 @@ class Application { if($appPath === false) { continue; } + // load commands using info.xml + $info = \OC_App::getAppInfo($app); + if (isset($info['commands'])) { + $this->loadCommandsFromInfoXml($info['commands']); + } + // load from register_command.php \OC_App::registerAutoloading($app, $appPath); $file = $appPath . '/appinfo/register_command.php'; if (file_exists($file)) { @@ -149,4 +154,20 @@ class Application { )); return $this->application->run($input, $output); } + + private function loadCommandsFromInfoXml($commands) { + foreach ($commands as $command) { + try { + $c = \OC::$server->query($command); + } catch (QueryException $e) { + if (class_exists($command)) { + $c = new $command(); + } else { + throw new \Exception("Console command '$command' is unknown and could not be loaded"); + } + } + + $this->application->add($c); + } + } } |