'danger', 'msg' => 'Pedido rejeitado (token CSRF inválido).']; header('Location: ' . $selfUrl, true, 303); exit; } $file = (string) ($_POST['filename'] ?? ''); $typed = trim((string) ($_POST['confirm_name'] ?? '')); $dropExtra = !empty($_POST['drop_extra']); if ($typed !== $file) { $_SESSION['restore_flash'] = ['type' => 'warning', 'msg' => 'O nome escrito não corresponde ao ficheiro escolhido — nada foi feito.']; header('Location: ' . $selfUrl . '?f=' . urlencode($file), true, 303); exit; } // A partir daqui a base de dados vai ser substituída. $report = restore_db($pdo, $file, ['safety' => true, 'drop_extra_tables' => $dropExtra]); // Depois do restauro: a tabela do registo também foi reposta, e é na nova que // tem de ficar escrito que isto aconteceu. if (function_exists('platform_audit')) { platform_audit($pdo, 'backup.restore', ['target_type' => 'backup', 'target_label' => $file, 'summary' => !empty($report['ok']) ? 'Base de dados reposta' : 'Restauro falhou', 'changes' => ['drop_extra_tables' => $dropExtra]]); } $_SESSION['restore_report'] = $report; header('Location: ' . $selfUrl, true, 303); exit; } $flash = $_SESSION['restore_flash'] ?? null; $report = $_SESSION['restore_report'] ?? null; unset($_SESSION['restore_flash'], $_SESSION['restore_report']); $all = backup_list(); $dbFiles = array_values(array_filter($all, fn($b) => ($b['type'] ?? '') === 'db')); $selected = (string) ($_GET['f'] ?? ''); $inspect = $selected !== '' ? restore_inspect($selected) : null; $tables = restore_current_tables($pdo); $layout_header = $platform_layout_header ?? ($repo_root . '/includes/header.php'); $layout_navbar = $platform_layout_navbar ?? ($repo_root . '/includes/navbar.php'); $layout_footer = $platform_layout_footer ?? ($repo_root . '/includes/footer.php'); $backupsUrl = $platform_backups_url ?? (function_exists('platform_admin_url') ? platform_admin_url('backups.php') : 'backups.php'); $pageTitle = 'Restaurar base de dados'; if (is_file($layout_header)) include $layout_header; if (is_file($layout_navbar)) include $layout_navbar; $h = fn($s) => htmlspecialchars((string) $s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
Substitui o esquema e os dados actuais por um artefacto de backup.
| Artefacto aplicado | = $h($report['filename']) ?> |
| Backup de segurança | = $report['safety_backup']
? '' . $h($report['safety_backup']) . ''
: 'nenhum' ?> |
| Statements | = (int) $report['applied'] ?> aplicados de = (int) $report['statements'] ?> |
| Tabelas | = (int) $report['tables_before'] ?> antes → = (int) $report['tables_after'] ?> depois |
| Tabelas removidas | = $h(implode(', ', $report['dropped_extra'])) ?>
Existiam aqui e não no artefacto. |
| Erro | = $h($report['error']) ?> |
O estado anterior está em = $h($report['safety_backup']) ?> —
restaurá-lo devolve a base ao que era antes desta tentativa.
Não há backups de base de dados em backups/.
Crie um a partir da página de Backups.
| Ficheiro | Tamanho | Criado | |
|---|---|---|---|
= $h($b['filename']) ?> |
= $h($b['size_human']) ?> | = $h(date('Y-m-d H:i', (int) $b['created_at'])) ?> | Inspeccionar |
= $h($inspect['filename']) ?> é um backup de ficheiros, não de base de dados.
| Ficheiro | = $h($inspect['filename']) ?> |
| Tamanho | = $h($inspect['size_human']) ?> |
| Entradas no ZIP | = (int) $inspect['entries'] ?> |
| Dump | = $h($inspect['sql_entry']) ?> |