mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 22:14:36 -04:00
Remove BaseMailerJob
This commit is contained in:
parent
7241430ce5
commit
2735efedd2
@ -14,7 +14,8 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Console\Commands\ImportMigrations;
|
use App\Console\Commands\ImportMigrations;
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Jobs\Mail\MailRouter;
|
use App\Jobs\Mail\NinjaMailerJob;
|
||||||
|
use App\Jobs\Mail\NinjaMailerObject;
|
||||||
use App\Jobs\Util\StartMigration;
|
use App\Jobs\Util\StartMigration;
|
||||||
use App\Mail\ExistingMigration;
|
use App\Mail\ExistingMigration;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
@ -248,7 +249,13 @@ class MigrationController extends BaseController
|
|||||||
if ($checks['existing_company'] == true && $checks['force'] == false) {
|
if ($checks['existing_company'] == true && $checks['force'] == false) {
|
||||||
nlog('Migrating: Existing company without force. (CASE_01)');
|
nlog('Migrating: Existing company without force. (CASE_01)');
|
||||||
|
|
||||||
MailRouter::dispatch(new ExistingMigration(), $existing_company, $user);
|
$nmo = new NinjaMailerObject;
|
||||||
|
$nmo->mailable = new ExistingMigration();
|
||||||
|
$nmo->company = $existing_company;
|
||||||
|
$nmo->settings = $existing_company->settings;
|
||||||
|
$nmo->to_user = $user;
|
||||||
|
|
||||||
|
NinjaMailerJob::dispatch($nmo);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'_id' => Str::uuid(),
|
'_id' => Str::uuid(),
|
||||||
|
@ -17,7 +17,8 @@ use App\Factory\PaymentFactory;
|
|||||||
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||||
use App\Import\ImportException;
|
use App\Import\ImportException;
|
||||||
use App\Import\Transformers\BaseTransformer;
|
use App\Import\Transformers\BaseTransformer;
|
||||||
use App\Jobs\Mail\MailRouter;
|
use App\Jobs\Mail\NinjaMailerJob;
|
||||||
|
use App\Jobs\Mail\NinjaMailerObject;
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
use App\Mail\Import\ImportCompleted;
|
use App\Mail\Import\ImportCompleted;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
@ -91,9 +92,10 @@ class CSVImport implements ShouldQueue {
|
|||||||
|
|
||||||
MultiDB::setDb( $this->company->db );
|
MultiDB::setDb( $this->company->db );
|
||||||
|
|
||||||
$this->company->owner()->setCompany( $this->company );
|
|
||||||
Auth::login( $this->company->owner(), true );
|
Auth::login( $this->company->owner(), true );
|
||||||
|
|
||||||
|
$this->company->owner()->setCompany( $this->company );
|
||||||
|
|
||||||
$this->buildMaps();
|
$this->buildMaps();
|
||||||
|
|
||||||
nlog( "import " . $this->import_type );
|
nlog( "import " . $this->import_type );
|
||||||
@ -127,7 +129,13 @@ class CSVImport implements ShouldQueue {
|
|||||||
'company' => $this->company,
|
'company' => $this->company,
|
||||||
];
|
];
|
||||||
|
|
||||||
MailRouter::dispatch( new ImportCompleted( $data ), $this->company, auth()->user() );
|
$nmo = new NinjaMailerObject;
|
||||||
|
$nmo->mailable = new ImportCompleted( $data );
|
||||||
|
$nmo->company = $this->company;
|
||||||
|
$nmo->settings = $this->company->settings;
|
||||||
|
$nmo->to_user = $this->company->owner();
|
||||||
|
|
||||||
|
NinjaMailerJob::dispatch($nmo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1,120 +0,0 @@
|
|||||||
<?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\Jobs\Mail;
|
|
||||||
|
|
||||||
use App\DataMapper\Analytics\EmailFailure;
|
|
||||||
use App\Jobs\Util\SystemLogger;
|
|
||||||
use App\Libraries\Google\Google;
|
|
||||||
use App\Models\SystemLog;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Providers\MailServiceProvider;
|
|
||||||
use App\Utils\Ninja;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
use Illuminate\Support\Facades\Lang;
|
|
||||||
use Turbo124\Beacon\Facades\LightLogs;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Multi Mailer implemented
|
|
||||||
@Deprecated 14/02/2021
|
|
||||||
*/
|
|
||||||
|
|
||||||
class BaseMailerJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesHash;
|
|
||||||
|
|
||||||
public $tries = 5; //number of retries
|
|
||||||
|
|
||||||
public $backoff = 5; //seconds to wait until retry
|
|
||||||
|
|
||||||
public $deleteWhenMissingModels = true;
|
|
||||||
|
|
||||||
public function setMailDriver()
|
|
||||||
{
|
|
||||||
/* 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!
|
|
||||||
|
|
||||||
/* Inject custom translations if any exist */
|
|
||||||
Lang::replace(Ninja::transformTranslations($this->settings));
|
|
||||||
|
|
||||||
switch ($this->settings->email_sending_method) {
|
|
||||||
case 'default':
|
|
||||||
break;
|
|
||||||
case 'gmail':
|
|
||||||
$this->setGmailMailer();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setGmailMailer()
|
|
||||||
{
|
|
||||||
$sending_user = $this->settings->gmail_sending_user_id;
|
|
||||||
|
|
||||||
$user = User::find($this->decodePrimaryKey($sending_user));
|
|
||||||
|
|
||||||
$google = (new Google())->init();
|
|
||||||
$google->getClient()->setAccessToken(json_encode($user->oauth_user_token));
|
|
||||||
|
|
||||||
if ($google->getClient()->isAccessTokenExpired()) {
|
|
||||||
$google->refreshToken($user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now that our token is refreshed and valid we can boot the
|
|
||||||
* mail driver at runtime and also set the token which will persist
|
|
||||||
* 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()]);
|
|
||||||
|
|
||||||
//(new MailServiceProvider(app()))->register();
|
|
||||||
|
|
||||||
nlog("after registering mail service provider");
|
|
||||||
nlog(config('services.gmail.token'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function logMailError($errors, $recipient_object)
|
|
||||||
{
|
|
||||||
SystemLogger::dispatch(
|
|
||||||
$errors,
|
|
||||||
SystemLog::CATEGORY_MAIL,
|
|
||||||
SystemLog::EVENT_MAIL_SEND,
|
|
||||||
SystemLog::TYPE_FAILURE,
|
|
||||||
$recipient_object
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function failed($exception = null)
|
|
||||||
{
|
|
||||||
nlog('mailer job failed');
|
|
||||||
nlog($exception->getMessage());
|
|
||||||
|
|
||||||
$job_failure = new EmailFailure();
|
|
||||||
$job_failure->string_metric5 = get_parent_class($this);
|
|
||||||
$job_failure->string_metric6 = $exception->getMessage();
|
|
||||||
|
|
||||||
LightLogs::create($job_failure)
|
|
||||||
->batch();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
<?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\Jobs\Mail;
|
|
||||||
|
|
||||||
use App\Libraries\MultiDB;
|
|
||||||
use App\Models\ClientContact;
|
|
||||||
use App\Models\Company;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Mail\Mailable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
|
|
||||||
/*Multi Mailer Router implemented*/
|
|
||||||
|
|
||||||
class MailRouter extends BaseMailerJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
public $mailable;
|
|
||||||
|
|
||||||
public $company;
|
|
||||||
|
|
||||||
public $to_user; //User or ClientContact
|
|
||||||
|
|
||||||
public $sending_method; //not sure if we even need this
|
|
||||||
|
|
||||||
public $settings;
|
|
||||||
|
|
||||||
public function __construct(Mailable $mailable, Company $company, $to_user, $sending_method = null)
|
|
||||||
{
|
|
||||||
$this->mailable = $mailable;
|
|
||||||
|
|
||||||
$this->company = $company;
|
|
||||||
|
|
||||||
$this->to_user = $to_user;
|
|
||||||
|
|
||||||
$this->sending_method = $sending_method;
|
|
||||||
|
|
||||||
if ($to_user instanceof ClientContact) {
|
|
||||||
$this->settings = $to_user->client->getMergedSettings();
|
|
||||||
} else {
|
|
||||||
$this->settings = $this->company->settings;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
/*If we are migrating data we don't want to fire these notification*/
|
|
||||||
if ($this->company->is_disabled) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiDB::setDb($this->company->db);
|
|
||||||
|
|
||||||
//if we need to set an email driver do it now
|
|
||||||
$this->setMailDriver();
|
|
||||||
|
|
||||||
//send email
|
|
||||||
try {
|
|
||||||
Mail::to($this->to_user->email)
|
|
||||||
->send($this->mailable);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
//$this->failed($e);
|
|
||||||
|
|
||||||
if ($this->to_user instanceof ClientContact) {
|
|
||||||
$this->logMailError($e->getMessage(), $this->to_user->client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,7 +28,7 @@ use Illuminate\Support\Facades\Mail;
|
|||||||
|
|
||||||
/*Multi Mailer implemented*/
|
/*Multi Mailer implemented*/
|
||||||
|
|
||||||
class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
class PaymentFailureMailer implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user