mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Remove illegal characters from pdf file names
This commit is contained in:
parent
f10f7dca42
commit
f52fb31ced
@ -142,11 +142,11 @@ class ActivityController extends BaseController
|
|||||||
$pdf = $this->makePdf(null, null, $backup->html_backup);
|
$pdf = $this->makePdf(null, null, $backup->html_backup);
|
||||||
|
|
||||||
if (isset($activity->invoice_id)) {
|
if (isset($activity->invoice_id)) {
|
||||||
$filename = $activity->invoice->number.'.pdf';
|
$filename = $activity->invoice->numberFormatter().'.pdf';
|
||||||
} elseif (isset($activity->quote_id)) {
|
} elseif (isset($activity->quote_id)) {
|
||||||
$filename = $activity->quote->number.'.pdf';
|
$filename = $activity->quote->numberFormatter().'.pdf';
|
||||||
} elseif (isset($activity->credit_id)) {
|
} elseif (isset($activity->credit_id)) {
|
||||||
$filename = $activity->credit->number.'.pdf';
|
$filename = $activity->credit->numberFormatter().'.pdf';
|
||||||
} else {
|
} else {
|
||||||
$filename = 'backup.pdf';
|
$filename = 'backup.pdf';
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class CreateEntityPdf implements ShouldQueue
|
|||||||
$entity_design_id = 'invoice_design_id';
|
$entity_design_id = 'invoice_design_id';
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_path = $path.$this->entity->number.'.pdf';
|
$file_path = $path.$this->entity->numberFormatter().'.pdf';
|
||||||
|
|
||||||
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
|
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
|
||||||
|
|
||||||
|
@ -186,6 +186,15 @@ class BaseModel extends Model
|
|||||||
*/
|
*/
|
||||||
public function getFileName($extension = 'pdf')
|
public function getFileName($extension = 'pdf')
|
||||||
{
|
{
|
||||||
return $this->number.'.'.$extension;
|
return $this->numberFormatter().'.'.$extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function numberFormatter()
|
||||||
|
{
|
||||||
|
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $this->number);
|
||||||
|
// Remove any runs of periods (thanks falstro!)
|
||||||
|
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
||||||
|
|
||||||
|
return $formatted_number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,9 +248,9 @@ class Credit extends BaseModel
|
|||||||
|
|
||||||
public function pdf_file_path($invitation = null)
|
public function pdf_file_path($invitation = null)
|
||||||
{
|
{
|
||||||
$storage_path = Storage::url($this->client->credit_filepath().$this->number.'.pdf');
|
$storage_path = Storage::url($this->client->credit_filepath().$this->numberFormatter().'.pdf');
|
||||||
|
|
||||||
if (Storage::exists($this->client->credit_filepath().$this->number.'.pdf')) {
|
if (Storage::exists($this->client->credit_filepath().$this->numberFormatter().'.pdf')) {
|
||||||
return $storage_path;
|
return $storage_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,9 +126,9 @@ class CreditInvitation extends BaseModel
|
|||||||
|
|
||||||
public function pdf_file_path()
|
public function pdf_file_path()
|
||||||
{
|
{
|
||||||
$storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->number.'.pdf');
|
$storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->numberFormatter().'.pdf');
|
||||||
|
|
||||||
if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->number.'.pdf')) {
|
if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->numberFormatter().'.pdf')) {
|
||||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||||
CreateEntityPdf::dispatchNow($this);
|
CreateEntityPdf::dispatchNow($this);
|
||||||
}
|
}
|
||||||
|
@ -388,9 +388,9 @@ class Invoice extends BaseModel
|
|||||||
$invitation = $this->invitations->first();
|
$invitation = $this->invitations->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
$storage_path = Storage::$type($this->client->invoice_filepath().$this->number.'.pdf');
|
$storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf');
|
||||||
|
|
||||||
if (! Storage::exists($this->client->invoice_filepath().$this->number.'.pdf')) {
|
if (! Storage::exists($this->client->invoice_filepath().$this->numberFormatter().'.pdf')) {
|
||||||
event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars()));
|
event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||||
CreateEntityPdf::dispatchNow($invitation);
|
CreateEntityPdf::dispatchNow($invitation);
|
||||||
}
|
}
|
||||||
|
@ -140,9 +140,9 @@ class InvoiceInvitation extends BaseModel
|
|||||||
|
|
||||||
public function pdf_file_path()
|
public function pdf_file_path()
|
||||||
{
|
{
|
||||||
$storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->number.'.pdf');
|
$storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf');
|
||||||
|
|
||||||
if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->number.'.pdf')) {
|
if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf')) {
|
||||||
event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars()));
|
event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars()));
|
||||||
CreateEntityPdf::dispatchNow($this);
|
CreateEntityPdf::dispatchNow($this);
|
||||||
}
|
}
|
||||||
|
@ -208,11 +208,11 @@ class Quote extends BaseModel
|
|||||||
$invitation = $this->invitations->first();
|
$invitation = $this->invitations->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
$storage_path = Storage::$type($this->client->quote_filepath().$this->number.'.pdf');
|
$storage_path = Storage::$type($this->client->quote_filepath().$this->numberFormatter().'.pdf');
|
||||||
|
|
||||||
nlog($storage_path);
|
nlog($storage_path);
|
||||||
|
|
||||||
if (! Storage::exists($this->client->quote_filepath().$this->number.'.pdf')) {
|
if (! Storage::exists($this->client->quote_filepath().$this->numberFormatter().'.pdf')) {
|
||||||
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
|
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||||
CreateEntityPdf::dispatchNow($invitation);
|
CreateEntityPdf::dispatchNow($invitation);
|
||||||
}
|
}
|
||||||
|
@ -130,9 +130,9 @@ class QuoteInvitation extends BaseModel
|
|||||||
|
|
||||||
public function pdf_file_path()
|
public function pdf_file_path()
|
||||||
{
|
{
|
||||||
$storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->number.'.pdf');
|
$storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf');
|
||||||
|
|
||||||
if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->number.'.pdf')) {
|
if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf')) {
|
||||||
event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars()));
|
event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars()));
|
||||||
CreateEntityPdf::dispatchNow($this);
|
CreateEntityPdf::dispatchNow($this);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class InvoiceObserver
|
|||||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
|
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath() . $invoice->number.'.pdf');
|
// UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath() . $invoice->numberFormatter().'.pdf');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ class CreditService
|
|||||||
|
|
||||||
public function deletePdf()
|
public function deletePdf()
|
||||||
{
|
{
|
||||||
UnlinkFile::dispatchNow(config('filesystems.default'), $this->credit->client->credit_filepath() . $this->credit->number.'.pdf');
|
UnlinkFile::dispatchNow(config('filesystems.default'), $this->credit->client->credit_filepath() . $this->credit->numberFormatter().'.pdf');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class GetCreditPdf extends AbstractService
|
|||||||
|
|
||||||
$path = $this->credit->client->credit_filepath();
|
$path = $this->credit->client->credit_filepath();
|
||||||
|
|
||||||
$file_path = $path.$this->credit->number.'.pdf';
|
$file_path = $path.$this->credit->numberFormatter().'.pdf';
|
||||||
|
|
||||||
$disk = config('filesystems.default');
|
$disk = config('filesystems.default');
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class GetInvoicePdf extends AbstractService
|
|||||||
|
|
||||||
$path = $this->invoice->client->invoice_filepath();
|
$path = $this->invoice->client->invoice_filepath();
|
||||||
|
|
||||||
$file_path = $path.$this->invoice->number.'.pdf';
|
$file_path = $path.$this->invoice->numberFormatter().'.pdf';
|
||||||
|
|
||||||
$disk = config('filesystems.default');
|
$disk = config('filesystems.default');
|
||||||
|
|
||||||
|
@ -274,8 +274,8 @@ class InvoiceService
|
|||||||
|
|
||||||
public function deletePdf()
|
public function deletePdf()
|
||||||
{
|
{
|
||||||
//UnlinkFile::dispatchNow(config('filesystems.default'), $this->invoice->client->invoice_filepath() . $this->invoice->number.'.pdf');
|
//UnlinkFile::dispatchNow(config('filesystems.default'), $this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf');
|
||||||
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath() . $this->invoice->number.'.pdf');
|
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class GetQuotePdf extends AbstractService
|
|||||||
|
|
||||||
$path = $this->quote->client->quote_filepath();
|
$path = $this->quote->client->quote_filepath();
|
||||||
|
|
||||||
$file_path = $path.$this->quote->number.'.pdf';
|
$file_path = $path.$this->quote->numberFormatter().'.pdf';
|
||||||
|
|
||||||
$disk = config('filesystems.default');
|
$disk = config('filesystems.default');
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ class QuoteService
|
|||||||
|
|
||||||
public function deletePdf()
|
public function deletePdf()
|
||||||
{
|
{
|
||||||
UnlinkFile::dispatchNow(config('filesystems.default'), $this->quote->client->quote_filepath() . $this->quote->number.'.pdf');
|
UnlinkFile::dispatchNow(config('filesystems.default'), $this->quote->client->quote_filepath() . $this->quote->numberFormatter().'.pdf');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ class RecurringService
|
|||||||
|
|
||||||
public function deletePdf()
|
public function deletePdf()
|
||||||
{
|
{
|
||||||
UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath() . $this->recurring_entity->number.'.pdf');
|
UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath() . $this->recurring_entity->numberFormatter().'.pdf');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ class Phantom
|
|||||||
$path = $entity_obj->client->recurring_invoice_filepath();
|
$path = $entity_obj->client->recurring_invoice_filepath();
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_path = $path.$entity_obj->number.'.pdf';
|
$file_path = $path.$entity_obj->numberFormatter().'.pdf';
|
||||||
|
|
||||||
$url = config('ninja.app_url').'/phantom/'.$entity.'/'.$invitation->key.'?phantomjs_secret='.config('ninja.phantomjs_secret');
|
$url = config('ninja.app_url').'/phantom/'.$entity.'/'.$invitation->key.'?phantomjs_secret='.config('ninja.phantomjs_secret');
|
||||||
info($url);
|
info($url);
|
||||||
@ -91,8 +91,8 @@ class Phantom
|
|||||||
|
|
||||||
$instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf);
|
$instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf);
|
||||||
|
|
||||||
nlog($instance);
|
// nlog($instance);
|
||||||
nlog($file_path);
|
// nlog($file_path);
|
||||||
return $file_path;
|
return $file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user