diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-06-27 22:09:09 +0200 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-07-01 12:52:06 +0200 |
commit | a773a8b915aafcb9fb6727384add9a5d01378932 (patch) | |
tree | e61904cee848752880e7c2edddad992770b4e124 /core | |
parent | 3b75c5b98cd0356e99c07d9696c49732f195b3f6 (diff) | |
download | nextcloud-server-a773a8b915aafcb9fb6727384add9a5d01378932.tar.gz nextcloud-server-a773a8b915aafcb9fb6727384add9a5d01378932.zip |
refactor: simplify background commands
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'core')
-rw-r--r-- | core/Command/Background/Ajax.php | 12 | ||||
-rw-r--r-- | core/Command/Background/Base.php | 49 | ||||
-rw-r--r-- | core/Command/Background/Cron.php | 12 | ||||
-rw-r--r-- | core/Command/Background/Mode.php | 46 | ||||
-rw-r--r-- | core/Command/Background/WebCron.php | 12 | ||||
-rw-r--r-- | core/register_command.php | 4 |
6 files changed, 47 insertions, 88 deletions
diff --git a/core/Command/Background/Ajax.php b/core/Command/Background/Ajax.php deleted file mode 100644 index 16486649bf0..00000000000 --- a/core/Command/Background/Ajax.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net> - * SPDX-License-Identifier: MIT - */ -namespace OC\Core\Command\Background; - -class Ajax extends Base { - protected function getMode(): string { - return 'ajax'; - } -} diff --git a/core/Command/Background/Base.php b/core/Command/Background/Base.php deleted file mode 100644 index 364c9fa3c0c..00000000000 --- a/core/Command/Background/Base.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net> - * SPDX-License-Identifier: MIT - */ -namespace OC\Core\Command\Background; - -use OCP\IAppConfig; - -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; - -/** - * An abstract base class for configuring the background job mode - * from the command line interface. - * Subclasses will override the getMode() function to specify the mode to configure. - */ -abstract class Base extends Command { - abstract protected function getMode(): string; - - public function __construct( - protected IAppConfig $config, - ) { - parent::__construct(); - } - - protected function configure(): void { - $mode = $this->getMode(); - $this->setName("background:$mode") - ->setDescription("Use $mode to run background jobs"); - } - - /** - * Executing this command will set the background job mode for owncloud. - * The mode to set is specified by the concrete sub class by implementing the - * getMode() function. - * - * @param InputInterface $input - * @param OutputInterface $output - * @return int - */ - protected function execute(InputInterface $input, OutputInterface $output): int { - $mode = $this->getMode(); - $this->config->setValueString('core', 'backgroundjobs_mode', $mode); - $output->writeln("Set mode for background jobs to '$mode'"); - return 0; - } -} diff --git a/core/Command/Background/Cron.php b/core/Command/Background/Cron.php deleted file mode 100644 index 9f010b456fa..00000000000 --- a/core/Command/Background/Cron.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net> - * SPDX-License-Identifier: MIT - */ -namespace OC\Core\Command\Background; - -class Cron extends Base { - protected function getMode(): string { - return 'cron'; - } -} diff --git a/core/Command/Background/Mode.php b/core/Command/Background/Mode.php new file mode 100644 index 00000000000..4c0f40bb4a2 --- /dev/null +++ b/core/Command/Background/Mode.php @@ -0,0 +1,46 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net> + * SPDX-License-Identifier: MIT + */ +namespace OC\Core\Command\Background; + +use OCP\IAppConfig; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class Mode extends Command { + public function __construct( + private IAppConfig $appConfig, + ) { + parent::__construct(); + } + + protected function configure(): void { + $this + ->setName('background:cron') + ->setAliases(['background:ajax', 'background:webcron']) + ->setDescription('Use cron, ajax or webcron to run background jobs'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + /** @var 'background:cron'|'background:ajax'|'background:webcron' $command */ + $command = $input->getArgument('command'); + + $mode = match ($command) { + 'background:cron' => 'cron', + 'background:ajax' => 'ajax', + 'background:webcron' => 'webcron', + }; + + $this->appConfig->setValueString('core', 'backgroundjobs_mode', $mode); + $output->writeln("Set mode for background jobs to '" . $mode . "'"); + + return 0; + } +} diff --git a/core/Command/Background/WebCron.php b/core/Command/Background/WebCron.php deleted file mode 100644 index 1e3e5ca5f17..00000000000 --- a/core/Command/Background/WebCron.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net> - * SPDX-License-Identifier: MIT - */ -namespace OC\Core\Command\Background; - -class WebCron extends Base { - protected function getMode(): string { - return 'webcron'; - } -} diff --git a/core/register_command.php b/core/register_command.php index 5185da496b6..021a21c8324 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -38,9 +38,7 @@ if ($config->getSystemValueBool('installed', false)) { $application->add(Server::get(Command\TwoFactorAuth\Disable::class)); $application->add(Server::get(Command\TwoFactorAuth\State::class)); - $application->add(Server::get(Command\Background\Cron::class)); - $application->add(Server::get(Command\Background\WebCron::class)); - $application->add(Server::get(Command\Background\Ajax::class)); + $application->add(Server::get(Command\Background\Mode::class)); $application->add(Server::get(Command\Background\Job::class)); $application->add(Server::get(Command\Background\ListCommand::class)); $application->add(Server::get(Command\Background\Delete::class)); |