@@ -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 }
0 commit comments