Skip to content

Commit 8f56d71

Browse files
committed
feat: add occ command for task type toggling
Signed-off-by: Jana Peper <[email protected]>
1 parent 28ff78b commit 8f56d71

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}

core/register_command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
$application->add(Server::get(Command\FilesMetadata\Get::class));
148148

149149
$application->add(Server::get(Command\TaskProcessing\GetCommand::class));
150+
$application->add(Server::get(Command\TaskProcessing\EnabledCommand::class));
150151
$application->add(Server::get(Command\TaskProcessing\ListCommand::class));
151152
$application->add(Server::get(Command\TaskProcessing\Statistics::class));
152153

0 commit comments

Comments
 (0)