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

106 lines
3.0 KiB
PHP
Raw Normal View History

<?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\User;
use App\Jobs\Mail\BaseMailerJob;
use App\Libraries\MultiDB;
use App\Mail\User\UserNotificationMailer;
use App\Models\Company;
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\Mail;
2020-10-28 11:10:49 +01:00
use stdClass;
class UserEmailChanged extends BaseMailerJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $new_email;
protected $old_email;
protected $company;
2020-08-10 06:55:44 +02:00
public $settings;
/**
* Create a new job instance.
*
2020-10-28 11:10:49 +01:00
* @param string $new_email
* @param string $old_email
* @param Company $company
*/
public function __construct(string $new_email, string $old_email, Company $company)
{
$this->new_email = $new_email;
$this->old_email = $old_email;
$this->company = $company;
2020-08-10 06:55:44 +02:00
$this->settings = $this->company->settings;
}
public function handle()
{
2020-11-25 15:19:52 +01:00
if ($this->company->is_disabled) {
2020-11-01 04:19:03 +01:00
return true;
2020-11-25 15:19:52 +01:00
}
2020-11-01 04:19:03 +01:00
//Set DB
MultiDB::setDb($this->company->db);
2020-08-06 05:04:09 +02:00
//If we need to set an email driver do it now
2020-08-10 06:55:44 +02:00
$this->setMailDriver();
2020-08-06 05:04:09 +02:00
/*Build the object*/
2020-10-28 11:10:49 +01:00
$mail_obj = new stdClass;
$mail_obj->subject = ctrans('texts.email_address_changed');
$mail_obj->markdown = 'email.admin.generic';
$mail_obj->from = [$this->company->owner()->email, $this->company->owner()->present()->name()];
$mail_obj->tag = $this->company->company_key;
$mail_obj->data = $this->getData();
2020-08-06 05:04:09 +02:00
//Send email via a Mailable class
2020-11-12 10:41:19 +01:00
//
try {
2020-11-25 15:19:52 +01:00
Mail::to($this->old_email)
->send(new UserNotificationMailer($mail_obj));
2020-11-25 15:19:52 +01:00
Mail::to($this->new_email)
->send(new UserNotificationMailer($mail_obj));
2020-11-25 15:19:52 +01:00
} catch (\Exception $e) {
//$this->failed($e);
2020-11-12 10:41:19 +01:00
$this->logMailError($e->getMessage(), $this->company->owner());
}
}
private function getData()
{
2020-07-22 09:26:54 +02:00
return [
'title' => ctrans('texts.email_address_changed'),
'message' => ctrans(
'texts.email_address_changed_message',
['old_email' => $this->old_email,
'new_email' => $this->new_email,
]
),
'url' => config('ninja.app_url'),
'button' => ctrans('texts.account_login'),
'signature' => $this->company->owner()->signature,
'logo' => $this->company->present()->logo(),
2020-09-21 00:17:57 +02:00
'settings' => $this->settings,
2020-10-20 04:23:48 +02:00
'whitelabel' => $this->company->account->isPaid() ? true : false,
];
}
}