From c0e3b8f49ae2a528d2f03eb7c3b478615c29ce2d Mon Sep 17 00:00:00 2001 From: Herafia Date: Tue, 27 Jan 2026 17:20:52 +0100 Subject: [PATCH 1/3] add param skip rules --- inc/ticket.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 2cc3a1c..aa9d9ef 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -92,7 +92,7 @@ public static function pre_item_update(CommonDBTM $item) } $input = $item->input; - if ($item instanceof CommonITILObject) { + if ($item instanceof Ticket) { // Special handling for history button escalation to pass template validation if (isset($item->input['_no_escalade_template_validation'])) { // Add existing ticket fields temporarily for template validation @@ -127,10 +127,14 @@ public static function pre_item_update(CommonDBTM $item) } $temp_input['_disablenotif'] = true; // Disable notifications for this validation + $temp_input['_skip_rules'] = true; $input = $item->prepareInputForUpdate($temp_input); unset($item->input['_no_escalade_template_validation']); // Clean up flag } else { - $input = $item->prepareInputForUpdate($item->input); + // Pass the _skip_rules flag via a temporary input array to avoid polluting $item->input + $tmp_input = $item->input; + $tmp_input['_skip_rules'] = true; + $input = $item->prepareInputForUpdate($tmp_input); } if (!$input) { return false; From 555d7fad53146ed43bfa515a82316bfff3e47e8f Mon Sep 17 00:00:00 2001 From: Herafia Date: Tue, 27 Jan 2026 17:22:13 +0100 Subject: [PATCH 2/3] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e864b5d..7f8ac0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Handle mandatory template fields in history button escalation - Fix `tag` deletion before escalation using `Escalate button` - Fix `label` button color +- Add param skip_rules ## [2.9.18] - 2025-30-09 From 6934fbf009d186e203f84f8b28778ff706d4dbfe Mon Sep 17 00:00:00 2001 From: Herafia Date: Wed, 28 Jan 2026 16:20:58 +0100 Subject: [PATCH 3/3] tests --- tests/Units/TicketTest.php | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/Units/TicketTest.php b/tests/Units/TicketTest.php index 6884918..afa4a6e 100644 --- a/tests/Units/TicketTest.php +++ b/tests/Units/TicketTest.php @@ -1525,4 +1525,77 @@ public function testHistoryButtonEscalationWithMandatoryAssignedGroupField() $ticket->getFromDB($ticket->getID()); $this->assertEquals($category->getID(), $ticket->fields['itilcategories_id']); } + + public function testRuleCreatesSingleTaskOnCategoryAssign() + { + $this->login(); + + // Create a task template that will be appended by the rule + $task_template = $this->createItem(\TaskTemplate::class, [ + 'name' => 'Rule created task template', + 'content' => 'Task created by rule', + 'is_recursive' => 1, + ]); + $this->assertGreaterThan(0, $task_template->getID()); + + // Create an ITIL category that will trigger the rule + $category = $this->createItem(\ITILCategory::class, [ + 'name' => 'Category that triggers task rule', + 'entities_id' => 0, + 'is_recursive' => 1, + ]); + $this->assertGreaterThan(0, $category->getID()); + + // Create a RuleTicket that appends the task template when the category is set + $rule = $this->createItem(\Rule::class, [ + 'name' => 'Create task on category assign', + 'sub_type' => 'RuleTicket', + 'match' => 'AND', + 'is_active' => 1, + // Trigger on update (could be ONADD | ONUPDATE but update is enough for this test) + 'condition' => \RuleTicket::ONUPDATE, + 'is_recursive' => 1, + ]); + $this->assertGreaterThan(0, $rule->getID()); + + // Add action to append task template + $this->createItem(\RuleAction::class, [ + 'rules_id' => $rule->getID(), + 'action_type' => 'append', + 'field' => 'task_template', + 'value' => $task_template->getID(), + ]); + + // Add criteria: ticket category must be the created category + $this->createItem(\RuleCriteria::class, [ + 'rules_id' => $rule->getID(), + 'criteria' => 'itilcategories_id', + 'condition' => \Rule::PATTERN_IS, + 'pattern' => $category->getID(), + ]); + + // Reset rule cache for ticket rules + \SingletonRuleList::getInstance("RuleTicket", 0)->load = 0; + \SingletonRuleList::getInstance("RuleTicket", 0)->list = []; + + // Create a ticket without category + $ticket = $this->createItem(\Ticket::class, [ + 'name' => 'Ticket for rule task creation', + 'content' => 'Content', + ]); + $this->assertGreaterThan(0, $ticket->getID()); + + // Ensure there is no task before assigning the category + $ticket_task = new \TicketTask(); + $this->assertEquals(0, count($ticket_task->find(['tickets_id' => $ticket->getID()]))); + + // Update the ticket to set the category - this should trigger the rule + $this->updateItem(\Ticket::class, $ticket->getID(), [ + 'itilcategories_id' => $category->getID(), + ]); + + // Verify that exactly one task was created for the ticket + $tasks = $ticket_task->find(['tickets_id' => $ticket->getID()]); + $this->assertEquals(1, count($tasks), 'Exactly one task should be created when assigning the category'); + } }