diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e72bab..55834ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed + +- Prevent a crash on the service catalog page when plugin files are updated before the database schema migration is applied. + ## [1.14.0] - 2026-04-30 ### Added diff --git a/inc/alert.class.php b/inc/alert.class.php index a965f63..806e4b9 100644 --- a/inc/alert.class.php +++ b/inc/alert.class.php @@ -542,9 +542,21 @@ public static function displayOnTicket() public static function displayOnServiceCatalog() { + if (!self::hasServiceCatalogDisplayFlag()) { + return; + } + self::displayAlerts(['show_only_service_catalog_alerts' => true]); } + private static function hasServiceCatalogDisplayFlag(): bool + { + /** @var DBmysql $DB */ + global $DB; + + return $DB->fieldExists(self::getTable(), 'is_displayed_onservicecatalog'); + } + public static function displayAlerts($params = []) { /** @var array $CFG_GLPI */ diff --git a/setup.php b/setup.php index bde7b69..039dde8 100644 --- a/setup.php +++ b/setup.php @@ -42,8 +42,9 @@ function plugin_init_news() /** * @var array $PLUGIN_HOOKS * @var array $CFG_GLPI + * @var DBmysql $DB */ - global $PLUGIN_HOOKS, $CFG_GLPI; + global $PLUGIN_HOOKS, $CFG_GLPI, $DB; $PLUGIN_HOOKS['csrf_compliant']['news'] = true; @@ -62,9 +63,11 @@ function plugin_init_news() $PLUGIN_HOOKS['display_central']['news'] = [ 'PluginNewsAlert', 'displayOnCentral', ]; - $PLUGIN_HOOKS['display_service_catalog']['news'] = [ - 'PluginNewsAlert', 'displayOnServiceCatalog', - ]; + if ($DB->fieldExists(PluginNewsAlert::getTable(), 'is_displayed_onservicecatalog')) { + $PLUGIN_HOOKS['display_service_catalog']['news'] = [ + 'PluginNewsAlert', 'displayOnServiceCatalog', + ]; + } $PLUGIN_HOOKS['pre_item_list']['news'] = ['PluginNewsAlert', 'preItemList']; $PLUGIN_HOOKS['pre_item_form']['news'] = ['PluginNewsAlert', 'preItemForm'];