* Return the first admin username from users.txt order. */
()
| 249 | * Return the first admin username from users.txt order. |
| 250 | */ |
| 251 | public static function getPrimaryAdminUsername(): string |
| 252 | { |
| 253 | self::ensureUserCaseMigration(); |
| 254 | $usersFile = USERS_DIR . USERS_FILE; |
| 255 | if (!file_exists($usersFile)) { |
| 256 | return ''; |
| 257 | } |
| 258 | |
| 259 | $lines = file($usersFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []; |
| 260 | foreach ($lines as $line) { |
| 261 | $line = trim($line); |
| 262 | if ($line === '') { |
| 263 | continue; |
| 264 | } |
| 265 | $parts = explode(':', $line); |
| 266 | if (count($parts) < 3) { |
| 267 | continue; |
| 268 | } |
| 269 | $username = $parts[0]; |
| 270 | $role = trim((string)$parts[2]); |
| 271 | if (!preg_match(REGEX_USER, $username)) { |
| 272 | continue; |
| 273 | } |
| 274 | if ($role === '1') { |
| 275 | return $username; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return ''; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Add a user. |
no test coverage detected