Skip to content

Commit 253df7d

Browse files
icewind1991provokateurin
authored andcommitted
fix: store legacy id mapping when creating a legacy share from unified share
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 3217b34 commit 253df7d

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

apps/files_sharing/lib/Sharing/LegacyBackend.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ public function updateShare(Share $share): void {
162162

163163
if ($create) {
164164
$legacyShare = $this->legacyManager->createShare($legacyShare);
165+
166+
$this->addLegacyFullId($share->id, $legacyShare->getProviderId(), $legacyShare->getId());
167+
165168
// No need to insert the legacy full id, because the listener in the SharingManager will already trigger this process.
166169
$legacyShares[$legacyShare->getFullId()] = $legacyShare;
167170
} elseif ($update) {
@@ -463,11 +466,11 @@ public function getShareByLegacyProviderAndId(string $legacyProvider, string $le
463466

464467
#[\Override]
465468
public function getUnmappedShares(IUser $user): array {
466-
// TODO: Make it work with all providers
469+
// TODO: Make it work with all providers (deck, talk)
467470
// TODO: Filter by user
468471
$qb = $this->connection->getQueryBuilder();
469472
$result = $qb
470-
->select('s.id')
473+
->select('s.id', 's.share_type')
471474
->from('share', 's')
472475
->leftJoin('s', 'share_legacy_mapping', 'l', $qb->expr()->eq('s.id', 'l.legacy_id'))
473476
->where($qb->expr()->isNull('l.legacy_id'))
@@ -482,16 +485,16 @@ public function getUnmappedShares(IUser $user): array {
482485
], IQueryBuilder::PARAM_INT_ARRAY)))
483486
->executeQuery();
484487

485-
/** @var list<int> $legacyIds */
486-
$legacyIds = $result->fetchFirstColumn();
487-
if ($legacyIds === []) {
488+
/** @var list<array{id: string|int, share_type: IShare::TYPE_*}> $rows */
489+
$rows = $result->fetchAll();
490+
if ($rows === []) {
488491
return [];
489492
}
490493

491494
$ids = [];
492-
foreach ($legacyIds as $legacyId) {
495+
foreach ($rows as $row) {
493496
$id = $this->snowflakeGenerator->nextId();
494-
$this->addLegacyFullId($id, 'ocinternal', (string)$legacyId);
497+
$this->addLegacyFullId($id, $this->legacyShareTypeToLegacyProvider($row['share_type']), (string)$row['id']);
495498
$ids[] = $id;
496499
}
497500

@@ -581,6 +584,22 @@ private function addLegacyFullId(string $id, string $legacyProvider, string $leg
581584
->executeStatement();
582585
}
583586

587+
/**
588+
* @param IShare::TYPE_* $legacyShareType
589+
* @return non-empty-string
590+
*/
591+
private function legacyShareTypeToLegacyProvider(int $legacyShareType): string {
592+
return match ($legacyShareType) {
593+
IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK => 'ocinternal',
594+
IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP => 'ocFederatedSharing',
595+
IShare::TYPE_EMAIL => 'ocMailShare',
596+
IShare::TYPE_CIRCLE => 'ocCircleShare',
597+
IShare::TYPE_ROOM => 'ocRoomShare',
598+
IShare::TYPE_DECK => 'deck',
599+
default => throw new RuntimeException('Unsupported legacy share type: ' . $legacyShareType),
600+
};
601+
}
602+
584603
/**
585604
* @param IShare::TYPE_* $legacyShareType
586605
* @return class-string<IShareRecipientType>
@@ -592,6 +611,7 @@ private function legacyShareTypeToRecipientTypeClass(int $legacyShareType): stri
592611
IShare::TYPE_LINK => TokenShareRecipientType::class,
593612
IShare::TYPE_EMAIL => EmailShareRecipientType::class,
594613
IShare::TYPE_CIRCLE => TeamShareRecipientType::class,
614+
// TODO talk, deck
595615
default => throw new RuntimeException('Unsupported legacy share type: ' . $legacyShareType),
596616
};
597617
}
@@ -607,6 +627,7 @@ private function recipientTypeClassToLegacyShareType(string $recipientTypeClass,
607627
TokenShareRecipientType::class => IShare::TYPE_LINK,
608628
EmailShareRecipientType::class => IShare::TYPE_EMAIL,
609629
TeamShareRecipientType::class => IShare::TYPE_CIRCLE,
630+
// TODO talk, deck
610631
default => throw new RuntimeException('Unsupported recipient type: ' . $recipientTypeClass),
611632
};
612633
}

apps/files_sharing/tests/Sharing/LegacyBackendTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public function testUpdateShare(): void {
434434
'password' => null,
435435
'password_expiration_time' => null,
436436
'send_password_by_talk' => false,
437-
'token' => 'secret',
437+
'token' => 'token secret',
438438
'parent' => null,
439439
'original_target' => null,
440440
'target' => '/foo',
@@ -463,7 +463,7 @@ public function testUpdateShare(): void {
463463
'password' => null,
464464
'password_expiration_time' => null,
465465
'send_password_by_talk' => false,
466-
'token' => 'secret',
466+
'token' => 'token secret',
467467
'parent' => null,
468468
'original_target' => null,
469469
'target' => '/foo.txt',
@@ -492,7 +492,7 @@ public function testUpdateShare(): void {
492492
'password' => null,
493493
'password_expiration_time' => null,
494494
'send_password_by_talk' => false,
495-
'token' => 'secret',
495+
'token' => 'email secret',
496496
'parent' => null,
497497
'original_target' => null,
498498
'target' => null,
@@ -521,7 +521,7 @@ public function testUpdateShare(): void {
521521
'password' => null,
522522
'password_expiration_time' => null,
523523
'send_password_by_talk' => false,
524-
'token' => 'secret',
524+
'token' => 'email secret',
525525
'parent' => null,
526526
'original_target' => null,
527527
'target' => null,
@@ -660,12 +660,12 @@ private function formatLegacyShare(IShare $legacyShare): array {
660660
private function getLegacyIds(string $id): array {
661661
$qb = $this->dbConnection->getQueryBuilder();
662662
$result = $qb
663-
->select('legacy_id')
663+
->select('legacy_provider', 'legacy_id')
664664
->from('share_legacy_mapping')
665665
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
666666
->executeQuery();
667-
/** @var list<string> $ids */
668-
$ids = $result->fetchFirstColumn();
669-
return $ids;
667+
/** @var list<array{legacy_provider: string, legacy_id: string}> $rows */
668+
$rows = $result->fetchAll();
669+
return array_map(fn (array $row): string => $row['legacy_provider'] . ':' . $row['legacy_id'], $rows);
670670
}
671671
}

0 commit comments

Comments
 (0)