From 73bd0522d4f23fb398524f524e846418e8a54d76 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 23 Apr 2023 20:46:38 +0200 Subject: [PATCH] fix nullsafe warnings --- _define.php | 4 ++-- src/Backend.php | 13 ++++++++----- src/BackendBehaviors.php | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/_define.php b/_define.php index d792d4d..51694f5 100644 --- a/_define.php +++ b/_define.php @@ -10,7 +10,7 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_RC_PATH')) { +if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) { return null; } @@ -22,7 +22,7 @@ $this->registerModule( [ 'requires' => [['core', '2.25']], 'permissions' => dcCore::app()->auth->makePermissions([ - dcAuth::PERMISSION_ADMIN, + dcCore::app()->auth::PERMISSION_ADMIN, ]), 'type' => 'plugin', 'support' => 'https://github.com/JcDenis/' . basename(__DIR__), diff --git a/src/Backend.php b/src/Backend.php index ad09acd..93ce456 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\postslistOptions; use ArrayObject; -use dcAuth; use dcCore; use dcNsProcess; use dcPostsActions; @@ -29,10 +28,14 @@ class Backend extends dcNsProcess { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->check( - dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), - dcCore::app()->blog->id - ); + static::$init = defined('DC_CONTEXT_ADMIN') + && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) + && dcCore::app()->auth->check( + dcCore::app()->auth->makePermissions([ + dcCore::app()->auth::PERMISSION_ADMIN, + ]), + dcCore::app()->blog->id + ); return static::$init; } diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 24bfd93..6fe0f6f 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -51,6 +51,11 @@ class BackendBehaviors public static function commentsDelete(dcPostsActions $pa, ArrayObject $post): void { + //nullsafe + if (is_null(dcCore::app()->blog)) { + return; + } + $ids = self::getPostsIds($pa); if (empty($_POST['confirmdeletecomments'])) { @@ -108,6 +113,11 @@ class BackendBehaviors public static function trackbacksDelete(dcPostsActions $pa, ArrayObject $post): void { + //nullsafe + if (is_null(dcCore::app()->blog)) { + return; + } + $ids = self::getPostsIds($pa); if (empty($_POST['confirmdeletetrackbacks'])) { @@ -157,6 +167,11 @@ class BackendBehaviors private static function updPostOption(int $id, string $option, int $value): void { + //nullsafe + if (is_null(dcCore::app()->blog)) { + return; + } + $id = abs((int) $id); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME); @@ -172,6 +187,11 @@ class BackendBehaviors private static function delPostComments(int $id, bool $tb = false): void { + //nullsafe + if (is_null(dcCore::app()->blog)) { + return; + } + $params = [ 'no_content' => true, 'post_id' => abs((int) $id),