Mode.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
  5. * SPDX-License-Identifier: MIT
  6. */
  7. namespace OC\Core\Command\Background;
  8. use OCP\IAppConfig;
  9. use Symfony\Component\Console\Command\Command;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. class Mode extends Command {
  13. public function __construct(
  14. private IAppConfig $appConfig,
  15. ) {
  16. parent::__construct();
  17. }
  18. protected function configure(): void {
  19. $this
  20. ->setName('background:cron')
  21. ->setAliases(['background:ajax', 'background:webcron'])
  22. ->setDescription('Use cron, ajax or webcron to run background jobs');
  23. }
  24. protected function execute(InputInterface $input, OutputInterface $output): int {
  25. /** @var 'background:cron'|'background:ajax'|'background:webcron' $command */
  26. $command = $input->getArgument('command');
  27. $mode = match ($command) {
  28. 'background:cron' => 'cron',
  29. 'background:ajax' => 'ajax',
  30. 'background:webcron' => 'webcron',
  31. };
  32. $this->appConfig->setValueString('core', 'backgroundjobs_mode', $mode);
  33. $output->writeln("Set mode for background jobs to '" . $mode . "'");
  34. return 0;
  35. }
  36. }