Skip to content

Commit 7c1a8a4

Browse files
committed
feat: Adapt a bit the snowflake ids API
- Rename setId() -> generateId() in SnowflakeAwareEntity Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 5f797eb commit 7c1a8a4

File tree

17 files changed

+48
-45
lines changed

17 files changed

+48
-45
lines changed

apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function shareReceived(ICloudFederationShare $share): string {
143143
}
144144

145145
$externalShare = new ExternalShare();
146-
$externalShare->setId();
146+
$externalShare->generateId();
147147
$externalShare->setRemote($remote);
148148
$externalShare->setRemoteId($remoteId);
149149
$externalShare->setShareToken($token);

apps/files_sharing/lib/External/ExternalShare.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public function jsonSerialize(): array {
105105
'user' => $this->getUser(),
106106
'mountpoint' => $this->getMountpoint(),
107107
'accepted' => $this->getAccepted(),
108+
109+
// Added later on
110+
'file_id' => null,
111+
'mimetype' => null,
112+
'permissions' => null,
113+
'mtime' => null,
114+
'type' => null,
108115
];
109116
}
110117

apps/files_sharing/lib/External/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private function updateSubShare(ExternalShare $externalShare, IUser $user, ?stri
184184
$subShare = $this->externalShareMapper->getUserShare($externalShare, $user);
185185
} catch (DoesNotExistException) {
186186
$subShare = new ExternalShare();
187-
$subShare->setId();
187+
$subShare->generateId();
188188
$subShare->setRemote($externalShare->getRemote());
189189
$subShare->setPassword($externalShare->getPassword());
190190
$subShare->setName($externalShare->getName());

apps/files_sharing/lib/ResponseDefinitions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,21 @@
8282
*
8383
* @psalm-type Files_SharingRemoteShare = array{
8484
* accepted: int,
85+
* file_id: int|null,
8586
* id: string,
87+
* mimetype: string|null,
8688
* mountpoint: string,
89+
* mtime: int|null,
8790
* name: string,
8891
* owner: string,
8992
* parent: string|null,
93+
* permissions: int|null,
9094
* remote: string,
9195
* remote_id: string,
9296
* share_token: string,
9397
* share_type: int,
98+
* type: string|null,
9499
* user: string,
95-
* file_id?: int,
96-
* mimetype?: string,
97-
* permissions?: int,
98-
* mtime?: int,
99-
* type?: string,
100100
* }
101101
*
102102
* @psalm-type Files_SharingSharee = array{

apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function setUp(): void {
6363

6464
if (isset($storage['share_token'])) {
6565
$externalShare = new ExternalShare();
66-
$externalShare->setId();
66+
$externalShare->generateId();
6767
$externalShare->setShareToken($storage['share_token']);
6868
$externalShare->setRemote($storage['remote']);
6969
$externalShare->setName('irrelevant');

apps/files_sharing/tests/External/ManagerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private function clearMounts(): void {
188188

189189
public function testAddUserShare(): void {
190190
$userShare = new ExternalShare();
191-
$userShare->setId();
191+
$userShare->generateId();
192192
$userShare->setRemote('http://localhost');
193193
$userShare->setShareToken('token1');
194194
$userShare->setPassword('');
@@ -203,7 +203,7 @@ public function testAddUserShare(): void {
203203

204204
public function testAddGroupShare(): void {
205205
$groupShare = new ExternalShare();
206-
$groupShare->setId();
206+
$groupShare->generateId();
207207
$groupShare->setRemote('http://localhost');
208208
$groupShare->setOwner('foobar');
209209
$groupShare->setShareType(IShare::TYPE_GROUP);
@@ -235,10 +235,10 @@ public function doTestAddShare(ExternalShare $shareData1, IUser|IGroup $userOrGr
235235

236236
$shareData2 = $shareData1->clone();
237237
$shareData2->setShareToken('token2');
238-
$shareData2->setId();
238+
$shareData2->generateId();
239239
$shareData3 = $shareData1->clone();
240240
$shareData3->setShareToken('token3');
241-
$shareData3->setId();
241+
$shareData3->generateId();
242242

243243
$this->setupMounts();
244244
$this->assertNotMount('SharedFolder');
@@ -438,7 +438,7 @@ private function createTestUserShare(string $userId = 'user1'): ExternalShare {
438438
$user = $this->createMock(IUser::class);
439439
$user->expects($this->any())->method('getUID')->willReturn($userId);
440440
$share = new ExternalShare();
441-
$share->setId();
441+
$share->generateId();
442442
$share->setRemote('http://localhost');
443443
$share->setShareToken('token1');
444444
$share->setPassword('');
@@ -458,7 +458,7 @@ private function createTestUserShare(string $userId = 'user1'): ExternalShare {
458458
*/
459459
private function createTestGroupShare(string $groupId = 'group1'): array {
460460
$share = new ExternalShare();
461-
$share->setId();
461+
$share->generateId();
462462
$share->setRemote('http://localhost');
463463
$share->setShareToken('token1');
464464
$share->setPassword('');
@@ -644,7 +644,7 @@ public function testDeleteUserShares(): void {
644644
// user 2 shares
645645
$manager2 = $this->createManagerForUser($user2);
646646
$share = new ExternalShare();
647-
$share->setId();
647+
$share->generateId();
648648
$share->setRemote('http://localhost');
649649
$share->setShareToken('token1');
650650
$share->setPassword('');
@@ -694,7 +694,7 @@ public function testDeleteGroupShares(): void {
694694
$manager2 = $this->createManagerForUser($user);
695695

696696
$share = new ExternalShare();
697-
$share->setId();
697+
$share->generateId();
698698
$share->setRemote('http://localhost');
699699
$share->setShareToken('token1');
700700
$share->setPassword('');

core/BackgroundJobs/MovePreviewJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private function processPreviews(int $fileId, bool $flatPath): void {
136136
$path = $fileId . '/' . $previewFile->getName();
137137
/** @var SimpleFile $previewFile */
138138
$preview = Preview::fromPath($path, $this->mimeTypeDetector);
139-
$preview->setId();
139+
$preview->generateId();
140140
if (!$preview) {
141141
$this->logger->error('Unable to import old preview at path.');
142142
continue;
@@ -170,7 +170,7 @@ private function processPreviews(int $fileId, bool $flatPath): void {
170170
$preview->setStorageId($result[0]['storage']);
171171
$preview->setEtag($result[0]['etag']);
172172
$preview->setSourceMimeType($this->mimeTypeLoader->getMimetypeById((int)$result[0]['mimetype']));
173-
$preview->setId();
173+
$preview->generateId();
174174
try {
175175
$preview = $this->previewMapper->insert($preview);
176176
} catch (Exception) {

lib/private/Authentication/Token/PublicKeyToken.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public function __construct() {
101101
$this->addType('passwordInvalid', Types::BOOLEAN);
102102
}
103103

104+
public function getId(): int {
105+
return (int)$this->id;
106+
}
107+
104108
public function getUID(): string {
105109
return $this->uid;
106110
}
@@ -123,7 +127,7 @@ public function getPassword(): ?string {
123127

124128
public function jsonSerialize(): array {
125129
return [
126-
'id' => $this->getId(),
130+
'id' => $this->id,
127131
'name' => $this->name,
128132
'lastActivity' => $this->lastActivity,
129133
'type' => $this->type,

lib/private/Preview/Generator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ private function generateProviderPreview(File $file, int $width, int $height, bo
348348

349349
try {
350350
$previewEntry = new Preview();
351-
$previewEntry->setId();
351+
$previewEntry->generateId();
352352
$previewEntry->setFileId($file->getId());
353353
$previewEntry->setStorageId($file->getMountPoint()->getNumericStorageId());
354354
$previewEntry->setSourceMimeType($file->getMimeType());
@@ -502,7 +502,7 @@ private function generatePreview(
502502
}
503503

504504
$previewEntry = new Preview();
505-
$previewEntry->setId();
505+
$previewEntry->generateId();
506506
$previewEntry->setFileId($file->getId());
507507
$previewEntry->setStorageId($file->getMountPoint()->getNumericStorageId());
508508
$previewEntry->setWidth($width);
@@ -543,7 +543,7 @@ public function savePreview(Preview $previewEntry, IImage $preview): Preview {
543543
throw new \RuntimeException('Unable to write preview file');
544544
}
545545
$previewEntry->setSize($size);
546-
$previewEntry->setId();
546+
$previewEntry->generateId();
547547
return $this->previewMapper->insert($previewEntry);
548548
}
549549
}

lib/private/Preview/Storage/LocalPreviewStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function scan(): int {
120120
$this->logger->error('Unable to parse preview information for ' . $file->getRealPath());
121121
continue;
122122
}
123-
$preview->setId();
123+
$preview->generateId();
124124
try {
125125
$preview->setSize($file->getSize());
126126
$preview->setMtime($file->getMtime());
@@ -154,7 +154,7 @@ public function scan(): int {
154154
$preview->setStorageId($result[0]['storage']);
155155
$preview->setEtag($result[0]['etag']);
156156
$preview->setSourceMimetype($result[0]['mimetype']);
157-
$preview->setId();
157+
$preview->generateId();
158158
// try to insert, if that fails the preview is already in the DB
159159
$this->previewMapper->insert($preview);
160160

0 commit comments

Comments
 (0)