From 791728c509bc4cac11bbf005b7d6de0b8099c93a Mon Sep 17 00:00:00 2001 From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:44:38 +0100 Subject: [PATCH 1/2] Feat(core): add GLPI 13 compatibility --- .github/workflows/continuous-integration.yml | 6 ++--- CHANGELOG.md | 1 + composer.json | 4 +-- composer.lock | 8 +++--- setup.php | 4 +-- ...rtFormcreatorActorsNotificationCommand.php | 26 +++++++++---------- src/Controller/GetReservationsController.php | 2 +- .../AccessControl/LanguageAccessControl.php | 4 +-- .../LanguageAccessControlConfig.php | 2 +- .../Destination/ActorNotificationField.php | 4 +-- .../ActorNotificationFieldConfig.php | 8 +++--- .../Destination/PreReservationFieldConfig.php | 6 ++--- src/Model/QuestionType/GlpiScopeQuestion.php | 6 ++--- src/Model/QuestionType/LdapQuestionConfig.php | 6 ++--- .../QuestionType/ReservationQuestion.php | 2 +- .../ReservationQuestionConfig.php | 4 +-- .../QuestionType/TableQuestionConfig.php | 12 ++++----- .../TreeCascadeDropdownQuestion.php | 2 +- src/Model/TicketReservationRequest.php | 12 ++++----- src/Service/InstallManager.php | 2 +- src/Service/LatestVersionProvider.php | 16 ++++++------ src/Service/SystemInfoParser.php | 10 +++---- ...rmcreatorActorsNotificationCommandTest.php | 6 ++--- .../TableQuestionRenderingTest.php | 2 +- .../TreeCascadeDropdownQuestionTest.php | 2 +- tests/Service/LatestVersionProviderTest.php | 6 ++--- tests/SystemInfoSamples.php | 6 ++--- 27 files changed, 85 insertions(+), 84 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 737b224..d27a969 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -23,16 +23,16 @@ permissions: jobs: generate-ci-matrix: name: "Generate CI matrix" - uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1" + uses: "stonebuzz/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@glpi13" with: - glpi-version: "12.0.x" + glpi-version: "13.0.x" ci: name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" needs: "generate-ci-matrix" strategy: fail-fast: false matrix: ${{ fromJson(needs.generate-ci-matrix.outputs.matrix) }} - uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1" + uses: "stonebuzz/plugin-ci-workflows/.github/workflows/continuous-integration.yml@glpi13" with: plugin-key: "advancedforms" glpi-version: "${{ matrix.glpi-version }}" diff --git a/CHANGELOG.md b/CHANGELOG.md index e6a0cb0..76ece3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - "Email followup" destination field to disable the followup per actor source, with a command to import it from Formcreator - Add "Allow specific languages" form access policy - Add "GLPI system information" and "GLPI core or plugins concerned" question types +- GLPI 13 compatibility ### Fixed diff --git a/composer.json b/composer.json index e6e21ab..22913ec 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { "require": { - "php": ">=8.2" + "php": ">=8.3" }, "config": { "autoloader-suffix": "PluginAdvancedforms", "optimize-autoloader": true, "platform": { - "php": "8.2.99" + "php": "8.3.99" }, "sort-packages": true } diff --git a/composer.lock b/composer.lock index e798ec8..69bc854 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4cacb822b12bf0d2a0dbcf952b20ef7b", + "content-hash": "54a9e05eb80da25a64cceb19515ba411", "packages": [], "packages-dev": [], "aliases": [], @@ -13,11 +13,11 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=8.2" + "php": ">=8.3" }, "platform-dev": {}, "platform-overrides": { - "php": "8.2.99" + "php": "8.3.99" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.11.0" } diff --git a/setup.php b/setup.php index a33e426..62cabfb 100644 --- a/setup.php +++ b/setup.php @@ -40,11 +40,11 @@ // Minimal GLPI version, inclusive /** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */ -define("PLUGIN_ADVANCEDFORMS_MIN_GLPI_VERSION", "12.0.0"); +define("PLUGIN_ADVANCEDFORMS_MIN_GLPI_VERSION", "13.0.0"); // Maximum GLPI version, exclusive /** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */ -define("PLUGIN_ADVANCEDFORMS_MAX_GLPI_VERSION", "12.0.99"); +define("PLUGIN_ADVANCEDFORMS_MAX_GLPI_VERSION", "13.0.99"); /** * Init hooks of the plugin. diff --git a/src/Console/ImportFormcreatorActorsNotificationCommand.php b/src/Console/ImportFormcreatorActorsNotificationCommand.php index 8e3d21b..dccc81d 100644 --- a/src/Console/ImportFormcreatorActorsNotificationCommand.php +++ b/src/Console/ImportFormcreatorActorsNotificationCommand.php @@ -67,42 +67,42 @@ final class ImportFormcreatorActorsNotificationCommand extends AbstractCommand { /** One config row per imported destination */ - public const IMPORTED_DESTINATIONS_CONFIG_CONTEXT = 'advancedforms:formcreator_actors_notification'; + public const string IMPORTED_DESTINATIONS_CONFIG_CONTEXT = 'advancedforms:formcreator_actors_notification'; - private const ACTORS_TABLE = 'glpi_plugin_formcreator_targets_actors'; + private const string ACTORS_TABLE = 'glpi_plugin_formcreator_targets_actors'; - private const FORMS_TABLE = 'glpi_plugin_formcreator_forms'; + private const string FORMS_TABLE = 'glpi_plugin_formcreator_forms'; - private const QUESTIONS_TABLE = 'glpi_plugin_formcreator_questions'; + private const string QUESTIONS_TABLE = 'glpi_plugin_formcreator_questions'; /** Formcreator target itemtype => [target table, destination type] */ - private const TARGETS = [ + private const array TARGETS = [ 'PluginFormcreatorTargetTicket' => ['glpi_plugin_formcreator_targettickets', FormDestinationTicket::class], 'PluginFormcreatorTargetChange' => ['glpi_plugin_formcreator_targetchanges', FormDestinationChange::class], 'PluginFormcreatorTargetProblem' => ['glpi_plugin_formcreator_targetproblems', FormDestinationProblem::class], ]; /** PluginFormcreatorTarget_Actor::ACTOR_ROLE_* => actor role */ - private const ROLES = [ + private const array ROLES = [ 1 => 'requester', 2 => 'observer', 3 => 'assign', ]; // PluginFormcreatorTarget_Actor::ACTOR_TYPE_* having an email followup - private const ACTOR_TYPE_CREATOR = 1; + private const int ACTOR_TYPE_CREATOR = 1; - private const ACTOR_TYPE_PERSON = 3; + private const int ACTOR_TYPE_PERSON = 3; - private const ACTOR_TYPE_QUESTION_PERSON = 4; + private const int ACTOR_TYPE_QUESTION_PERSON = 4; - private const ACTOR_TYPE_SUPPLIER = 7; + private const int ACTOR_TYPE_SUPPLIER = 7; - private const ACTOR_TYPE_QUESTION_SUPPLIER = 8; + private const int ACTOR_TYPE_QUESTION_SUPPLIER = 8; - private const ACTOR_TYPE_QUESTION_ACTORS = 9; + private const int ACTOR_TYPE_QUESTION_ACTORS = 9; - private const QUESTION_ACTOR_TYPES = [ + private const array QUESTION_ACTOR_TYPES = [ self::ACTOR_TYPE_QUESTION_PERSON, self::ACTOR_TYPE_QUESTION_SUPPLIER, self::ACTOR_TYPE_QUESTION_ACTORS, diff --git a/src/Controller/GetReservationsController.php b/src/Controller/GetReservationsController.php index ac750a9..3620335 100644 --- a/src/Controller/GetReservationsController.php +++ b/src/Controller/GetReservationsController.php @@ -61,7 +61,7 @@ public function __invoke(Request $request): Response // No lower bound given by the caller: only return current/future slots, // never the item's whole reservation history. - $now = $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s'); + $now = \Session::getCurrentTime() ?? date('Y-m-d H:i:s'); $where = [ 'reservationitems_id' => $reservationitems_id, 'end' => ['>', $begin !== '' ? $begin : $now], diff --git a/src/Model/AccessControl/LanguageAccessControl.php b/src/Model/AccessControl/LanguageAccessControl.php index 80a66f3..20275ac 100644 --- a/src/Model/AccessControl/LanguageAccessControl.php +++ b/src/Model/AccessControl/LanguageAccessControl.php @@ -49,7 +49,7 @@ final class LanguageAccessControl implements ControlTypeInterface { - public const INPUT_NAME = '_advancedforms_languages'; + public const string INPUT_NAME = '_advancedforms_languages'; #[Override] public function getLabel(): string @@ -134,7 +134,7 @@ public function canAnswer( // Deny (not Abstain) so the language restricts every other policy: // "All users" + this policy means "all users using a listed language". - $language = $_SESSION['glpilanguage'] ?? null; + $language = \Session::getLanguage(); if (!in_array($language, $config->getLanguages(), true)) { return AccessVote::Deny; } diff --git a/src/Model/AccessControl/LanguageAccessControlConfig.php b/src/Model/AccessControl/LanguageAccessControlConfig.php index 8200f89..f8a8e9d 100644 --- a/src/Model/AccessControl/LanguageAccessControlConfig.php +++ b/src/Model/AccessControl/LanguageAccessControlConfig.php @@ -38,7 +38,7 @@ final readonly class LanguageAccessControlConfig implements JsonFieldInterface { - public const KEY_LANGUAGES = 'languages'; + public const string KEY_LANGUAGES = 'languages'; /** @param string[] $languages GLPI language codes (see LanguageRegistry) */ public function __construct( diff --git a/src/Model/Destination/ActorNotificationField.php b/src/Model/Destination/ActorNotificationField.php index b97b5e7..47f74d8 100644 --- a/src/Model/Destination/ActorNotificationField.php +++ b/src/Model/Destination/ActorNotificationField.php @@ -74,7 +74,7 @@ final class ActorNotificationField extends AbstractConfigField { /** Strategies with a single toggle for all the actors they find. */ - private const STRATEGY_LEVEL_SOURCES = [ + private const array STRATEGY_LEVEL_SOURCES = [ ITILActorFieldStrategy::FORM_FILLER, ITILActorFieldStrategy::FORM_FILLER_SUPERVISOR, ITILActorFieldStrategy::LAST_VALID_ANSWER, @@ -83,7 +83,7 @@ final class ActorNotificationField extends AbstractConfigField ]; /** Groups have no email followup on an ITIL object. */ - private const NOTIFIABLE_ITEMTYPES = [User::class, Supplier::class]; + private const array NOTIFIABLE_ITEMTYPES = [User::class, Supplier::class]; #[Override] public function getLabel(): string diff --git a/src/Model/Destination/ActorNotificationFieldConfig.php b/src/Model/Destination/ActorNotificationFieldConfig.php index bc49451..7e65535 100644 --- a/src/Model/Destination/ActorNotificationFieldConfig.php +++ b/src/Model/Destination/ActorNotificationFieldConfig.php @@ -51,13 +51,13 @@ #[HasFieldWithQuestionId(self::DISABLED_QUESTION_IDS, is_array: true, list_of_strategies_field: self::ROLES)] final class ActorNotificationFieldConfig implements JsonFieldInterface { - public const ROLES = 'roles'; + public const string ROLES = 'roles'; - public const DISABLED_STRATEGIES = 'disabled_strategies'; + public const string DISABLED_STRATEGIES = 'disabled_strategies'; - public const DISABLED_ACTORS = 'disabled_actors'; + public const string DISABLED_ACTORS = 'disabled_actors'; - public const DISABLED_QUESTION_IDS = 'disabled_question_ids'; + public const string DISABLED_QUESTION_IDS = 'disabled_question_ids'; /** @var array */ private array $actors_configs = []; diff --git a/src/Model/Destination/PreReservationFieldConfig.php b/src/Model/Destination/PreReservationFieldConfig.php index 0fbce0e..7245db5 100644 --- a/src/Model/Destination/PreReservationFieldConfig.php +++ b/src/Model/Destination/PreReservationFieldConfig.php @@ -41,11 +41,11 @@ #[HasFieldWithQuestionId(self::SPECIFIC_QUESTION_ID)] final readonly class PreReservationFieldConfig implements JsonFieldInterface, ConfigFieldWithStrategiesInterface { - public const STRATEGY = 'strategy'; + public const string STRATEGY = 'strategy'; - public const SPECIFIC_QUESTION_ID = 'specific_question_id'; + public const string SPECIFIC_QUESTION_ID = 'specific_question_id'; - public const REQUIRE_APPROVAL = 'require_approval'; + public const string REQUIRE_APPROVAL = 'require_approval'; public function __construct( private PreReservationFieldStrategy $strategy, diff --git a/src/Model/QuestionType/GlpiScopeQuestion.php b/src/Model/QuestionType/GlpiScopeQuestion.php index 19915c6..1eaa1a5 100644 --- a/src/Model/QuestionType/GlpiScopeQuestion.php +++ b/src/Model/QuestionType/GlpiScopeQuestion.php @@ -56,11 +56,11 @@ final class GlpiScopeQuestion extends AbstractQuestionType implements ConfigurableItemInterface, QuestionTypeValidationInterface { - public const CORE_VALUE = 'GLPI'; + public const string CORE_VALUE = 'GLPI'; - private const MAX_VALUES = 50; + private const int MAX_VALUES = 50; - private const MAX_VALUE_LENGTH = 255; + private const int MAX_VALUE_LENGTH = 255; #[Override] public function getCategory(): QuestionTypeCategoryInterface diff --git a/src/Model/QuestionType/LdapQuestionConfig.php b/src/Model/QuestionType/LdapQuestionConfig.php index ae3b0b7..445781e 100644 --- a/src/Model/QuestionType/LdapQuestionConfig.php +++ b/src/Model/QuestionType/LdapQuestionConfig.php @@ -39,11 +39,11 @@ final readonly class LdapQuestionConfig implements JsonFieldInterface { // Unique reference to hardcoded name used for serialization - public const AUTHLDAP_ID = "authldap_id"; + public const string AUTHLDAP_ID = "authldap_id"; - public const LDAP_FILTER = "ldap_filter"; + public const string LDAP_FILTER = "ldap_filter"; - public const LDAP_ATTRIBUTE_ID = "ldap_attribute_id"; + public const string LDAP_ATTRIBUTE_ID = "ldap_attribute_id"; public function __construct( private int $authldap_id = 0, diff --git a/src/Model/QuestionType/ReservationQuestion.php b/src/Model/QuestionType/ReservationQuestion.php index e3bd60b..057fba5 100644 --- a/src/Model/QuestionType/ReservationQuestion.php +++ b/src/Model/QuestionType/ReservationQuestion.php @@ -161,7 +161,7 @@ public function renderEndUserTemplate(Question $question): string 'allowed_itemtypes' => $config->getAllowedItemtypes(), 'show_calendar' => $config->isCalendarEnabled(), // Server/session time: the calendar runs in UTC mode, like core planning. - 'now' => $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s'), + 'now' => \Session::getCurrentTime() ?? date('Y-m-d H:i:s'), ]); } diff --git a/src/Model/QuestionType/ReservationQuestionConfig.php b/src/Model/QuestionType/ReservationQuestionConfig.php index 68c8314..f34c9e1 100644 --- a/src/Model/QuestionType/ReservationQuestionConfig.php +++ b/src/Model/QuestionType/ReservationQuestionConfig.php @@ -39,9 +39,9 @@ final readonly class ReservationQuestionConfig implements JsonFieldInterface { // Unique reference to hardcoded name used for serialization - public const ALLOWED_ITEMTYPES = 'allowed_itemtypes'; + public const string ALLOWED_ITEMTYPES = 'allowed_itemtypes'; - public const SHOW_CALENDAR = 'show_calendar'; + public const string SHOW_CALENDAR = 'show_calendar'; /** @param array $allowed_itemtypes */ public function __construct( diff --git a/src/Model/QuestionType/TableQuestionConfig.php b/src/Model/QuestionType/TableQuestionConfig.php index da27c27..60123e6 100644 --- a/src/Model/QuestionType/TableQuestionConfig.php +++ b/src/Model/QuestionType/TableQuestionConfig.php @@ -38,18 +38,18 @@ final readonly class TableQuestionConfig implements JsonFieldInterface { - public const COLUMNS = 'columns'; + public const string COLUMNS = 'columns'; // Column sub-keys - public const COL_NAME = 'name'; + public const string COL_NAME = 'name'; - public const COL_QUESTION_TYPE = 'question_type'; + public const string COL_QUESTION_TYPE = 'question_type'; - public const COL_REQUIRED = 'required'; + public const string COL_REQUIRED = 'required'; - public const COL_ITEMTYPE = 'itemtype'; + public const string COL_ITEMTYPE = 'itemtype'; - public const COL_PATTERN = 'pattern'; + public const string COL_PATTERN = 'pattern'; /** * @param array $columns diff --git a/src/Model/QuestionType/TreeCascadeDropdownQuestion.php b/src/Model/QuestionType/TreeCascadeDropdownQuestion.php index f841e3f..f64951d 100644 --- a/src/Model/QuestionType/TreeCascadeDropdownQuestion.php +++ b/src/Model/QuestionType/TreeCascadeDropdownQuestion.php @@ -473,7 +473,7 @@ public static function getTranslatedItemsCriteria(string $itemtype, array $where [ 'AND' => [ 'namet.itemtype' => $itemtype, - 'namet.language' => $_SESSION['glpilanguage'], + 'namet.language' => \Session::getLanguage(), 'namet.field' => 'name', ], ], diff --git a/src/Model/TicketReservationRequest.php b/src/Model/TicketReservationRequest.php index a5c44a2..db8b8ff 100644 --- a/src/Model/TicketReservationRequest.php +++ b/src/Model/TicketReservationRequest.php @@ -53,13 +53,13 @@ final class TicketReservationRequest extends CommonDBChild public static string $rightname = 'ticket'; - public const STATUS_WAITING = 1; + public const int STATUS_WAITING = 1; - public const STATUS_ACCEPTED = 2; + public const int STATUS_ACCEPTED = 2; - public const STATUS_REFUSED = 3; + public const int STATUS_REFUSED = 3; - public const STATUS_CANCELED = 4; + public const int STATUS_CANCELED = 4; #[Override] public static function getTable($classname = null): string @@ -150,7 +150,7 @@ public function approve(int $users_id_validate, string $comment = ''): bool 'comment_validation' => $comment, // Keep a link back to the created Reservation for traceability and cleanup. 'reservations_id' => $reservation->getID(), - 'validation_date' => $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s'), + 'validation_date' => \Session::getCurrentTime() ?? date('Y-m-d H:i:s'), ]); if ($updated) { @@ -167,7 +167,7 @@ public function refuse(int $users_id_validate, string $comment = ''): bool 'status' => self::STATUS_REFUSED, 'users_id_validate' => $users_id_validate, 'comment_validation' => $comment, - 'validation_date' => $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s'), + 'validation_date' => \Session::getCurrentTime() ?? date('Y-m-d H:i:s'), ]); if ($updated) { diff --git a/src/Service/InstallManager.php b/src/Service/InstallManager.php index c27e960..ae49703 100644 --- a/src/Service/InstallManager.php +++ b/src/Service/InstallManager.php @@ -63,7 +63,7 @@ final class InstallManager * technicians would require a custom target resolving the linked ticket, so * it is left for admins to add (or a follow-up), not seeded here. */ - private const NOTIFICATIONS = [ + private const array NOTIFICATIONS = [ 'reservation_request_created' => [ 'name' => 'New pre-reservation request', 'targets' => [[Notification::AUTHOR, Notification::USER_TYPE]], diff --git a/src/Service/LatestVersionProvider.php b/src/Service/LatestVersionProvider.php index 80084cb..c084f8f 100644 --- a/src/Service/LatestVersionProvider.php +++ b/src/Service/LatestVersionProvider.php @@ -48,21 +48,21 @@ */ final readonly class LatestVersionProvider { - public const STATUS_UP_TO_DATE = 'up_to_date'; + public const string STATUS_UP_TO_DATE = 'up_to_date'; - public const STATUS_OUTDATED = 'outdated'; + public const string STATUS_OUTDATED = 'outdated'; - public const STATUS_UNKNOWN = 'unknown'; + public const string STATUS_UNKNOWN = 'unknown'; - public const RELEASES_CACHE_KEY = 'advancedforms_glpi_releases'; + public const string RELEASES_CACHE_KEY = 'advancedforms_glpi_releases'; - public const MARKETPLACE_CACHE_KEY_PREFIX = 'advancedforms_marketplace_'; + public const string MARKETPLACE_CACHE_KEY_PREFIX = 'advancedforms_marketplace_'; - private const GITHUB_RELEASES_URL = 'https://api.github.com/repos/glpi-project/glpi/releases?per_page=100'; + private const string GITHUB_RELEASES_URL = 'https://api.github.com/repos/glpi-project/glpi/releases?per_page=100'; - private const MARKETPLACE_PAGE_SIZE = 200; + private const int MARKETPLACE_PAGE_SIZE = 200; - private const MARKETPLACE_MAX_PAGES = 20; + private const int MARKETPLACE_MAX_PAGES = 20; private const FAILURE_CACHE_TTL = 5 * MINUTE_TIMESTAMP; diff --git a/src/Service/SystemInfoParser.php b/src/Service/SystemInfoParser.php index 51936a4..e1330f2 100644 --- a/src/Service/SystemInfoParser.php +++ b/src/Service/SystemInfoParser.php @@ -52,14 +52,14 @@ */ final class SystemInfoParser { - public const MAX_LENGTH = 200000; + public const int MAX_LENGTH = 200000; - private const MAX_LINE_LENGTH = 2000; + private const int MAX_LINE_LENGTH = 2000; - private const MAX_PLUGINS = 300; + private const int MAX_PLUGINS = 300; /** Single value fields, first match wins. */ - private const FIELD_PATTERNS = [ + private const array FIELD_PATTERNS = [ 'glpi_version' => '/^\s*GLPI:?\s+(\d+\.\d+\.\d+[^\s(]*)/', 'install_mode' => '/^\s*Installation mode:\s*(\S+)/', 'integrity' => '/^\s*Source Integrity:\s*(.+)$/', @@ -70,7 +70,7 @@ final class SystemInfoParser 'db_version' => '/^\s*Server Version:\s*(.+)$/', ]; - private const PLUGIN_PATTERN = '/^\s*(\S+)\s+Name:\s*(.+?)\s+Version:\s*(\S+)\s+State:\s*(.+?)\s+Install Method:\s*(\S+)\s*$/'; + private const string PLUGIN_PATTERN = '/^\s*(\S+)\s+Name:\s*(.+?)\s+Version:\s*(\S+)\s+State:\s*(.+?)\s+Install Method:\s*(\S+)\s*$/'; /** @return ParsedSystemInfo|null */ public static function parse(string $raw): ?array diff --git a/tests/Console/ImportFormcreatorActorsNotificationCommandTest.php b/tests/Console/ImportFormcreatorActorsNotificationCommandTest.php index 7bfed37..810a7b1 100644 --- a/tests/Console/ImportFormcreatorActorsNotificationCommandTest.php +++ b/tests/Console/ImportFormcreatorActorsNotificationCommandTest.php @@ -56,11 +56,11 @@ final class ImportFormcreatorActorsNotificationCommandTest extends MapperTestCas { use ActorNotificationConfigAssertionsTrait; - private const ROLE_REQUESTER = 1; + private const int ROLE_REQUESTER = 1; - private const ROLE_OBSERVER = 2; + private const int ROLE_OBSERVER = 2; - private const ROLE_ASSIGN = 3; + private const int ROLE_ASSIGN = 3; public function testDryRunDisplaysChangesWithoutSaving(): void { diff --git a/tests/Model/QuestionType/TableQuestionRenderingTest.php b/tests/Model/QuestionType/TableQuestionRenderingTest.php index df7752a..4917f42 100644 --- a/tests/Model/QuestionType/TableQuestionRenderingTest.php +++ b/tests/Model/QuestionType/TableQuestionRenderingTest.php @@ -61,7 +61,7 @@ */ final class TableQuestionRenderingTest extends AdvancedFormsTestCase { - private const MODULE_PATH = '/plugins/advancedforms/js/modules/AfTableQuestion.js'; + private const string MODULE_PATH = '/plugins/advancedforms/js/modules/AfTableQuestion.js'; private TableQuestion $type; diff --git a/tests/Model/QuestionType/TreeCascadeDropdownQuestionTest.php b/tests/Model/QuestionType/TreeCascadeDropdownQuestionTest.php index 6e4860d..a5f917c 100644 --- a/tests/Model/QuestionType/TreeCascadeDropdownQuestionTest.php +++ b/tests/Model/QuestionType/TreeCascadeDropdownQuestionTest.php @@ -840,7 +840,7 @@ public function testDropdownsShowTranslatedNames(): void 'entities_id' => $entity_id, ]); - $language = $_SESSION['glpilanguage']; + $language = \Session::getLanguage(); foreach ([[$hardware, 'Hardware'], [$screen, 'Screen'], [$software, 'Software']] as [$category, $translation]) { $this->createItem(DropdownTranslation::class, [ 'itemtype' => ITILCategory::class, diff --git a/tests/Service/LatestVersionProviderTest.php b/tests/Service/LatestVersionProviderTest.php index f9d4520..54f3452 100644 --- a/tests/Service/LatestVersionProviderTest.php +++ b/tests/Service/LatestVersionProviderTest.php @@ -48,9 +48,9 @@ final class LatestVersionProviderTest extends GLPITestCase { - private const REGISTRATION_KEY = 'advancedforms-test-registration-key'; + private const string REGISTRATION_KEY = 'advancedforms-test-registration-key'; - private const GITHUB_RELEASES = [ + private const array GITHUB_RELEASES = [ ['tag_name' => '12.0.3', 'prerelease' => false], ['tag_name' => '11.0.14-rc1', 'prerelease' => true], ['tag_name' => '11.0.13', 'prerelease' => false], @@ -253,7 +253,7 @@ private function fakeRegistration(): void // Cached registration information avoids a call to the registration API $_SESSION['glpilanguage'] ??= 'en_GB'; - $lang = preg_replace('/^([a-z]+)_.+$/', '$1', $_SESSION['glpilanguage']); + $lang = preg_replace('/^([a-z]+)_.+$/', '$1', \Session::getLanguage()); $GLPI_CACHE->set( sprintf('registration_%s_%s_informations', sha1(self::REGISTRATION_KEY), $lang), ['is_valid' => true, 'validation_message' => null, 'owner' => null, 'subscription' => null], diff --git a/tests/SystemInfoSamples.php b/tests/SystemInfoSamples.php index 61c374d..797ab43 100644 --- a/tests/SystemInfoSamples.php +++ b/tests/SystemInfoSamples.php @@ -37,7 +37,7 @@ final class SystemInfoSamples { /** GLPI 11.0+ format: escaped content wrapped in
. */
-    public const MODERN = <<GLPI information
 GLPI: 11.0.12 (/ => /var/www/glpi)
 Installation mode: TARBALL
