@@ -61,21 +61,36 @@ protected function configure(): void {
6161 );
6262 }
6363
64+ protected function formatGroupName (IGroup $ group ): string {
65+ $ idLabel = '' ;
66+ if ($ group ->getGID () !== $ group ->getDisplayName ()) {
67+ $ idLabel = sprintf (' (Group ID: %s) ' , $ group ->getGID ());
68+ }
69+ return sprintf ('%s%s ' , $ group ->getDisplayName (), $ idLabel );
70+ }
71+
6472 protected function promoteGroup (IGroup $ group , InputInterface $ input , OutputInterface $ output ): void {
65- if ($ input ->getOption ('yes ' ) === false ) {
66- /** @var QuestionHelper $helper */
67- $ helper = $ this ->getHelper ('question ' );
73+ $ access = $ this ->backend ->getLDAPAccess ($ group ->getGID ());
74+ $ currentlyPromotedGroupId = $ access ->connection ->ldapAdminGroup ;
75+ if ($ currentlyPromotedGroupId === $ group ->getGID ()) {
76+ $ output ->writeln ('<info>The specified group is already promoted</info> ' );
77+ return ;
78+ }
6879
69- $ idLabel = '' ;
70- if ($ group ->getGID () !== $ group ->getDisplayName ()) {
71- $ idLabel = sprintf (' (Group ID: %s) ' , $ group ->getGID ());
80+ if ($ input ->getOption ('yes ' ) === false ) {
81+ $ currentlyPromotedGroup = $ this ->groupManager ->get ($ currentlyPromotedGroupId );
82+ $ demoteLabel = '' ;
83+ if ($ currentlyPromotedGroup instanceof IGroup && $ this ->backend ->groupExists ($ currentlyPromotedGroup ->getGID ())) {
84+ $ groupNameLabel = $ this ->formatGroupName ($ currentlyPromotedGroup );
85+ $ demoteLabel = sprintf ('and demote %s ' , $ groupNameLabel );
7286 }
7387
74- $ q = new Question (sprintf ('Promote %s%s to the admin group (y|N)? ' , $ group ->getDisplayName (), $ idLabel ));
88+ /** @var QuestionHelper $helper */
89+ $ helper = $ this ->getHelper ('question ' );
90+ $ q = new Question (sprintf ('Promote %s to the admin group %s(y|N)? ' , $ this ->formatGroupName ($ group ), $ demoteLabel ));
7591 $ input ->setOption ('yes ' , $ helper ->ask ($ input , $ output , $ q ) === 'y ' );
7692 }
7793 if ($ input ->getOption ('yes ' ) === true ) {
78- $ access = $ this ->backend ->getLDAPAccess ($ group ->getGID ());
7994 $ access ->connection ->setConfiguration (['ldapAdminGroup ' => $ group ->getGID ()]);
8095 $ access ->connection ->saveConfiguration ();
8196 $ output ->writeln (sprintf ('<info>Group %s was promoted</info> ' , $ group ->getDisplayName ()));
0 commit comments