1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for emails - remove mime types

This commit is contained in:
David Bomba 2022-07-27 14:57:17 +10:00
parent 0d4eb7e37a
commit 9bf603e584
9 changed files with 61 additions and 65 deletions

View File

@ -507,7 +507,7 @@ class CreditController extends BaseController
$ids = request()->input('ids');
if(Ninja::isHosted() && in_array('email', $action) && !auth()->user()->company()->account->account_sms_verified)
if(Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified)
return response(['message' => 'Please verify your account to send emails.'], 400);
$credits = Credit::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();

View File

@ -551,7 +551,7 @@ class InvoiceController extends BaseController
$ids = request()->input('ids');
if(Ninja::isHosted() && in_array('email', $action) && !auth()->user()->company()->account->account_sms_verified)
if(Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified)
return response(['message' => 'Please verify your account to send emails.'], 400);
$invoices = Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();

View File

@ -489,7 +489,7 @@ class PurchaseOrderController extends BaseController
$ids = request()->input('ids');
if(Ninja::isHosted() && in_array('email', $action) && !auth()->user()->company()->account->account_sms_verified)
if(Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified)
return response(['message' => 'Please verify your account to send emails.'], 400);
$purchase_orders = PurchaseOrder::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();

View File

@ -518,7 +518,7 @@ class QuoteController extends BaseController
$ids = request()->input('ids');
if(Ninja::isHosted() && in_array('email', $action) && !auth()->user()->company()->account->account_sms_verified)
if(Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified)
return response(['message' => 'Please verify your account to send emails.'], 400);
$quotes = Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();

View File

@ -129,11 +129,11 @@ class CreditEmailEngine extends BaseEmailEngine
// Storage::url
foreach ($this->credit->documents as $document) {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
foreach ($this->credit->company->documents as $document) {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
}

View File

@ -137,62 +137,13 @@ class PurchaseOrderEmailEngine extends BaseEmailEngine
// Storage::url
foreach ($this->purchase_order->documents as $document) {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
foreach ($this->purchase_order->company->documents as $document) {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
// $line_items = $this->purchase_order->line_items;
// foreach($line_items as $item)
// {
// $expense_ids = [];
// if(property_exists($item, 'expense_id'))
// {
// $expense_ids[] = $item->expense_id;
// }
// if(count($expense_ids) > 0){
// $expenses = Expense::whereIn('id', $this->transformKeys($expense_ids))
// ->where('invoice_documents', 1)
// ->cursor()
// ->each(function ($expense){
// foreach($expense->documents as $document)
// {
// $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
// }
// });
// }
// $task_ids = [];
// if(property_exists($item, 'task_id'))
// {
// $task_ids[] = $item->task_id;
// }
// if(count($task_ids) > 0 && $this->purchase_order->company->purchase_order_task_documents){
// $tasks = Task::whereIn('id', $this->transformKeys($task_ids))
// ->cursor()
// ->each(function ($task){
// foreach($task->documents as $document)
// {
// $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
// }
// });
// }
// }
}
return $this;

View File

@ -128,11 +128,11 @@ class QuoteEmailEngine extends BaseEmailEngine
// Storage::url
foreach ($this->quote->documents as $document) {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
foreach ($this->quote->company->documents as $document) {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
}

View File

@ -11,6 +11,7 @@
namespace App\Mail;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Invoice\CreateUbl;
use App\Models\Account;
use App\Models\Client;
@ -23,6 +24,7 @@ use App\Utils\TemplateEngine;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
class TemplateEmail extends Mailable
{
@ -120,15 +122,36 @@ class TemplateEmail extends Mailable
});
/*In the hosted platform we need to slow things down a little for Storage to catch up.*/
if (Ninja::isHosted()) {
sleep(1);
if(Ninja::isHosted()){
$path = false;
if($this->invitation->invoice)
$path = $this->client->invoice_filepath($this->invitation).$this->invitation->invoice->numberFormatter().'.pdf';
elseif($this->invitation->quote)
$path = $this->client->quote_filepath($this->invitation).$this->invitation->quote->numberFormatter().'.pdf';
elseif($this->invitation->credit)
$path = $this->client->credit_filepath($this->invitation).$this->invitation->credit->numberFormatter().'.pdf';
if($path && !Storage::disk(config('filesystems.default'))->exists($path)){
sleep(2);
if(!Storage::disk(config('filesystems.default'))->exists($path)) {
CreateEntityPdf::dispatchSync($this->invitation);
sleep(2);
}
}
}
foreach ($this->build_email->getAttachments() as $file) {
if (is_string($file)) {
$this->attach($file);
} elseif (is_array($file)) {
$this->attach($file['path'], ['as' => $file['name'], 'mime' => $file['mime']]);
$this->attach($file['path'], ['as' => $file['name'], 'mime' => null]);
}
}

View File

@ -12,6 +12,7 @@
namespace App\Mail;
use App\Jobs\Invoice\CreateUbl;
use App\Jobs\Vendor\CreatePurchaseOrderPdf;
use App\Models\Account;
use App\Models\Client;
use App\Models\User;
@ -24,6 +25,7 @@ use App\Utils\VendorHtmlEngine;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
class VendorTemplateEmail extends Mailable
{
@ -114,15 +116,35 @@ class VendorTemplateEmail extends Mailable
});
/*In the hosted platform we need to slow things down a little for Storage to catch up.*/
if (Ninja::isHosted()) {
sleep(1);
// if (Ninja::isHosted()) {
// sleep(1);
// }
if(Ninja::isHosted()){
$path = false;
if($this->invitation->purchase_order)
$path = $this->vendor->purchase_order_filepath($this->invitation).$this->invitation->purchase_order->numberFormatter().'.pdf';
if($path && !Storage::disk(config('filesystems.default'))->exists($path)){
sleep(2);
if(!Storage::disk(config('filesystems.default'))->exists($path)) {
CreatePurchaseOrderPdf::dispatchSync($this->invitation);
sleep(2);
}
}
}
foreach ($this->build_email->getAttachments() as $file) {
if (is_string($file)) {
$this->attach($file);
} elseif (is_array($file)) {
$this->attach($file['path'], ['as' => $file['name'], 'mime' => $file['mime']]);
$this->attach($file['path'], ['as' => $file['name'], 'mime' => null]);
}
}