-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use typed api for changing backgroundjobs_mode
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
- Loading branch information
Showing
5 changed files
with
58 additions
and
46 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* 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'; | ||
} | ||
// Implementation in OC\Core\Command\Background\Base | ||
} |
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 |
---|---|---|
@@ -1,50 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
namespace OC\Core\Command\Background; | ||
|
||
use OCP\IConfig; | ||
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(); | ||
private string $mode; | ||
|
||
public function __construct( | ||
protected IConfig $config, | ||
public function __construct(private IAppConfig $appConfig, | ||
) { | ||
$this->mode = match ($this::class) { | ||
Ajax::class => 'ajax', | ||
Cron::class => 'cron', | ||
WebCron::class => 'webcron', | ||
}; | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void { | ||
$mode = $this->getMode(); | ||
$this | ||
->setName("background:$mode") | ||
->setDescription("Use $mode to run background jobs"); | ||
->setName('background:' . $this->mode) | ||
->setDescription('Use ' . $this->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->setAppValue('core', 'backgroundjobs_mode', $mode); | ||
$output->writeln("Set mode for background jobs to '$mode'"); | ||
$this->appConfig->setValueString('core', 'backgroundjobs_mode', $this->mode); | ||
$output->writeln("Set mode for background jobs to '" . $this->mode . "'"); | ||
return 0; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* 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'; | ||
} | ||
// Implementation in OC\Core\Command\Background\Base | ||
} |
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