mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
add file export system for admins
- ExportController: getAllThesisFiles(), buildExportManifest(), createExportZip() builds a ZIP archive with manifest.json + files/ mirror of storage/theses/ - Database: getAllThesisFilesForExport() queries all thesis_files + identifier - AdminLogger: logFilesExport() audit log entry - admin/actions/export-files.php: thin dispatcher, streams zip with headers - templates/admin/index.php: 'Exporter fichiers' button next to CSV export
This commit is contained in:
48
app/public/admin/actions/export-files.php
Normal file
48
app/public/admin/actions/export-files.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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';
|
||||
|
||||
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) {
|
||||
error_log('Files export error: ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
exit('Erreur lors de la création de l\'archive : ' . htmlspecialchars($e->getMessage()));
|
||||
}
|
||||
|
||||
exit;
|
||||
Reference in New Issue
Block a user