diff --git a/VERSION.txt b/VERSION.txt index 184f305de134..9a532528f270 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.5.10 \ No newline at end of file +5.5.11 \ No newline at end of file diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 598156ce711a..b157176b027c 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -102,6 +102,17 @@ class NinjaMailerJob implements ShouldQueue $this->nmo->mailable->tag($this->company->company_key); + if($this->nmo->invitation) + { + + $this->nmo + ->mailable + ->withSymfonyMessage(function ($message) { + $message->getHeaders()->addTextHeader('x-invitation', $this->nmo->invitation->key); + }); + + } + //send email try { nlog("trying to send to {$this->nmo->to_user->email} ". now()->toDateTimeString()); diff --git a/app/Jobs/PostMark/ProcessPostmarkWebhook.php b/app/Jobs/PostMark/ProcessPostmarkWebhook.php index 64b590ad0917..0dca3f00e727 100644 --- a/app/Jobs/PostMark/ProcessPostmarkWebhook.php +++ b/app/Jobs/PostMark/ProcessPostmarkWebhook.php @@ -26,6 +26,7 @@ use App\Models\Company; use App\Models\CreditInvitation; use App\Models\InvoiceInvitation; use App\Models\Payment; +use App\Models\PurchaseOrderInvitation; use App\Models\QuoteInvitation; use App\Models\RecurringInvoiceInvitation; use App\Models\SystemLog; @@ -283,6 +284,8 @@ class ProcessPostmarkWebhook implements ShouldQueue return $invitation; elseif($invitation = CreditInvitation::where('message_id', $message_id)->first()) return $invitation; + elseif($invitation = PurchaseOrderInvitation::where('message_id', $message_id)->first()) + return $invitation; else return $invitation; } diff --git a/app/Listeners/Mail/MailSentListener.php b/app/Listeners/Mail/MailSentListener.php index 7d52131bb551..e1a620c0e770 100644 --- a/app/Listeners/Mail/MailSentListener.php +++ b/app/Listeners/Mail/MailSentListener.php @@ -12,9 +12,15 @@ namespace App\Listeners\Mail; use App\Libraries\MultiDB; +use App\Models\CreditInvitation; +use App\Models\InvoiceInvitation; +use App\Models\PurchaseOrderInvitation; +use App\Models\QuoteInvitation; +use App\Models\RecurringInvoiceInvitation; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Events\MessageSent; use Illuminate\Support\Facades\Notification; +use Symfony\Component\Mime\MessageConverter; class MailSentListener implements ShouldQueue { @@ -35,19 +41,50 @@ class MailSentListener implements ShouldQueue */ public function handle(MessageSent $event) { - nlog("mail listener"); - nlog($event); - // if (property_exists($event->message, 'invitation') && $event->message->invitation) { - // MultiDB::setDb($event->sent->invitation->company->db); - // if ($event->message->getHeaders()->get('x-pm-message-id')) { - // $postmark_id = $event->sent->getHeaders()->get('x-pm-message-id')->getValue(); + $message_id = $event->sent->getMessageId(); + + $message = MessageConverter::toEmail($event->sent->getOriginalMessage()); + + $invitation_key = $message->getHeaders()->get('x-invitation')->getValue(); + + if($message_id && $invitation_key) + { + + $invitation = $this->discoverInvitation($invitation_key); + + if(!$invitation) + return; + + $invitation->message_id = $message_id; + $invitation->save(); + } - // // nlog($postmark_id); - // $invitation = $event->sent->invitation; - // $invitation->message_id = $postmark_id; - // $invitation->save(); - // } - // } } + + private function discoverInvitation($key) + { + + $invitation = false; + + foreach (MultiDB::$dbs as $db) + { + + if($invitation = InvoiceInvitation::on($db)->where('key', $key)->first()) + return $invitation; + elseif($invitation = QuoteInvitation::on($db)->where('key', $key)->first()) + return $invitation; + elseif($invitation = RecurringInvoiceInvitation::on($db)->where('key', $key)->first()) + return $invitation; + elseif($invitation = CreditInvitation::on($db)->where('key', $key)->first()) + return $invitation; + elseif($invitation = PurchaseOrderInvitation::on($db)->where('key', $key)->first()) + return $invitation; + + } + + return $invitation; + + } + } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 495ebf41aadd..53bb69bbb4ca 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -271,9 +271,9 @@ class EventServiceProvider extends ServiceProvider ], MessageSending::class => [ ], - // MessageSent::class => [ - // MailSentListener::class, - // ], + MessageSent::class => [ + MailSentListener::class, + ], UserWasCreated::class => [ CreatedUserActivity::class, SendVerificationNotification::class, diff --git a/config/ninja.php b/config/ninja.php index 7db45a89e570..286bbdc05d9f 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.10', - 'app_tag' => '5.5.10', + 'app_version' => '5.5.11', + 'app_tag' => '5.5.11', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),