aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/Command/Background/Ajax.php12
-rw-r--r--core/Command/Background/Base.php49
-rw-r--r--core/Command/Background/Cron.php12
-rw-r--r--core/Command/Background/Mode.php46
-rw-r--r--core/Command/Background/WebCron.php12
-rw-r--r--core/register_command.php4
-rw-r--r--lib/composer/composer/autoload_classmap.php5
-rw-r--r--lib/composer/composer/autoload_static.php5
-rw-r--r--tests/lib/Command/BackgroundJobsTest.php38
-rw-r--r--tests/lib/Command/BackgroundModeTest.php59
10 files changed, 108 insertions, 134 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));
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 3dcd614de21..9fa3b5bf765 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1081,15 +1081,12 @@ return array(
'OC\\Core\\Command\\App\\ListApps' => $baseDir . '/core/Command/App/ListApps.php',
'OC\\Core\\Command\\App\\Remove' => $baseDir . '/core/Command/App/Remove.php',
'OC\\Core\\Command\\App\\Update' => $baseDir . '/core/Command/App/Update.php',
- 'OC\\Core\\Command\\Background\\Ajax' => $baseDir . '/core/Command/Background/Ajax.php',
- 'OC\\Core\\Command\\Background\\Base' => $baseDir . '/core/Command/Background/Base.php',
- 'OC\\Core\\Command\\Background\\Cron' => $baseDir . '/core/Command/Background/Cron.php',
'OC\\Core\\Command\\Background\\Delete' => $baseDir . '/core/Command/Background/Delete.php',
'OC\\Core\\Command\\Background\\Job' => $baseDir . '/core/Command/Background/Job.php',
'OC\\Core\\Command\\Background\\JobBase' => $baseDir . '/core/Command/Background/JobBase.php',
'OC\\Core\\Command\\Background\\JobWorker' => $baseDir . '/core/Command/Background/JobWorker.php',
'OC\\Core\\Command\\Background\\ListCommand' => $baseDir . '/core/Command/Background/ListCommand.php',
- 'OC\\Core\\Command\\Background\\WebCron' => $baseDir . '/core/Command/Background/WebCron.php',
+ 'OC\\Core\\Command\\Background\\Mode' => $baseDir . '/core/Command/Background/Mode.php',
'OC\\Core\\Command\\Base' => $baseDir . '/core/Command/Base.php',
'OC\\Core\\Command\\Broadcast\\Test' => $baseDir . '/core/Command/Broadcast/Test.php',
'OC\\Core\\Command\\Check' => $baseDir . '/core/Command/Check.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 493708f2e39..38d06cbc9e3 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -1114,15 +1114,12 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Command\\App\\ListApps' => __DIR__ . '/../../..' . '/core/Command/App/ListApps.php',
'OC\\Core\\Command\\App\\Remove' => __DIR__ . '/../../..' . '/core/Command/App/Remove.php',
'OC\\Core\\Command\\App\\Update' => __DIR__ . '/../../..' . '/core/Command/App/Update.php',
- 'OC\\Core\\Command\\Background\\Ajax' => __DIR__ . '/../../..' . '/core/Command/Background/Ajax.php',
- 'OC\\Core\\Command\\Background\\Base' => __DIR__ . '/../../..' . '/core/Command/Background/Base.php',
- 'OC\\Core\\Command\\Background\\Cron' => __DIR__ . '/../../..' . '/core/Command/Background/Cron.php',
'OC\\Core\\Command\\Background\\Delete' => __DIR__ . '/../../..' . '/core/Command/Background/Delete.php',
'OC\\Core\\Command\\Background\\Job' => __DIR__ . '/../../..' . '/core/Command/Background/Job.php',
'OC\\Core\\Command\\Background\\JobBase' => __DIR__ . '/../../..' . '/core/Command/Background/JobBase.php',
'OC\\Core\\Command\\Background\\JobWorker' => __DIR__ . '/../../..' . '/core/Command/Background/JobWorker.php',
'OC\\Core\\Command\\Background\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/Background/ListCommand.php',
- 'OC\\Core\\Command\\Background\\WebCron' => __DIR__ . '/../../..' . '/core/Command/Background/WebCron.php',
+ 'OC\\Core\\Command\\Background\\Mode' => __DIR__ . '/../../..' . '/core/Command/Background/Mode.php',
'OC\\Core\\Command\\Base' => __DIR__ . '/../../..' . '/core/Command/Base.php',
'OC\\Core\\Command\\Broadcast\\Test' => __DIR__ . '/../../..' . '/core/Command/Broadcast/Test.php',
'OC\\Core\\Command\\Check' => __DIR__ . '/../../..' . '/core/Command/Check.php',
diff --git a/tests/lib/Command/BackgroundJobsTest.php b/tests/lib/Command/BackgroundJobsTest.php
deleted file mode 100644
index f066cb5b28a..00000000000
--- a/tests/lib/Command/BackgroundJobsTest.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
- * SPDX-License-Identifier: MIT
- */
-namespace Test\Command;
-
-use OC\Core\Command\Background\Ajax;
-use OC\Core\Command\Background\Cron;
-use OC\Core\Command\Background\WebCron;
-use OCP\IAppConfig;
-use Symfony\Component\Console\Input\StringInput;
-use Symfony\Component\Console\Output\NullOutput;
-use Test\TestCase;
-
-class BackgroundJobsTest extends TestCase {
- public function testCronCommand() {
- $appConfig = \OCP\Server::get(IAppConfig::class);
- $job = new Cron($appConfig);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('cron', $appConfig->getValueString('core', 'backgroundjobs_mode'));
- }
-
- public function testAjaxCommand() {
- $appConfig = \OCP\Server::get(IAppConfig::class);
- $job = new Ajax($appConfig);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('ajax', $appConfig->getValueString('core', 'backgroundjobs_mode'));
- }
-
- public function testWebCronCommand() {
- $appConfig = \OCP\Server::get(IAppConfig::class);
- $job = new WebCron($appConfig);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('webcron', $appConfig->getValueString('core', 'backgroundjobs_mode'));
- }
-}
diff --git a/tests/lib/Command/BackgroundModeTest.php b/tests/lib/Command/BackgroundModeTest.php
new file mode 100644
index 00000000000..941449c98bb
--- /dev/null
+++ b/tests/lib/Command/BackgroundModeTest.php
@@ -0,0 +1,59 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
+ * SPDX-License-Identifier: MIT
+ */
+namespace Test\Command;
+
+use OC\Core\Command\Background\Mode;
+use OCP\IAppConfig;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputDefinition;
+use Symfony\Component\Console\Tester\CommandTester;
+use Test\TestCase;
+
+class BackgroundModeTest extends TestCase {
+ private IAppConfig $appConfig;
+
+ private Mode $command;
+
+ public function setUp(): void {
+ $this->appConfig = $this->createMock(IAppConfig::class);
+
+ $inputDefinition = new InputDefinition([
+ new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
+ ]);
+
+ $this->command = new Mode($this->appConfig);
+ $this->command->setDefinition($inputDefinition);
+ }
+
+ /**
+ * @dataProvider dataModeCommand
+ */
+ public function testModeCommand(string $mode): void {
+ $this->appConfig->expects($this->once())
+ ->method('setValueString')
+ ->with('core', 'backgroundjobs_mode', $mode);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute(['command' => 'background:' . $mode]);
+
+ $commandTester->assertCommandIsSuccessful();
+
+ $output = $commandTester->getDisplay();
+ $this->assertStringContainsString($mode, $output);
+ }
+
+ public function dataModeCommand(): array {
+ return [
+ 'ajax' => ['ajax'],
+ 'cron' => ['cron'],
+ 'webcron' => ['webcron'],
+ ];
+ }
+}