Added new options for migrations (#3628)

- New 'existing.blade' e-mail
- Added .php_cs cache in .gitignore
- Updated MigrationController with new options
This commit is contained in:
Benjamin Beganović 2020-04-14 00:20:54 +02:00 committed by GitHub
parent 23e48c0fdc
commit 4af53922ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 1 deletions

2
.gitignore vendored
View File

@ -27,3 +27,5 @@ local_version.txt
storage/migrations
nbproject
/composer.lock
.php_cs.cache

View File

@ -22,6 +22,7 @@ use App\Http\Requests\Account\CreateAccountRequest;
use App\Http\Requests\Migration\UploadMigrationFileRequest;
use App\Jobs\Account\CreateAccount;
use App\Jobs\Util\StartMigration;
use App\Mail\ExistingMigration;
use App\Mail\MigrationFailed;
use App\Models\Account;
use App\Models\Company;
@ -197,8 +198,45 @@ class MigrationController extends BaseController
public function startMigration(Request $request, Company $company)
{
$user = auth()->user();
$existing_company = Company::where('company_key', $request->company_key)->first();
info('Request key: ' . $request->company_key);
if ($request->company_key !== $company->company_key) {
info('Migration type: Fresh migration with new company. MigrationController::203');
// If there's company with same 'company_key' as from request we would crash it
// to avoid duplicate 'company_key' insert error. This should never happen, but just in case to prevent it.
if ($existing_company) {
Mail::to($user)->send(new ExistingMigration());
return;
}
$account = (new ImportMigrations())->getAccount();
$company = (new ImportMigrations())->getCompany($account);
CompanyToken::create([
'user_id' => $user->id,
'company_id' => $company->id,
'account_id' => $account->id,
'name' => $request->token_name ?? Str::random(12),
'token' => $request->token ?? \Illuminate\Support\Str::random(64),
]);
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
'permissions' => '',
'settings' => null,
]);
}
if (($request->company_key == $company->company_key) && ($request->has('force') && !empty($request->force))) {
info('Migration type: Completely wipe company and start again. MigrationController::228');
if ($request->has('force') && !empty($request->force)) {
$this->purgeCompany($company);
$account = (new ImportMigrations())->getAccount();
@ -223,6 +261,18 @@ class MigrationController extends BaseController
]);
}
if (($request->company_key == $company->company_key) && !$request->force) {
info('Migration type: Nothing, skip this since no "force" is provided.. MigrationController::255');
Mail::to($user)->send(new ExistingMigration());
return response()->json([
'_id' => Str::uuid(),
'method' => config('queue.default'),
'started_at' => now(),
], 200);
}
$migration_file = $request->file('migration')
->storeAs('migrations', $request->file('migration')->getClientOriginalName());

View File

@ -0,0 +1,33 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ExistingMigration extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('email.migration.existing');
}
}

View File

@ -0,0 +1,31 @@
@component('email.template.master', ['design' => 'light'])
@slot('header')
@component('email.components.header')
Migration already completed
@endcomponent
@endslot
@slot('greeting')
Hello,
@endslot
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' => '&copy; InvoiceNinja'])
For any info, please visit InvoiceNinja.
@endcomponent
@endslot
@endcomponent