diff --git a/apps/user_ldap/lib/Command/PromoteGroup.php b/apps/user_ldap/lib/Command/PromoteGroup.php index 5fc3905414f5c..e2e0d356ec822 100644 --- a/apps/user_ldap/lib/Command/PromoteGroup.php +++ b/apps/user_ldap/lib/Command/PromoteGroup.php @@ -62,20 +62,31 @@ protected function configure(): void { } protected function promoteGroup(IGroup $group, InputInterface $input, OutputInterface $output): void { + $access = $this->backend->getLDAPAccess($group->getGID()); + $currentlyPromotedGroupId = $access->connection->ldapAdminGroup; + if ($currentlyPromotedGroupId === $group->getGID()) { + $output->writeln('The specified group is already promoted'); + return; + } + if ($input->getOption('yes') === false) { - /** @var QuestionHelper $helper */ - $helper = $this->getHelper('question'); + $currentlyPromotedGroup = $this->groupManager->get($currentlyPromotedGroupId); + $demoteLabel = ''; + if ($currentlyPromotedGroup instanceof IGroup && $this->backend->groupExists($currentlyPromotedGroup->getGID())) { + $demoteLabel = sprintf('and demote %s (Group ID: %s) ', $currentlyPromotedGroup->getDisplayName(), $currentlyPromotedGroupId); + } $idLabel = ''; if ($group->getGID() !== $group->getDisplayName()) { $idLabel = sprintf(' (Group ID: %s)', $group->getGID()); } - $q = new Question(sprintf('Promote %s%s to the admin group (y|N)? ', $group->getDisplayName(), $idLabel)); + /** @var QuestionHelper $helper */ + $helper = $this->getHelper('question'); + $q = new Question(sprintf('Promote %s%s to the admin group %s(y|N)? ', $group->getDisplayName(), $idLabel, $demoteLabel)); $input->setOption('yes', $helper->ask($input, $output, $q) === 'y'); } if ($input->getOption('yes') === true) { - $access = $this->backend->getLDAPAccess($group->getGID()); $access->connection->setConfiguration(['ldapAdminGroup' => $group->getGID()]); $access->connection->saveConfiguration(); $output->writeln(sprintf('Group %s was promoted', $group->getDisplayName()));