1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Jobs/Mail/EntitySentMailer.php

97 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2020-08-06 05:04:09 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-08-06 05:04:09 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Mail;
use App\Jobs\Util\SystemLogger;
use App\Libraries\Google\Google;
use App\Libraries\MultiDB;
use App\Mail\Admin\EntityNotificationMailer;
use App\Mail\Admin\EntitySentObject;
use App\Models\SystemLog;
use App\Models\User;
use App\Providers\MailServiceProvider;
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\Config;
use Illuminate\Support\Facades\Mail;
2020-08-06 05:04:09 +02:00
/*Multi Mailer implemented*/
class EntitySentMailer extends BaseMailerJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $company;
public $user;
public $invitation;
public $entity_type;
public $entity;
2020-08-10 06:55:44 +02:00
public $settings;
/**
* Create a new job instance.
*
2020-10-28 11:10:49 +01:00
* @param $invitation
* @param $entity_type
* @param $user
* @param $company
*/
public function __construct($invitation, $entity_type, $user, $company)
{
$this->company = $company;
$this->user = $user;
$this->invitation = $invitation;
$this->entity = $invitation->{$entity_type};
$this->entity_type = $entity_type;
2020-08-10 06:55:44 +02:00
$this->settings = $invitation->contact->client->getMergedSettings();
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//Set DB
MultiDB::setDb($this->company->db);
//if we need to set an email driver do it now
2020-08-10 06:55:44 +02:00
$this->setMailDriver();
$mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build();
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];
//send email
Mail::to($this->user->email)
->send(new EntityNotificationMailer($mail_obj));
//catch errors
if (count(Mail::failures()) > 0) {
2020-08-08 06:38:02 +02:00
return $this->logMailError(Mail::failures(), $this->entity->client);
}
}
}