@@ -67,7 +67,7 @@ final class SystemInfoSamples
 TXT;
 
     /** GLPI 10.0 format: unescaped content, no colon after "GLPI". */
-    public const LEGACY = <<GLPI constants
GLPI 10.0.18 (/glpi => /var/www/html/glpi)
 Installation mode: GIT
 Source Integrity: N/A
@@ -77,7 +77,7 @@ final class SystemInfoSamples
 TXT;
 
     /** Manual copy of the rendered table: no markup at all. */
-    public const PLAIN = << /var/www/glpi)
 Installation mode: DOCKER
 Source Integrity: 2 files changed

From 5a1e8c82658dc41afb07f0f1554fca5744fdc3b1 Mon Sep 17 00:00:00 2001
From: Stanislas Kita <7335054+stonebuzz@users.noreply.github.com>
Date: Mon, 30 Nov 2026 09:52:06 +0100
Subject: [PATCH 2/2] fix CI

---
 src/Controller/GetReservationsController.php  |  3 ++-
 .../AccessControl/LanguageAccessControl.php   |  3 ++-
 .../QuestionType/ReservationQuestion.php      |  3 ++-
 .../TreeCascadeDropdownQuestion.php           | 22 ++++++++++---------
 src/Model/TicketReservationRequest.php        |  4 ++--
 .../actor_notification_config_field.html.twig |  2 +-
 .../question_types/table_config.html.twig     |  6 ++---
 templates/glpi_scope_end_user.html.twig       |  2 +-
 templates/reservation_question.html.twig      |  2 +-
 templates/system_info_end_user.html.twig      |  2 +-
 templates/table_end_user.html.twig            |  2 +-
 .../timeline/reservation_request.html.twig    |  2 +-
 templates/tree_cascade_dropdown.html.twig     |  6 ++---
 .../tree_cascade_dropdown_children.html.twig  |  2 +-
 .../TreeCascadeDropdownQuestionTest.php       |  2 +-
 tests/Service/LatestVersionProviderTest.php   |  3 ++-
 16 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/src/Controller/GetReservationsController.php b/src/Controller/GetReservationsController.php
