From 76631a7f5953af9df3fba4d10cee97485e67bd4c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 30 Mar 2022 10:54:20 +1100 Subject: [PATCH] Hosted Migration Filtering --- app/Console/Commands/ExportMigrations.php | 1 + app/Http/Controllers/AppController.php | 7 ++++++- app/Http/Middleware/MigrationLookup.php | 17 ++++++++++++----- app/Jobs/HostedMigration.php | 2 +- config/ninja.php | 3 +++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/ExportMigrations.php b/app/Console/Commands/ExportMigrations.php index 65fe69c483..cc4d682552 100644 --- a/app/Console/Commands/ExportMigrations.php +++ b/app/Console/Commands/ExportMigrations.php @@ -99,6 +99,7 @@ class ExportMigrations extends Command private function export($user) { $this->account = $user->account; + Auth::login($user); $date = date('Y-m-d'); $accountKey = $this->account->account_key; diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index b5c7bb9f7f..19e33fe5a9 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -345,7 +345,12 @@ class AppController extends BaseController FROM information_schema.TABLES WHERE TABLE_NAME='clients' AND TABLE_SCHEMA='ninja'"); - if (count($result) && $result[0]->engine == 'InnoDB') { + if(property_exists($result[0], 'engine')) + $engine = $result[0]->engine; + else + $engine = $result[0]->ENGINE; + + if (count($result) && $engine == 'InnoDB') { return; } diff --git a/app/Http/Middleware/MigrationLookup.php b/app/Http/Middleware/MigrationLookup.php index aacc21abc0..f18b9199f1 100644 --- a/app/Http/Middleware/MigrationLookup.php +++ b/app/Http/Middleware/MigrationLookup.php @@ -11,6 +11,7 @@ use App\Models\LookupProposalInvitation; use App\Models\LookupAccountToken; use App\Models\LookupUser; use Auth; +use Illuminate\Support\Carbon; use Utils; class MigrationLookup @@ -21,9 +22,11 @@ class MigrationLookup return $next($request); } - - //need to wrap an additional block over this to funnel users in a particular range - + //need to wrap an additional block over this to funnel users in a particular range + if(auth()->user()->id >= config('ninja.migration_user_start') && + auth()->user()->id <= config('ninja.migration_user_end') && + (!auth()->user()->account->company->plan_expires || Carbon::parse(auth()->user()->account->company->plan_expires)->lt(now()))) + { if ($guard == 'user') { if(request()->is('migration/*') || request()->is('settings/*')) { @@ -32,10 +35,14 @@ class MigrationLookup } - } - return redirect('/settings/account_management'); + return redirect('/settings/account_management')->with('warning','V4 is now disabled for your account. Please migrate.'); + } + elseif(!auth()->user()->account->company->plan_expires || Carbon::parse(auth()->user()->account->company->plan_expires)->lt(now())){ + session()->flash('warning','Please consider migrating to V5, V4 has entered end of life.'); + } + return $next($request); } } diff --git a/app/Jobs/HostedMigration.php b/app/Jobs/HostedMigration.php index 26fd2e8e0d..7c0939c7f2 100644 --- a/app/Jobs/HostedMigration.php +++ b/app/Jobs/HostedMigration.php @@ -165,7 +165,7 @@ class HostedMigration extends Job $localMigrationData['force'] = array_key_exists('force', $company); Storage::makeDirectory('migrations'); - $file = Storage::path("migrations/{$fileName}.zip"); + $file = Storage::path("app/migrations/{$fileName}.zip"); //$file = storage_path("migrations/{$fileName}.zip"); diff --git a/config/ninja.php b/config/ninja.php index aeeece9de4..709bdaa573 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -48,5 +48,8 @@ return [ ], 'ninja_hosted_secret' => env('NINJA_HOSTED_SECRET', false), + 'migration_db' => env('MIGRATION_DB', DB_NINJA_1), + 'migration_user_start' => env('MIGRATION_USER_START', 1), + 'migration_user_end' => env('MIGRATION_USER_END', 1000), ];