From 5ad41db0ce9a671b389746100fe476237c645cae Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 24 Jul 2021 10:30:41 +1000 Subject: [PATCH 1/4] Add is_migrated flag to companies table --- app/Console/Commands/ForceMigration.php | 1 + ...add_migration_flag_for_companies_table.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 database/migrations/2021_07_24_002820_add_migration_flag_for_companies_table.php diff --git a/app/Console/Commands/ForceMigration.php b/app/Console/Commands/ForceMigration.php index 1c99e08ac8a4..4b6ca8a24f4f 100644 --- a/app/Console/Commands/ForceMigration.php +++ b/app/Console/Commands/ForceMigration.php @@ -58,6 +58,7 @@ class ForceMigration extends Command $data = []; $company = Company::where('plan', 'free') + ->where('is_migrated', false) ->with('accounts') ->first(); 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() + { + // + } +} From 3671bcced5187884ca2988d1123c41669e4fff8f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 24 Jul 2021 10:33:07 +1000 Subject: [PATCH 2/4] MInor fixes --- app/Console/Commands/ForceMigration.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Console/Commands/ForceMigration.php b/app/Console/Commands/ForceMigration.php index 4b6ca8a24f4f..31e40f5f32c7 100644 --- a/app/Console/Commands/ForceMigration.php +++ b/app/Console/Commands/ForceMigration.php @@ -76,6 +76,9 @@ class ForceMigration extends Command } $this->dispatch(new HostedMigration($user, $data, $db, true)); + + $company->is_migrated = true; + $company->save(); } } From ba45d0b272f7fb25ee236e4709c514a432d1e41d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 25 Jul 2021 09:11:28 +1000 Subject: [PATCH 3/4] Checks for contact id --- app/Traits/GenerateMigrationResources.php | 7 +++++++ 1 file changed, 7 insertions(+) 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, From 1a4b9ddac6b96e752df478f407048b77daac1c11 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 25 Jul 2021 11:41:13 +1000 Subject: [PATCH 4/4] Fixes for forced migration --- app/Console/Commands/ForceMigration.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/ForceMigration.php b/app/Console/Commands/ForceMigration.php index 31e40f5f32c7..d18b52513ab1 100644 --- a/app/Console/Commands/ForceMigration.php +++ b/app/Console/Commands/ForceMigration.php @@ -57,10 +57,16 @@ class ForceMigration extends Command { $data = []; - $company = Company::where('plan', 'free') - ->where('is_migrated', false) - ->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; @@ -72,7 +78,6 @@ class ForceMigration extends Command $data['companies'][$key]['id'] = $account->id; - } $this->dispatch(new HostedMigration($user, $data, $db, true));