diff options
author | Julien Veyssier <julien-nc@posteo.net> | 2023-08-03 23:11:29 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2023-08-09 14:58:02 +0200 |
commit | 8e657a894583c6276697dc03767a2c201a97fc1b (patch) | |
tree | 05860d8f2819e948d3c6d9a08ab7b79e238d4829 /lib | |
parent | 6eb18570c0822ed1d774c5243e153fd0ee406fd1 (diff) | |
download | nextcloud-server-8e657a894583c6276697dc03767a2c201a97fc1b.tar.gz nextcloud-server-8e657a894583c6276697dc03767a2c201a97fc1b.zip |
allow anon text processing scheduling
add a textprocessing_tasks index
convert anotations to method attributes
refactor TP manager
add mapper methods
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
(cherry picked from commit 41b19cf969956fe57fcb35e3dee0200d5c29b6d7)
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/TextProcessing/Db/Task.php | 6 | ||||
-rw-r--r-- | lib/private/TextProcessing/Db/TaskMapper.php | 23 | ||||
-rw-r--r-- | lib/private/TextProcessing/Manager.php | 33 | ||||
-rw-r--r-- | lib/public/TextProcessing/FreePromptTaskType.php | 2 | ||||
-rw-r--r-- | lib/public/TextProcessing/IManager.php | 13 |
7 files changed, 71 insertions, 8 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 7de1df8e5fc..ecf3466392f 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1133,6 +1133,7 @@ return array( 'OC\\Core\\Migrations\\Version27000Date20230309104802' => $baseDir . '/core/Migrations/Version27000Date20230309104802.php', 'OC\\Core\\Migrations\\Version28000Date20230616104802' => $baseDir . '/core/Migrations/Version28000Date20230616104802.php', 'OC\\Core\\Migrations\\Version28000Date20230728104802' => $baseDir . '/core/Migrations/Version28000Date20230728104802.php', + 'OC\\Core\\Migrations\\Version28000Date20230803221055' => $baseDir . '/core/Migrations/Version28000Date20230803221055.php', 'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index ecd68f980b2..cbfb6bc0189 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1166,6 +1166,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Core\\Migrations\\Version27000Date20230309104802' => __DIR__ . '/../../..' . '/core/Migrations/Version27000Date20230309104802.php', 'OC\\Core\\Migrations\\Version28000Date20230616104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230616104802.php', 'OC\\Core\\Migrations\\Version28000Date20230728104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230728104802.php', + 'OC\\Core\\Migrations\\Version28000Date20230803221055' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230803221055.php', 'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', diff --git a/lib/private/TextProcessing/Db/Task.php b/lib/private/TextProcessing/Db/Task.php index 8c2ddb74f1f..9c6f16d11ae 100644 --- a/lib/private/TextProcessing/Db/Task.php +++ b/lib/private/TextProcessing/Db/Task.php @@ -39,11 +39,11 @@ use OCP\TextProcessing\Task as OCPTask; * @method string getOutput() * @method setStatus(int $type) * @method int getStatus() - * @method setUserId(string $type) - * @method string getuserId() + * @method setUserId(?string $userId) + * @method string|null getUserId() * @method setAppId(string $type) * @method string getAppId() - * @method setIdentifier(string $type) + * @method setIdentifier(string $identifier) * @method string getIdentifier() */ class Task extends Entity { diff --git a/lib/private/TextProcessing/Db/TaskMapper.php b/lib/private/TextProcessing/Db/TaskMapper.php index cf78006d6d9..6fde1e510b5 100644 --- a/lib/private/TextProcessing/Db/TaskMapper.php +++ b/lib/private/TextProcessing/Db/TaskMapper.php @@ -60,13 +60,34 @@ class TaskMapper extends QBMapper { } /** + * @param int $id + * @param string|null $userId + * @return Task + * @throws DoesNotExistException + * @throws Exception + * @throws MultipleObjectsReturnedException + */ + public function findByIdAndUser(int $id, ?string $userId): Task { + $qb = $this->db->getQueryBuilder(); + $qb->select(Task::$columns) + ->from($this->tableName) + ->where($qb->expr()->eq('id', $qb->createPositionalParameter($id))); + if ($userId === null) { + $qb->andWhere($qb->expr()->isNull('user_id')); + } else { + $qb->andWhere($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId))); + } + return $this->findEntity($qb); + } + + /** * @param string $userId * @param string $appId * @param string|null $identifier * @return array * @throws Exception */ - public function findByApp(string $userId, string $appId, ?string $identifier = null): array { + public function findUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array { $qb = $this->db->getQueryBuilder(); $qb->select(Task::$columns) ->from($this->tableName) diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index da38dc876a7..c8302f1e8df 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -178,6 +178,8 @@ class Manager implements IManager { } /** + * Get a task from its id + * * @param int $id The id of the task * @return OCPTask * @throws RuntimeException If the query failed @@ -197,14 +199,41 @@ class Manager implements IManager { } /** + * Get a task from its user id and task id + * If userId is null, this can only get a task that was scheduled anonymously + * + * @param int $id The id of the task + * @param string|null $userId The user id that scheduled the task + * @return OCPTask + * @throws RuntimeException If the query failed + * @throws NotFoundException If the task could not be found + */ + public function getUserTask(int $id, ?string $userId): OCPTask { + try { + $taskEntity = $this->taskMapper->findByIdAndUser($id, $userId); + return $taskEntity->toPublicTask(); + } catch (DoesNotExistException $e) { + throw new NotFoundException('Could not find task with the provided id and user id'); + } catch (MultipleObjectsReturnedException $e) { + throw new RuntimeException('Could not uniquely identify task with given id and user id', 0, $e); + } catch (Exception $e) { + throw new RuntimeException('Failure while trying to find task by id and user id: ' . $e->getMessage(), 0, $e); + } + } + + /** + * Get a list of tasks scheduled by a specific user for a specific app + * and optionally with a specific identifier. + * This cannot be used to get anonymously scheduled tasks + * * @param string $userId * @param string $appId * @param string|null $identifier * @return array */ - public function getTasksByApp(string $userId, string $appId, ?string $identifier = null): array { + public function getUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array { try { - $taskEntities = $this->taskMapper->findByApp($userId, $appId, $identifier); + $taskEntities = $this->taskMapper->findUserTasksByApp($userId, $appId, $identifier); return array_map(static function (DbTask $taskEntity) { return $taskEntity->toPublicTask(); }, $taskEntities); diff --git a/lib/public/TextProcessing/FreePromptTaskType.php b/lib/public/TextProcessing/FreePromptTaskType.php index a1e52e268a3..2cb8d6b7946 100644 --- a/lib/public/TextProcessing/FreePromptTaskType.php +++ b/lib/public/TextProcessing/FreePromptTaskType.php @@ -61,6 +61,6 @@ class FreePromptTaskType implements ITaskType { * @since 27.1.0 */ public function getDescription(): string { - return $this->l->t('Runs an arbitrary prompt through the built-in language model.'); + return $this->l->t('Runs an arbitrary prompt through the language model.'); } } diff --git a/lib/public/TextProcessing/IManager.php b/lib/public/TextProcessing/IManager.php index c7b101ad510..00646528e68 100644 --- a/lib/public/TextProcessing/IManager.php +++ b/lib/public/TextProcessing/IManager.php @@ -82,10 +82,21 @@ interface IManager { public function getTask(int $id): Task; /** + * @param int $id The id of the task + * @param string|null $userId The user id that scheduled the task + * @return Task + * @throws RuntimeException If the query failed + * @throws NotFoundException If the task could not be found + * @since 27.1.0 + */ + public function getUserTask(int $id, ?string $userId): Task; + + /** * @param string $userId * @param string $appId * @param string|null $identifier * @return array + * @since 27.1.0 */ - public function getTasksByApp(string $userId, string $appId, ?string $identifier = null): array; + public function getUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array; } |