From 8a985c69548d1ae0db63f684431e8eb86ed0e096 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Jun 2021 11:06:31 +1000 Subject: [PATCH 1/6] Make all livewire components MultiDB aware --- app/Http/Livewire/CreditsTable.php | 8 ++++++++ app/Http/Livewire/DocumentsTable.php | 6 ++++++ app/Http/Livewire/InvoicesTable.php | 5 +++++ app/Http/Livewire/PayNowDropdown.php | 5 +++++ app/Http/Livewire/PaymentMethodsTable.php | 7 +++++++ app/Http/Livewire/PaymentsTable.php | 7 +++++++ app/Http/Livewire/QuotesTable.php | 10 ++++++++++ .../Livewire/RecurringInvoiceCancellation.php | 18 ++++++++++++++---- app/Http/Livewire/RequiredClientInfo.php | 8 +++++++- app/Http/Livewire/SubscriptionPlanSwitch.php | 5 +++++ .../SubscriptionRecurringInvoicesTable.php | 8 ++++++++ app/Http/Livewire/TasksTable.php | 8 ++++++++ .../portal/ninja2020/credits/index.blade.php | 2 +- .../portal/ninja2020/documents/index.blade.php | 2 +- .../portal/ninja2020/invoices/index.blade.php | 2 +- .../ninja2020/invoices/payment.blade.php | 2 +- .../portal/ninja2020/invoices/show.blade.php | 2 +- .../portal/ninja2020/layout/payments.blade.php | 2 +- .../ninja2020/payment_methods/index.blade.php | 2 +- .../portal/ninja2020/payments/index.blade.php | 2 +- .../portal/ninja2020/quotes/index.blade.php | 2 +- .../includes/modals/cancellation.blade.php | 2 +- .../recurring_invoices/index.blade.php | 2 +- .../ninja2020/subscriptions/index.blade.php | 2 +- .../ninja2020/subscriptions/switch.blade.php | 2 +- .../portal/ninja2020/tasks/index.blade.php | 2 +- 26 files changed, 104 insertions(+), 19 deletions(-) diff --git a/app/Http/Livewire/CreditsTable.php b/app/Http/Livewire/CreditsTable.php index 4ea703c2db5b..3d8713e0b77a 100644 --- a/app/Http/Livewire/CreditsTable.php +++ b/app/Http/Livewire/CreditsTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\Credit; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -24,6 +25,13 @@ class CreditsTable extends Component public $per_page = 10; + public $company; + + public function mount() + { + MultiDB::setDb($this->company->db); + } + public function render() { $query = Credit::query() diff --git a/app/Http/Livewire/DocumentsTable.php b/app/Http/Livewire/DocumentsTable.php index 465effc98493..f71cf116a4ca 100644 --- a/app/Http/Livewire/DocumentsTable.php +++ b/app/Http/Livewire/DocumentsTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\Client; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -25,8 +26,13 @@ class DocumentsTable extends Component public $per_page = 10; + public $company; + public function mount($client) { + + MultiDB::setDb($this->company->db); + $this->client = $client; } diff --git a/app/Http/Livewire/InvoicesTable.php b/app/Http/Livewire/InvoicesTable.php index 783c832df58a..2659f1fdd0e4 100644 --- a/app/Http/Livewire/InvoicesTable.php +++ b/app/Http/Livewire/InvoicesTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\Invoice; use App\Utils\Traits\WithSorting; use Carbon\Carbon; @@ -26,8 +27,12 @@ class InvoicesTable extends Component public $status = []; + public $company; + public function mount() { + MultiDB::setDb($this->company->db); + $this->sort_asc = false; $this->sort_field = 'date'; diff --git a/app/Http/Livewire/PayNowDropdown.php b/app/Http/Livewire/PayNowDropdown.php index 440872077fa7..8ca1dfc77dc5 100644 --- a/app/Http/Livewire/PayNowDropdown.php +++ b/app/Http/Livewire/PayNowDropdown.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use Livewire\Component; class PayNowDropdown extends Component @@ -20,8 +21,12 @@ class PayNowDropdown extends Component public $methods; + public $company; + public function mount(int $total) { + MultiDB::setDb($this->company->db); + $this->total = $total; $this->methods = auth()->user()->client->service()->getPaymentMethods($total); diff --git a/app/Http/Livewire/PaymentMethodsTable.php b/app/Http/Livewire/PaymentMethodsTable.php index 3a6d9d14a7a5..8a37e715374e 100644 --- a/app/Http/Livewire/PaymentMethodsTable.php +++ b/app/Http/Livewire/PaymentMethodsTable.php @@ -5,6 +5,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\ClientGatewayToken; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -16,10 +17,16 @@ class PaymentMethodsTable extends Component use WithSorting; public $per_page = 10; + public $client; + public $company; + public function mount($client) { + + MultiDB::setDb($this->company->db); + $this->client = $client; } diff --git a/app/Http/Livewire/PaymentsTable.php b/app/Http/Livewire/PaymentsTable.php index 0a41f98d4dd8..f9bd5991bd3a 100644 --- a/app/Http/Livewire/PaymentsTable.php +++ b/app/Http/Livewire/PaymentsTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\Payment; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -23,11 +24,17 @@ class PaymentsTable extends Component use WithPagination; public $per_page = 10; + public $user; + public $company; + public function mount() { + MultiDB::setDb($this->company->db); + $this->user = auth()->user(); + } public function render() diff --git a/app/Http/Livewire/QuotesTable.php b/app/Http/Livewire/QuotesTable.php index c14847eccd98..f697c965bfd3 100644 --- a/app/Http/Livewire/QuotesTable.php +++ b/app/Http/Livewire/QuotesTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\Quote; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -23,8 +24,17 @@ class QuotesTable extends Component use WithPagination; public $per_page = 10; + public $status = []; + public $company; + + public function mount() + { + MultiDB::setDb($this->company->db); + + } + public function render() { $query = Quote::query() diff --git a/app/Http/Livewire/RecurringInvoiceCancellation.php b/app/Http/Livewire/RecurringInvoiceCancellation.php index d3904c874330..06ade750d9ae 100644 --- a/app/Http/Livewire/RecurringInvoiceCancellation.php +++ b/app/Http/Livewire/RecurringInvoiceCancellation.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\RecurringInvoice; use Livewire\Component; @@ -22,6 +23,18 @@ class RecurringInvoiceCancellation extends Component */ public $invoice; + public $company; + + public function mount() + { + MultiDB::setDb($this->company->db); + } + + public function render() + { + return render('components.livewire.recurring-invoice-cancellation'); + } + public function processCancellation() { if ($this->invoice->subscription) { @@ -31,8 +44,5 @@ class RecurringInvoiceCancellation extends Component return redirect()->route('client.recurring_invoices.request_cancellation', ['recurring_invoice' => $this->invoice->hashed_id]); } - public function render() - { - return render('components.livewire.recurring-invoice-cancellation'); - } + } diff --git a/app/Http/Livewire/RequiredClientInfo.php b/app/Http/Livewire/RequiredClientInfo.php index 2b51cacbb841..6c00e8d3ea14 100644 --- a/app/Http/Livewire/RequiredClientInfo.php +++ b/app/Http/Livewire/RequiredClientInfo.php @@ -13,6 +13,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\ClientContact; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; @@ -65,7 +66,12 @@ class RequiredClientInfo extends Component public $show_form = false; - public function mount() {} + public $company; + + public function mount() + { + MultiDB::setDb($this->company->db); + } public function handleSubmit(array $data): bool { diff --git a/app/Http/Livewire/SubscriptionPlanSwitch.php b/app/Http/Livewire/SubscriptionPlanSwitch.php index 9ad9f35dc672..3454e38330a9 100644 --- a/app/Http/Livewire/SubscriptionPlanSwitch.php +++ b/app/Http/Livewire/SubscriptionPlanSwitch.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\ClientContact; use App\Models\Subscription; use Illuminate\Support\Facades\Cache; @@ -71,8 +72,12 @@ class SubscriptionPlanSwitch extends Component */ public $hash; + public $company; + public function mount() { + MultiDB::setDb($this->company->db); + $this->total = $this->amount; $this->methods = $this->contact->client->service()->getPaymentMethods($this->amount); diff --git a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php index f5c0947593ae..59ef4d028005 100644 --- a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php +++ b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\RecurringInvoice; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -24,6 +25,13 @@ class SubscriptionRecurringInvoicesTable extends Component public $per_page = 10; + public $company; + + public function mount() + { + MultiDB::setDb($this->company->db); + } + public function render() { $query = RecurringInvoice::query() diff --git a/app/Http/Livewire/TasksTable.php b/app/Http/Livewire/TasksTable.php index 9a741ed49dd7..9881ba377253 100644 --- a/app/Http/Livewire/TasksTable.php +++ b/app/Http/Livewire/TasksTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\Task; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -24,6 +25,13 @@ class TasksTable extends Component public $per_page = 10; + public $company; + + public function mount() + { + MultiDB::setDb($this->company->db); + } + public function render() { $query = Task::query() diff --git a/resources/views/portal/ninja2020/credits/index.blade.php b/resources/views/portal/ninja2020/credits/index.blade.php index d75caf6ab950..b485339c7a2e 100644 --- a/resources/views/portal/ninja2020/credits/index.blade.php +++ b/resources/views/portal/ninja2020/credits/index.blade.php @@ -13,6 +13,6 @@ @section('body')
- @livewire('credits-table') + @livewire('credits-table', ['company' => $company])
@endsection \ No newline at end of file diff --git a/resources/views/portal/ninja2020/documents/index.blade.php b/resources/views/portal/ninja2020/documents/index.blade.php index 46435884c292..61fc9a649808 100644 --- a/resources/views/portal/ninja2020/documents/index.blade.php +++ b/resources/views/portal/ninja2020/documents/index.blade.php @@ -14,5 +14,5 @@ @csrf - @livewire('documents-table', ['client' => $client]) + @livewire('documents-table', ['client' => $client, 'company' => $company]) @endsection diff --git a/resources/views/portal/ninja2020/invoices/index.blade.php b/resources/views/portal/ninja2020/invoices/index.blade.php index c7f685ce2654..944886d785de 100644 --- a/resources/views/portal/ninja2020/invoices/index.blade.php +++ b/resources/views/portal/ninja2020/invoices/index.blade.php @@ -20,6 +20,6 @@
- @livewire('invoices-table') + @livewire('invoices-table', ['company' => $company])
@endsection diff --git a/resources/views/portal/ninja2020/invoices/payment.blade.php b/resources/views/portal/ninja2020/invoices/payment.blade.php index de057c8cce5f..2673b298d1c8 100644 --- a/resources/views/portal/ninja2020/invoices/payment.blade.php +++ b/resources/views/portal/ninja2020/invoices/payment.blade.php @@ -19,7 +19,7 @@
- @livewire('pay-now-dropdown', ['total' => $total]) + @livewire('pay-now-dropdown', ['total' => $total, 'company' => $company])
diff --git a/resources/views/portal/ninja2020/invoices/show.blade.php b/resources/views/portal/ninja2020/invoices/show.blade.php index 047c23d99063..ced84accceb0 100644 --- a/resources/views/portal/ninja2020/invoices/show.blade.php +++ b/resources/views/portal/ninja2020/invoices/show.blade.php @@ -47,7 +47,7 @@ @if($settings->client_portal_allow_under_payment || $settings->client_portal_allow_over_payment) @else - @livewire('pay-now-dropdown', ['total' => $invoice->partial > 0 ? $invoice->partial : $invoice->balance]) + @livewire('pay-now-dropdown', ['total' => $invoice->partial > 0 ? $invoice->partial : $invoice->balance, 'company' => $company]) @endif
diff --git a/resources/views/portal/ninja2020/layout/payments.blade.php b/resources/views/portal/ninja2020/layout/payments.blade.php index f72f97a85c7e..d986f9f8efd0 100644 --- a/resources/views/portal/ninja2020/layout/payments.blade.php +++ b/resources/views/portal/ninja2020/layout/payments.blade.php @@ -11,7 +11,7 @@ @endpush @section('body') - @livewire('required-client-info', ['fields' => method_exists($gateway, 'getClientRequiredFields') ? $gateway->getClientRequiredFields() : [], 'contact' => auth('contact')->user(), 'countries' => $countries]) + @livewire('required-client-info', ['fields' => method_exists($gateway, 'getClientRequiredFields') ? $gateway->getClientRequiredFields() : [], 'contact' => auth('contact')->user(), 'countries' => $countries, 'company' => $company])
diff --git a/resources/views/portal/ninja2020/payment_methods/index.blade.php b/resources/views/portal/ninja2020/payment_methods/index.blade.php index b265cbdcd0ff..60d72006081e 100644 --- a/resources/views/portal/ninja2020/payment_methods/index.blade.php +++ b/resources/views/portal/ninja2020/payment_methods/index.blade.php @@ -3,6 +3,6 @@ @section('body')
- @livewire('payment-methods-table', ['client' => $client]) + @livewire('payment-methods-table', ['client' => $client, 'company' => $company])
@endsection diff --git a/resources/views/portal/ninja2020/payments/index.blade.php b/resources/views/portal/ninja2020/payments/index.blade.php index 3f54a73769b5..22bc5cccf64a 100644 --- a/resources/views/portal/ninja2020/payments/index.blade.php +++ b/resources/views/portal/ninja2020/payments/index.blade.php @@ -3,6 +3,6 @@ @section('body')
- @livewire('payments-table') + @livewire('payments-table', ['company' => $company])
@endsection \ No newline at end of file diff --git a/resources/views/portal/ninja2020/quotes/index.blade.php b/resources/views/portal/ninja2020/quotes/index.blade.php index 5ce9880a52bb..845485d79807 100644 --- a/resources/views/portal/ninja2020/quotes/index.blade.php +++ b/resources/views/portal/ninja2020/quotes/index.blade.php @@ -22,6 +22,6 @@
- @livewire('quotes-table') + @livewire('quotes-table', ['company' => $company])
@endsection \ No newline at end of file diff --git a/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php b/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php index c75064b298f9..59401a923f79 100644 --- a/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php +++ b/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php @@ -34,7 +34,7 @@
- @livewire('recurring-invoice-cancellation', ['invoice' => $invoice]) + @livewire('recurring-invoice-cancellation', ['invoice' => $invoice, 'company' => $company])
- @livewire('subscription-plan-switch', compact('recurring_invoice', 'subscription', 'target', 'contact', 'amount')) + @livewire('subscription-plan-switch', compact('recurring_invoice', 'subscription', 'target', 'contact', 'amount', 'company'))
@endsection diff --git a/resources/views/portal/ninja2020/tasks/index.blade.php b/resources/views/portal/ninja2020/tasks/index.blade.php index 783e325a25b3..c60fd34cd8f6 100644 --- a/resources/views/portal/ninja2020/tasks/index.blade.php +++ b/resources/views/portal/ninja2020/tasks/index.blade.php @@ -3,6 +3,6 @@ @section('body')
- @livewire('tasks-table') + @livewire('tasks-table', ['company' => $company])
@endsection From 4b6d17fa8d97b1222c0f103687ba1822b716c9d3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Jun 2021 15:42:39 +1000 Subject: [PATCH 2/6] Working on Company Import limiter --- app/Jobs/Company/CompanyImport.php | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 486b74fde904..683ece09cfd3 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -88,6 +88,8 @@ class CompanyImport implements ShouldQueue private $request_array = []; + private $message = ''; + private $importables = [ // 'company', 'users', @@ -157,6 +159,8 @@ class CompanyImport implements ShouldQueue // nlog($this->backup_file); + + if(array_key_exists('import_settings', $this->request_array) && $this->request_array['import_settings'] == 'true') { $this->preFlightChecks()->importSettings(); } @@ -171,6 +175,67 @@ class CompanyImport implements ShouldQueue } + /** + * On the hosted platform we cannot allow the + * import to start if there are users > plan number + * due to entity user_id dependencies + * + * @return bool + */ + private function checkUserCount() + { + + if(Ninja::isSelfHost()) + return true; + + $backup_users = $this->backup_file->users; + $company_users = $this->company->users; + $company_owner = $this->company->owner(); + + if(Ninja::isFreeHostedClient()){ + + if(count($backup_users) > 1){ + $this->message = 'Only one user can be in the import for a Free Account'; + } + + if(count($backup_users) == 1 && $company_owner->email != $backup_users[0]->email) { + $this->message = 'Account emails do not match. Account owner email must match backup user email'; + } + + $backup_users_emails = array_column($backup_users, 'email'); + $company_users_emails = $company_users->pluck('email')->toArray(); + + $existing_user_count = count(array_intersect($backup_users_emails, $company_users_emails)); + + if($existing_user_count == 1) + return true; + + if($existing_user_count > 1){ + + if($this->account->plan == 'pro') + $this->message = 'Pro plan is limited to one user, you have multiple users in the backup file'; + + if($this->account->plan == 'enterprise'){ + + $total_import_users = count($backup_users_emails); + $account_plan_num_user = $this->account->num_users; + + if($total_import_users > $account_plan_num_user){ + + $this->message = "Total user count ({$total_import_users}) greater than your plan allows ({$account_plan_num_user})"; + } + + } + } + + if(strlen($this->message) > 1){ + return false; + } + + return true; + } + + } //check if this is a complete company import OR if it is selective /* From 1baadd96b487dbb9d21b146c40ddcfc3da5fa6de Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Jun 2021 15:50:09 +1000 Subject: [PATCH 3/6] Enforce client and user limits with Company Import --- app/Jobs/Company/CompanyImport.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 683ece09cfd3..6271aadee2f9 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -159,8 +159,6 @@ class CompanyImport implements ShouldQueue // nlog($this->backup_file); - - if(array_key_exists('import_settings', $this->request_array) && $this->request_array['import_settings'] == 'true') { $this->preFlightChecks()->importSettings(); } @@ -189,7 +187,9 @@ class CompanyImport implements ShouldQueue return true; $backup_users = $this->backup_file->users; + $company_users = $this->company->users; + $company_owner = $this->company->owner(); if(Ninja::isFreeHostedClient()){ @@ -203,13 +203,11 @@ class CompanyImport implements ShouldQueue } $backup_users_emails = array_column($backup_users, 'email'); + $company_users_emails = $company_users->pluck('email')->toArray(); $existing_user_count = count(array_intersect($backup_users_emails, $company_users_emails)); - if($existing_user_count == 1) - return true; - if($existing_user_count > 1){ if($this->account->plan == 'pro') @@ -218,6 +216,7 @@ class CompanyImport implements ShouldQueue if($this->account->plan == 'enterprise'){ $total_import_users = count($backup_users_emails); + $account_plan_num_user = $this->account->num_users; if($total_import_users > $account_plan_num_user){ @@ -232,6 +231,18 @@ class CompanyImport implements ShouldQueue return false; } + if(Ninja::isFreeHostedClient() && count($this->backup_file->clients) > config('ninja.quotas.free.clients')){ + + $client_count = count($this->backup_file->clients); + + $client_limit = config('ninja.quotas.free.clients'); + + $this->message = "You are attempting to import ({$client_count}) clients, your current plan allows a total of ({$client_limit})"; + + return false; + + } + return true; } From b29c9f25e3cf2d71c2cbbf83957bcfaac8ffebd7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Jun 2021 07:23:20 +1000 Subject: [PATCH 4/6] Company Import mailer --- app/Jobs/Company/CompanyImport.php | 28 +++++++- app/Mail/Import/CompanyImportFailure.php | 64 +++++++++++++++++++ resources/lang/en/texts.php | 2 + .../email/import/import_failure.blade.php | 22 +++++++ 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 app/Mail/Import/CompanyImportFailure.php create mode 100644 resources/views/email/import/import_failure.blade.php 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_subject')}}

+ +

{{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 From 60e44c127ce65136a8e226b94cfff75deda180e0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Jun 2021 07:45:40 +1000 Subject: [PATCH 5/6] Fixes for logging in company import --- app/Jobs/Company/CompanyImport.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 98a83a0a3a86..826dd63b5d12 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -151,6 +151,8 @@ class CompanyImport implements ShouldQueue $this->company = Company::where('company_key', $this->company->company_key)->firstOrFail(); $this->account = $this->company->account; + nlog("Company ID = {$this->company->id}"); + $this->backup_file = Cache::get($this->hash); if ( empty( $this->backup_file ) ) From b9262e59fa525185f178cdc99330ba5fb82eb06a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Jun 2021 07:46:00 +1000 Subject: [PATCH 6/6] Fixes for logging in company import --- app/Jobs/Company/CompanyImport.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 826dd63b5d12..01722574b086 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -152,7 +152,7 @@ class CompanyImport implements ShouldQueue $this->account = $this->company->account; nlog("Company ID = {$this->company->id}"); - + $this->backup_file = Cache::get($this->hash); if ( empty( $this->backup_file ) ) @@ -339,6 +339,8 @@ class CompanyImport implements ShouldQueue $method = "import_{$import}"; + nlog($method); + $this->{$method}(); }