Compare commits

...

5 Commits

Author SHA1 Message Date
Daniel Kesselberg a5796292cf
Lazy load dav app
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
2020-01-26 21:19:24 +01:00
Daniel Kesselberg 421054f691
Lazy load core commands
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
2020-01-26 21:15:33 +01:00
Daniel Kesselberg 87fd20fcf6
Make it possible to register core commands lazy
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
2020-01-26 21:00:00 +01:00
Daniel Kesselberg 134cc6132d
Lazy command load for files_external list and export
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
2020-01-26 20:23:28 +01:00
Daniel Kesselberg 7395693fcc
Add command loader to delay instance creation
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
2020-01-26 20:23:01 +01:00
13 changed files with 168 additions and 79 deletions

View File

@ -32,6 +32,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CreateAddressBook extends Command {
public const NAME = 'dav:create-addressbook';
/** @var IUserManager */
private $userManager;
@ -53,7 +54,7 @@ class CreateAddressBook extends Command {
protected function configure() {
$this
->setName('dav:create-addressbook')
->setName(self::NAME)
->setDescription('Create a dav addressbook')
->addArgument('user',
InputArgument::REQUIRED,

View File

@ -38,6 +38,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CreateCalendar extends Command {
public const NAME = 'dav:create-calendar';
/** @var IUserManager */
protected $userManager;
@ -62,7 +63,7 @@ class CreateCalendar extends Command {
protected function configure() {
$this
->setName('dav:create-calendar')
->setName(self::NAME)
->setDescription('Create a dav calendar')
->addArgument('user',
InputArgument::REQUIRED,

View File

@ -41,6 +41,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ListCalendars extends Command {
public const NAME = 'dav:list-calendars';
/** @var IUserManager */
protected $userManager;
@ -60,7 +61,7 @@ class ListCalendars extends Command {
protected function configure() {
$this
->setName('dav:list-calendars')
->setName(self::NAME)
->setDescription('List all calendars of a user')
->addArgument('uid',
InputArgument::REQUIRED,

View File

@ -43,6 +43,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class MoveCalendar extends Command {
public const NAME = 'dav:move-calendar';
/** @var IUserManager */
private $userManager;
@ -94,7 +95,7 @@ class MoveCalendar extends Command {
protected function configure() {
$this
->setName('dav:move-calendar')
->setName(self::NAME)
->setDescription('Move a calendar from an user to another')
->addArgument('name',
InputArgument::REQUIRED,

View File

@ -36,6 +36,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* have no matching principal. Happened because of a bug in the calendar app.
*/
class RemoveInvalidShares extends Command {
public const NAME = 'dav:remove-invalid-shares';
/** @var IDBConnection */
private $connection;
@ -52,7 +53,7 @@ class RemoveInvalidShares extends Command {
protected function configure() {
$this
->setName('dav:remove-invalid-shares')
->setName(self::NAME)
->setDescription('Remove invalid dav shares');
}

View File

@ -36,6 +36,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* @package OCA\DAV\Command
*/
class SendEventReminders extends Command {
public const NAME = 'dav:send-event-reminders';
/** @var ReminderService */
protected $reminderService;
@ -59,7 +60,7 @@ class SendEventReminders extends Command {
*/
protected function configure():void {
$this
->setName('dav:send-event-reminders')
->setName(self::NAME)
->setDescription('Sends event reminders');
}

View File

@ -37,6 +37,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncBirthdayCalendar extends Command {
public const NAME = 'dav:sync-birthday-calendar';
/** @var BirthdayService */
private $birthdayService;
@ -62,7 +63,7 @@ class SyncBirthdayCalendar extends Command {
protected function configure() {
$this
->setName('dav:sync-birthday-calendar')
->setName(self::NAME)
->setDescription('Synchronizes the birthday calendar')
->addArgument('user',
InputArgument::OPTIONAL,

View File

@ -30,6 +30,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncSystemAddressBook extends Command {
public const NAME = 'dav:sync-system-addressbook';
/** @var SyncService */
private $syncService;
@ -44,7 +45,7 @@ class SyncSystemAddressBook extends Command {
protected function configure() {
$this
->setName('dav:sync-system-addressbook')
->setName(self::NAME)
->setDescription('Synchronizes users to the system addressbook');
}

View File

@ -29,10 +29,11 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Export extends ListCommand {
public const NAME = 'files_external:export';
protected function configure() {
$this
->setName('files_external:export')
->setName(self::NAME)
->setDescription('Export mount configurations')
->addArgument(
'user_id',

View File

@ -38,6 +38,8 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ListCommand extends Base {
public const NAME = 'files_external:list';
/**
* @var GlobalStoragesService
*/
@ -70,7 +72,7 @@ class ListCommand extends Base {
protected function configure() {
$this
->setName('files_external:list')
->setName(self::NAME)
->setDescription('List configured admin or personal mounts')
->addArgument(
'user_id',

View File

@ -44,10 +44,10 @@
/** @var $application Symfony\Component\Console\Application */
$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
$application->add(new OC\Core\Command\Status);
$application->add(new OC\Core\Command\Check(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\App\CheckCode());
$application->add(new OC\Core\Command\L10n\CreateJs());
$coreCommandFactories['status'] = \OC\Core\Command\Status::class;
$coreCommandFactories['check'] = \OC\Core\Command\Check::class;
$coreCommandFactories['app:check-code'] = \OC\Core\Command\App\CheckCode::class;
$coreCommandFactories['l10n:createjs'] = \OC\Core\Command\L10n\CreateJs::class;
$application->add(new \OC\Core\Command\Integrity\SignApp(
\OC::$server->getIntegrityCodeChecker(),
new \OC\IntegrityCheck\Helpers\FileAccessHelper(),
@ -57,53 +57,49 @@ $application->add(new \OC\Core\Command\Integrity\SignCore(
\OC::$server->getIntegrityCodeChecker(),
new \OC\IntegrityCheck\Helpers\FileAccessHelper()
));
$application->add(new \OC\Core\Command\Integrity\CheckApp(
\OC::$server->getIntegrityCodeChecker()
));
$application->add(new \OC\Core\Command\Integrity\CheckCore(
\OC::$server->getIntegrityCodeChecker()
));
$coreCommandFactories['integrity:check-app'] = \OC\Core\Command\Integrity\CheckApp::class;
$coreCommandFactories['integrity:check-core'] = \OC\Core\Command\Integrity\CheckCore::class;
if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\App\Install());
$application->add(new OC\Core\Command\App\GetPath());
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
$application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->getLogger()));
$application->add(\OC::$server->query(\OC\Core\Command\App\Update::class));
$coreCommandFactories['app:enable'] = \OC\Core\Command\App\Enable::class;
$coreCommandFactories['app:disable'] = \OC\Core\Command\App\Disable::class;
$coreCommandFactories['app:install'] = \OC\Core\Command\App\Install::class;
$coreCommandFactories['app:getpath'] = \OC\Core\Command\App\GetPath::class;
$coreCommandFactories['app:list'] = \OC\Core\Command\App\ListApps::class;
$coreCommandFactories['app:remove'] = \OC\Core\Command\App\Remove::class;
$coreCommandFactories['app:update'] = \OC\Core\Command\App\Update::class;
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class));
$coreCommandFactories['twofactorauth:cleanup'] = \OC\Core\Command\TwoFactorAuth\Cleanup::class;
$coreCommandFactories['twofactorauth:enforce'] = \OC\Core\Command\TwoFactorAuth\Enforce::class;
$coreCommandFactories['twofactorauth:enable'] = \OC\Core\Command\TwoFactorAuth\Enable::class;
$coreCommandFactories['twofactorauth:disable'] = \OC\Core\Command\TwoFactorAuth\Disable::class;
$coreCommandFactories['twofactorauth:state'] = \OC\Core\Command\TwoFactorAuth\State::class;
$application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));
$coreCommandFactories['background:cron'] = \OC\Core\Command\Background\Cron::class;
$coreCommandFactories['background:webcron'] = \OC\Core\Command\Background\WebCron::class;
$coreCommandFactories['background:ajax'] = \OC\Core\Command\Background\Ajax::class;
$application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class));
$coreCommandFactories['broadcast:test'] = \OC\Core\Command\Broadcast\Test::class;
$application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
$coreCommandFactories['config:app:delete'] = \OC\Core\Command\Config\App\DeleteConfig::class;
$coreCommandFactories['config:app:get'] = \OC\Core\Command\Config\App\GetConfig::class;
$coreCommandFactories['config:app:set'] = \OC\Core\Command\Config\App\SetConfig::class;
$coreCommandFactories['config:import'] = \OC\Core\Command\Config\Import::class;
$coreCommandFactories['config:list'] = \OC\Core\Command\Config\ListConfigs::class;
$coreCommandFactories['config:system:delete'] = \OC\Core\Command\Config\System\DeleteConfig::class;
$coreCommandFactories['config:system:get'] = \OC\Core\Command\Config\System\GetConfig::class;
$coreCommandFactories['config:system:set'] = \OC\Core\Command\Config\System\SetConfig::class;
$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger()));
$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager()));
$application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig()));
$coreCommandFactories['db:convert-type'] = \OC\Core\Command\Db\ConvertType::class;
$coreCommandFactories['db:convert-mysql-charset'] = \OC\Core\Command\Db\ConvertMysqlToMB4::class;
$coreCommandFactories['db:convert-filecache-bigint'] = \OC\Core\Command\Db\ConvertFilecacheBigInt::class;
$coreCommandFactories['db:add-missing-indices'] = \OC\Core\Command\Db\AddMissingIndices::class;
$coreCommandFactories['migrations:status'] = \OC\Core\Command\Db\Migrations\StatusCommand::class;
$coreCommandFactories['migrations:migrate'] = \OC\Core\Command\Db\Migrations\MigrateCommand::class;
$coreCommandFactories['migrations:generate'] = \OC\Core\Command\Db\Migrations\GenerateCommand::class;
$coreCommandFactories['migrations:generate-from-schema'] = \OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand::class;
$coreCommandFactories['migrations:execute'] = \OC\Core\Command\Db\Migrations\ExecuteCommand::class;
$application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
@ -119,8 +115,8 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
new \Symfony\Component\Console\Helper\QuestionHelper())
);
$application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig()));
$coreCommandFactories['log:manage'] = \OC\Core\Command\Log\Manage::class;
$coreCommandFactories['log:file'] = \OC\Core\Command\Log\File::class;
$view = new \OC\Files\View();
$util = new \OC\Encryption\Util(
@ -139,14 +135,14 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
);
$application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util));
$application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory()));
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader()));
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
$coreCommandFactories['maintenance:data-fingerprint'] = \OC\Core\Command\Maintenance\DataFingerprint::class;
$coreCommandFactories['maintenance:mimetype:update-db'] = \OC\Core\Command\Maintenance\Mimetype\UpdateDB::class;
$coreCommandFactories['maintenance:mimetype:update-js'] = \OC\Core\Command\Maintenance\Mimetype\UpdateJS::class;
$coreCommandFactories['maintenance:mode'] = \OC\Core\Command\Maintenance\Mode::class;
$coreCommandFactories['maintenance:update:htaccess'] = \OC\Core\Command\Maintenance\UpdateHtaccess::class;
$coreCommandFactories['maintenance:theme:update'] = \OC\Core\Command\Maintenance\UpdateTheme::class;
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class)));
$coreCommandFactories['upgrade'] = \OC\Core\Command\Upgrade::class;
$application->add(new OC\Core\Command\Maintenance\Repair(
new \OC\Repair([], \OC::$server->getEventDispatcher()),
\OC::$server->getConfig(),
@ -154,22 +150,21 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
\OC::$server->getAppManager()
));
$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$coreCommandFactories['user:add'] = \OC\Core\Command\User\Add::class;
$coreCommandFactories['user:delete'] = \OC\Core\Command\User\Delete::class;
$coreCommandFactories['user:disable'] = \OC\Core\Command\User\Disable::class;
$coreCommandFactories['user:enable'] = \OC\Core\Command\User\Enable::class;
$coreCommandFactories['user:lastseen'] = \OC\Core\Command\User\LastSeen::class;
$coreCommandFactories['user:resetpassword'] = \OC\Core\Command\User\ResetPassword::class;
$coreCommandFactories['user:setting'] = \OC\Core\Command\User\Setting::class;
$coreCommandFactories['user:list'] = \OC\Core\Command\User\ListCommand::class;
$coreCommandFactories['user:info'] = \OC\Core\Command\User\Info::class;
$application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$coreCommandFactories['group:add'] = \OC\Core\Command\Group\Add::class;
$coreCommandFactories['group:delete'] = \OC\Core\Command\Group\Delete::class;
$coreCommandFactories['group:list'] = \OC\Core\Command\Group\ListCommand::class;
$coreCommandFactories['group:adduser'] = \OC\Core\Command\Group\AddUser::class;
$coreCommandFactories['group:removeuser'] = \OC\Core\Command\Group\RemoveUser::class;
$application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core')));
$application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null)));

View File

@ -56,6 +56,8 @@ class Application {
private $logger;
/** @var MemoryInfo */
private $memoryInfo;
/** @var array */
private $commandFactories = [];
/**
* @param IConfig $config
@ -115,6 +117,8 @@ class Application {
);
}
$coreCommandFactories = [];
try {
require_once __DIR__ . '/../../../core/register_command.php';
if ($this->config->getSystemValue('installed', false)) {
@ -156,6 +160,9 @@ class Application {
}
}
$consoleCommandLoader = new ConsoleCommandLoader(array_merge($coreCommandFactories, $this->commandFactories));
$this->application->setCommandLoader($consoleCommandLoader);
if ($input->getFirstArgument() !== 'check') {
$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
if (!empty($errors)) {
@ -216,6 +223,11 @@ class Application {
private function loadCommandsFromInfoXml($commands) {
foreach ($commands as $command) {
if (defined("$command::NAME")) {
$this->commandFactories[constant("$command::NAME")] = $command;
continue;
}
try {
$c = \OC::$server->query($command);
} catch (QueryException $e) {

View File

@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace OC\Console;
/**
* @copyright Copyright (c) 2020 Daniel Kesselberg <mail@danielkesselberg.de>
*
* @author Daniel Kesselberg <mail@danielkesselberg.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
use OCP\AppFramework\QueryException;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\Console\Exception\CommandNotFoundException;
class ConsoleCommandLoader implements CommandLoaderInterface {
private $nameToClass;
/**
* @param string[] $nameToClass Indexed by command names
*/
public function __construct(array $nameToClass) {
$this->nameToClass = $nameToClass;
}
/**
* {@inheritdoc}
*/
public function has($name) {
return isset($this->nameToClass[$name]);
}
/**
* {@inheritdoc}
*/
public function get($name) {
if (!isset($this->nameToClass[$name])) {
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
}
try {
return \OC::$server->query($this->nameToClass[$name]);
} catch (QueryException $e) {
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
}
}
/**
* {@inheritdoc}
*/
public function getNames() {
return array_keys($this->nameToClass);
}
}