Files
xamxam/app/public/admin/actions/export-files.php
Pontoporeia 6cc0e407f3 Error tests, FK violations fix
- ErrorHandler tests: 77 assertions covering FK extraction, normalization, dedup, edge cases. Fix FK table map for child tables.
- Fix FK violation: (int)null → 0 in createThesis for orientation/ap/finality/license FK columns. Add FK value logging to updateThesis.
- Add CURRENT_ISSUES.md with summary of FK violation, dev debugging, and tag dedup status for next conversation
2026-05-19 00:08:05 +02:00

50 lines
1.5 KiB
PHP

<?php
/**
* Export all thesis files as a ZIP archive.
*
* The ZIP contains:
* - manifest.json — maps every thesis to its files with DB-relevant metadata
* - files/ — mirror of storage/theses/ directory structure
*
* Thin dispatcher — delegates all data assembly to ExportController,
* then streams the response.
*/
require_once __DIR__ . "/../../../bootstrap.php";
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once APP_ROOT . '/src/Controllers/ExportController.php';
require_once APP_ROOT . '/src/AdminLogger.php';
require_once APP_ROOT . '/src/ErrorHandler.php';
try {
$controller = ExportController::create();
// Build the zip
$zipPath = $controller->createExportZip();
$fileSize = filesize($zipPath);
$fileCount = count($controller->getAllThesisFiles());
// Audit log (before headers in case log fails — but it's best-effort anyway)
AdminLogger::make()->logFilesExport($fileCount, (int)$fileSize);
$filename = 'xamxam-files-' . date('Y-m-d') . '.zip';
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: ' . $fileSize);
header('Cache-Control: no-cache, must-revalidate');
readfile($zipPath);
// Clean up temp file
@unlink($zipPath);
} catch (Exception $e) {
ErrorHandler::log('export_files', $e);
http_response_code(500);
exit('Erreur lors de la création de l\'archive : ' . htmlspecialchars(ErrorHandler::userMessage($e)));
}
exit;