1111use OCA \User_SAML \Service \GroupMigration ;
1212use Psr \Log \LoggerInterface ;
1313use Symfony \Component \Console \Input \InputInterface ;
14+ use Symfony \Component \Console \Input \InputOption ;
1415use Symfony \Component \Console \Output \OutputInterface ;
1516use Throwable ;
1617
@@ -23,20 +24,30 @@ public function __construct(
2324 }
2425 #[\Override]
2526 protected function configure (): void {
26- $ this ->setName ('saml:group-migration:copy-incomplete-members ' );
27- $ this ->setDescription ('Transfers remaining group members from old local to current SAML groups ' );
27+ $ this ->setName ('saml:group-migration:copy-incomplete-members ' )
28+ ->setDescription ('Transfers remaining group members from old local to current SAML groups ' )
29+ ->addOption ('dry-run ' , null , InputOption::VALUE_NONE , 'Output the SQL queries instead of running them. ' );
2830 }
2931
3032 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
33+ $ dryRun = $ input ->getOption ('dry-run ' );
34+
3135 $ groupsToTreat = $ this ->groupMigration ->findGroupsWithLocalMembers ();
3236 if (empty ($ groupsToTreat )) {
33- if ($ output ->isVerbose ()) {
37+ if ($ output ->isVerbose () || $ dryRun ) {
3438 $ output ->writeln ('<info>No pending group member transfer</info> ' );
3539 }
3640 return 0 ;
3741 }
3842
39- if (!$ this ->doMemberTransfer ($ groupsToTreat , $ output )) {
43+ if ($ dryRun ) {
44+ $ output ->writeln ('<info>Found the following SAML group with a corresponding local group:</info> ' );
45+ foreach ($ groupsToTreat as $ group ) {
46+ $ output ->writeln ('<info>- ' . $ group . '</info> ' );
47+ }
48+ }
49+
50+ if (!$ this ->doMemberTransfer ($ groupsToTreat , $ output , $ dryRun )) {
4051 if (!$ output ->isQuiet ()) {
4152 $ output ->writeln ('<comment>Not all group members could be transferred completely. Rerun this command or check the Nextcloud log.</comment> ' );
4253 }
@@ -54,16 +65,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5465 * @param OutputInterface $output
5566 * @return bool
5667 */
57- protected function doMemberTransfer (array $ groups , OutputInterface $ output ): bool {
68+ protected function doMemberTransfer (array $ groups , OutputInterface $ output, bool $ dryRun ): bool {
5869 $ errorOccurred = false ;
5970 for ($ i = 0 ; $ i < 2 ; $ i ++) {
6071 $ retry = [];
6172 foreach ($ groups as $ gid ) {
6273 try {
63- $ isComplete = $ this ->groupMigration ->migrateGroupUsers ($ gid );
74+ $ isComplete = $ this ->groupMigration ->migrateGroupUsers ($ gid, $ output , $ dryRun );
6475 if (!$ isComplete ) {
6576 $ retry [] = $ gid ;
66- } else {
77+ } elseif (! $ dryRun ) {
6778 $ this ->groupMigration ->cleanUpOldGroupUsers ($ gid );
6879 if ($ output ->isVerbose ()) {
6980 $ output ->writeln (sprintf ('<info>Members transferred successfully for group %s</info> ' , $ gid ));
0 commit comments