From d44eade7995faf6f87f5fa835dd7f474a7d8a260 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 20 Apr 2023 22:39:11 +0200 Subject: [PATCH] cosmetic nullsafe fix --- src/Backend.php | 15 +++++++++++++++ src/Install.php | 5 +++++ src/Widgets.php | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/src/Backend.php b/src/Backend.php index e7123af..6ef163c 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -43,6 +43,11 @@ class Backend extends dcNsProcess dcCore::app()->addBehaviors([ 'initWidgets' => [Widgets::class, 'initWidgets'], 'adminDashboardItemsV2' => function (ArrayObject $__dashboard_items): void { + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs) || is_null(dcCore::app()->blog)) { + return; + } + if (!dcCore::app()->auth->user_prefs->get('dashboard')->get('dcLatestVersionsItems')) { return; } @@ -92,6 +97,11 @@ class Backend extends dcNsProcess }, 'adminDashboardOptionsFormV2' => function (): void { + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { + return; + } + if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('dcLatestVersionsItems')) { dcCore::app()->auth->user_prefs->get('dashboard')->put( 'dcLatestVersionsItems', @@ -111,6 +121,11 @@ class Backend extends dcNsProcess }, 'adminAfterDashboardOptionsUpdate' => function (?string $user_id): void { + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { + return; + } + dcCore::app()->auth->user_prefs->get('dashboard')->put( 'dcLatestVersionsItems', !empty($_POST['dcLatestVersionsItems']), diff --git a/src/Install.php b/src/Install.php index 6580f57..64f5d7a 100644 --- a/src/Install.php +++ b/src/Install.php @@ -33,6 +33,11 @@ class Install extends dcNsProcess return false; } + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->blog)) { + return false; + } + dcCore::app()->blog->settings->get(My::id())->put( 'builds', 'stable,unstable,testing', diff --git a/src/Widgets.php b/src/Widgets.php index 3438273..ad820d8 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -53,6 +53,11 @@ class Widgets return ''; } + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->blog)) { + return ''; + } + # Builds to check $builds = explode(',', (string) dcCore::app()->blog->settings->get(My::id())->get('builds')); if (empty($builds[0])) {