From 1d085820cf12a1e583aef2a147ba8a6d4d389022 Mon Sep 17 00:00:00 2001 From: Rom1-B <8530352+Rom1-B@users.noreply.github.com> Date: Thu, 21 May 2026 14:26:17 +0200 Subject: [PATCH] Fix(dashboard): reject invalid reports_id when adding a widget --- CHANGELOG.md | 6 ++++++ front/dashboard.form.php | 8 +++++--- hook.php | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d9cc5d0..1b0f3317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Fixed + +- Fix dashboard crash when adding a report without selecting one (invalid `reports_id` value) + ## [1.9.5] - 2026-05-12 ### Fixed diff --git a/front/dashboard.form.php b/front/dashboard.form.php index 82d7929d..eb9d417c 100644 --- a/front/dashboard.form.php +++ b/front/dashboard.form.php @@ -44,9 +44,11 @@ Html::back(); } elseif (isset($_POST['addReports'])) { - $dashboard = new PluginMreportingDashboard(); - $post = ['users_id' => $_SESSION['glpiID'], 'reports_id' => $_POST['report']]; - $dashboard->add($post); + $report_id = (int) ($_POST['report'] ?? 0); + if ($report_id > 0) { + $dashboard = new PluginMreportingDashboard(); + $dashboard->add(['users_id' => $_SESSION['glpiID'], 'reports_id' => $report_id]); + } Html::back(); } else { diff --git a/hook.php b/hook.php index 8727f7bb..6274bd85 100644 --- a/hook.php +++ b/hook.php @@ -238,6 +238,16 @@ function plugin_mreporting_install() $migration->addField('glpi_plugin_mreporting_preferences', 'selectors', 'text'); $migration->migrationOneTable('glpi_plugin_mreporting_preferences'); + // == Fix dashboard entries with invalid reports_id (e.g. -1 from empty dropdown selection) + $DB->delete('glpi_plugin_mreporting_dashboards', ['reports_id' => ['<=', 0]]); + $migration->changeField( + 'glpi_plugin_mreporting_dashboards', + 'reports_id', + 'reports_id', + "int {$default_key_sign} NOT NULL", + ); + $migration->migrationOneTable('glpi_plugin_mreporting_dashboards'); + // == Init available reports require_once __DIR__ . '/inc/baseclass.class.php'; require_once __DIR__ . '/inc/common.class.php';