mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 06:32:40 +01:00
Don't store PDFs
This commit is contained in:
parent
5b78717de4
commit
7756ca7436
@ -795,7 +795,11 @@ class InvoiceController extends BaseController
|
|||||||
|
|
||||||
$file_path = $invoice->service()->getInvoicePdf($contact);
|
$file_path = $invoice->service()->getInvoicePdf($contact);
|
||||||
|
|
||||||
return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache']);
|
return response()->streamDownload(function () use ($file_path) {
|
||||||
|
echo file_get_contents($file_path);
|
||||||
|
}, basename($file_path), ['Cache-Control:' => 'no-cache']);
|
||||||
|
|
||||||
|
//return response()->download(Storage::url($file_path), basename($file_path), ['Cache-Control:' => 'no-cache']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -844,12 +848,15 @@ class InvoiceController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function deliveryNote(ShowInvoiceRequest $request, Invoice $invoice)
|
public function deliveryNote(ShowInvoiceRequest $request, Invoice $invoice)
|
||||||
{
|
{
|
||||||
$file_path = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact);
|
$file = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$file = public_path("storage/{$file_path}");
|
|
||||||
|
|
||||||
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache']);
|
return response()->streamDownload(function () use ($file) {
|
||||||
|
echo file_get_contents($file);
|
||||||
|
}, basename($file), ['Cache-Control:' => 'no-cache']);
|
||||||
|
|
||||||
|
// return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return response(['message' => 'Oops, something went wrong. Make sure you have symlink to storage/ in public/ directory.'], 500);
|
return response(['message' => 'Oops, something went wrong. Make sure you have symlink to storage/ in public/ directory.'], 500);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ use App\Utils\HostedPDF\NinjaPdf;
|
|||||||
use App\Utils\HtmlEngine;
|
use App\Utils\HtmlEngine;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\PhantomJS\Phantom;
|
use App\Utils\PhantomJS\Phantom;
|
||||||
|
use App\Utils\TempFile;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\MakesInvoiceHtml;
|
use App\Utils\Traits\MakesInvoiceHtml;
|
||||||
use App\Utils\Traits\NumberFormatter;
|
use App\Utils\Traits\NumberFormatter;
|
||||||
@ -187,22 +188,23 @@ class CreateEntityPdf implements ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($pdf) {
|
// if ($pdf) {
|
||||||
|
|
||||||
try{
|
// try{
|
||||||
|
|
||||||
Storage::disk($this->disk)->put($file_path, $pdf);
|
// // Storage::disk($this->disk)->put($file_path, $pdf);
|
||||||
|
|
||||||
}
|
// }
|
||||||
catch(\Exception $e)
|
// catch(\Exception $e)
|
||||||
{
|
// {
|
||||||
|
|
||||||
throw new FilePermissionsFailure('Could not write the PDF, permission issues!');
|
// throw new FilePermissionsFailure('Could not write the PDF, permission issues!');
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// // nlog("entity says path = {$file_path}");
|
||||||
|
return TempFile::filePath($pdf, $this->entity->numberFormatter().'.pdf');
|
||||||
|
|
||||||
return $file_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function failed($e)
|
public function failed($e)
|
||||||
|
@ -39,8 +39,6 @@ class UnlinkFile implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
// nlog("deleting");
|
|
||||||
// nlog($this->file_path);
|
|
||||||
Storage::disk($this->disk)->delete($this->file_path);
|
Storage::disk($this->disk)->delete($this->file_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ class GenerateDeliveryNote
|
|||||||
? $this->invoice->design_id
|
? $this->invoice->design_id
|
||||||
: $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id'));
|
: $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id'));
|
||||||
|
|
||||||
$file_path = sprintf('%s%s_delivery_note.pdf', $this->invoice->client->invoice_filepath(), $this->invoice->number);
|
$filename = sprintf('%s_delivery_note.pdf', $this->invoice->number);
|
||||||
|
|
||||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
||||||
return (new Phantom)->generate($this->invoice->invitations->first());
|
return (new Phantom)->generate($this->invoice->invitations->first());
|
||||||
@ -91,8 +91,6 @@ class GenerateDeliveryNote
|
|||||||
->design($template)
|
->design($template)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
// Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775);
|
|
||||||
|
|
||||||
if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
||||||
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
||||||
}
|
}
|
||||||
@ -104,12 +102,8 @@ class GenerateDeliveryNote
|
|||||||
info($maker->getCompiledHTML());
|
info($maker->getCompiledHTML());
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::disk($this->disk)->put($file_path, $pdf);
|
return TempFile::filePath($pdf, $filename);
|
||||||
|
// Storage::disk($this->disk)->put($file_path, $pdf);
|
||||||
/* Copy from remote disk to local when using cloud file storage. */
|
// return $file_path;
|
||||||
if(config('filesystems.default') == 's3')
|
|
||||||
return TempFile::path(Storage::disk($this->disk)->url($file_path));
|
|
||||||
|
|
||||||
return $file_path;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,24 +35,26 @@ class GetInvoicePdf extends AbstractService
|
|||||||
|
|
||||||
$invitation = $this->invoice->invitations->where('client_contact_id', $this->contact->id)->first();
|
$invitation = $this->invoice->invitations->where('client_contact_id', $this->contact->id)->first();
|
||||||
|
|
||||||
$path = $this->invoice->client->invoice_filepath();
|
// $path = $this->invoice->client->invoice_filepath();
|
||||||
|
|
||||||
$file_path = $path.$this->invoice->numberFormatter().'.pdf';
|
// $file_path = $path.$this->invoice->numberFormatter().'.pdf';
|
||||||
|
|
||||||
$disk = config('filesystems.default');
|
// $disk = config('filesystems.default');
|
||||||
|
|
||||||
$file = Storage::disk($disk)->exists($file_path);
|
// $file = Storage::disk($disk)->exists($file_path);
|
||||||
|
|
||||||
if (! $file) {
|
// if (! $file) {
|
||||||
$file_path = CreateEntityPdf::dispatchNow($invitation);
|
return CreateEntityPdf::dispatchNow($invitation);
|
||||||
}
|
// }
|
||||||
|
// return TempFile::filePath($pdf, $file_path);
|
||||||
|
|
||||||
|
// return $file_path;
|
||||||
|
|
||||||
/* Copy from remote disk to local when using cloud file storage. */
|
/* Copy from remote disk to local when using cloud file storage. */
|
||||||
if(config('filesystems.default') == 's3')
|
// if(config('filesystems.default') == 's3')
|
||||||
return TempFile::path(Storage::disk($disk)->url($file_path));
|
// return TempFile::path(Storage::disk($disk)->url($file_path));
|
||||||
|
|
||||||
// return Storage::disk($disk)->url($file_path);
|
// // return Storage::disk($disk)->url($file_path);
|
||||||
return Storage::disk($disk)->path($file_path);
|
// return Storage::disk($disk)->path($file_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user