From e56846131ff59855d1c11a86686b106ecd626c42 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 28 Jun 2021 15:15:02 +1000 Subject: [PATCH] Sync Accounts between v4 and v5 --- app/Console/Commands/ExportMigrations.php | 1 + app/Console/Commands/SyncAccounts.php | 82 +++++++++++++++++++++++ app/Console/Kernel.php | 12 ++++ app/Constants.php | 2 + 4 files changed, 97 insertions(+) create mode 100644 app/Console/Commands/SyncAccounts.php diff --git a/app/Console/Commands/ExportMigrations.php b/app/Console/Commands/ExportMigrations.php index 8e8f086689..536c23a354 100644 --- a/app/Console/Commands/ExportMigrations.php +++ b/app/Console/Commands/ExportMigrations.php @@ -101,6 +101,7 @@ class ExportMigrations extends Command 'expenses' => $this->getExpenses(), 'tasks' => $this->getTasks(), 'documents' => $this->getDocuments(), + 'ninja_tokens' => $this->getNinjaToken(), ]; $file = storage_path("migrations/{$fileName}.zip"); diff --git a/app/Console/Commands/SyncAccounts.php b/app/Console/Commands/SyncAccounts.php new file mode 100644 index 0000000000..4832f2edcb --- /dev/null +++ b/app/Console/Commands/SyncAccounts.php @@ -0,0 +1,82 @@ + DB_NINJA_1]); + + $this->updateAccounts(); + + config(['database.default' => DB_NINJA_2]); + + $this->updateAccounts(); + + } + + private function updateAccounts() + { + $data = []; + + $a = Company::whereIn('plan', ['pro', 'enterprise']) + ->with('accounts') + ->chunk(100)->each(function ($company) use ($data){ + + $accounts = $company->accounts->pluck('account_key'); + + $data[] = [ + 'plan' => $company->plan, + 'plan_term' => $company->plan_term, + 'plan_started' => $company->plan_started, + 'plan_paid' => $company->plan_paid, + 'plan_expires' => $company->plan_expires, + 'num_users' => $company->num_users, + 'accounts' => $accounts + ]; + + }); + + //post DATA + } +} \ No newline at end of file diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 19250788a6..6ba769617d 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,6 +2,7 @@ namespace App\Console; +use App\Libraries\Utils; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Utils; @@ -32,6 +33,7 @@ class Kernel extends ConsoleKernel 'App\Console\Commands\CalculatePayouts', 'App\Console\Commands\UpdateKey', 'App\Console\Commands\ExportMigrations', + 'App\Console\Commands\SyncAccounts', ]; /** @@ -55,5 +57,15 @@ class Kernel extends ConsoleKernel ->command('ninja:send-reminders --force') ->sendOutputTo($logFile) ->daily(); + + if(Utils::isNinjaProd()) + { + + $schedule + ->command('ninja:sync-v5') + ->withoutOverlapping() + ->daily(); + + } } } diff --git a/app/Constants.php b/app/Constants.php index a0c03b8f3f..13d0be48c5 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -631,6 +631,8 @@ if (! defined('APP_NAME')) { define('INVOICE_FIELDS_PRODUCT', 'product_fields'); define('INVOICE_FIELDS_TASK', 'task_fields'); + define('NINJA_V5_TOKEN', env('NINJA_V5_TOKEN',false)); + $creditCards = [ 1 => ['card' => 'images/credit_cards/Test-Visa-Icon.png', 'text' => 'Visa'], 2 => ['card' => 'images/credit_cards/Test-MasterCard-Icon.png', 'text' => 'Master Card'],