fix nullsafe warnings

master
Jean-Christian Paul Denis 2023-04-23 20:46:38 +02:00
parent 1d1156d438
commit 73bd0522d4
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 30 additions and 7 deletions

View File

@ -10,7 +10,7 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @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; return null;
} }
@ -22,7 +22,7 @@ $this->registerModule(
[ [
'requires' => [['core', '2.25']], 'requires' => [['core', '2.25']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN, dcCore::app()->auth::PERMISSION_ADMIN,
]), ]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/' . basename(__DIR__), 'support' => 'https://github.com/JcDenis/' . basename(__DIR__),

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postslistOptions; namespace Dotclear\Plugin\postslistOptions;
use ArrayObject; use ArrayObject;
use dcAuth;
use dcCore; use dcCore;
use dcNsProcess; use dcNsProcess;
use dcPostsActions; use dcPostsActions;
@ -29,8 +28,12 @@ class Backend extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->check( static::$init = defined('DC_CONTEXT_ADMIN')
dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_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 dcCore::app()->blog->id
); );

View File

@ -51,6 +51,11 @@ class BackendBehaviors
public static function commentsDelete(dcPostsActions $pa, ArrayObject $post): void public static function commentsDelete(dcPostsActions $pa, ArrayObject $post): void
{ {
//nullsafe
if (is_null(dcCore::app()->blog)) {
return;
}
$ids = self::getPostsIds($pa); $ids = self::getPostsIds($pa);
if (empty($_POST['confirmdeletecomments'])) { if (empty($_POST['confirmdeletecomments'])) {
@ -108,6 +113,11 @@ class BackendBehaviors
public static function trackbacksDelete(dcPostsActions $pa, ArrayObject $post): void public static function trackbacksDelete(dcPostsActions $pa, ArrayObject $post): void
{ {
//nullsafe
if (is_null(dcCore::app()->blog)) {
return;
}
$ids = self::getPostsIds($pa); $ids = self::getPostsIds($pa);
if (empty($_POST['confirmdeletetrackbacks'])) { if (empty($_POST['confirmdeletetrackbacks'])) {
@ -157,6 +167,11 @@ class BackendBehaviors
private static function updPostOption(int $id, string $option, int $value): void private static function updPostOption(int $id, string $option, int $value): void
{ {
//nullsafe
if (is_null(dcCore::app()->blog)) {
return;
}
$id = abs((int) $id); $id = abs((int) $id);
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME); $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 private static function delPostComments(int $id, bool $tb = false): void
{ {
//nullsafe
if (is_null(dcCore::app()->blog)) {
return;
}
$params = [ $params = [
'no_content' => true, 'no_content' => true,
'post_id' => abs((int) $id), 'post_id' => abs((int) $id),