<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } RBAC::enforce('fleet.migrate'); $backups = []; $migrationDir = '/var/www/backups/migrations/'; if (is_dir($migrationDir)) { $files = scandir($migrationDir); foreach ($files as $f) { if (pathinfo($f, PATHINFO_EXTENSION) === 'sql') $backups[] = $f; } rsort($backups); } ?> <div id="migration-ui" class="editor-form"> <span class="section-label">Data Migration</span> <div class="panel"> <span class="section-label">Export Current Schema</span> <div class="form-group"><span>Include Data</span> <select id="mig-scope" class="form-group input"> <option value="schema">Schema Only</option> <option value="full">Schema + Data</option> <option value="data">Data Only</option> </select> </div> <div class="form-group"><span>Tables (comma-separated, blank = all)</span><input id="mig-tables" class="form-group input" type="text" placeholder="orders,order_items,users"></div> <div class="form-actions"><a id="mig-export" class="btn btn-primary" href="javascript:void(0)"><span>Export Migration</span></a></div> </div> <div class="panel"> <span class="section-label">Import Migration</span> <div class="form-group"><span>Select Migration File</span> <select id="mig-file" class="form-group input"> <option value="">-- select --</option><?php foreach ($backups as $b): ?> <option value="<?= UI::e($b) ?> "><?= UI::e($b) ?> </option><?php endforeach; ?> </select> </div> <div class="form-group"><span>Mode</span> <select id="mig-mode" class="form-group input"> <option value="merge">Merge (skip existing)</option> <option value="replace">Replace (overwrite)</option> </select> </div> <div class="form-actions"><a id="mig-import" class="btn btn-warning" href="javascript:void(0)"><span>Run Import</span></a></div> <span class="pay-info">Import requires elevated verification.</span> </div> <div id="mig-log" class="term-output" style="display:none"></div> </div> <script nonce="<?= $cspNonce ?? '' ?> "> document.getElementById('mig-export').addEventListener('click',function(){ window.dashFetch('verify',{action:'migration_export','data[scope]':document.getElementById('mig-scope').value,'data[tables]':document.getElementById('mig-tables').value},function(r){var log=document.getElementById('mig-log');log.style.display='block';log.innerHTML='<div class="term-result">'+JSON.stringify(r)+'</div>';}); }); document.getElementById('mig-import').addEventListener('click',function(){ if(!confirm('Run migration import? This modifies the database.'))return; window.dashFetch('verify',{action:'migration_import','data[file]':document.getElementById('mig-file').value,'data[mode]':document.getElementById('mig-mode').value},function(r){var log=document.getElementById('mig-log');log.style.display='block';log.innerHTML='<div class="term-result">'+JSON.stringify(r)+'</div>';}); }); </script>