mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 07:14:37 -04:00
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:
parent
23e48c0fdc
commit
4af53922ed
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,3 +27,5 @@ local_version.txt
|
|||||||
storage/migrations
|
storage/migrations
|
||||||
nbproject
|
nbproject
|
||||||
/composer.lock
|
/composer.lock
|
||||||
|
|
||||||
|
.php_cs.cache
|
@ -22,6 +22,7 @@ use App\Http\Requests\Account\CreateAccountRequest;
|
|||||||
use App\Http\Requests\Migration\UploadMigrationFileRequest;
|
use App\Http\Requests\Migration\UploadMigrationFileRequest;
|
||||||
use App\Jobs\Account\CreateAccount;
|
use App\Jobs\Account\CreateAccount;
|
||||||
use App\Jobs\Util\StartMigration;
|
use App\Jobs\Util\StartMigration;
|
||||||
|
use App\Mail\ExistingMigration;
|
||||||
use App\Mail\MigrationFailed;
|
use App\Mail\MigrationFailed;
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
@ -197,8 +198,45 @@ class MigrationController extends BaseController
|
|||||||
public function startMigration(Request $request, Company $company)
|
public function startMigration(Request $request, Company $company)
|
||||||
{
|
{
|
||||||
$user = auth()->user();
|
$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);
|
$this->purgeCompany($company);
|
||||||
|
|
||||||
$account = (new ImportMigrations())->getAccount();
|
$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')
|
$migration_file = $request->file('migration')
|
||||||
->storeAs('migrations', $request->file('migration')->getClientOriginalName());
|
->storeAs('migrations', $request->file('migration')->getClientOriginalName());
|
||||||
|
|
||||||
|
33
app/Mail/ExistingMigration.php
Normal file
33
app/Mail/ExistingMigration.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
31
resources/views/email/migration/existing.blade.php
Normal file
31
resources/views/email/migration/existing.blade.php
Normal 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' => '© InvoiceNinja'])
|
||||||
|
For any info, please visit InvoiceNinja.
|
||||||
|
@endcomponent
|
||||||
|
@endslot
|
||||||
|
|
||||||
|
@endcomponent
|
Loading…
x
Reference in New Issue
Block a user