Skip to content

Commit

Permalink
enh(GroupMigration): repair step to catch up with unmigrated group me…
Browse files Browse the repository at this point in the history
…mbers

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jul 11, 2024
1 parent 8f6eb98 commit 9fde08d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ While theoretically any other authentication provider implementing either one of
</post-migration>
<live-migration>
<step>OCA\User_SAML\Migration\CleanupRemovedConfig</step>
<step>OCA\User_SAML\Migration\TransferGroupMembers</step>
</live-migration>
</repair-steps>
<commands>
Expand Down
52 changes: 52 additions & 0 deletions lib/Migration/TransferGroupMembers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_SAML\Migration;

use OCA\User_SAML\Service\GroupMigration;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Psr\Log\LoggerInterface;
use Throwable;

class TransferGroupMembers implements IRepairStep {

public function __construct(
private GroupMigration $groupMigration,
private LoggerInterface $logger,
) {
}

public function getName(): string {
return 'Move potential left members from old local groups to SAML groups';
}

public function run(IOutput $output): void {
$groupsToTreat = $this->groupMigration->findGroupsWithLocalMembers();
if (empty($groupsToTreat)) {
return;
}
$hasError = false;
$output->startProgress(count($groupsToTreat));
foreach ($groupsToTreat as $gid) {
try {
if ($this->groupMigration->migrateGroupUsers($gid)) {
$this->groupMigration->cleanUpOldGroupUsers($gid);
}
} catch (Throwable $e) {
$hasError = true;
$this->logger->warning('Error while transferring group members of {gid}', ['gid' => $gid, 'exception' => $e]);
} finally {
$output->advance();
}
}
$output->finishProgress();
if ($hasError) {
$output->warning('There were errors while transferring group members to SAML groups. You may try later `occ saml:group-migration:copy-incomplete-members` later and check your nextcloud.log.');
}
}
}

0 comments on commit 9fde08d

Please sign in to comment.