diff --git a/app/Http/Controllers/ClientPortal/DocumentController.php b/app/Http/Controllers/ClientPortal/DocumentController.php index f24615f13618..de2fa66c7e20 100644 --- a/app/Http/Controllers/ClientPortal/DocumentController.php +++ b/app/Http/Controllers/ClientPortal/DocumentController.php @@ -22,8 +22,6 @@ use App\Utils\Traits\MakesHash; use Illuminate\Contracts\View\Factory; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; -use ZipStream\Option\Archive; -use ZipStream\ZipStream; class DocumentController extends Controller { @@ -71,25 +69,34 @@ class DocumentController extends Controller public function downloadMultiple(DownloadMultipleDocumentsRequest $request) { $documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) - ->where('company_id', auth()->guard('contact')->user()->company->id) + ->where('company_id', auth()->guard('contact')->user()->company_id) ->get(); - $documents->map(function ($document) { - if (auth()->guard('contact')->user()->client->id != $document->documentable->id) { - abort(401, 'Permission denied'); + $zipFile = new \PhpZip\ZipFile(); + + try{ + + foreach ($documents as $document) { + $zipFile->addFile(TempFile::path($document->filePath()), $document->name); } - }); - $options = new Archive(); + $filename = now() . '-documents.zip'; + $filepath = sys_get_temp_dir() . '/' . $filename; - $options->setSendHttpHeaders(true); + $zipFile->saveAsFile($filepath) // save the archive to a file + ->close(); // close archive + + return response()->download($filepath, $filename)->deleteFileAfterSend(true); - $zip = new ZipStream(now() . '-documents.zip', $options); - - foreach ($documents as $document) { - $zip->addFileFromPath(basename($document->diskPath()), TempFile::path($document->filePath())); + } + catch(\PhpZip\Exception\ZipException $e){ + // handle exception + } + finally{ + $zipFile->close(); } - $zip->finish(); } + + } diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 9a38d07f0ee5..6dad4a19ab79 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -28,8 +28,6 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; -use ZipStream\Option\Archive; -use ZipStream\ZipStream; use Illuminate\Http\Request; class InvoiceController extends Controller @@ -198,9 +196,6 @@ class InvoiceController extends Controller * @param array $ids * * @return void - * @throws \ZipStream\Exception\FileNotFoundException - * @throws \ZipStream\Exception\FileNotReadableException - * @throws \ZipStream\Exception\OverflowException */ private function downloadInvoicePDF(array $ids) { @@ -230,22 +225,6 @@ class InvoiceController extends Controller return $this->buildZip($invoices); - // // enable output of HTTP headers - // $options = new Archive(); - // $options->setSendHttpHeaders(true); - - // // create a new zipstream object - // $zip = new ZipStream(date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.invoices')).'.zip', $options); - - // foreach ($invoices as $invoice) { - - // #add it to the zip - // $zip->addFile(basename($invoice->pdf_file_path()), file_get_contents($invoice->pdf_file_path(null, 'url', true))); - - // } - - // // finish the zip stream - // $zip->finish(); } diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index fec64c9b411e..378fd8aa0b28 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -28,8 +28,6 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; use Symfony\Component\HttpFoundation\BinaryFileResponse; -use ZipStream\Option\Archive; -use ZipStream\ZipStream; use Illuminate\Http\Request; use Illuminate\Support\Carbon; @@ -140,21 +138,38 @@ class QuoteController extends Controller }, basename($file), ['Content-Type' => 'application/pdf']); } - // enable output of HTTP headers - $options = new Archive(); - $options->setSendHttpHeaders(true); + return $this->buildZip($quotes); - // create a new zipstream object - $zip = new ZipStream(date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.invoices')).'.zip', $options); + } - foreach ($quotes as $quote) { - $zip->addFile(basename($quote->pdf_file_path()), file_get_contents($quote->pdf_file_path(null, 'url', true))); + private function buildZip($quotes) + { + // create new archive + $zipFile = new \PhpZip\ZipFile(); + try{ + + foreach ($quotes as $quote) { + + #add it to the zip + $zipFile->addFromString(basename($quote->pdf_file_path()), file_get_contents($quote->pdf_file_path(null, 'url', true))); + + } + + $filename = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.quotes')).'.zip'; + $filepath = sys_get_temp_dir() . '/' . $filename; + + $zipFile->saveAsFile($filepath) // save the archive to a file + ->close(); // close archive + + return response()->download($filepath, $filename)->deleteFileAfterSend(true); - // $zip->addFileFromPath(basename($quote->pdf_file_path()), TempFile::path($quote->pdf_file_path())); } - - // finish the zip stream - $zip->finish(); + catch(\PhpZip\Exception\ZipException $e){ + // handle exception + } + finally{ + $zipFile->close(); + } } protected function approve(array $ids, $process = false) diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index d8917c494052..4e6fcc528b7a 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -33,8 +33,6 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Storage; -use ZipStream\Option\Archive; -use ZipStream\ZipStream; use Illuminate\Support\Facades\App; class CompanyExport implements ShouldQueue diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 5150740c8e84..ffc88ff8325a 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -74,8 +74,6 @@ use Illuminate\Support\Str; use JsonMachine\JsonDecoder\ExtJsonDecoder; use JsonMachine\JsonMachine; use ZipArchive; -use ZipStream\Option\Archive; -use ZipStream\ZipStream; use function GuzzleHttp\json_encode; diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index 0dff22aa35c8..18fa2f0b95d3 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -25,8 +25,6 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; -use ZipStream\Option\Archive; -use ZipStream\ZipStream; use ZipArchive; class ZipInvoices implements ShouldQueue diff --git a/composer.json b/composer.json index fb87b944e72f..90cbe1790d12 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,6 @@ "league/fractal": "^0.17.0", "league/omnipay": "^3.1", "livewire/livewire": "^2.6", - "maennchen/zipstream-php": "^1.2", "mollie/mollie-api-php": "^2.36", "nelexa/zip": "^4.0", "nwidart/laravel-modules": "^8.0", diff --git a/resources/js/clients/shared/multiple-downloads.js b/resources/js/clients/shared/multiple-downloads.js index d3662fff8377..7dd69e860d64 100644 --- a/resources/js/clients/shared/multiple-downloads.js +++ b/resources/js/clients/shared/multiple-downloads.js @@ -24,6 +24,7 @@ const appendToElement = (parent, value) => { _temp.hidden = true; _parent.append(_temp); + }; window.appendToElement = appendToElement;