From 3e61408ba56e547531fb84858b09386d5170df0e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 22 Jan 2023 17:46:56 +1100 Subject: [PATCH] Fixes for observers --- VERSION.txt | 2 +- app/Observers/ClientContactObserver.php | 6 +++--- app/Observers/VendorContactObserver.php | 2 +- app/Services/Email/EmailDefaults.php | 8 +++++++- app/Services/Email/EmailMailer.php | 16 ++++------------ config/ninja.php | 4 ++-- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 989c3a1b34..e17a8ff63c 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.5.58 \ No newline at end of file +5.5.59 \ No newline at end of file diff --git a/app/Observers/ClientContactObserver.php b/app/Observers/ClientContactObserver.php index 2e98506958..54c49fff1d 100644 --- a/app/Observers/ClientContactObserver.php +++ b/app/Observers/ClientContactObserver.php @@ -57,7 +57,7 @@ class ClientContactObserver //ensure entity state is preserved - InvoiceInvitation::withTrashed()->where('client_contact_id', 1)->cursor()->each(function ($invite){ + InvoiceInvitation::withTrashed()->where('client_contact_id', $client_contact_id)->cursor()->each(function ($invite){ if($invite->invoice()->doesnthave('invitations')) $invite->invoice->service()->createInvitations(); @@ -65,14 +65,14 @@ class ClientContactObserver }); - QuoteInvitation::withTrashed()->where('client_contact_id', 1)->cursor()->each(function ($invite){ + QuoteInvitation::withTrashed()->where('client_contact_id', $client_contact_id)->cursor()->each(function ($invite){ if($invite->invoice()->doesnthave('invitations')) $invite->quote->service()->createInvitations(); }); - RecurringInvoiceInvitation::withTrashed()->where('client_contact_id', 1)->cursor()->each(function ($invite){ + RecurringInvoiceInvitation::withTrashed()->where('client_contact_id', $client_contact_id)->cursor()->each(function ($invite){ if($invite->recurring_invoice()->doesnthave('invitations')) $invite->quote->service()->createInvitations(); diff --git a/app/Observers/VendorContactObserver.php b/app/Observers/VendorContactObserver.php index 41e9833fa6..13061f3fcb 100644 --- a/app/Observers/VendorContactObserver.php +++ b/app/Observers/VendorContactObserver.php @@ -51,7 +51,7 @@ class VendorContactObserver $vendorContact->purchase_order_invitations()->delete(); - PurchaseOrderInvitation::withTrashed()->where('vendor_contact_id', 1)->cursor()->each(function ($invite){ + PurchaseOrderInvitation::withTrashed()->where('vendor_contact_id', $vendor_contact_id)->cursor()->each(function ($invite){ if($invite->purchase_order()->doesnthave('invitations')) $invite->purchase_order->service()->createInvitations(); diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index 3648a63dd3..5080336008 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -135,7 +135,13 @@ class EmailDefaults * Sets the FROM address */ private function setFrom(): self - { + { + + if(Ninja::isHosted() && $this->email_object->settings->email_sending_method == 'default'){ + $this->email_object->from = new Address(config('mail.from.address'), $this->email_service->company->owner()->name()); + return $this; + } + if($this->email_object->from) return $this; diff --git a/app/Services/Email/EmailMailer.php b/app/Services/Email/EmailMailer.php index a5be905327..cf6d4a7504 100644 --- a/app/Services/Email/EmailMailer.php +++ b/app/Services/Email/EmailMailer.php @@ -13,36 +13,28 @@ namespace App\Services\Email; use App\DataMapper\Analytics\EmailFailure; use App\DataMapper\Analytics\EmailSuccess; -use App\DataMapper\EmailTemplateDefaults; use App\Events\Invoice\InvoiceWasEmailedAndFailed; use App\Events\Payment\PaymentWasEmailedAndFailed; use App\Jobs\Util\SystemLogger; use App\Libraries\Google\Google; use App\Libraries\MultiDB; -use App\Models\Account; use App\Models\ClientContact; -use App\Models\Company; use App\Models\InvoiceInvitation; use App\Models\Payment; use App\Models\SystemLog; use App\Models\User; -use App\Services\Email\EmailObject; use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use GuzzleHttp\Exception\ClientException; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Mail\Attachment; use Illuminate\Mail\Mailable; -use Illuminate\Mail\Mailables\Address; -use Illuminate\Mail\Mailer; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Mail; -use League\CommonMark\CommonMarkConverter; use Turbo124\Beacon\Facades\LightLogs; class EmailMailer implements ShouldQueue @@ -311,7 +303,7 @@ class EmailMailer implements ShouldQueue $user = $this->resolveSendingUser(); - $this->mailable + $this->email_mailable ->from($user->email, $user->name()); } @@ -331,7 +323,7 @@ class EmailMailer implements ShouldQueue $user = $this->resolveSendingUser(); - $this->mailable + $this->email_mailable ->from($user->email, $user->name()); } @@ -362,7 +354,7 @@ class EmailMailer implements ShouldQueue } - $this->mailable + $this->email_mailable ->from($user->email, $user->name()) ->withSymfonyMessage(function ($message) use($token) { $message->getHeaders()->addTextHeader('gmailtoken', $token); @@ -427,7 +419,7 @@ class EmailMailer implements ShouldQueue return $this->setMailDriver(); } - $this->mailable + $this->email_mailable ->from($user->email, $user->name()) ->withSymfonyMessage(function ($message) use($token) { $message->getHeaders()->addTextHeader('gmailtoken', $token); diff --git a/config/ninja.php b/config/ninja.php index 26966fd9ae..cd0e594e5c 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.5.58', - 'app_tag' => '5.5.58', + 'app_version' => '5.5.59', + 'app_tag' => '5.5.59', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),