28 lines
1.1 KiB
PHP
28 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
if (PHP_SAPI !== 'cli') { http_response_code(404); exit(1); }
|
|
if (!in_array('--confirm-demo-reset', $argv, true)) {
|
|
fwrite(STDERR, "Usage: php scripts/reset-demo.php --confirm-demo-reset\n"); exit(2);
|
|
}
|
|
$root = dirname(__DIR__);
|
|
foreach (['DB','Migrations','I18n','AppSettings','Auth','AuditService','BackupService','DemoDataService'] as $service) {
|
|
require_once $root . '/app/Services/' . $service . '.php';
|
|
}
|
|
Migrations::run($root . '/migrations');
|
|
I18n::setLocale(AppSettings::get('app_language'));
|
|
$db = DB::pdo();
|
|
$backup = BackupService::create('scheduled-demo-reset');
|
|
try {
|
|
$db->beginTransaction();
|
|
$removed = DemoDataService::reset($db);
|
|
DemoDataService::seed($db, null);
|
|
$db->commit();
|
|
DemoDataService::clearFiles();
|
|
DemoDataService::installFiles($db);
|
|
fwrite(STDOUT, json_encode(['ok'=>true,'backup'=>$backup['name'],'removed'=>$removed], JSON_UNESCAPED_UNICODE) . PHP_EOL);
|
|
} catch (Throwable $e) {
|
|
if ($db->inTransaction()) $db->rollBack();
|
|
fwrite(STDERR, json_encode(['ok'=>false,'error'=>$e->getMessage()], JSON_UNESCAPED_UNICODE) . PHP_EOL);
|
|
exit(1);
|
|
}
|