1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-19 16:01:34 +02:00

Forced Migration

This commit is contained in:
David Bomba 2021-07-23 09:37:08 +10:00
parent 37c7ec4265
commit e25c6b8ee2
3 changed files with 102 additions and 2 deletions

View File

@ -0,0 +1,81 @@
<?php
namespace App\Console\Commands;
use App\Jobs\HostedMigration;
use App\Libraries\Utils;
use App\Models\Company;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Auth;
class ForceMigration extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ninja:force-migrate-v5';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Force migrate accounts to v5 - (Hosted function only)';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
return;
if(!Utils::isNinjaProd())
return;
config(['database.default' => DB_NINJA_1]);
$this->forceMigrate();
}
private function forceMigrate()
{
$data = [];
$company = Company::where('plan', 'free')
->with('accounts')
->first();
$user = $company->accounts->first()->users()->whereNull('public_id')->orWhere('public_id', 0)->first();
$db = DB_NINJA_1;
if($company){
foreach($company->accounts as $key => $account)
{
$data['companies'][$key]['id'] = $account->id;
}
$this->dispatch(new HostedMigration($user, $data, $db, true));
}
}
}

View File

@ -64,7 +64,12 @@ class Kernel extends ConsoleKernel
->command('ninja:sync-v5')
->withoutOverlapping()
->daily();
// $schedule
// ->command('ninja:force-migrate-v5')
// ->everyMinute()
// ->withoutOverlapping();
}
}
}

View File

@ -25,11 +25,14 @@ class HostedMigration extends Job
public $migration_token;
public function __construct(User $user, array $data, $db)
private $forced;
public function __construct(User $user, array $data, $db, $forced = false)
{
$this->user = $user;
$this->data = $data;
$this->db = $db;
$this->forced = $forced;
$this->v4_secret = config('ninja.ninja_hosted_secret');
}
@ -106,6 +109,17 @@ class HostedMigration extends Job
$this->account = $account;
if($this->forced){
//forced migration - we need to set this v4 account as inactive.
//set activate URL
$account_email_settings = $this->account->account_email_settings;
$account_email_settings->account_email_settings->forward_url_for_v5 = "https://ninja_user{$this->account->id}.invoicing.co";
$account_email_settings->save();
$this->account->subdomain = "ninja_user{$this->account->id}";
}
$date = date('Y-m-d');
$accountKey = $this->account->account_key;