|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 5 | + */ |
| 6 | +namespace OC\Core\Command\TaskProcessing; |
| 7 | + |
| 8 | +use OC\Core\Command\Base; |
| 9 | +use OCP\IConfig; |
| 10 | +use OCP\TaskProcessing\IManager; |
| 11 | +use Symfony\Component\Console\Input\InputArgument; |
| 12 | +use Symfony\Component\Console\Input\InputInterface; |
| 13 | +use Symfony\Component\Console\Output\OutputInterface; |
| 14 | + |
| 15 | +class EnabledCommand extends Base { |
| 16 | + public function __construct( |
| 17 | + protected IManager $taskProcessingManager, |
| 18 | + private IConfig $config, |
| 19 | + ) { |
| 20 | + parent::__construct(); |
| 21 | + } |
| 22 | + |
| 23 | + protected function configure() { |
| 24 | + $this |
| 25 | + ->setName('taskprocessing:task:enabled') |
| 26 | + ->setDescription('Enable or disable a task type') |
| 27 | + ->addArgument( |
| 28 | + 'task-type-id', |
| 29 | + InputArgument::REQUIRED, |
| 30 | + 'ID of the task type to configure' |
| 31 | + ) |
| 32 | + ->addArgument( |
| 33 | + 'enabled', |
| 34 | + InputArgument::REQUIRED, |
| 35 | + 'status of the task type availability. Set 1 to enable and 0 to disable.' |
| 36 | + ); |
| 37 | + parent::configure(); |
| 38 | + } |
| 39 | + |
| 40 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
| 41 | + $enabled = (bool)$input->getArgument('enabled'); |
| 42 | + $taskType = $input->getArgument('task-type-id'); |
| 43 | + $json = $this->config->getAppValue('core', 'ai.taskprocessing_type_preferences'); |
| 44 | + if ($json === '') { |
| 45 | + $taskTypeSettings = []; |
| 46 | + } else { |
| 47 | + $taskTypeSettings = json_decode($json, true); |
| 48 | + } |
| 49 | + if ($enabled) { |
| 50 | + $taskTypeSettings[$taskType] = true; |
| 51 | + } else { |
| 52 | + $taskTypeSettings[$taskType] = false; |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + $this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskTypeSettings)); |
| 57 | + $this->writeArrayInOutputFormat($input, $output, $taskTypeSettings); |
| 58 | + return 0; |
| 59 | + } |
| 60 | +} |
0 commit comments