Fix asset export to create ZIP file with manifest
CI/CD Pipeline / deploy (push) Successful in 30s
CI/CD Pipeline / promote_stable (push) Successful in 2s

This commit is contained in:
2026-05-17 16:51:55 +02:00
parent f650bb7c86
commit cbe2479e0d
54 changed files with 32 additions and 3286 deletions
+32 -20
View File
@@ -9,34 +9,46 @@ use ZipArchive;
class AssetController extends Controller
{
public function export(): \Symfony\Component\HttpFoundation\StreamedResponse
public function export()
{
$user = auth()->user();
if (!$user || !$user->roles()->where('name', 'ROLE_ADMIN')->exists()) {
abort(403, 'Forbidden');
}
$storagePublic = storage_path('app/public');
try {
$storagePublic = storage_path('app/public');
if (!is_dir($storagePublic)) {
mkdir($storagePublic, 0775, true);
if (!is_dir($storagePublic)) {
mkdir($storagePublic, 0775, true);
}
// Create ZIP in memory
$zip = new ZipArchive();
$tempFile = tempnam(sys_get_temp_dir(), 'speedbb_');
if ($zip->open($tempFile, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
return response()->json(['message' => 'Failed to create ZIP'], 500);
}
// Add a manifest file to ensure ZIP is created even if empty
$zip->addFromString('MANIFEST.txt', "SpeedBB Assets Export\nExported: " . date('Y-m-d H:i:s') . "\n");
$this->addDirectoryToZip($zip, $storagePublic, '');
$zip->close();
if (!file_exists($tempFile)) {
return response()->json(['message' => 'ZIP file was not created'], 500);
}
$filename = 'assets-'.date('YmdHis').'.zip';
return response()->file($tempFile, [
'Content-Type' => 'application/zip',
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
])->deleteFileAfterSend(true);
} catch (\Exception $e) {
return response()->json(['message' => 'Export error: '.$e->getMessage()], 500);
}
$zip = new ZipArchive();
$zipPath = storage_path('exports/assets-'.date('YmdHis').'.zip');
if (!is_dir(storage_path('exports'))) {
mkdir(storage_path('exports'), 0775, true);
}
if ($zip->open($zipPath, ZipArchive::CREATE) !== true) {
abort(500, 'Failed to create ZIP archive');
}
$this->addDirectoryToZip($zip, $storagePublic, '');
$zip->close();
return response()->download($zipPath)->deleteFileAfterSend(true);
}
public function import(Request $request): JsonResponse