Skip to content

Commit 0e25a33

Browse files
Merge pull request #1937 from nextcloud/backport/1904/stable31
[stable31] ignore non-existant users
2 parents 08ca031 + 5b025fc commit 0e25a33

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

lib/Command/MigrateCustomGroups.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
class MigrateCustomGroups extends Base {
2626
private OutputInterface $output;
27-
/** @var IFederatedUser[] */
27+
/** @var array<string, null|IFederatedUser> */
2828
private array $fedList = [];
2929

3030
public function __construct(
@@ -81,11 +81,17 @@ public function migrateTeams(): void {
8181
$name = '_' . $name;
8282
}
8383

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

8893
$this->circlesManager->startSession($owner);
94+
8995
try {
9096
$circle = $this->circlesManager->createCircle($name);
9197
} catch (\Exception $e) {
@@ -116,8 +122,14 @@ public function migrateTeams(): void {
116122
continue; // owner is already in the circles
117123
}
118124

125+
$fedUser = $this->cachedFed($userId);
126+
if ($fedUser === null) {
127+
$this->output->writeln('<error>unknown user</error> ' . $userId);
128+
continue;
129+
}
119130
$this->output->writeln(' - new member <info>' . $userId . '</info>');
120-
$member = $this->circlesManager->addMember($circle->getSingleId(), $this->cachedFed($userId));
131+
132+
$member = $this->circlesManager->addMember($circle->getSingleId(), $fedUser);
121133
if ($rowM['role'] === '1') {
122134
$this->circlesManager->levelMember($member->getId(), Member::LEVEL_ADMIN);
123135
}
@@ -167,11 +179,16 @@ public function updateShares(string $groupUri, string $circleId, array $memberId
167179
* manage local cache FederatedUser
168180
*
169181
* @param string $userId
170-
* @return FederatedUser
182+
* @return null|FederatedUser
171183
*/
172-
private function cachedFed(string $userId): FederatedUser {
184+
private function cachedFed(string $userId): ?FederatedUser {
173185
if (!array_key_exists($userId, $this->fedList)) {
174-
$this->fedList[$userId] = $this->circlesManager->getLocalFederatedUser($userId);
186+
try {
187+
$this->fedList[$userId] = $this->circlesManager->getLocalFederatedUser($userId);
188+
} catch (\Exception $e) {
189+
$this->logger->warning('unknown local user ' . $userId, ['exception' => $e]);
190+
$this->fedList[$userId] = null;
191+
}
175192
}
176193

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

194211
$count = 0;
195212
foreach ($memberIds as $memberId) {
213+
$fedUser = $this->cachedFed($memberId);
214+
if ($fedUser === null) {
215+
// we dont update, user does not exist anymore
216+
continue;
217+
}
196218
$update->setParameter('old_recipient', $memberId);
197-
$update->setParameter('new_recipient', $this->cachedFed($memberId)->getSingleId());
219+
$update->setParameter('new_recipient', $fedUser->getSingleId());
198220
$count += $update->executeStatement();
199221
}
200222

0 commit comments

Comments
 (0)