fix nullsafe warnings

This commit is contained in:
Jean-Christian Paul Denis 2023-04-23 22:44:18 +02:00
parent 1b1ea26327
commit 28ccb5fd0c
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 22 additions and 2 deletions

View File

@ -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_CONTENT_ADMIN,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]),
'type' => 'plugin',
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=333002#p333002',

View File

@ -114,6 +114,11 @@ class BackendBehaviors
public static function adminAfterDashboardOptionsUpdate(?string $user_id): void
{
// nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
return;
}
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsItems',
!empty($_POST['topWriterPostsItems']),
@ -149,6 +154,11 @@ class BackendBehaviors
private static function setDefaultPref(): array
{
// nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
return [];
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsItems')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put(
'topWriterPostsItems',

View File

@ -24,6 +24,11 @@ class Utils
{
public static function posts(string $period, int $limit, bool $sort_desc = true): array
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
return [];
}
$req = 'SELECT COUNT(*) AS count, U.user_id ' .
'FROM ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' .
'INNER JOIN ' . dcCore::app()->prefix . dcAuth::USER_TABLE_NAME . ' U ON U.user_id = P.user_id ' .
@ -82,6 +87,11 @@ class Utils
public static function comments(string $period, int $limit, bool $sort_desc = true, bool $exclude = false): array
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
return [];
}
$req = 'SELECT COUNT(*) AS count, comment_email ' .
'FROM ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P, ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' .
'WHERE P.post_id=C.post_id ' .