aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <DeepDiver1975@users.noreply.github.com>2016-09-30 10:09:52 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-10-11 19:48:26 +0200
commitc5ca71ee8289886c5892880679b200755fdc6dcc (patch)
tree040b66c0ea15d3c95000613fb14374f5fa5ffd5b
parent675230f86d74325d41cec4df59578919241934ce (diff)
downloadnextcloud-server-c5ca71ee8289886c5892880679b200755fdc6dcc.tar.gz
nextcloud-server-c5ca71ee8289886c5892880679b200755fdc6dcc.zip
[9.2] Register commands in info.xml (#26248)
* Use DI to load console commands from the apps - class name to be defined in the info.xml * Load commands from info.xml * Fix unit test * Allow Di magic for IMountManager Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--apps/dav/appinfo/info.xml6
-rw-r--r--apps/dav/appinfo/register_command.php39
-rw-r--r--apps/federation/appinfo/info.xml4
-rw-r--r--apps/federation/appinfo/register_command.php27
-rw-r--r--apps/files/appinfo/info.xml6
-rw-r--r--apps/files/appinfo/register_command.php34
-rw-r--r--apps/files_trashbin/appinfo/info.xml5
-rw-r--r--apps/files_trashbin/appinfo/register_command.php36
-rw-r--r--apps/files_versions/appinfo/info.xml6
-rw-r--r--apps/files_versions/appinfo/register_command.php34
-rw-r--r--lib/private/App/InfoParser.php6
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php5
-rw-r--r--lib/private/Console/Application.php25
-rw-r--r--tests/data/app/expected-info.json3
14 files changed, 61 insertions, 175 deletions
diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml
index c9cd6798018..4d3b1757284 100644
--- a/apps/dav/appinfo/info.xml
+++ b/apps/dav/appinfo/info.xml
@@ -29,4 +29,10 @@
<step>OCA\DAV\Migration\GenerateBirthdays</step>
</live-migration>
</repair-steps>
+ <commands>
+ <command>OCA\DAV\Command\CreateAddressBook</command>
+ <command>OCA\DAV\Command\CreateCalendar</command>
+ <command>OCA\DAV\Command\SyncBirthdayCalendar</command>
+ <command>OCA\DAV\Command\SyncSystemAddressBook</command>
+ </commands>
</info>
diff --git a/apps/dav/appinfo/register_command.php b/apps/dav/appinfo/register_command.php
deleted file mode 100644
index 57bf8ff5dd9..00000000000
--- a/apps/dav/appinfo/register_command.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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/>
- *
- */
-use OCA\DAV\AppInfo\Application;
-use OCA\DAV\Command\CreateAddressBook;
-use OCA\DAV\Command\CreateCalendar;
-use OCA\DAV\Command\SyncBirthdayCalendar;
-use OCA\DAV\Command\SyncSystemAddressBook;
-
-$dbConnection = \OC::$server->getDatabaseConnection();
-$userManager = OC::$server->getUserManager();
-$groupManager = OC::$server->getGroupManager();
-
-$app = new Application();
-
-/** @var Symfony\Component\Console\Application $application */
-$application->add(new CreateCalendar($userManager, $groupManager, $dbConnection));
-$application->add(new CreateAddressBook($userManager, $app->getContainer()->query(\OCA\DAV\CardDAV\CardDavBackend::class)));
-$application->add(new SyncSystemAddressBook($app->getSyncService()));
-$application->add(new SyncBirthdayCalendar($userManager, $app->getContainer()->query(\OCA\DAV\CalDAV\BirthdayService::class)));
diff --git a/apps/federation/appinfo/info.xml b/apps/federation/appinfo/info.xml
index da65fef2446..cec3f8341a9 100644
--- a/apps/federation/appinfo/info.xml
+++ b/apps/federation/appinfo/info.xml
@@ -23,4 +23,8 @@
<settings>
<admin>OCA\Federation\Settings\Admin</admin>
</settings>
+
+ <commands>
+ <command>OCA\Federation\Command\SyncFederationAddressBooks</command>
+ </commands>
</info>
diff --git a/apps/federation/appinfo/register_command.php b/apps/federation/appinfo/register_command.php
deleted file mode 100644
index c7cec58efd4..00000000000
--- a/apps/federation/appinfo/register_command.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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/>
- *
- */
-$app = new \OCA\Federation\AppInfo\Application();
-$syncService = $app->getSyncService();
-
-/** @var Symfony\Component\Console\Application $application */
-$application->add(new \OCA\Federation\Command\SyncFederationAddressBooks($syncService));
diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml
index 513940f73a9..37a85f33afc 100644
--- a/apps/files/appinfo/info.xml
+++ b/apps/files/appinfo/info.xml
@@ -26,4 +26,10 @@
<settings>
<admin>OCA\Files\Settings\Admin</admin>
</settings>
+
+ <commands>
+ <command>OCA\Files\Command\Scan</command>
+ <command>OCA\Files\Command\DeleteOrphanedFiles</command>
+ <command>OCA\Files\Command\TransferOwnership</command>
+ </commands>
</info>
diff --git a/apps/files/appinfo/register_command.php b/apps/files/appinfo/register_command.php
deleted file mode 100644
index e0d3ba622f3..00000000000
--- a/apps/files/appinfo/register_command.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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/>
- *
- */
-
-$dbConnection = \OC::$server->getDatabaseConnection();
-$userManager = OC::$server->getUserManager();
-$shareManager = \OC::$server->getShareManager();
-$mountManager = \OC::$server->getMountManager();
-
-/** @var Symfony\Component\Console\Application $application */
-$application->add(new OCA\Files\Command\Scan($userManager));
-$application->add(new OCA\Files\Command\DeleteOrphanedFiles($dbConnection));
-$application->add(new OCA\Files\Command\TransferOwnership($userManager, $shareManager, $mountManager));
diff --git a/apps/files_trashbin/appinfo/info.xml b/apps/files_trashbin/appinfo/info.xml
index 16ed81efd77..2fd88ff7765 100644
--- a/apps/files_trashbin/appinfo/info.xml
+++ b/apps/files_trashbin/appinfo/info.xml
@@ -25,4 +25,9 @@ To prevent a user from running out of disk space, the Deleted files app will not
<background-jobs>
<job>OCA\Files_Trashbin\BackgroundJob\ExpireTrash</job>
</background-jobs>
+
+ <commands>
+ <command>OCA\Files_Trashbin\Command\CleanUp</command>
+ <command>OCA\Files_Trashbin\Command\ExpireTrash</command>
+ </commands>
</info>
diff --git a/apps/files_trashbin/appinfo/register_command.php b/apps/files_trashbin/appinfo/register_command.php
deleted file mode 100644
index e0dafc60cd9..00000000000
--- a/apps/files_trashbin/appinfo/register_command.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- *
- * @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/>
- *
- */
-
-
-use OCA\Files_Trashbin\AppInfo\Application;
-use OCA\Files_Trashbin\Command\CleanUp;
-use OCA\Files_Trashbin\Command\ExpireTrash;
-
-$app = new Application();
-$expiration = $app->getContainer()->query('Expiration');
-$userManager = OC::$server->getUserManager();
-$rootFolder = \OC::$server->getRootFolder();
-$dbConnection = \OC::$server->getDatabaseConnection();
-
-/** @var Symfony\Component\Console\Application $application */
-$application->add(new CleanUp($rootFolder, $userManager, $dbConnection));
-$application->add(new ExpireTrash($userManager, $expiration));
diff --git a/apps/files_versions/appinfo/info.xml b/apps/files_versions/appinfo/info.xml
index b167104016a..026ed406d7c 100644
--- a/apps/files_versions/appinfo/info.xml
+++ b/apps/files_versions/appinfo/info.xml
@@ -7,7 +7,6 @@
<description>
This application automatically maintains older versions of files that are changed. When enabled, a hidden versions folder is provisioned in every user’s directory and is used to store old file versions. A user can revert to an older version through the web interface at any time, with the replaced file becoming a version. The app automatically manages the versions folder to ensure the user doesn’t run out of Quota because of versions.
In addition to the expiry of versions, the versions app makes certain never to use more than 50% of the user’s currently available free space. If stored versions exceed this limit, the app will delete the oldest versions first until it meets this limit. More information is available in the Versions documentation.
-
</description>
<version>1.4.0</version>
<types>
@@ -25,4 +24,9 @@ In addition to the expiry of versions, the versions app makes certain never to u
<background-jobs>
<job>OCA\Files_Versions\BackgroundJob\ExpireVersions</job>
</background-jobs>
+
+ <commands>
+ <command>OCA\Files_Versions\Command\CleanUp</command>
+ <command>OCA\Files_Versions\Command\ExpireVersions</command>
+ </commands>
</info>
diff --git a/apps/files_versions/appinfo/register_command.php b/apps/files_versions/appinfo/register_command.php
deleted file mode 100644
index bca869075aa..00000000000
--- a/apps/files_versions/appinfo/register_command.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- *
- * @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/>
- *
- */
-
-
-use OCA\Files_Versions\AppInfo\Application;
-use OCA\Files_Versions\Command\CleanUp;
-use OCA\Files_Versions\Command\ExpireVersions;
-
-$app = new Application();
-$expiration = $app->getContainer()->query('Expiration');
-$userManager = OC::$server->getUserManager();
-$rootFolder = \OC::$server->getRootFolder();
-/** @var Symfony\Component\Console\Application $application */
-$application->add(new CleanUp($rootFolder, $userManager));
-$application->add(new ExpireVersions($userManager, $expiration));
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);
+ }
+ }
}
diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json
index 6ddd3ae8568..fb596f296da 100644
--- a/tests/data/app/expected-info.json
+++ b/tests/data/app/expected-info.json
@@ -76,5 +76,6 @@
"uninstall": []
},
"background-jobs": [],
- "two-factor-providers": []
+ "two-factor-providers": [],
+ "commands": []
}