Skip to content
Merged
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
36 changes: 29 additions & 7 deletions lib/Command/MigrateCustomGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class MigrateCustomGroups extends Base {
private OutputInterface $output;
/** @var IFederatedUser[] */
/** @var array<string, null|IFederatedUser> */
private array $fedList = [];

public function __construct(
Expand Down Expand Up @@ -81,11 +81,17 @@ public function migrateTeams(): void {
$name = '_' . $name;
}

$this->output->writeln('+ New Team <info>' . $name . '</info>, owned by <info>' . $ownerId . '</info>');

// based on owner's userid, we create federateduser and a new circle
$this->output->writeln('+ New Team <info>' . $name . '</info>, owner by <info>' . $ownerId . '</info>');
$owner = $this->cachedFed($ownerId);
if ($owner === null) {
$this->output->writeln('<error>unknown user</error> ' . $ownerId);
continue;
}

$this->circlesManager->startSession($owner);

try {
$circle = $this->circlesManager->createCircle($name);
} catch (\Exception $e) {
Expand Down Expand Up @@ -116,8 +122,14 @@ public function migrateTeams(): void {
continue; // owner is already in the circles
}

$fedUser = $this->cachedFed($userId);
if ($fedUser === null) {
$this->output->writeln('<error>unknown user</error> ' . $userId);
continue;
}
$this->output->writeln(' - new member <info>' . $userId . '</info>');
$member = $this->circlesManager->addMember($circle->getSingleId(), $this->cachedFed($userId));

$member = $this->circlesManager->addMember($circle->getSingleId(), $fedUser);
if ($rowM['role'] === '1') {
$this->circlesManager->levelMember($member->getId(), Member::LEVEL_ADMIN);
}
Expand Down Expand Up @@ -167,11 +179,16 @@ public function updateShares(string $groupUri, string $circleId, array $memberId
* manage local cache FederatedUser
*
* @param string $userId
* @return FederatedUser
* @return null|FederatedUser
*/
private function cachedFed(string $userId): FederatedUser {
private function cachedFed(string $userId): ?FederatedUser {
if (!array_key_exists($userId, $this->fedList)) {
$this->fedList[$userId] = $this->circlesManager->getLocalFederatedUser($userId);
try {
$this->fedList[$userId] = $this->circlesManager->getLocalFederatedUser($userId);
} catch (\Exception $e) {
$this->logger->warning('unknown local user ' . $userId, ['exception' => $e]);
$this->fedList[$userId] = null;
}
}

return $this->fedList[$userId];
Expand All @@ -193,8 +210,13 @@ private function fixShareChildren(array $shareIds, array $memberIds): void {

$count = 0;
foreach ($memberIds as $memberId) {
$fedUser = $this->cachedFed($memberId);
if ($fedUser === null) {
// we dont update, user does not exist anymore
continue;
}
$update->setParameter('old_recipient', $memberId);
$update->setParameter('new_recipient', $this->cachedFed($memberId)->getSingleId());
$update->setParameter('new_recipient', $fedUser->getSingleId());
$count += $update->executeStatement();
}

Expand Down
Loading