From 026f9b6a1de07ffe3f65e9df1d0abfe4c74e33c4 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Fri, 31 Jan 2020 20:20:43 -0600 Subject: [PATCH] updated moon mailer to record mail sent when it's sent to eve api --- app/Console/Commands/Moons/MoonMailer.php | 13 ------------- app/Jobs/ProcessSendEveMailJob.php | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/Moons/MoonMailer.php b/app/Console/Commands/Moons/MoonMailer.php index d19a17524..2c34ca35d 100644 --- a/app/Console/Commands/Moons/MoonMailer.php +++ b/app/Console/Commands/Moons/MoonMailer.php @@ -111,9 +111,6 @@ class MoonMailerCommand extends Command //Increment the delay for the mail to not hit rate limits $delay += 30; - //After the mail is dispatched, saved the sent mail record - $this->SaveSentRecord($mail->sender, $mail->subject, $mail->body, $mail->recipient, $mail->recipient_type); - //Update the moon as not being paid for the next month? foreach($rentals as $rental) { $previous = new Carbon($rental->Paid_Until); @@ -138,16 +135,6 @@ class MoonMailerCommand extends Command ]); } - private function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) { - $sentmail = new SentMail; - $sentmail->sender = $sender; - $sentmail->subject = $subject; - $sentmail->body = $body; - $sentmail->recipient = $recipient; - $sentmail->recipient_type = $recipientType; - $sentmail->save(); - } - private function GetMoonList($moons) { //Declare the variable to be used as a global part of the function $list = array(); diff --git a/app/Jobs/ProcessSendEveMailJob.php b/app/Jobs/ProcessSendEveMailJob.php index 162441c39..f58c2d6f0 100644 --- a/app/Jobs/ProcessSendEveMailJob.php +++ b/app/Jobs/ProcessSendEveMailJob.php @@ -19,6 +19,7 @@ use App\Models\Esi\EsiScope; use App\Models\Esi\EsiToken; use App\Models\Mail\EveMail; use App\Models\Jobs\JobStatus; +use App\Models\Mail\SentMail; class ProcessSendEveMailJob implements ShouldQueue { @@ -38,6 +39,7 @@ class ProcessSendEveMailJob implements ShouldQueue */ public $retries = 3; + private $sender; private $body; private $recipient; private $recipient_type; @@ -53,6 +55,7 @@ class ProcessSendEveMailJob implements ShouldQueue $this->recipient = $mail->recipient; $this->recipient_type = $mail->recipient_type; $this->subject = $mail->subject; + $this->sender = $mail->sender; $this->connection = 'redis'; } @@ -90,12 +93,14 @@ class ProcessSendEveMailJob implements ShouldQueue ]], 'subject' => $this->subject, ])->invoke('post', '/characters/{character_id}/mail/', [ - 'character_id'=> $config['primary'], + 'character_id'=> $this->sender, ]); } catch(RequestFailedException $e) { Log::warning($e); return null; } + + $this->SaveSentRecord($this->sender, $this->subject, $this->body, $this->recipient, $this->recipient_type); $this->delete(); } @@ -110,4 +115,14 @@ class ProcessSendEveMailJob implements ShouldQueue { Log::critical($exception); } + + private function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) { + $sentmail = new SentMail; + $sentmail->sender = $sender; + $sentmail->subject = $subject; + $sentmail->body = $body; + $sentmail->recipient = $recipient; + $sentmail->recipient_type = $recipientType; + $sentmail->save(); + } }