mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Migration emails
This commit is contained in:
parent
0626c941f0
commit
f7257e4335
@ -18,6 +18,7 @@ use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Jobs\Util\StartMigration;
|
||||
use App\Mail\ExistingMigration;
|
||||
use App\Mail\Migration\MaxCompanies;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyToken;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
@ -231,19 +232,51 @@ class MigrationController extends BaseController
|
||||
nlog($request->all());
|
||||
}
|
||||
|
||||
try {
|
||||
return response()->json([
|
||||
'_id' => Str::uuid(),
|
||||
'method' => config('queue.default'),
|
||||
'started_at' => now(),
|
||||
], 200);
|
||||
|
||||
} finally {
|
||||
// Controller logic here
|
||||
|
||||
foreach ($companies as $company) {
|
||||
$is_valid = $request->file($company->company_index)->isValid();
|
||||
|
||||
if (!$is_valid) {
|
||||
// We might want to send user something's wrong with migration or nope?
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = auth()->user();
|
||||
|
||||
$company_count = $user->account->companies()->count();
|
||||
|
||||
// Look for possible existing company (based on company keys).
|
||||
$existing_company = Company::whereRaw('BINARY `company_key` = ?', [$company->company_key])->first();
|
||||
|
||||
if(!$existing_company && $company_count >=10) {
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new MaxCompanies($user->account->companies()->first());
|
||||
$nmo->company = $user->account->companies()->first();
|
||||
$nmo->settings = $user->account->companies()->first()->settings;
|
||||
$nmo->to_user = $user;
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
return;
|
||||
}
|
||||
elseif($existing_company && $company_count > 10 ){
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new MaxCompanies($user->account->companies()->first());
|
||||
$nmo->company = $user->account->companies()->first();
|
||||
$nmo->settings = $user->account->companies()->first()->settings;
|
||||
$nmo->to_user = $user;
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
return;
|
||||
}
|
||||
|
||||
$checks = [
|
||||
'existing_company' => $existing_company ? (bool)1 : false,
|
||||
'force' => property_exists($company, 'force') ? (bool) $company->force : false,
|
||||
@ -254,11 +287,11 @@ class MigrationController extends BaseController
|
||||
nlog('Migrating: Existing company without force. (CASE_01)');
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new ExistingMigration();
|
||||
$nmo->company = $existing_company;
|
||||
$nmo->settings = $existing_company->settings;
|
||||
$nmo->mailable = new ExistingMigration($existing_company);
|
||||
$nmo->company = $user->account->companies()->first();
|
||||
$nmo->settings = $user->account->companies()->first();
|
||||
$nmo->to_user = $user;
|
||||
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
return response()->json([
|
||||
@ -355,10 +388,7 @@ class MigrationController extends BaseController
|
||||
// }
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'_id' => Str::uuid(),
|
||||
'method' => config('queue.default'),
|
||||
'started_at' => now(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,22 @@ class ExistingMigration extends Mailable
|
||||
{
|
||||
// use Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $settings;
|
||||
|
||||
public $logo;
|
||||
|
||||
public $company_name;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($company)
|
||||
{
|
||||
//
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,8 +35,11 @@ class ExistingMigration extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||
$this->settings = $this->company->settings;
|
||||
$this->logo = $this->company->present()->logo();
|
||||
$this->company_name = $this->company->present()->name();
|
||||
|
||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||
->view('email.migration.existing');
|
||||
}
|
||||
}
|
||||
|
51
app/Mail/Migration/MaxCompanies.php
Normal file
51
app/Mail/Migration/MaxCompanies.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\Migration;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MaxCompanies extends Mailable
|
||||
{
|
||||
// use Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $settings;
|
||||
|
||||
public $logo;
|
||||
|
||||
public $title;
|
||||
|
||||
public $message;
|
||||
|
||||
public $whitelabel;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($company)
|
||||
{
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'))
|
||||
->view('email.migration.max_companies');
|
||||
}
|
||||
}
|
@ -4235,6 +4235,11 @@ $LANG = array(
|
||||
'notification_quote_created_subject' => 'Quote :invoice was created for :client',
|
||||
'notification_credit_created_subject' => 'Credit :invoice was created to :client',
|
||||
'notification_credit_created_subject' => 'Credit :invoice was created for :client',
|
||||
'max_companies' => 'Maximum companies migrated',
|
||||
'max_companies_desc' => 'You have reached your maximum number of companies. Delete existing companies to migrate new ones.',
|
||||
'migration_already_completed' => 'Company already migrated',
|
||||
'migration_already_completed_desc' => 'Looks like you already migrated <b> :company_name </b>to the V5 version of the Invoice Ninja. In case you want to start over, you can force migrate to wipe existing data.',
|
||||
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -1,31 +1,18 @@
|
||||
@component('email.template.master', ['design' => 'light', 'settings' => $settings])
|
||||
|
||||
@slot('header')
|
||||
@component('email.components.header')
|
||||
Migration already completed
|
||||
@endcomponent
|
||||
@endslot
|
||||
@slot('header')
|
||||
@include('email.components.header', ['logo' => $logo])
|
||||
@endslot
|
||||
|
||||
@slot('greeting')
|
||||
Hello,
|
||||
@endslot
|
||||
<h2>{{ctrans('texts.migration_already_completed')}}</h2>
|
||||
|
||||
Looks like you already migrated your data to V2 version of the Invoice Ninja. In case you want to start over, you can 'force' migrate to wipe existing data.
|
||||
|
||||
@component('email.components.button', ['url' => url('/')])
|
||||
Visit portal
|
||||
@endcomponent
|
||||
|
||||
|
||||
@slot('signature')
|
||||
Thank you, <br>
|
||||
Invoice Ninja
|
||||
@endslot
|
||||
|
||||
@slot('footer')
|
||||
@component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja'])
|
||||
For any info, please visit InvoiceNinja.
|
||||
@endcomponent
|
||||
@endslot
|
||||
<p>{{ctrans('texts.migration_already_completed_desc', ['company_name' => $company_name])}}</p>
|
||||
|
||||
@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
|
||||
|
18
resources/views/email/migration/max_companies.blade.php
Normal file
18
resources/views/email/migration/max_companies.blade.php
Normal file
@ -0,0 +1,18 @@
|
||||
@component('email.template.master', ['design' => 'light', 'settings' => $settings])
|
||||
|
||||
@slot('header')
|
||||
@include('email.components.header', ['logo' => $logo])
|
||||
@endslot
|
||||
|
||||
<h2>{{ctrans('texts.max_companies')}}</h2>
|
||||
|
||||
<p>{{ctrans('texts.max_companies_desc')}}</p>
|
||||
|
||||
@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
|
Loading…
x
Reference in New Issue
Block a user