Skip to content

Commit e08058d

Browse files
committed
After review 0
1 parent 7461691 commit e08058d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

config/parameters.yml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ parameters:
8585
env(MAILQUEUE_THROTTLE): '5'
8686
messaging.max_process_time: '%%env(MESSAGING_MAX_PROCESS_TIME)%%'
8787
env(MESSAGING_MAX_PROCESS_TIME): '600'
88+
89+
phplist.admin.password: '%%env(PHPLIST_ADMIN_PASSWORD)%%'
90+
env(PHPLIST_ADMIN_PASSWORD): 'password'

src/Migrations/Version20251103SeedInitialAdmin.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
88
use Doctrine\DBAL\Schema\Schema;
99
use Doctrine\Migrations\AbstractMigration;
10+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1012

11-
final class Version20251103SeedInitialAdmin extends AbstractMigration
13+
final class Version20251103SeedInitialAdmin extends AbstractMigration implements ContainerAwareInterface
1214
{
15+
private ?ContainerInterface $container = null;
16+
17+
public function setContainer(ContainerInterface $container = null): void
18+
{
19+
$this->container = $container;
20+
}
21+
1322
public function getDescription(): string
1423
{
1524
return 'Seed initial admin user';
@@ -23,6 +32,14 @@ public function up(Schema $schema): void
2332
get_class($platform)
2433
));
2534

35+
$password = null;
36+
if ($this->container instanceof ContainerInterface && $this->container->hasParameter('phplist.admin.password')) {
37+
$password = (string) $this->container->getParameter('phplist.admin.password');
38+
}
39+
if ($password === null || $password === '') {
40+
$password = getenv('PHPLIST_ADMIN_PASSWORD') ?: '';
41+
}
42+
2643
$this->addSql(<<<'SQL'
2744
INSERT INTO phplist_admin (id, created, modified, loginname, namelc, email, password, passwordchanged, disabled, superuser, privileges)
2845
VALUES (1, NOW(), NOW(), 'admin', 'admin', '[email protected]', :hash, CURRENT_DATE, FALSE, TRUE, :privileges)
@@ -31,7 +48,7 @@ public function up(Schema $schema): void
3148
modified = EXCLUDED.modified,
3249
privileges = EXCLUDED.privileges
3350
SQL, [
34-
'hash' => hash('sha256', 'password'),
51+
'hash' => hash('sha256', $password),
3552
'privileges' => 'a:4:{s:11:"subscribers";b:1;s:9:"campaigns";b:1;s:10:"statistics";b:1;s:8:"settings";b:1;}',
3653
]);
3754
}
@@ -44,6 +61,5 @@ public function down(Schema $schema): void
4461
get_class($platform)
4562
));
4663

47-
$this->addSql('DELETE FROM phplist_admin WHERE id = 1');
48-
}
64+
$this->addSql("DELETE FROM phplist_admin WHERE id = 1 AND loginname = 'admin' AND email = '[email protected]'"); }
4965
}

0 commit comments

Comments
 (0)