> /percorso/log/mago_sync.log 2>&1 */ if (PHP_SAPI !== 'cli') { http_response_code(403); exit('Solo da riga di comando'); } set_time_limit(0); date_default_timezone_set('Europe/Rome'); // --- vendor e .env: li cerco in userarea e fino a 3 cartelle sopra --- $dirs = [__DIR__, dirname(__DIR__), dirname(__DIR__, 2), dirname(__DIR__, 3)]; foreach ($dirs as $d) { if (file_exists($d . '/vendor/autoload.php')) { require_once $d . '/vendor/autoload.php'; break; } } if (class_exists('Dotenv\Dotenv')) { foreach ($dirs as $d) { if (file_exists($d . '/.env')) { Dotenv\Dotenv::createImmutable($d)->safeLoad(); break; } } } // --- DB della piattaforma --- require_once __DIR__ . '/class/db-functions.php'; require_once __DIR__ . '/class/MagoSync.php'; $opts = getopt('', ['limit::', 'full', 'from::', 'skip-customers']); $runOpts = [ 'limit' => isset($opts['limit']) ? (int)$opts['limit'] : null, 'full' => isset($opts['full']), 'from' => $opts['from'] ?? null, 'skip_customers' => isset($opts['skip-customers']), ]; try { $pdo = DBHandlerSelect::getInstance()->getConnection(); $sync = new MagoSync($pdo, MagoClient::fromEnv(), function ($msg) { echo $msg . PHP_EOL; }); echo '=== Sync Mago ' . date('Y-m-d H:i:s') . ' ===' . PHP_EOL; $report = $sync->run($runOpts); echo json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL; exit(!empty($report['ok']) ? 0 : 1); } catch (Throwable $e) { fwrite(STDERR, 'ERRORE: ' . $e->getMessage() . PHP_EOL); exit(1); }