1515use Symfony \Component \Console \Input \InputInterface ;
1616use Symfony \Component \Console \Output \OutputInterface ;
1717use Symfony \Component \Console \Question \Question ;
18+ use Symfony \Component \DependencyInjection \Attribute \Autowire ;
1819
1920#[AsCommand(
2021 name: 'phplist:defaults:import ' ,
2122 description: 'Imports default values into the database (e.g., default admin with all privileges). '
2223)]
2324class ImportDefaultsCommand extends Command
2425{
25- private const DEFAULT_LOGIN = 'admin ' ;
26+ private const DEFAULT_LOGIN = 'test1 ' ;
2627 private const DEFAULT_EMAIL = 'admin@example.com ' ;
2728
2829 public function __construct (
2930 private readonly AdministratorRepository $ administratorRepository ,
3031 private readonly AdministratorManager $ administratorManager ,
3132 private readonly EntityManagerInterface $ entityManager ,
33+ #[Autowire('%app.default_admin_password% ' )]
34+ private readonly string $ defaultAdminPassword = ''
3235 ) {
3336 parent ::__construct ();
3437 }
@@ -37,15 +40,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3740 {
3841 $ login = self ::DEFAULT_LOGIN ;
3942 $ email = self ::DEFAULT_EMAIL ;
40- $ envPassword = getenv ('PHPLIST_ADMIN_PASSWORD ' );
41- $ envPassword = is_string ($ envPassword ) && trim ($ envPassword ) !== '' ? $ envPassword : null ;
43+ $ password = $ this ->defaultAdminPassword !== '' ? $ this ->defaultAdminPassword : null ;
4244
4345 $ allPrivileges = $ this ->allPrivilegesGranted ();
4446
4547 $ existing = $ this ->administratorRepository ->findOneBy (['loginName ' => $ login ]);
4648 if ($ existing === null ) {
4749 // If creating the default admin, require a password. Prefer env var, else prompt for input.
48- $ password = $ envPassword ;
4950 if ($ password === null ) {
5051 /** @var QuestionHelper $helper */
5152 $ helper = $ this ->getHelper ('question ' );
0 commit comments