From 37c7ec426568dd04f00479bbf2f2f0f3b0c53edd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 23 Jul 2021 08:24:00 +1000 Subject: [PATCH 1/4] Update export migrations --- app/Console/Commands/ExportMigrations.php | 34 +++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/ExportMigrations.php b/app/Console/Commands/ExportMigrations.php index 536c23a354..dfdc295eed 100644 --- a/app/Console/Commands/ExportMigrations.php +++ b/app/Console/Commands/ExportMigrations.php @@ -17,7 +17,7 @@ class ExportMigrations extends Command * * @var string */ - protected $signature = 'migrations:export {--user=} {--random=}'; + protected $signature = 'migrations:export {--user=} {--email=} {--random=}'; /** * The console command description. @@ -46,8 +46,36 @@ class ExportMigrations extends Command $this->info('Note: Migrations will be stored inside of (storage/migrations) folder.'); if($this->option('user')) { - $record = User::findOrFail($this->option('user')); - return $this->export($record); + $record = User::on(DB_NINJA_1)->find($this->option('user')); + + if($record) + return $this->export($record); + + $record = User::on(DB_NINJA_2)->find($this->option('user')); + + if($record) + return $this->export($record); + + + $this->info('I could not find that user - sorry'); + return; + } + + + if($this->option('email')) { + $record = User::on(DB_NINJA_1)->where('email', $this->option('user'))->first(); + + if($record) + return $this->export($record); + + $record = User::on(DB_NINJA_2)->where('email', $this->option('user'))->first(); + + if($record) + return $this->export($record); + + + $this->info('I could not find that user by email - sorry'); + return; } if($this->option('random')){ From e25c6b8ee2b2d793218260a98e8639f9289496d5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 23 Jul 2021 09:37:08 +1000 Subject: [PATCH 2/4] Forced Migration --- app/Console/Commands/ForceMigration.php | 81 +++++++++++++++++++++++++ app/Console/Kernel.php | 7 ++- app/Jobs/HostedMigration.php | 16 ++++- 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 app/Console/Commands/ForceMigration.php diff --git a/app/Console/Commands/ForceMigration.php b/app/Console/Commands/ForceMigration.php new file mode 100644 index 0000000000..1c99e08ac8 --- /dev/null +++ b/app/Console/Commands/ForceMigration.php @@ -0,0 +1,81 @@ + 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)); + } + + } +} \ No newline at end of file diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 617e3929ab..0bf4611c82 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -64,7 +64,12 @@ class Kernel extends ConsoleKernel ->command('ninja:sync-v5') ->withoutOverlapping() ->daily(); - + + + // $schedule + // ->command('ninja:force-migrate-v5') + // ->everyMinute() + // ->withoutOverlapping(); } } } diff --git a/app/Jobs/HostedMigration.php b/app/Jobs/HostedMigration.php index e0725dbdf6..c63ec9052e 100644 --- a/app/Jobs/HostedMigration.php +++ b/app/Jobs/HostedMigration.php @@ -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; From e58e6b39806cfd848acd3e7706a9231a10c125bf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 23 Jul 2021 14:38:55 +1000 Subject: [PATCH 3/4] Forced Migratoin --- app/Jobs/HostedMigration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Jobs/HostedMigration.php b/app/Jobs/HostedMigration.php index c63ec9052e..4eb2873630 100644 --- a/app/Jobs/HostedMigration.php +++ b/app/Jobs/HostedMigration.php @@ -114,10 +114,10 @@ class HostedMigration extends Job //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->account_email_settings->forward_url_for_v5 = "https://invoiceninja-{$this->account->id}.invoicing.co"; $account_email_settings->save(); - $this->account->subdomain = "ninja_user{$this->account->id}"; + $this->account->subdomain = "invoiceninja-{$this->account->id}"; } $date = date('Y-m-d'); From 97271449ed85c87f3f26e2c552ac5e0d9cd5cbf5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 24 Jul 2021 08:32:46 +1000 Subject: [PATCH 4/4] Fixes for min max limits on migration --- app/Traits/GenerateMigrationResources.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 23b23b109e..08e01bfe66 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -2015,8 +2015,8 @@ trait GenerateMigrationResources } $fees_and_limits = new \stdClass(); - $fees_and_limits->min_limit = $ags->min_limit; - $fees_and_limits->max_limit = $ags->max_limit; + $fees_and_limits->min_limit = $ags->min_limit ?: -1; + $fees_and_limits->max_limit = $ags->max_limit ?: -1; $fees_and_limits->fee_amount = $ags->fee_amount; $fees_and_limits->fee_percent = $ags->fee_percent; $fees_and_limits->fee_tax_name1 = $ags->tax_name1;