diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 6271aadee2f9..98a83a0a3a86 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -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; } diff --git a/app/Mail/Import/CompanyImportFailure.php b/app/Mail/Import/CompanyImportFailure.php new file mode 100644 index 000000000000..383e5fecea83 --- /dev/null +++ b/app/Mail/Import/CompanyImportFailure.php @@ -0,0 +1,64 @@ +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'); + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index e329553bd1f9..9670fe609788 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -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; diff --git a/resources/views/email/import/import_failure.blade.php b/resources/views/email/import/import_failure.blade.php new file mode 100644 index 000000000000..d22b3b610ec0 --- /dev/null +++ b/resources/views/email/import/import_failure.blade.php @@ -0,0 +1,22 @@ +@component('email.template.master', ['design' => 'light', 'settings' => $settings]) + + @slot('header') + @include('email.components.header', ['logo' => $logo]) + @endslot + +
{{ctrans('texts.company_import_failure_body')}}
+ + @if($user_message) +{{ $user_message }}
+ @endif + + @if(isset($whitelabel) && !$whitelabel) + @slot('footer') + @component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja']) + For any info, please visit InvoiceNinja. + @endcomponent + @endslot + @endif +@endcomponent