-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46185 from nextcloud/debt/noid/migrate-background…
…-commands-to-iappconfig refactor: simplify background commands
- Loading branch information
Showing
10 changed files
with
108 additions
and
134 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
]; | ||
} | ||
} |