@@ -105,11 +105,13 @@ public function getServerConfigurationHosts(): array {
105105 public function getNextServerConfigurationPrefix (): string {
106106 $ prefixes = $ this ->getServerConfigurationPrefixes ();
107107
108- if (count ($ prefixes ) === 0 ) {
108+ $ filteredPrefixes = array_filter ($ prefixes , fn ($ p ) => preg_match ('/^s\d{2}$/ ' , $ p ));
109+
110+ if (count ($ filteredPrefixes ) === 0 ) {
109111 $ prefix = 's01 ' ;
110112 } else {
111- sort ($ prefixes );
112- $ lastKey = array_pop ($ prefixes );
113+ sort ($ filteredPrefixes );
114+ $ lastKey = array_pop ($ filteredPrefixes );
113115 $ lastNumber = (int )str_replace ('s ' , '' , $ lastKey );
114116 $ prefix = 's ' . str_pad ((string )($ lastNumber + 1 ), 2 , '0 ' , STR_PAD_LEFT );
115117 }
@@ -119,6 +121,22 @@ public function getNextServerConfigurationPrefix(): string {
119121 return $ prefix ;
120122 }
121123
124+ /**
125+ * registers the given prefix as used, if it is not already in use
126+ *
127+ * @param string $prefix the prefix to register
128+ * @return string|false the given prefix on success, false if it is already in use
129+ */
130+ public function registerNewServerConfigurationPrefix (string $ prefix ): string |false {
131+ $ prefixes = $ this ->getServerConfigurationPrefixes ();
132+ if (in_array ($ prefix , $ prefixes )) {
133+ return false ;
134+ }
135+ $ prefixes [] = $ prefix ;
136+ $ this ->appConfig ->setValueArray ('user_ldap ' , 'configuration_prefixes ' , $ prefixes );
137+ return $ prefix ;
138+ }
139+
122140 private function getServersConfig (string $ value ): array {
123141 $ regex = '/ ' . $ value . '$/S ' ;
124142
0 commit comments