First commit
This commit is contained in:
7
scripts/bootstrap.php
Normal file
7
scripts/bootstrap.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
return require dirname(__DIR__) . '/app/bootstrap.php';
|
||||
37
scripts/create-admin.php
Normal file
37
scripts/create-admin.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$f3 = require __DIR__ . '/bootstrap.php';
|
||||
$db = $f3->get('DB');
|
||||
|
||||
$username = trim((string) ($argv[1] ?? ''));
|
||||
if ($username === '') {
|
||||
fwrite(STDERR, "Usage: php scripts/create-admin.php <username>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fwrite(STDOUT, 'Mot de passe (10 caractères minimum): ');
|
||||
if (stripos(PHP_OS, 'WIN') !== 0) {
|
||||
system('stty -echo');
|
||||
}
|
||||
$password = trim((string) fgets(STDIN));
|
||||
if (stripos(PHP_OS, 'WIN') !== 0) {
|
||||
system('stty echo');
|
||||
}
|
||||
fwrite(STDOUT, PHP_EOL);
|
||||
|
||||
if ($password === '') {
|
||||
fwrite(STDERR, "Mot de passe vide.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
User::bootstrap($db);
|
||||
|
||||
try {
|
||||
$id = (new User($db))->create($username, $password);
|
||||
fwrite(STDOUT, "Admin créé (ID {$id}).\n");
|
||||
} catch (RuntimeException $e) {
|
||||
fwrite(STDERR, $e->getMessage() . "\n");
|
||||
exit(1);
|
||||
}
|
||||
12
scripts/install.php
Normal file
12
scripts/install.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$f3 = require __DIR__ . '/bootstrap.php';
|
||||
$db = $f3->get('DB');
|
||||
|
||||
User::bootstrap($db);
|
||||
Post::bootstrap($db);
|
||||
Media::bootstrap($db);
|
||||
|
||||
fwrite(STDOUT, 'Base initialisée : ' . app_db_path() . "\n");
|
||||
Reference in New Issue
Block a user