Expand create user command to create db and add permissions
This commit is contained in:
parent
9887282b62
commit
13b8091451
@ -8,6 +8,7 @@ use Symfony\Component\Console\Command\Command;
|
|||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
|
|
||||||
#[AsCommand('app:user:create')]
|
#[AsCommand('app:user:create')]
|
||||||
@ -48,6 +49,14 @@ class CreateUserCommand extends Command
|
|||||||
|
|
||||||
$output->writeln(sprintf('User "%s" successfully created', $user));
|
$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;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user