index 3620335..8541b5b 100644
--- a/src/Controller/GetReservationsController.php
+++ b/src/Controller/GetReservationsController.php
@@ -33,6 +33,7 @@
 
 namespace GlpiPlugin\Advancedforms\Controller;
 
+use Session;
 use Glpi\Http\Firewall;
 use Glpi\Security\Attribute\SecurityStrategy;
 use Reservation;
@@ -61,7 +62,7 @@ public function __invoke(Request $request): Response
 
         // No lower bound given by the caller: only return current/future slots,
         // never the item's whole reservation history.
-        $now = \Session::getCurrentTime() ?? date('Y-m-d H:i:s');
+        $now = Session::getCurrentTime() ?? date('Y-m-d H:i:s');
         $where = [
             'reservationitems_id' => $reservationitems_id,
             'end' => ['>', $begin !== '' ? $begin : $now],
diff --git a/src/Model/AccessControl/LanguageAccessControl.php b/src/Model/AccessControl/LanguageAccessControl.php
index 20275ac..65c91ee 100644
--- a/src/Model/AccessControl/LanguageAccessControl.php
+++ b/src/Model/AccessControl/LanguageAccessControl.php
@@ -33,6 +33,7 @@
 
 namespace GlpiPlugin\Advancedforms\Model\AccessControl;
 
+use Session;
 use Dropdown;
 use Glpi\Application\View\TemplateRenderer;
 use Glpi\DBAL\JsonFieldInterface;
@@ -134,7 +135,7 @@ public function canAnswer(
 
         // Deny (not Abstain) so the language restricts every other policy:
         // "All users" + this policy means "all users using a listed language".
-        $language = \Session::getLanguage();
+        $language = Session::getLanguage();
         if (!in_array($language, $config->getLanguages(), true)) {
             return AccessVote::Deny;
         }
diff --git a/src/Model/QuestionType/ReservationQuestion.php b/src/Model/QuestionType/ReservationQuestion.php
index 057fba5..a00ac6c 100644
--- a/src/Model/QuestionType/ReservationQuestion.php
+++ b/src/Model/QuestionType/ReservationQuestion.php
@@ -33,6 +33,7 @@
 
 namespace GlpiPlugin\Advancedforms\Model\QuestionType;
 
+use Session;
 use Glpi\Application\View\TemplateRenderer;
 use Glpi\DBAL\JsonFieldInterface;
 use Glpi\Form\Destination\CommonITILField\Category;
@@ -161,7 +162,7 @@ public function renderEndUserTemplate(Question $question): string
             'allowed_itemtypes' => $config->getAllowedItemtypes(),
             'show_calendar'     => $config->isCalendarEnabled(),
             // Server/session time: the calendar runs in UTC mode, like core planning.
-            'now'               => \Session::getCurrentTime() ?? date('Y-m-d H:i:s'),
+            'now'               => Session::getCurrentTime() ?? date('Y-m-d H:i:s'),
         ]);
     }
 
