Skip to content

Commit

Permalink
fix: expose lastUpdated in OCS API
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed May 15, 2024
1 parent cac812d commit 6c4992d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
*
* @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,
Expand Down
5 changes: 5 additions & 0 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@
"type": "object",
"required": [
"id",
"lastUpdated",
"type",
"status",
"userId",
Expand All @@ -547,6 +548,10 @@
"type": "integer",
"format": "int64"
},
"lastUpdated": {
"type": "integer",
"format": "int64"
},
"type": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions lib/private/TaskProcessing/Db/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function toPublicTask(): OCPTask {
$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());
Expand Down
22 changes: 21 additions & 1 deletion lib/public/TaskProcessing/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ final class Task implements \JsonSerializable {

protected ?float $progress = null;

protected int $lastUpdated;

/**
* @since 30.0.0
*/
Expand Down Expand Up @@ -89,6 +91,7 @@ final public function __construct(
protected readonly ?string $userId,
protected readonly ?string $customId = '',
) {
$this->lastUpdated = time();
}

/**
Expand Down Expand Up @@ -195,13 +198,30 @@ final public function getUserId(): ?string {
}

/**
* @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<array-key, list<numeric|string>|numeric|string>, output: ?array<array-key, list<numeric|string>|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<array-key, list<numeric|string>|numeric|string>, output: ?array<array-key, list<numeric|string>|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(),
Expand Down

0 comments on commit 6c4992d

Please sign in to comment.