Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/phpunit-32bits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:

strategy:
fail-fast: false
matrix:
php-versions: ['8.3', '8,5']

steps:
- name: Checkout server
Expand All @@ -43,7 +41,7 @@ jobs:
uses: docker://ghcr.io/nextcloud/continuous-integration-php8.4-32bit:latest
with:
args: /bin/sh -c "
git config --global --add safe.directory /github/workspace &&
git config --global --add safe.directory ${GITHUB_WORKSPACE} &&
composer install --no-interaction"

- name: Set up Nextcloud
Expand Down
2 changes: 1 addition & 1 deletion apps/sharing/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
* id: non-empty-string,
* owner: SharingUser,
* // Unix time in milliseconds
* last_updated: non-negative-int,
* last_updated: numeric-string,
* state: SharingState,
* sources: list<SharingSource>,
* recipients: list<SharingRecipient>,
Expand Down
6 changes: 2 additions & 4 deletions apps/sharing/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,8 @@
"$ref": "#/components/schemas/User"
},
"last_updated": {
"type": "integer",
"format": "int64",
"description": "Unix time in milliseconds",
"minimum": 0
"type": "string",
"description": "Unix time in milliseconds"
},
"state": {
"$ref": "#/components/schemas/State"
Expand Down
44 changes: 22 additions & 22 deletions apps/sharing/tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected function searchRecipients(ShareAccessContext $accessContext, ?array $f
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function createShare(ShareAccessContext $accessContext): array {
Expand All @@ -177,12 +177,12 @@ protected function createShare(ShareAccessContext $accessContext): array {
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function updateShareState(ShareAccessContext $accessContext, string $id, ShareState $state): array {
Expand All @@ -195,12 +195,12 @@ protected function updateShareState(ShareAccessContext $accessContext, string $i
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function addShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
Expand All @@ -214,12 +214,12 @@ protected function addShareSource(ShareAccessContext $accessContext, string $id,
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function removeShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
Expand All @@ -233,12 +233,12 @@ protected function removeShareSource(ShareAccessContext $accessContext, string $
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function addShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
Expand All @@ -253,12 +253,12 @@ protected function addShareRecipient(ShareAccessContext $accessContext, string $
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function removeShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
Expand All @@ -273,12 +273,12 @@ protected function removeShareRecipient(ShareAccessContext $accessContext, strin
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function updateShareRecipientSecret(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient, string $secret): array {
Expand All @@ -294,12 +294,12 @@ protected function updateShareRecipientSecret(ShareAccessContext $accessContext,
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function updateShareProperty(ShareAccessContext $accessContext, string $id, ShareProperty $property): array {
Expand All @@ -313,12 +313,12 @@ protected function updateShareProperty(ShareAccessContext $accessContext, string
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function updateSharePermission(ShareAccessContext $accessContext, string $id, SharePermission $permission): array {
Expand All @@ -332,12 +332,12 @@ protected function updateSharePermission(ShareAccessContext $accessContext, stri
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

/**
* @return array<string, mixed>
* @return SharingShare
*/
#[Override]
protected function selectSharePermissionPreset(ShareAccessContext $accessContext, string $id, string $permissionPresetClass): array {
Expand All @@ -350,7 +350,7 @@ protected function selectSharePermissionPreset(ShareAccessContext $accessContext
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

Expand Down Expand Up @@ -379,7 +379,7 @@ protected function getShare(ShareAccessContext $accessContext, string $id): arra
],
[],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}

Expand All @@ -399,7 +399,7 @@ protected function getShares(ShareAccessContext $accessContext, ?string $filterS
['limit', $limit],
],
);
/** @psalm-suppress MixedReturnStatement */
/** @var SharingShare[] */
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
}
}
14 changes: 11 additions & 3 deletions apps/sharing/tests/Controller/ApiV1ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,53 +95,63 @@ protected function searchRecipients(ShareAccessContext $accessContext, ?array $f

#[Override]
protected function createShare(ShareAccessContext $accessContext): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->createShare());
}

#[Override]
protected function updateShareState(ShareAccessContext $accessContext, string $id, ShareState $state): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateShareState($id, $state->value));
}

#[Override]
protected function addShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->addShareSource($id, $source->class, $source->value));
}

#[Override]
protected function removeShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->removeShareSource($id, $source->class, $source->value));
}

#[Override]
protected function addShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->addShareRecipient($id, $recipient->class, $recipient->value, $recipient->instance));
}

#[Override]
protected function removeShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->removeShareRecipient($id, $recipient->class, $recipient->value, $recipient->instance));
}

#[Override]
protected function updateShareRecipientSecret(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient, string $secret): array {
/** @psalm-suppress ArgumentTypeCoercion */
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateShareRecipientSecret($id, $recipient->class, $recipient->value, $recipient->instance, $secret));
}

#[Override]
protected function updateShareProperty(ShareAccessContext $accessContext, string $id, ShareProperty $property): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateShareProperty($id, $property->class, $property->value));
}

#[Override]
protected function updateSharePermission(ShareAccessContext $accessContext, string $id, SharePermission $permission): array {
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateSharePermission($id, $permission->class, $permission->enabled));
}

#[Override]
protected function selectSharePermissionPreset(ShareAccessContext $accessContext, string $id, string $permissionPresetClass): array {
/** @psalm-suppress ArgumentTypeCoercion */
/** @var SharingShare */
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->selectSharePermissionPreset($id, $permissionPresetClass));
}

