From bf4768bd7bf507ac1394446ea2325c545452f50a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Oct 2021 19:33:48 +1100 Subject: [PATCH 1/4] Minor fixes for designs --- app/Http/Requests/Design/StoreDesignRequest.php | 4 ++++ app/Http/Requests/Design/UpdateDesignRequest.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/Http/Requests/Design/StoreDesignRequest.php b/app/Http/Requests/Design/StoreDesignRequest.php index 2186853cff50..c5bbd093bbcc 100644 --- a/app/Http/Requests/Design/StoreDesignRequest.php +++ b/app/Http/Requests/Design/StoreDesignRequest.php @@ -58,6 +58,10 @@ class StoreDesignRequest extends Request $input['design']['header'] = ''; } + if (! array_key_exists('body', $input['design']) || is_null($input['design']['body'])) { + $input['design']['body'] = ''; + } + $this->replace($input); } } diff --git a/app/Http/Requests/Design/UpdateDesignRequest.php b/app/Http/Requests/Design/UpdateDesignRequest.php index fa260fc4ea13..e971c695aaa2 100644 --- a/app/Http/Requests/Design/UpdateDesignRequest.php +++ b/app/Http/Requests/Design/UpdateDesignRequest.php @@ -57,6 +57,10 @@ class UpdateDesignRequest extends Request $input['design']['header'] = ''; } + if (! array_key_exists('body', $input['design']) || is_null($input['design']['body'])) { + $input['design']['body'] = ''; + } + $this->replace($input); } } From 9cf26601f94f1c4a842f9e78514f168d00db8c4c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Oct 2021 20:25:14 +1100 Subject: [PATCH 2/4] Minor fixes --- app/Mail/SupportMessageSent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Mail/SupportMessageSent.php b/app/Mail/SupportMessageSent.php index 9cf431f99406..d0cc8e5de96b 100644 --- a/app/Mail/SupportMessageSent.php +++ b/app/Mail/SupportMessageSent.php @@ -64,12 +64,12 @@ class SupportMessageSent extends Mailable $db = str_replace("db-ninja-", "", $company->db); $is_large = $company->is_large ? "L" : "S"; $platform = array_key_exists('platform', $this->data) ? $this->data['platform'] : "U"; - $migrated = strlen($company->company_key) == 32 ? "M" : "T"; + $migrated = strlen($company->company_key) == 32 ? "M" : ""; if(Ninja::isHosted()) $subject = "{$priority}Hosted-{$db}-{$is_large}{$platform}{$migrated} :: {$plan} :: ".date('M jS, g:ia'); else - $subject = "{$priority}Self Hosted :: {$plan}{$platform} :: ".date('M jS, g:ia'); + $subject = "{$priority}Self Hosted :: {$plan} :: {$platform} :: ".date('M jS, g:ia'); return $this->from(config('mail.from.address'), $user->present()->name()) ->replyTo($user->email, $user->present()->name()) From 0b84c86aedb98a84db02d6b07d0f39b1329dbf94 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Oct 2021 20:37:57 +1100 Subject: [PATCH 3/4] Add back eager loads --- app/Models/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index 5b1216e1178e..aaf56737c465 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -84,9 +84,9 @@ class Client extends BaseModel implements HasLocalePreference ]; protected $with = [ - // 'gateway_tokens', - // 'documents', - // 'contacts.company', + 'gateway_tokens', + 'documents', + 'contacts.company', // 'currency', // 'primary_contact', // 'country', From 21d08d2d7e28d6d8b2e103d397bcaaeaa9b60eb6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Oct 2021 20:56:05 +1100 Subject: [PATCH 4/4] Trigger model created event manually after model calculations have been performed --- app/Observers/InvoiceObserver.php | 1 - app/Repositories/BaseRepository.php | 24 ++++++++++++++++----- app/Services/Credit/CreditService.php | 2 +- app/Services/Invoice/InvoiceService.php | 2 +- app/Services/Quote/QuoteService.php | 2 +- app/Services/Recurring/RecurringService.php | 2 +- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index 6fdb6ee82907..f58e1018f26a 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -34,7 +34,6 @@ class InvoiceObserver ->where('event_id', Webhook::EVENT_CREATE_INVOICE) ->exists(); - if ($subscriptions) { $invoice->load('client'); diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 9f0eece3a67f..b4e11a655cdf 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -29,8 +29,9 @@ class BaseRepository use MakesHash; use SavesDocuments; - public $import_mode = false; + public bool $import_mode = false; + private bool $new_model = false; /** * @param $entity * @param $type @@ -207,9 +208,9 @@ class BaseRepository $model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4; if(!$model->id) - $model->save(); - else - $model->saveQuietly(); + $this->new_model = true; + + $model->saveQuietly(); /* Model now persisted, now lets do some child tasks */ @@ -323,6 +324,9 @@ class BaseRepository //links tasks and expenses back to the invoice. $model->service()->linkEntities()->save(); + if($this->new_model) + event('eloquent.created: App\Models\Invoice', $model); + } if ($model instanceof Credit) { @@ -331,7 +335,10 @@ class BaseRepository if (! $model->design_id) $model->design_id = $this->decodePrimaryKey($client->getSetting('credit_design_id')); - + + + if($this->new_model) + event('eloquent.created: App\Models\Credit', $model); } if ($model instanceof Quote) { @@ -341,6 +348,10 @@ class BaseRepository $model = $model->calc()->getQuote(); + + if($this->new_model) + event('eloquent.created: App\Models\Quote', $model); + } if ($model instanceof RecurringInvoice) { @@ -350,6 +361,9 @@ class BaseRepository $model = $model->calc()->getRecurringInvoice(); + + if($this->new_model) + event('eloquent.created: App\Models\RecurringInvoice', $model); } $model->save(); diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 7dc17e62424f..eea08769e1fa 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -155,7 +155,7 @@ class CreditService */ public function save() : ?Credit { - $this->credit->save(); + $this->credit->saveQuietly(); return $this->credit; } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index b4f3e4312463..55754f834210 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -490,7 +490,7 @@ class InvoiceService */ public function save() :?Invoice { - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 6d1fd5e340fb..b8865b8d2abf 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -202,7 +202,7 @@ class QuoteService */ public function save() : ?Quote { - $this->quote->save(); + $this->quote->saveQuietly(); return $this->quote; } diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php index 0012f556d10e..6bd522120edd 100644 --- a/app/Services/Recurring/RecurringService.php +++ b/app/Services/Recurring/RecurringService.php @@ -105,7 +105,7 @@ class RecurringService public function save() { - $this->recurring_entity->save(); + $this->recurring_entity->saveQuietly(); return $this->recurring_entity; }