From b33df0746ef19302dbf8c261a2f5bb0f260a80f7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 20 Apr 2021 22:45:35 +1000 Subject: [PATCH] Check white label license periodically --- app/Http/Controllers/LicenseController.php | 12 ++++++++++++ app/Jobs/Util/VersionCheck.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/Http/Controllers/LicenseController.php b/app/Http/Controllers/LicenseController.php index 4549203ce4..d762b69c90 100644 --- a/app/Http/Controllers/LicenseController.php +++ b/app/Http/Controllers/LicenseController.php @@ -81,6 +81,7 @@ class LicenseController extends BaseController */ public function index() { + $this->checkLicense(); /* Catch claim license requests */ if (config('ninja.environment') == 'selfhost' && request()->has('license_key')) { @@ -140,4 +141,15 @@ class LicenseController extends BaseController return response()->json($error, 400); } + + private function checkLicense() + { + $account = auth()->user()->company()->account; + + if($account->plan == 'white_label' && $account->plan_expires->lt(now())){ + $account->plan = null; + $account->plan_expires = null; + $account->save(); + } + } } diff --git a/app/Jobs/Util/VersionCheck.php b/app/Jobs/Util/VersionCheck.php index 2d61275f0d..8348b984f6 100644 --- a/app/Jobs/Util/VersionCheck.php +++ b/app/Jobs/Util/VersionCheck.php @@ -12,6 +12,7 @@ namespace App\Jobs\Util; use App\Models\Account; +use App\Utils\Ninja; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -40,5 +41,16 @@ class VersionCheck implements ShouldQueue if ($version_file) { Account::whereNotNull('id')->update(['latest_version' => $version_file]); } + + if(Ninja::isSelfHost()) + { + $account = Account::first(); + + if($account->plan == 'white_label' && $account->plan_expires->lt(now())){ + $account->plan = null; + $account->plan_expires = null; + $account->save(); + } + } } }