diff --git a/app/Jobs/ProcessSendEveMailJob.php b/app/Jobs/ProcessSendEveMailJob.php new file mode 100644 index 000000000..5c8f6ff41 --- /dev/null +++ b/app/Jobs/ProcessSendEveMailJob.php @@ -0,0 +1,120 @@ +body = $mail->body; + $this->recipient = $mail->recipient; + $this->recipient_type = $mail->recipient_type; + $this->subject = $mail->subject; + + $this->connection = 'redis'; + } + + /** + * Execute the job. + * Utilized by using SendEveMailJob::dispatch($mail); + * The model is passed into the dispatch function, then added to the queue + * for processing. + * + * @return void + */ + public function handle() + { + //Get the esi configuration + $config = config('esi'); + + //Retrieve the token for main character to send mails from + $token = EsiToken::where(['character_id'=> 92626011])->first(); + + //Create the ESI authentication container + $config = config('esi'); + $authentication = new EsiAuthentication([ + 'client_id' => $config['client_id'], + 'secret' => $config['secret'], + 'refresh_token' => $token->refresh_token, + ]); + + //Setup the Eseye class + $esi = new Eseye($authentication); + + //Attemp to send the mail + try { + $esi->setBody([ + 'approved_cost' => 100, + 'body' => $this->body, + 'recipients' => [[ + 'recipient_id' => (int)92626011, + 'recipient_type' => $this->recipient_type, + ]], + 'subject' => $this->subject, + ])->invoke('post', '/characters/{character_id}/mail/', [ + 'character_id'=> 92626011, + ]); + } catch(RequestFailedException $e) { + Log::warning($e); + return null; + } + + $this->delete(); + } + + /** + * The job failed to process. + * + * @param Exception $exception + * @return void + */ + public function failed($exception) + { + Log::critical($exception); + } +} diff --git a/app/Jobs/SendEveMailJob.php b/app/Jobs/SendEveMailJob.php index 3c95998d3..606122386 100644 --- a/app/Jobs/SendEveMailJob.php +++ b/app/Jobs/SendEveMailJob.php @@ -73,14 +73,14 @@ class SendEveMailJob implements ShouldQueue $config = config('esi'); //Retrieve the token for main character to send mails from - $token = EsiToken::where(['character_id'=> $config['primary']])->get(); + $token = EsiToken::where(['character_id'=> 92626011])->first(); //Create the ESI authentication container $config = config('esi'); $authentication = new EsiAuthentication([ 'client_id' => $config['client_id'], 'secret' => $config['secret'], - 'refresh_token' => $token[0]->refresh_token, + 'refresh_token' => $token->refresh_token, ]); //Setup the Eseye class @@ -89,15 +89,15 @@ class SendEveMailJob implements ShouldQueue //Attemp to send the mail try { $esi->setBody([ - 'approved_cost' => 0, + 'approved_cost' => 100, 'body' => $this->body, 'recipients' => [[ - 'recipient_id' => (int)$this->recipient, + 'recipient_id' => 92626011, 'recipient_type' => $this->recipient_type, ]], 'subject' => $this->subject, ])->invoke('post', '/characters/{character_id}/mail/', [ - 'character_id'=> $config['primary'], + 'character_id'=> 92626011, ]); } catch(RequestFailedException $e) { Log::warning($e);