Base.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. namespace OC\Core\Command\Background;
  7. use OCP\IConfig;
  8. use Symfony\Component\Console\Command\Command;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. /**
  12. * An abstract base class for configuring the background job mode
  13. * from the command line interface.
  14. * Subclasses will override the getMode() function to specify the mode to configure.
  15. */
  16. abstract class Base extends Command {
  17. abstract protected function getMode();
  18. public function __construct(
  19. protected IConfig $config,
  20. ) {
  21. parent::__construct();
  22. }
  23. protected function configure(): void {
  24. $mode = $this->getMode();
  25. $this
  26. ->setName("background:$mode")
  27. ->setDescription("Use $mode to run background jobs");
  28. }
  29. /**
  30. * Executing this command will set the background job mode for owncloud.
  31. * The mode to set is specified by the concrete sub class by implementing the
  32. * getMode() function.
  33. *
  34. * @param InputInterface $input
  35. * @param OutputInterface $output
  36. * @return int
  37. */
  38. protected function execute(InputInterface $input, OutputInterface $output): int {
  39. $mode = $this->getMode();
  40. $this->config->setAppValue('core', 'backgroundjobs_mode', $mode);
  41. $output->writeln("Set mode for background jobs to '$mode'");
  42. return 0;
  43. }
  44. }