aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndy Scherzinger <info@andy-scherzinger.de>2024-12-18 20:08:28 +0100
committerGitHub <noreply@github.com>2024-12-18 20:08:28 +0100
commita60f71bd939eeb94012d608736c0e96e72b20e95 (patch)
tree0125bc6590660551ac768a6e2019fb2e8efedb2c /lib
parentd2923aa30f9a6f1829d53fa000454ad3fdeb2bf3 (diff)
parent75e64e294229fdee5d3005e1c9a930f45f159195 (diff)
downloadnextcloud-server-a60f71bd939eeb94012d608736c0e96e72b20e95.tar.gz
nextcloud-server-a60f71bd939eeb94012d608736c0e96e72b20e95.zip
Merge pull request #49727 from nextcloud/feat/make-tasks-types-toggleable
Feat: make taskprocessing task types toggleable
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_psr4.php1
-rw-r--r--lib/composer/composer/autoload_static.php9
-rw-r--r--lib/private/TaskProcessing/Manager.php38
-rw-r--r--lib/public/TaskProcessing/IManager.php4
5 files changed, 50 insertions, 3 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index df4011f0589..7064b97f430 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1267,6 +1267,7 @@ return array(
'OC\\Core\\Command\\SystemTag\\Delete' => $baseDir . '/core/Command/SystemTag/Delete.php',
'OC\\Core\\Command\\SystemTag\\Edit' => $baseDir . '/core/Command/SystemTag/Edit.php',
'OC\\Core\\Command\\SystemTag\\ListCommand' => $baseDir . '/core/Command/SystemTag/ListCommand.php',
+ 'OC\\Core\\Command\\TaskProcessing\\EnabledCommand' => $baseDir . '/core/Command/TaskProcessing/EnabledCommand.php',
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => $baseDir . '/core/Command/TaskProcessing/GetCommand.php',
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => $baseDir . '/core/Command/TaskProcessing/ListCommand.php',
'OC\\Core\\Command\\TaskProcessing\\Statistics' => $baseDir . '/core/Command/TaskProcessing/Statistics.php',
diff --git a/lib/composer/composer/autoload_psr4.php b/lib/composer/composer/autoload_psr4.php
index b07b2c0074b..09892528d3a 100644
--- a/lib/composer/composer/autoload_psr4.php
+++ b/lib/composer/composer/autoload_psr4.php
@@ -10,5 +10,6 @@ return array(
'OC\\' => array($baseDir . '/lib/private'),
'OCP\\' => array($baseDir . '/lib/public'),
'NCU\\' => array($baseDir . '/lib/unstable'),
+ 'Bamarni\\Composer\\Bin\\' => array($vendorDir . '/bamarni/composer-bin-plugin/src'),
'' => array($baseDir . '/lib/private/legacy'),
);
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index bbe553913ee..adb0bf6899b 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -21,6 +21,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
array (
'NCU\\' => 4,
),
+ 'B' =>
+ array (
+ 'Bamarni\\Composer\\Bin\\' => 21,
+ ),
);
public static $prefixDirsPsr4 = array (
@@ -40,6 +44,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
array (
0 => __DIR__ . '/../../..' . '/lib/unstable',
),
+ 'Bamarni\\Composer\\Bin\\' =>
+ array (
+ 0 => __DIR__ . '/..' . '/bamarni/composer-bin-plugin/src',
+ ),
);
public static $fallbackDirsPsr4 = array (
@@ -1308,6 +1316,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Command\\SystemTag\\Delete' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Delete.php',
'OC\\Core\\Command\\SystemTag\\Edit' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Edit.php',
'OC\\Core\\Command\\SystemTag\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/SystemTag/ListCommand.php',
+ 'OC\\Core\\Command\\TaskProcessing\\EnabledCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/EnabledCommand.php',
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/GetCommand.php',
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/ListCommand.php',
'OC\\Core\\Command\\TaskProcessing\\Statistics' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/Statistics.php',
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php
index ffa39912a01..96cdc8c44f8 100644
--- a/lib/private/TaskProcessing/Manager.php
+++ b/lib/private/TaskProcessing/Manager.php
@@ -565,6 +565,29 @@ class Manager implements IManager {
}
/**
+ * @return array
+ */
+ private function _getTaskTypeSettings(): array {
+ try {
+ $json = $this->config->getAppValue('core', 'ai.taskprocessing_type_preferences', '');
+ if ($json === '') {
+ return [];
+ }
+ return json_decode($json, true, flags: JSON_THROW_ON_ERROR);
+ } catch (\JsonException $e) {
+ $this->logger->error('Failed to get settings. JSON Error in ai.taskprocessing_type_preferences', ['exception' => $e]);
+ $taskTypeSettings = [];
+ $taskTypes = $this->_getTaskTypes();
+ foreach ($taskTypes as $taskType) {
+ $taskTypeSettings[$taskType->getId()] = false;
+ };
+
+ return $taskTypeSettings;
+ }
+
+ }
+
+ /**
* @param ShapeDescriptor[] $spec
* @param array<array-key, string|numeric> $defaults
* @param array<array-key, ShapeEnumValue[]> $enumValues
@@ -721,12 +744,17 @@ class Manager implements IManager {
throw new \OCP\TaskProcessing\Exception\Exception('No matching provider found');
}
- public function getAvailableTaskTypes(): array {
- if ($this->availableTaskTypes === null) {
+ public function getAvailableTaskTypes(bool $showDisabled = false): array {
+ // Either we have no cache or showDisabled is turned on, which we don't want to cache, ever.
+ if ($this->availableTaskTypes === null || $showDisabled) {
$taskTypes = $this->_getTaskTypes();
+ $taskTypeSettings = $this->_getTaskTypeSettings();
$availableTaskTypes = [];
foreach ($taskTypes as $taskType) {
+ if ((!$showDisabled) && isset($taskTypeSettings[$taskType->getId()]) && !$taskTypeSettings[$taskType->getId()]) {
+ continue;
+ }
try {
$provider = $this->getPreferredProvider($taskType->getId());
} catch (\OCP\TaskProcessing\Exception\Exception $e) {
@@ -752,9 +780,15 @@ class Manager implements IManager {
}
}
+ if ($showDisabled) {
+ // Do not cache showDisabled, ever.
+ return $availableTaskTypes;
+ }
+
$this->availableTaskTypes = $availableTaskTypes;
}
+
return $this->availableTaskTypes;
}
diff --git a/lib/public/TaskProcessing/IManager.php b/lib/public/TaskProcessing/IManager.php
index 1b59bb12ad4..68825e82533 100644
--- a/lib/public/TaskProcessing/IManager.php
+++ b/lib/public/TaskProcessing/IManager.php
@@ -46,10 +46,12 @@ interface IManager {
public function getPreferredProvider(string $taskTypeId);
/**
+ * @param bool $showDisabled if false, disabled task types will be filtered
* @return array<string, array{name: string, description: string, inputShape: ShapeDescriptor[], inputShapeEnumValues: ShapeEnumValue[][], inputShapeDefaults: array<array-key, numeric|string>, optionalInputShape: ShapeDescriptor[], optionalInputShapeEnumValues: ShapeEnumValue[][], optionalInputShapeDefaults: array<array-key, numeric|string>, outputShape: ShapeDescriptor[], outputShapeEnumValues: ShapeEnumValue[][], optionalOutputShape: ShapeDescriptor[], optionalOutputShapeEnumValues: ShapeEnumValue[][]}>
* @since 30.0.0
+ * @since 31.0.0 Added the `showDisabled` argument.
*/
- public function getAvailableTaskTypes(): array;
+ public function getAvailableTaskTypes(bool $showDisabled = false): array;
/**
* @param Task $task The task to run