diff --git a/app/Console/Commands/ForceMigration.php b/app/Console/Commands/ForceMigration.php index 1c99e08ac8a4..d18b52513ab1 100644 --- a/app/Console/Commands/ForceMigration.php +++ b/app/Console/Commands/ForceMigration.php @@ -57,9 +57,16 @@ class ForceMigration extends Command { $data = []; - $company = Company::where('plan', 'free') - ->with('accounts') - ->first(); + $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(); $db = DB_NINJA_1; @@ -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(); } } diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 08e01bfe6667..1d25e554bcb3 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -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, diff --git a/database/migrations/2021_07_24_002820_add_migration_flag_for_companies_table.php b/database/migrations/2021_07_24_002820_add_migration_flag_for_companies_table.php new file mode 100644 index 000000000000..c7b35f2bb384 --- /dev/null +++ b/database/migrations/2021_07_24_002820_add_migration_flag_for_companies_table.php @@ -0,0 +1,30 @@ +boolean('is_migrated')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}