Company Import mailer

This commit is contained in:
David Bomba 2021-06-08 07:23:20 +10:00
parent 1baadd96b4
commit b29c9f25e3
4 changed files with 113 additions and 3 deletions

View File

@ -19,6 +19,7 @@ use App\Jobs\Util\UnlinkFile;
use App\Libraries\MultiDB;
use App\Mail\DownloadBackup;
use App\Mail\DownloadInvoices;
use App\Mail\Import\CompanyImportFailure;
use App\Models\Activity;
use App\Models\Backup;
use App\Models\Client;
@ -165,9 +166,18 @@ class CompanyImport implements ShouldQueue
if(array_key_exists('import_data', $this->request_array) && $this->request_array['import_data'] == 'true') {
$this->preFlightChecks()
->purgeCompanyData()
->importData();
try{
$this->preFlightChecks()
->purgeCompanyData()
->importData();
}
catch(\Exception $e){
info($e->getMessage());
}
}
@ -263,6 +273,18 @@ class CompanyImport implements ShouldQueue
}
if(!$this->checkUserCount())
{
$nmo = new NinjaMailerObject;
$nmo->mailable = new CompanyImportFailure($this->company, $this->message);
$nmo->company = $this->company;
$nmo->settings = $this->company->settings;
$nmo->to_user = $this->company->owner();
NinjaMailerJob::dispatchNow($nmo);
throw new \Exception('Company import check failed');
}
return $this;
}

View File

@ -0,0 +1,64 @@
<?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\Mail\Import;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class CompanyImportFailure extends Mailable
{
// use Queueable, SerializesModels;
public $company;
public $settings;
public $logo;
public $title;
public $message;
public $whitelabel;
public $user_message;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($company, $user_message)
{
$this->company = $company;
$this->user_message = $user_message;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->settings = $this->company->settings;
$this->logo = $this->company->present()->logo();
$this->title = ctrans('texts.max_companies');
$this->message = ctrans('texts.max_companies_desc');
$this->whitelabel = $this->company->account->isPaid();
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject(ctrans('texts.company_import_failure_subject'))
->view('email.migration.max_companies');
}
}

View File

@ -4254,6 +4254,8 @@ $LANG = array(
'account_passwordless_login' => 'Account passwordless login',
'user_duplicate_error' => 'Cannot add the same user to the same company',
'user_cross_linked_error' => 'User exists but cannot be crossed linked to multiple accounts',
'company_import_failure_subject' => 'Error importing :company',
'company_import_failure_body' => 'There was an error importing the company data, the error message was:',
);
return $LANG;

View File

@ -0,0 +1,22 @@
@component('email.template.master', ['design' => 'light', 'settings' => $settings])
@slot('header')
@include('email.components.header', ['logo' => $logo])
@endslot
<h2>{{ctrans('texts.company_import_failure_subject')}}</h2>
<p>{{ctrans('texts.company_import_failure_body')}}</p>
@if($user_message)
<p>{{ $user_message }}</p>
@endif
@if(isset($whitelabel) && !$whitelabel)
@slot('footer')
@component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '&copy; InvoiceNinja'])
For any info, please visit InvoiceNinja.
@endcomponent
@endslot
@endif
@endcomponent