diff --git a/src/Model/QuestionType/TreeCascadeDropdownQuestion.php b/src/Model/QuestionType/TreeCascadeDropdownQuestion.php
index f64951d..be9a118 100644
--- a/src/Model/QuestionType/TreeCascadeDropdownQuestion.php
+++ b/src/Model/QuestionType/TreeCascadeDropdownQuestion.php
@@ -36,7 +36,9 @@
 use DBmysql;
 use CommonTreeDropdown;
 use DropdownTranslation;
-use Glpi\DBAL\QueryExpression;
+use Glpi\DBAL\QueryFunction;
+use Glpi\DBAL\QueryIdentifier;
+use Glpi\DBAL\QueryValue;
 use Glpi\Application\View\TemplateRenderer;
 use Glpi\DBAL\JsonFieldInterface;
 use Glpi\Form\Condition\ConditionHandler\ItemAsTextConditionHandler;
@@ -443,7 +445,6 @@ private function getValidItemsForLevel(string $itemtype, array $base_where, arra
     public static function getTranslatedItemsCriteria(string $itemtype, array $where): array
     {
         $table = $itemtype::getTable();
-        $name_field = DBmysql::quoteName($table . '.name');
 
         $criteria = [
             'SELECT' => [$table . '.id', $table . '.name'],
@@ -456,14 +457,15 @@ public static function getTranslatedItemsCriteria(string $itemtype, array $where
             return $criteria;
         }
 
-        $translated_name = sprintf(
-            "COALESCE(NULLIF(%s, ''), %s)",
-            DBmysql::quoteName('namet.value'),
-            $name_field,
-        );
         $criteria['SELECT'] = [
             $table . '.id',
-            new QueryExpression($translated_name . ' AS ' . DBmysql::quoteName('name')),
+            QueryFunction::coalesce(
+                [
+                    QueryFunction::nullif(new QueryIdentifier('namet.value'), new QueryValue('')),
+                    new QueryIdentifier($table . '.name'),
+                ],
+                'name',
+            ),
         ];
         $criteria['LEFT JOIN'] = [
             'glpi_dropdowntranslations AS namet' => [
@@ -473,14 +475,14 @@ public static function getTranslatedItemsCriteria(string $itemtype, array $where
                     [
                         'AND' => [
                             'namet.itemtype' => $itemtype,
-                            'namet.language' => \Session::getLanguage(),
+                            'namet.language' => Session::getLanguage(),
                             'namet.field'    => 'name',
                         ],
                     ],
                 ],
             ],
         ];
-        $criteria['ORDER'] = [new QueryExpression($translated_name . ' ASC')];
+        $criteria['ORDER'] = ['name ASC'];
 
         return $criteria;
     }
diff --git a/src/Model/TicketReservationRequest.php b/src/Model/TicketReservationRequest.php
index db8b8ff..9aaea4d 100644
--- a/src/Model/TicketReservationRequest.php
+++ b/src/Model/TicketReservationRequest.php
@@ -150,7 +150,7 @@ public function approve(int $users_id_validate, string $comment = ''): bool
             'comment_validation' => $comment,
             // Keep a link back to the created Reservation for traceability and cleanup.
             'reservations_id' => $reservation->getID(),
-            'validation_date' => \Session::getCurrentTime() ?? date('Y-m-d H:i:s'),
+            'validation_date' => Session::getCurrentTime() ?? date('Y-m-d H:i:s'),
         ]);
 
         if ($updated) {
@@ -167,7 +167,7 @@ public function refuse(int $users_id_validate, string $comment = ''): bool
             'status' => self::STATUS_REFUSED,
             'users_id_validate' => $users_id_validate,
             'comment_validation' => $comment,
-            'validation_date' => \Session::getCurrentTime() ?? date('Y-m-d H:i:s'),
+            'validation_date' => Session::getCurrentTime() ?? date('Y-m-d H:i:s'),
         ]);
 
         if ($updated) {
diff --git a/templates/destination/actor_notification_config_field.html.twig b/templates/destination/actor_notification_config_field.html.twig
index eba6723..bb287cb 100644
--- a/templates/destination/actor_notification_config_field.html.twig
+++ b/templates/destination/actor_notification_config_field.html.twig
@@ -38,7 +38,7 @@
           data-testid="actor-notification-helper"
           data-bs-toggle="tooltip" data-bs-trigger="hover focus" data-bs-placement="top"
           data-bs-title="{{ helper }}">?
-    
 
-
diff --git a/templates/glpi_scope_end_user.html.twig b/templates/glpi_scope_end_user.html.twig
index d4f8b00..4ae3872 100644
--- a/templates/glpi_scope_end_user.html.twig
+++ b/templates/glpi_scope_end_user.html.twig
@@ -42,7 +42,7 @@
     
 
 
-
diff --git a/templates/reservation_question.html.twig b/templates/reservation_question.html.twig
index 77c1cf1..38f9b7c 100644
--- a/templates/reservation_question.html.twig
+++ b/templates/reservation_question.html.twig
@@ -76,7 +76,7 @@
 
     
 
-
diff --git a/templates/table_end_user.html.twig b/templates/table_end_user.html.twig
index e000dfd..2c4a51b 100644
--- a/templates/table_end_user.html.twig
+++ b/templates/table_end_user.html.twig
@@ -205,7 +205,7 @@
     >
 
 
-