Merge pull request #1705 from nextcloud/us_register-commands-in-info.xml

[oc] Register commands in info.xml
This commit is contained in:
Joas Schilling 2016-10-11 22:03:01 +02:00 committed by GitHub
commit 8a700d7b44
15 changed files with 68 additions and 175 deletions

View File

@ -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>

View File

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

View File

@ -23,4 +23,8 @@
<settings>
<admin>OCA\Federation\Settings\Admin</admin>
</settings>
<commands>
<command>OCA\Federation\Command\SyncFederationAddressBooks</command>
</commands>
</info>

View File

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

View File

@ -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>

View File

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

View 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>

View File

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

View 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 users 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 doesnt 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 users 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>

View File

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

View 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));

View 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) {

View File

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

View File

@ -76,5 +76,6 @@
"uninstall": []
},
"background-jobs": [],
"two-factor-providers": []
"two-factor-providers": [],
"commands": []
}

View File

@ -118,5 +118,12 @@ class InfoXmlTest extends TestCase {
$this->assertInstanceOf($migration, \OC::$server->query($migration));
}
}
if (isset($appInfo['commands'])) {
foreach ($appInfo['commands'] as $command) {
$this->assertTrue(class_exists($command), 'Asserting command "'. $command . '"exists');
$this->assertInstanceOf($command, \OC::$server->query($command));
}
}
}
}