Expand create user command to create db and add permissions

This commit is contained in:
Tim 2024-09-24 00:50:08 +02:00
parent 9887282b62
commit 13b8091451

View File

@ -8,6 +8,7 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
#[AsCommand('app:user:create')]
@ -48,6 +49,14 @@ class CreateUserCommand extends Command
$output->writeln(sprintf('User "%s" successfully created', $user));
// ask to create a database for the user
$createDbQuestion = new ConfirmationQuestion('Create a database for this user?', false);
if ($question->ask($input, $output, $createDbQuestion)) {
$this->db->createDatabase($user);
$this->db->grantDatabaseAdminPermission($user, $user, $host);
$output->writeln(sprintf('Database "%s" successfully created and granted to "%s"', $user, $user));
}
return Command::SUCCESS;
}
}