- application/services/DemoSeedService.php: logica seed/clone golden #151 -> 996001/996002 (riusabile) - DemoController::resetDataset: re-seed reale via service (?scope=demo|sandbox|default both), non piu stub - scripts/seed-demo-dataset.php: thin CLI wrapper sul service Testato prod: POST /api/demo/reset-dataset (X-Internal-Key) scope=sandbox -> 200, 996002 ri-seedata. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
36 lines
1.7 KiB
PHP
36 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* NIS2 Agile - Seed dataset DEMO isolato (CLI thin wrapper)
|
|
* ----------------------------------------------------------------------------
|
|
* Logica nel service: application/services/DemoSeedService.php (usato anche da
|
|
* DemoController::resetDataset). Questo è solo il bootstrap CLI.
|
|
*
|
|
* ESEGUIRE SU HETZNER. NB: nis2-app monta SOLO application/+public/ → per girare
|
|
* via `docker exec` copiare sotto application/:
|
|
* cp scripts/seed-demo-dataset.php application/_seed.php
|
|
* docker exec -i nis2-app php /var/www/nis2-agile/application/_seed.php
|
|
* rm application/_seed.php
|
|
* Opzioni: --only=996001 (un solo org)
|
|
* ============================================================================
|
|
*/
|
|
if (PHP_SAPI !== 'cli') { fwrite(STDERR, "Solo CLI\n"); exit(1); }
|
|
|
|
// env reale del processo FPM (vault) se in docker exec; altrimenti .env via env.php
|
|
$e = @file_get_contents('/proc/1/environ');
|
|
if ($e) foreach (explode("\0", $e) as $p) { if (strpos($p, '=') !== false) { putenv($p); [$k, $v] = explode('=', $p, 2); $_ENV[$k] = $v; $_SERVER[$k] = $v; } }
|
|
if (!defined('BASE_PATH')) define('BASE_PATH', dirname(__DIR__));
|
|
if (!defined('APP_PATH')) define('APP_PATH', BASE_PATH . '/application');
|
|
require_once APP_PATH . '/config/env.php';
|
|
require_once APP_PATH . '/config/config.php';
|
|
require_once APP_PATH . '/config/database.php';
|
|
require_once APP_PATH . '/services/DemoSeedService.php';
|
|
|
|
$opts = getopt('', ['only::']);
|
|
$targets = isset($opts['only'])
|
|
? array_intersect_key(DemoSeedService::TARGETS, [(int) $opts['only'] => 1])
|
|
: DemoSeedService::TARGETS;
|
|
|
|
$res = DemoSeedService::seed($targets);
|
|
foreach ($res as $org => $msg) echo "ORG $org: $msg\n";
|
|
echo "Seed dataset demo completato (" . implode(',', array_keys($res)) . ").\n";
|