]> source.dussan.org Git - nextcloud-server.git/commitdiff
[9.2] Register commands in info.xml (#26248)
authorThomas Müller <DeepDiver1975@users.noreply.github.com>
Fri, 30 Sep 2016 08:09:52 +0000 (10:09 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Tue, 11 Oct 2016 17:48:26 +0000 (19:48 +0200)
* 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>
14 files changed:
apps/dav/appinfo/info.xml
apps/dav/appinfo/register_command.php [deleted file]
apps/federation/appinfo/info.xml
apps/federation/appinfo/register_command.php [deleted file]
apps/files/appinfo/info.xml
apps/files/appinfo/register_command.php [deleted file]
apps/files_trashbin/appinfo/info.xml
apps/files_trashbin/appinfo/register_command.php [deleted file]
apps/files_versions/appinfo/info.xml
apps/files_versions/appinfo/register_command.php [deleted file]
lib/private/App/InfoParser.php
lib/private/AppFramework/DependencyInjection/DIContainer.php
lib/private/Console/Application.php
tests/data/app/expected-info.json

index c9cd679801807311179fd03a70a9a46dcd5c1ce8..4d3b17572840576fbfae8c9d6e6ddcc3df5b5e04 100644 (file)
                        <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 (file)
index 57bf8ff..0000000
+++ /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)));
index da65fef2446a254be2de766e58b52ce3ca494346..cec3f8341a9c96b760603c96994ed63712cf900c 100644 (file)
@@ -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 (file)
index c7cec58..0000000
+++ /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));
index 513940f73a95c2355cafeffa9dc66de6324d79c1..37a85f33afc06cfdea1bb186c68b73e325788bff 100644 (file)
        <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 (file)
index e0d3ba6..0000000
+++ /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));
index 16ed81efd77db69e005ce86e1f6c987311373802..2fd88ff7765a7222823d5a504be3c4d265d8328b 100644 (file)
@@ -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 (file)
index e0dafc6..0000000
+++ /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));
index b167104016a90e615d992e43f9a7fbe702b84ae1..026ed406d7c2be452ebca2e28916db40c7e0c730 100644 (file)
@@ -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 (file)
index bca8690..0000000
+++ /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));
index fbeb932763e0a6770d374e0deafd5b7b8a2975dd..44f495534c9746e03fe809e4bcdeca5a45744f0f 100644 (file)
@@ -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));
index b6f8d8f458d51ea85d71036e26f9452af95cea46..5fc200a1bce1462f36edb175f823b51263ff3f83 100644 (file)
@@ -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) {
index 3033d7beb867e24cccdc30e1589e84b8ffa78cc9..299b23714b6a7b1af154c47fa9f48d8068f8f876 100644 (file)
 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);
+               }
+       }
 }
index 6ddd3ae8568fc387ad31084e40f9c6891950062d..fb596f296dac5ebddead173b35b4b07800d0f255 100644 (file)
@@ -76,5 +76,6 @@
                "uninstall": []
        },
        "background-jobs": [],
-       "two-factor-providers": []
+       "two-factor-providers": [],
+       "commands": []
 }