1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Merge pull request #6329 from turbo124/master

Force migrations
This commit is contained in:
David Bomba 2021-07-25 11:41:42 +10:00 committed by GitHub
commit 74a56afe6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 4 deletions

View File

@ -57,8 +57,15 @@ class ForceMigration extends Command
{
$data = [];
$company = Company::where('plan', 'free')
$company = Company::on(DB_NINJA_1)
->whereNull('plan')
->orWhereIn('plan', ['','free'])
->whereHas('accounts', function ($query){
$query->where('account_key', 'NOT LIKE', substr(NINJA_ACCOUNT_KEY, 0, 30) . '%');
})
->with('accounts')
->withCount('accounts')
->having('accounts_count', '>=', 1)
->first();
$user = $company->accounts->first()->users()->whereNull('public_id')->orWhere('public_id', 0)->first();
@ -71,10 +78,12 @@ class ForceMigration extends Command
$data['companies'][$key]['id'] = $account->id;
}
$this->dispatch(new HostedMigration($user, $data, $db, true));
$company->is_migrated = true;
$company->save();
}
}

View File

@ -443,6 +443,10 @@ trait GenerateMigrationResources
foreach($agts as $agt) {
$payment_method = $agt->default_payment_method;
if(!$payment_method)
continue;
$contact = Contact::where('id', $payment_method->contact_id)->withTrashed()->first();
$transformed[] = [
@ -1631,6 +1635,9 @@ trait GenerateMigrationResources
$contact = Contact::where('id', $payment_method->contact_id)->withTrashed()->first();
$agt = AccountGatewayToken::where('id', $payment_method->account_gateway_token_id)->withTrashed()->first();
if(!$contact && !$agt)
continue;
$transformed[] = [
'id' => $payment_method->id,
'company_id' => $this->account->id,

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddMigrationFlagForCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function ($table) {
$table->boolean('is_migrated')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}