2020-05-14 13:33:29 +02:00
|
|
|
<?php
|
2020-08-06 05:04:09 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +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
|
|
|
|
*/
|
2020-05-14 13:33:29 +02:00
|
|
|
|
|
|
|
namespace App\Jobs\Mail;
|
|
|
|
|
2020-05-16 04:04:24 +02:00
|
|
|
use App\Jobs\Util\SystemLogger;
|
|
|
|
use App\Libraries\Google\Google;
|
2020-05-14 13:33:29 +02:00
|
|
|
use App\Libraries\MultiDB;
|
2020-05-19 00:22:18 +02:00
|
|
|
use App\Mail\Admin\EntityNotificationMailer;
|
2020-05-20 08:59:29 +02:00
|
|
|
use App\Mail\Admin\EntityViewedObject;
|
2020-05-16 04:04:24 +02:00
|
|
|
use App\Models\SystemLog;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Providers\MailServiceProvider;
|
2020-05-14 13:33:29 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2020-05-16 04:04:24 +02:00
|
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
2020-05-14 13:33:29 +02:00
|
|
|
|
2020-08-06 05:04:09 +02:00
|
|
|
/*Multi Mailer implemented*/
|
|
|
|
|
2020-05-20 08:59:29 +02:00
|
|
|
class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
|
2020-05-14 13:33:29 +02:00
|
|
|
{
|
|
|
|
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;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-05-14 13:33:29 +02:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct($invitation, $entity_type, $user, $company)
|
|
|
|
{
|
|
|
|
$this->company = $company;
|
|
|
|
|
|
|
|
$this->user = $user;
|
|
|
|
|
|
|
|
$this->invitation = $invitation;
|
|
|
|
|
|
|
|
$this->entity = $invitation->{$entity_type};
|
2020-05-16 12:26:16 +02:00
|
|
|
|
|
|
|
$this->entity_type = $entity_type;
|
2020-08-10 06:55:44 +02:00
|
|
|
|
|
|
|
$this->settings = $invitation->contact->client->getMergedSettings();
|
2020-05-14 13:33:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-05-20 08:59:29 +02:00
|
|
|
|
2020-05-19 00:22:18 +02:00
|
|
|
//Set DB
|
2020-05-14 13:33:29 +02:00
|
|
|
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();
|
2020-05-14 13:33:29 +02:00
|
|
|
|
2020-05-20 08:59:29 +02:00
|
|
|
$mail_obj = (new EntityViewedObject($this->invitation, $this->entity_type))->build();
|
|
|
|
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];
|
2020-05-14 13:33:29 +02:00
|
|
|
|
2020-05-16 04:04:24 +02:00
|
|
|
//send email
|
2020-05-19 00:22:18 +02:00
|
|
|
Mail::to($this->user->email)
|
|
|
|
->send(new EntityNotificationMailer($mail_obj));
|
2020-05-16 04:04:24 +02:00
|
|
|
|
|
|
|
//catch errors
|
|
|
|
if (count(Mail::failures()) > 0) {
|
2020-08-08 06:38:02 +02:00
|
|
|
return $this->logMailError(Mail::failures(), $this->invoice->client);
|
2020-05-14 13:33:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|