summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/Controller/TextProcessingApiController.php30
-rw-r--r--core/routes.php1
-rw-r--r--lib/private/TextProcessing/Manager.php12
-rw-r--r--lib/public/TextProcessing/IManager.php8
4 files changed, 51 insertions, 0 deletions
diff --git a/core/Controller/TextProcessingApiController.php b/core/Controller/TextProcessingApiController.php
index c713a70481c..e1d7788be27 100644
--- a/core/Controller/TextProcessingApiController.php
+++ b/core/Controller/TextProcessingApiController.php
@@ -157,6 +157,36 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController {
}
/**
+ * This endpoint allows to delete a scheduled task for a user
+ *
+ * @param int $id The id of the task
+ *
+ * @return DataResponse<Http::STATUS_OK, array{task: CoreTextProcessingTask}, array{}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
+ *
+ * 200: Task returned
+ * 404: Task not found
+ */
+ #[NoAdminRequired]
+ public function deleteTask(int $id): DataResponse {
+ try {
+ $task = $this->textProcessingManager->getUserTask($id, $this->userId);
+
+ $this->textProcessingManager->deleteTask($task);
+
+ $json = $task->jsonSerialize();
+
+ return new DataResponse([
+ 'task' => $json,
+ ]);
+ } catch (NotFoundException $e) {
+ return new DataResponse(['message' => $this->l->t('Task not found')], Http::STATUS_NOT_FOUND);
+ } catch (\RuntimeException $e) {
+ return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
+ }
+ }
+
+
+ /**
* This endpoint returns a list of tasks of a user that are related
* with a specific appId and optionally with an identifier
*
diff --git a/core/routes.php b/core/routes.php
index 90578ee6f0d..ad8638e0b1e 100644
--- a/core/routes.php
+++ b/core/routes.php
@@ -149,6 +149,7 @@ $application->registerRoutes($this, [
['root' => '/textprocessing', 'name' => 'TextProcessingApi#taskTypes', 'url' => '/tasktypes', 'verb' => 'GET'],
['root' => '/textprocessing', 'name' => 'TextProcessingApi#schedule', 'url' => '/schedule', 'verb' => 'POST'],
['root' => '/textprocessing', 'name' => 'TextProcessingApi#getTask', 'url' => '/task/{id}', 'verb' => 'GET'],
+ ['root' => '/textprocessing', 'name' => 'TextProcessingApi#deleteTask', 'url' => '/task/{id}', 'verb' => 'DELETE'],
['root' => '/textprocessing', 'name' => 'TextProcessingApi#listTasksByApp', 'url' => '/tasks/app/{appId}', 'verb' => 'GET'],
],
]);
diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php
index c8302f1e8df..b9cb06c298e 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\Task;
use OCP\TextProcessing\Task as OCPTask;
use OC\TextProcessing\Db\TaskMapper;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -178,6 +179,17 @@ class Manager implements IManager {
}
/**
+ * @inheritDoc
+ */
+ public function deleteTask(Task $task): void {
+ $taskEntity = DbTask::fromPublicTask($task);
+ $this->taskMapper->delete($taskEntity);
+ $this->jobList->remove(TaskBackgroundJob::class, [
+ 'taskId' => $task->getId()
+ ]);
+ }
+
+ /**
* Get a task from its id
*
* @param int $id The id of the task
diff --git a/lib/public/TextProcessing/IManager.php b/lib/public/TextProcessing/IManager.php
index 00646528e68..dec0baba4bb 100644
--- a/lib/public/TextProcessing/IManager.php
+++ b/lib/public/TextProcessing/IManager.php
@@ -73,6 +73,14 @@ interface IManager {
public function scheduleTask(Task $task) : void;
/**
+ * Delete a task that has been scheduled before
+ *
+ * @param Task $task The task to delete
+ * @since 27.1.0
+ */
+ public function deleteTask(Task $task): void;
+
+ /**
* @param int $id The id of the task
* @return Task
* @throws RuntimeException If the query failed