From 6c4992de54d7ce78ff19f588d403162b0c8f580a Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 15 May 2024 09:30:05 +0200 Subject: [PATCH] fix: expose lastUpdated in OCS API Signed-off-by: Marcel Klehr --- core/ResponseDefinitions.php | 1 + core/openapi.json | 5 +++++ lib/private/TaskProcessing/Db/Task.php | 1 + lib/public/TaskProcessing/Task.php | 22 +++++++++++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index 6b537a3c461..e0e8bed0044 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -195,6 +195,7 @@ namespace OCA\Core; * * @psalm-type CoreTaskProcessingTask = array{ * id: int, + * lastUpdated: int, * type: string, * status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', * userId: ?string, diff --git a/core/openapi.json b/core/openapi.json index d4067eac3cd..50846c2d198 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -532,6 +532,7 @@ "type": "object", "required": [ "id", + "lastUpdated", "type", "status", "userId", @@ -547,6 +548,10 @@ "type": "integer", "format": "int64" }, + "lastUpdated": { + "type": "integer", + "format": "int64" + }, "type": { "type": "string" }, diff --git a/lib/private/TaskProcessing/Db/Task.php b/lib/private/TaskProcessing/Db/Task.php index 9293f4dc236..8a30f84e6bd 100644 --- a/lib/private/TaskProcessing/Db/Task.php +++ b/lib/private/TaskProcessing/Db/Task.php @@ -125,6 +125,7 @@ class Task extends Entity { $task = new OCPTask($this->getType(), json_decode($this->getInput(), true, 512, JSON_THROW_ON_ERROR), $this->getAppId(), $this->getuserId(), $this->getCustomId()); $task->setId($this->getId()); $task->setStatus($this->getStatus()); + $task->setLastUpdated($this->getLastUpdated()); $task->setOutput(json_decode($this->getOutput(), true, 512, JSON_THROW_ON_ERROR)); $task->setCompletionExpectedAt($this->getCompletionExpectedAt()); $task->setErrorMessage($this->getErrorMessage()); diff --git a/lib/public/TaskProcessing/Task.php b/lib/public/TaskProcessing/Task.php index b6aa6376279..ee00446865e 100644 --- a/lib/public/TaskProcessing/Task.php +++ b/lib/public/TaskProcessing/Task.php @@ -44,6 +44,8 @@ final class Task implements \JsonSerializable { protected ?float $progress = null; + protected int $lastUpdated; + /** * @since 30.0.0 */ @@ -89,6 +91,7 @@ final class Task implements \JsonSerializable { protected readonly ?string $userId, protected readonly ?string $customId = '', ) { + $this->lastUpdated = time(); } /** @@ -195,13 +198,30 @@ final class Task implements \JsonSerializable { } /** - * @psalm-return array{id: ?int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array|numeric|string>, output: ?array|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float} + * @return int + * @since 30.0.0 + */ + final public function getLastUpdated(): int { + return $this->lastUpdated; + } + + /** + * @param int $lastUpdated + * @since 30.0.0 + */ + final public function setLastUpdated(int $lastUpdated): void { + $this->lastUpdated = $lastUpdated; + } + + /** + * @psalm-return array{id: ?int, lastUpdated: int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array|numeric|string>, output: ?array|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float} * @since 30.0.0 */ final public function jsonSerialize(): array { return [ 'id' => $this->getId(), 'type' => $this->getTaskTypeId(), + 'lastUpdated' => $this->getLastUpdated(), 'status' => self::statusToString($this->getStatus()), 'userId' => $this->getUserId(), 'appId' => $this->getAppId(), -- 2.39.5