From 08999d08cdd25ee19bc9fef1f198d48f7a03f676 Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Thu, 4 Dec 2025 21:11:24 +0100 Subject: [PATCH] feat(sales): add sales feature toggle --- .env.example | 4 ++++ app/Http/Controllers/SaleController.php | 18 ++++++++++++------ config/sales.php | 17 +++++++++++++++++ resources/views/sales/index.blade.php | 11 ++++++++++- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 config/sales.php diff --git a/.env.example b/.env.example index 9715a3a..91ba170 100644 --- a/.env.example +++ b/.env.example @@ -87,3 +87,7 @@ VITE_PUSHER_HOST="${PUSHER_HOST}" VITE_PUSHER_PORT="${PUSHER_PORT}" VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +# Enable or disable fetching live Sale Rotation data from the external API. +# Set to true to enable fetching, false to show the maintenance message. +SALES_ENABLED=false diff --git a/app/Http/Controllers/SaleController.php b/app/Http/Controllers/SaleController.php index 4ccf6c8..3f8d5c1 100644 --- a/app/Http/Controllers/SaleController.php +++ b/app/Http/Controllers/SaleController.php @@ -4,24 +4,29 @@ namespace App\Http\Controllers; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; class SaleController extends Controller { public function index() { + // If the feature toggle is disabled, do not attempt to fetch sales data and return the maintenance view. + if (!config('sales.enabled')) { + return view('sales.index'); + } + try { $sales = Cache::remember('sales_data', 60 * 60 * 8, static function () { $lmi_api_key = config('services.lmi.api_key'); $response = Http::withHeaders([ - 'Authorization' => 'Bearer '.$lmi_api_key, + 'Authorization' => 'Bearer ' . $lmi_api_key, ])->get('https://lmi.orianna.dev/api/lol-sales'); $response = $response->json(); - if ($response['champion_sales'] === null) { - logger()->error('LMI has broken'); - + if (! isset($response['champion_sales']) || $response['champion_sales'] === null) { + Log::error('LMI has broken'); return abort(503, 'Trying to access array offset on value of type null'); } @@ -29,14 +34,15 @@ class SaleController extends Controller }); } catch (\Exception $exception) { if ($exception->getMessage() === 'Trying to access array offset on value of type null') { - logger()->error('LMI has broken'); + Log::error('LMI has broken'); abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.'); } else { - logger()->error('An error occurred while trying to fetch the Sale Rotation', ['error' => $exception->getMessage()]); + Log::error('An error occurred while trying to fetch the Sale Rotation', ['error' => $exception->getMessage()]); abort(500, 'Sorry, an error occurred while trying to fetch the Sale Rotation. Please try again later.'); } } return view('sales.index', ['sales' => $sales]); } + } diff --git a/config/sales.php b/config/sales.php new file mode 100644 index 0000000..99236e8 --- /dev/null +++ b/config/sales.php @@ -0,0 +1,17 @@ + env('SALES_ENABLED', false), +]; diff --git a/resources/views/sales/index.blade.php b/resources/views/sales/index.blade.php index 605d86f..ba75475 100644 --- a/resources/views/sales/index.blade.php +++ b/resources/views/sales/index.blade.php @@ -6,6 +6,15 @@ and skins are currently on sale and grab a good deal!') @section('content') - + @isset($sales) + + @else +
+

+ Sale Rotation

+

Sale Rotation is currently under construction due to breaking changes. We are sorry

+
+ @endisset @endsection