diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index b9cb06c298e..47af57bf3ec 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -28,6 +28,7 @@ namespace OC\TextProcessing; use OC\AppFramework\Bootstrap\Coordinator; use OC\TextProcessing\Db\Task as DbTask; use OCP\IConfig; +use OCP\TextProcessing\IProviderWithId; use OCP\TextProcessing\Task; use OCP\TextProcessing\Task as OCPTask; use OC\TextProcessing\Db\TaskMapper; @@ -120,7 +121,12 @@ class Manager implements IManager { $preferences = json_decode($json, true); if (isset($preferences[$task->getType()])) { // If a preference for this task type is set, move the preferred provider to the start - $provider = current(array_filter($providers, fn ($provider) => $provider::class === $preferences[$task->getType()])); + $provider = current(array_filter($providers, function ($provider) use ($preferences, $task) { + if ($provider instanceof IProviderWithId) { + return $provider->getId() === $preferences[$task->getType()]; + } + return $provider::class === $preferences[$task->getType()]; + })); if ($provider !== false) { $providers = array_filter($providers, fn ($p) => $p !== $provider); array_unshift($providers, $provider); diff --git a/lib/public/TextProcessing/IProvider.php b/lib/public/TextProcessing/IProvider.php index 6132e60b493..01c17f4bfbf 100644 --- a/lib/public/TextProcessing/IProvider.php +++ b/lib/public/TextProcessing/IProvider.php @@ -56,7 +56,7 @@ interface IProvider { * provider handles * * @since 27.1.0 - * @return class-string + * @return class-string|string */ public function getTaskType(): string; } diff --git a/lib/public/TextProcessing/IProviderWithId.php b/lib/public/TextProcessing/IProviderWithId.php new file mode 100644 index 00000000000..3d86b50b2c8 --- /dev/null +++ b/lib/public/TextProcessing/IProviderWithId.php @@ -0,0 +1,39 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +namespace OCP\TextProcessing; + +/** + * @since 28.0.0 + */ +interface IProviderWithId extends IProvider { + + /** + * The id of this provider + * @since 28.0.0 + */ + public function getId(): string; +} diff --git a/lib/public/TextProcessing/ITaskTypeWithId.php b/lib/public/TextProcessing/ITaskTypeWithId.php new file mode 100644 index 00000000000..b86b831f266 --- /dev/null +++ b/lib/public/TextProcessing/ITaskTypeWithId.php @@ -0,0 +1,37 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\TextProcessing; + +/** + * @since 28.0.0 + */ +interface ITaskTypeWithId { + /** + * The id of this provider + * @since 28.0.0 + */ + public function getId(): string; +} diff --git a/lib/public/TextProcessing/Task.php b/lib/public/TextProcessing/Task.php index 446e414cb04..52a7637bd7c 100644 --- a/lib/public/TextProcessing/Task.php +++ b/lib/public/TextProcessing/Task.php @@ -29,8 +29,8 @@ namespace OCP\TextProcessing; * This is a text processing task * @since 27.1.0 * @psalm-template T of ITaskType - * @psalm-template S as class-string - * @psalm-template P as IProvider + * @psalm-template S as class-string | string + * @psalm-template P as IProvider | IProvider */ final class Task implements \JsonSerializable { protected ?int $id = null;