From d96ffdf1740c35fbfdff2e44ee95ae5c56cde636 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Thu, 19 Dec 2024 09:41:15 +0100 Subject: [PATCH 1/2] Add missing inputs for rules using ticket validation criteria --- src/CommonITILValidation.php | 1 + src/Rule.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/CommonITILValidation.php b/src/CommonITILValidation.php index f85fdc710b6..d5a778ef59b 100644 --- a/src/CommonITILValidation.php +++ b/src/CommonITILValidation.php @@ -453,6 +453,7 @@ public function post_updateItem($history = true) 'id' => $this->fields[static::$items_id], 'global_validation' => self::computeValidationStatus($item), '_from_itilvalidation' => true, + 'itemtype' => static::$itemtype ]; $item->update($input); } diff --git a/src/Rule.php b/src/Rule.php index 4b75f0b569b..e61ad1c9953 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -1716,7 +1716,13 @@ public function checkCriteria($criteria, &$input) $partial_regex_result = []; // Undefine criteria field : set to blank if (!isset($input[$criteria->fields["criteria"]])) { - $input[$criteria->fields["criteria"]] = ''; + if (isset($input['itemtype'])) { + $itemtype = new $input['itemtype'](); + $item = $itemtype->getById($input['id']); + $input[$criteria->fields["criteria"]] = $item->fields[$criteria->fields["criteria"]]; + } else { + $input[$criteria->fields["criteria"]] = ''; + } } //If the value is not an array From 5004f1810bca47a4050a501375d0b3210f94bb33 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Thu, 19 Dec 2024 10:47:57 +0100 Subject: [PATCH 2/2] Fix SonarCloud warning --- src/CommonITILValidation.php | 3 +-- src/Rule.php | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/CommonITILValidation.php b/src/CommonITILValidation.php index d5a778ef59b..e772fcd1a2d 100644 --- a/src/CommonITILValidation.php +++ b/src/CommonITILValidation.php @@ -453,8 +453,7 @@ public function post_updateItem($history = true) 'id' => $this->fields[static::$items_id], 'global_validation' => self::computeValidationStatus($item), '_from_itilvalidation' => true, - 'itemtype' => static::$itemtype - ]; + ] + $item->fields; $item->update($input); } } diff --git a/src/Rule.php b/src/Rule.php index e61ad1c9953..4b75f0b569b 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -1716,13 +1716,7 @@ public function checkCriteria($criteria, &$input) $partial_regex_result = []; // Undefine criteria field : set to blank if (!isset($input[$criteria->fields["criteria"]])) { - if (isset($input['itemtype'])) { - $itemtype = new $input['itemtype'](); - $item = $itemtype->getById($input['id']); - $input[$criteria->fields["criteria"]] = $item->fields[$criteria->fields["criteria"]]; - } else { - $input[$criteria->fields["criteria"]] = ''; - } + $input[$criteria->fields["criteria"]] = ''; } //If the value is not an array