Expand All @@ -150,11 +160,9 @@ protected function deleteShare(ShareAccessContext $accessContext, string $id): v
$this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->deleteShare($id));
}

/**
* @psalm-suppress MixedReturnTypeCoercion
*/
#[Override]
protected function getShare(ShareAccessContext $accessContext, string $id): array {
/** @var SharingShare */
return $this->executeRequest(new ShareAccessContext($accessContext->currentUser, null, [], $accessContext->overrideChecks), fn (ApiV1Controller $controller): DataResponse => $controller->getShare($id, $accessContext->secret, $accessContext->arguments));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/ServerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getServerId(): int {
if ($serverid < 1) {
// Fallback: generates a server ID based on hostname
/** @var int<0,max> */
$serverid = PHP_INT_SIZE === 4
$serverid = PHP_INT_SIZE === 8
? hexdec(hash('xxh32', $this->getHostname()))
// Makes sure it doesn't overflow 32 bits int
: hexdec(substr(hash('xxh32', $this->getHostname()), -3));
Expand Down
24 changes: 12 additions & 12 deletions lib/private/Sharing/SharingBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ public function setLastUpdated(array $ids, \DateTimeImmutable $lastUpdated): voi

$rowCount = $qb
->update('sharing_share')
->set('last_updated', $qb->createNamedParameter(SharingManager::timeToMs($lastUpdated), IQueryBuilder::PARAM_INT))
->where($qb->expr()->in('id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)))
->set('last_updated', $qb->createNamedParameter(SharingManager::timeToMs($lastUpdated)))
->where($qb->expr()->in('id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
->executeStatement();
if ($rowCount !== count($chunk)) {
throw new ShareNotFoundException();
Expand Down Expand Up @@ -618,7 +618,7 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID,
}

// The key type is array-key, because PHP will automatically cast the value. We can't type it as integer though, because we need to also support 32 bit systems and there the autocasting doesn't happen, if the value is too large.
/** @var array<array-key, array{id: non-empty-string, owner: ShareUser, last_updated: non-negative-int, state: ShareState, sources: list<ShareSource>, recipients: list<ShareRecipient>, properties: array<class-string<ISharePropertyType>, ShareProperty>, permissions: array<class-string<ISharePermissionType>, SharePermission>}> $shares */
/** @var array<array-key, array{id: non-empty-string, owner: ShareUser, last_updated: numeric-string, state: ShareState, sources: list<ShareSource>, recipients: list<ShareRecipient>, properties: array<class-string<ISharePropertyType>, ShareProperty>, permissions: array<class-string<ISharePermissionType>, SharePermission>}> $shares */
$shares = [];
foreach ($queries as $qb) {
$qb
Expand Down Expand Up @@ -672,8 +672,8 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID,

/** @var non-empty-string $id */
$id = (string)$row['id'];
/** @var non-negative-int $lastUpdated */
$lastUpdated = (int)$row['last_updated'];
/** @var numeric-string $lastUpdated */
$lastUpdated = (string)$row['last_updated'];
/** @var string $state */
$state = $row['state'];
$shares[$id] ??= [
Expand Down Expand Up @@ -718,10 +718,10 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID,
'ss.source_value',
)
->from('sharing_share_sources', 'ss')
->where($qb->expr()->in('ss.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
->where($qb->expr()->in('ss.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)));

$result = $qb->executeQuery();
/** @var array{source_class_id: mixed, source_value: non-empty-string, share_id: int}[] $rows */
/** @var array{source_class_id: mixed, source_value: non-empty-string, share_id: string}[] $rows */
$rows = $result->fetchAll();

foreach ($rows as $row) {
Expand Down Expand Up @@ -749,7 +749,7 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID,
}

$value = $row['source_value'];
$id = (string)$row['share_id'];
$id = $row['share_id'];
$shares[$id]['sources'][] = new ShareSource(
$typeClass,
$value,
Expand Down Expand Up @@ -777,7 +777,7 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID,
'sr.initiator_instance',
)
->from('sharing_share_recipients', 'sr')
->where($qb->expr()->in('sr.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
->where($qb->expr()->in('sr.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)));

foreach ($qb->executeQuery()->fetchAll() as $row) {
/** @var class-string<IShareRecipientType> $typeClass */
Expand Down Expand Up @@ -890,7 +890,7 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID,
'sp.property_value',
)
->from('sharing_share_properties', 'sp')
->where($qb->expr()->in('sp.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
->where($qb->expr()->in('sp.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)));

$result = $qb->executeQuery();
foreach ($result->fetchAll() as $row) {
Expand Down Expand Up @@ -961,7 +961,7 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID,
'sp.permission_enabled',
)
->from('sharing_share_permissions', 'sp')
->where($qb->expr()->in('sp.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
->where($qb->expr()->in('sp.share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)));

$result = $qb->executeQuery();
foreach ($result->fetchAll() as $row) {
Expand Down Expand Up @@ -1110,7 +1110,7 @@ public function createSharePermissionDefaultValue(Share $share, string $permissi
return $share;
}

private static function parseTimestamp(int $timestampMs): \DateTimeImmutable {
private static function parseTimestamp(string $timestampMs): \DateTimeImmutable {
if (method_exists(\DateTimeImmutable::class, 'createFromTimestamp')) {
// with php 8.3 the method doesn't exist and psalm doesn't know the return type
/** @psalm-suppress MixedReturnStatement */
Expand Down
Loading
Loading