selectMultipleFromDb($select, User::class); $userRepository = new UserRepository(); $usernameGenerator = new UsernameGenerator(); foreach ($users as $user) { do { $username = $usernameGenerator->generate(); } while ($userRepository->getByUsername($username)); $user->setUsername($username); Container::$persistentDataManager->saveToDb($user); }