1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00

Merge pull request #4921 from turbo124/v5-develop

Fixes for switching mailers are runtime when using queues
This commit is contained in:
David Bomba 2021-02-16 23:24:57 +11:00 committed by GitHub
commit 0e9e5eb744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 23 deletions

View File

@ -28,28 +28,27 @@ class GmailTransport extends Transport
*/
protected $gmail;
/**
* The GMail OAuth Token.
* @var string token
*/
protected $token;
/**
* Create a new Gmail transport instance.
*
* @param Mail $gmail
* @param string $token
*/
public function __construct(Mail $gmail, string $token)
public function __construct(Mail $gmail)
{
$this->gmail = $gmail;
$this->token = $token;
}
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
/*We should nest the token in the message and then discard it as needed*/
$token = $message->get('GmailToken');
nlog("gmail transporter token = {$token}");
$message->remove('GmailToken');
nlog("inside gmail sender with token {$this->token}");
$this->beforeSendPerformed($message);

View File

@ -1,5 +1,13 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Helpers\Mail;
use Illuminate\Mail\MailManager;
@ -12,12 +20,6 @@ class GmailTransportManager extends MailManager
{
protected function createGmailTransport()
{
info("booting gmail transport");
// $token = $this->app['config']->get('services.gmail.token', []);
$token = config('services.gmail.token');
$mail = new Mail;
return new GmailTransport($mail, $token);
return new GmailTransport(new Mail);
}
}

View File

@ -84,6 +84,7 @@ class NinjaMailerJob implements ShouldQueue
/* Singletons need to be rebooted each time just in case our Locale is changing*/
App::forgetInstance('translator');
App::forgetInstance('mail.manager'); //singletons must be destroyed!
App::forgetInstance('mailer');
/* Inject custom translations if any exist */
Lang::replace(Ninja::transformTranslations($this->nmo->settings));
@ -120,15 +121,24 @@ class NinjaMailerJob implements ShouldQueue
* just for this request.
*/
config(['mail.driver' => 'gmail']);
config(['services.gmail.token' => $user->oauth_user_token->access_token]);
config(['mail.from.address' => $user->email]);
config(['mail.from.name' => $user->present()->name()]);
// config(['mail.driver' => 'gmail']);
// config(['services.gmail.token' => $user->oauth_user_token->access_token]);
// config(['mail.from.address' => $user->email]);
// config(['mail.from.name' => $user->present()->name()]);
(new MailServiceProvider(app()))->register();
// (new MailServiceProvider(app()))->register();
// nlog("after registering mail service provider");
// nlog(config('services.gmail.token'));
$token = $user->oauth_user_token->access_token;
$this->nmo
->mailable
->from($user->email, $user->present()->name())
->withSwiftMessage(function ($message) use($token) {
$message->getHeaders()->addTextHeader('GmailToken', $token);
});
nlog("after registering mail service provider");
nlog(config('services.gmail.token'));
}
private function logMailError($errors, $recipient_object)