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

100 lines
3.1 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\User;
2021-02-18 00:30:31 +01:00
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Libraries\MultiDB;
use App\Mail\User\UserNotificationMailer;
use App\Models\Company;
2021-02-18 00:30:31 +01:00
use App\Models\User;
2022-10-24 12:49:05 +02:00
use App\Utils\Ninja;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
2022-10-24 12:49:05 +02:00
use Illuminate\Support\Facades\App;
2020-10-28 11:10:49 +01:00
use stdClass;
2021-02-18 00:30:31 +01:00
class UserEmailChanged implements ShouldQueue
{
2024-01-14 05:05:00 +01:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
2020-08-10 06:55:44 +02:00
public $settings;
/**
* Create a new job instance.
*
2023-08-07 07:30:34 +02:00
* @param \App\Models\User $new_user
2023-08-13 12:00:26 +02:00
* @param \stdClass $old_user
2023-08-07 07:30:34 +02:00
* @param \App\Models\Company $company
*/
2023-10-02 08:20:26 +02:00
public function __construct(protected User $new_user, protected \stdClass $old_user, protected Company $company, protected bool $is_react = false)
{
2020-08-10 06:55:44 +02:00
$this->settings = $this->company->settings;
}
public function handle()
{
//Set DB
MultiDB::setDb($this->company->db);
2022-10-24 12:49:05 +02:00
App::forgetInstance('translator');
$t = app('translator');
$t->replace(Ninja::transformTranslations($this->company->settings));
App::setLocale($this->company->getLocale());
2020-08-06 05:04:09 +02:00
/*Build the object*/
2024-01-14 05:05:00 +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
2024-01-14 05:05:00 +01:00
$nmo = new NinjaMailerObject();
2021-02-18 00:30:31 +01:00
$nmo->mailable = new UserNotificationMailer($mail_obj);
$nmo->settings = $this->settings;
$nmo->company = $this->company;
$nmo->to_user = $this->old_user;
NinjaMailerJob::dispatch($nmo, true);
2021-02-18 00:30:31 +01:00
2023-10-02 08:20:26 +02:00
$this->new_user->service()->invite($this->company, $this->is_react);
}
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',
2021-02-18 11:33:54 +01:00
['old_email' => $this->old_user->email,
'new_email' => $this->new_user->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,
];
}
}