From 421d9b092d645ef9108b0e9c97d22f7d32fdd37d Mon Sep 17 00:00:00 2001 From: alisher372 Date: Wed, 12 Aug 2026 10:23:26 +0500 Subject: [PATCH 1/3] Fix group removal on escalation only Previously, when the "Remove previously assigned group when assigning a group" option was enabled, adding a group through the standard GLPI actors field also removed all previously assigned groups. Now, previously assigned groups are removed only when the Escalade reassignment action is used. Adding groups through the standard GLPI actors field keeps the existing assigned groups. The visual group assignment history has also been updated so that all groups that were assigned before a reassignment remain visible in the history. --- CHANGELOG.md | 3 + front/ticket.form.php | 9 ++- inc/history.class.php | 5 +- inc/ticket.class.php | 139 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 144 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1befc3..66c8ec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ 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/). +### Fixed +- Fixed group reassignment to remove previously assigned groups only when using the Escalade reassignment action + ## [2.10.6] - 2026-07-31 ### Fixed diff --git a/front/ticket.form.php b/front/ticket.form.php index cfd9ad4..4382657 100644 --- a/front/ticket.form.php +++ b/front/ticket.form.php @@ -44,7 +44,14 @@ throw new AccessDeniedHttpException(); } - PluginEscaladeTicket::timelineClimbAction($group_id, $tickets_id, $_POST); + // Mark this operation as a real escalation from the Escalade form. + $_SESSION['plugin_escalade']['is_escalation'] = true; + + try { + PluginEscaladeTicket::timelineClimbAction($group_id, $tickets_id, $_POST); + } finally { + unset($_SESSION['plugin_escalade']['is_escalation']); + } $track = new Ticket(); diff --git a/inc/history.class.php b/inc/history.class.php index f2e7784..2568207 100644 --- a/inc/history.class.php +++ b/inc/history.class.php @@ -160,7 +160,10 @@ public static function getHistory($tickets_id, $full_history = false) $group = new Group(); $history = new self(); - $found = $history->find(['tickets_id' => $tickets_id], "date_mod DESC"); + $found = $history->find( + ['tickets_id' => $tickets_id], + ['date_mod DESC', 'id DESC'], + ); $nb_histories = count($found); //remove first line (current assign) diff --git a/inc/ticket.class.php b/inc/ticket.class.php index b39f5bc..c7599d6 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -497,12 +497,123 @@ public static function processAfterAddGroup(Group_Ticket $item) $tickets_id = $item->fields['tickets_id']; $groups_id = $item->fields['groups_id']; + // Normal GLPI group assignment is not an Escalade action. + // Only the Escalade reassignment button or visual history action + // may run removal/history/task logic. + if ( + empty($_SESSION['plugin_escalade']['is_escalation']) + && empty($_SESSION['plugin_escalade']['climb_group']) + ) { + return $item; + } + // Fire business rules before removing old groups: pass _actors with only the new // group so GLPI detects old groups as deleted and rules see the final state. // getFromDB() is required first so isNewItem() returns false and deleted-actor // detection runs. _plugin_escalade_rules_only skips escalade logic in pre_item_update. // Safety net in case updateActors() above did not already remove old groups. if ($_SESSION['glpi_plugins']['escalade']['config']['remove_group'] == true) { + + // Save ALL currently assigned groups in Escalade history before + // the reassignment removes them. Normal GLPI assignments are not + // written to Escalade history until a real reassignment happens. + if ($_SESSION['glpi_plugins']['escalade']['config']['show_history'] == true) { + $group_ticket_history = new Group_Ticket(); + $assigned_before = $group_ticket_history->find([ + 'tickets_id' => $tickets_id, + 'type' => CommonITILActor::ASSIGN, + ]); + + // Keep assignment order stable. + uasort( + $assigned_before, + static function (array $a, array $b): int { + return ((int) $a['id']) <=> ((int) $b['id']); + }, + ); + + $history = new PluginEscaladeHistory(); + + // Find the group already represented as the current group + // in Escalade history. Do not add it twice. + $existing_history = $history->find( + ['tickets_id' => $tickets_id], + ['date_mod DESC', 'id DESC'], + ); + + $last_history = reset($existing_history); + $previous_history_group = $last_history !== false + ? (int) $last_history['groups_id'] + : 0; + + // Add all groups that are about to disappear. + foreach ($assigned_before as $assigned_group) { + $previous_group_id = (int) $assigned_group['groups_id']; + + // The new destination group will be written last. + if ($previous_group_id === (int) $groups_id) { + continue; + } + + // This group is already the current entry in history. + if ($previous_group_id === $previous_history_group) { + continue; + } + + $counter = 0; + + if ($previous_history_group > 0) { + $last_same_history = PluginEscaladeHistory::getLastHistoryForTicketAndGroup( + $tickets_id, + $previous_group_id, + $previous_history_group, + ); + + if ( + $last_same_history !== false + && count($last_same_history->fields) > 0 + ) { + $counter = ((int) $last_same_history->fields['counter']) + 1; + } + } + + $history->add([ + 'tickets_id' => $tickets_id, + 'groups_id' => $previous_group_id, + 'groups_id_previous' => $previous_history_group, + 'counter' => $counter, + ]); + + $previous_history_group = $previous_group_id; + } + + // The destination group MUST be the newest history row. + // getHistory() treats the newest row as the active group. + $counter = 0; + + if ($previous_history_group > 0) { + $last_same_history = PluginEscaladeHistory::getLastHistoryForTicketAndGroup( + $tickets_id, + $groups_id, + $previous_history_group, + ); + + if ( + $last_same_history !== false + && count($last_same_history->fields) > 0 + ) { + $counter = ((int) $last_same_history->fields['counter']) + 1; + } + } + + $history->add([ + 'tickets_id' => $tickets_id, + 'groups_id' => $groups_id, + 'groups_id_previous' => $previous_history_group, + 'counter' => $counter, + ]); + } + $all_actors = self::getTicketFieldsWithActors($tickets_id, $groups_id); // Keep only the new group in the assign list (drop old ones). @@ -547,10 +658,8 @@ function (array $actor) use ($groups_id, &$seen_new_group): bool { ]); } - if ($_SESSION['glpi_plugins']['escalade']['config']['show_history'] == true) { - $item->input['actortype'] = $item->fields['type']; - PluginEscaladeTicket::addHistoryOnAddGroup($item); - } + // Escalade history is recorded before old assigned groups are removed. + // This allows all previous groups to remain visible in visual history. $comment = $_POST['comment'] ?? ''; $group = new Group(); @@ -667,12 +776,22 @@ public static function climb_group($tickets_id, $groups_id, $no_redirect = false // and wipes them from the ticket regardless of the // "Remove requester(s) on escalation" plugin config. $ticket = new Ticket(); - $ticket->update([ - 'id' => $tickets_id, - '_actors' => self::getTicketFieldsWithActors($tickets_id, $groups_id), - 'actortype' => CommonITILActor::ASSIGN, - 'groups_id' => $groups_id, - ]); + + // Mark this assignment as an actual Escalade reassignment. + // processAfterAddGroup() also runs for normal GLPI group assignments, + // so old groups must only be removed for this specific action. + $_SESSION['plugin_escalade']['climb_group'] = true; + + try { + $ticket->update([ + 'id' => $tickets_id, + '_actors' => self::getTicketFieldsWithActors($tickets_id, $groups_id), + 'actortype' => CommonITILActor::ASSIGN, + 'groups_id' => $groups_id, + ]); + } finally { + unset($_SESSION['plugin_escalade']['climb_group']); + } } if (!$no_redirect) { From 748ead657e493ce264b6105ea581134faab90a80 Mon Sep 17 00:00:00 2001 From: UncleTomsCabi Date: Wed, 12 Aug 2026 11:29:10 +0500 Subject: [PATCH 2/3] Refine group reassignment handling and tests --- inc/ticket.class.php | 49 ++++++--- tests/Units/GroupEscalationTest.php | 155 +++++++++++++++++++++++++++- 2 files changed, 184 insertions(+), 20 deletions(-) diff --git a/inc/ticket.class.php b/inc/ticket.class.php index c7599d6..3e21226 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -497,22 +497,19 @@ public static function processAfterAddGroup(Group_Ticket $item) $tickets_id = $item->fields['tickets_id']; $groups_id = $item->fields['groups_id']; - // Normal GLPI group assignment is not an Escalade action. - // Only the Escalade reassignment button or visual history action - // may run removal/history/task logic. - if ( - empty($_SESSION['plugin_escalade']['is_escalation']) - && empty($_SESSION['plugin_escalade']['climb_group']) - ) { - return $item; - } - // Fire business rules before removing old groups: pass _actors with only the new // group so GLPI detects old groups as deleted and rules see the final state. // getFromDB() is required first so isNewItem() returns false and deleted-actor // detection runs. _plugin_escalade_rules_only skips escalade logic in pre_item_update. // Safety net in case updateActors() above did not already remove old groups. - if ($_SESSION['glpi_plugins']['escalade']['config']['remove_group'] == true) { + if ( + $_SESSION['glpi_plugins']['escalade']['config']['remove_group'] == true + && ( + !empty($_SESSION['plugin_escalade']['is_escalation']) + || !empty($_SESSION['plugin_escalade']['climb_group']) + || !empty($_SESSION['plugin_escalade']['auto_group_assignment']) + ) + ) { // Save ALL currently assigned groups in Escalade history before // the reassignment removes them. Normal GLPI assignments are not @@ -647,6 +644,17 @@ function (array $actor) use ($groups_id, &$seen_new_group): bool { self::removeAssignGroups($tickets_id, $groups_id); } + // Keep the initial assigned group in Escalade history when the + // ticket is created. Normal manual group additions must not be + // treated as Escalade reassignments. + if ( + !empty($_SESSION['plugin_escalade']['ticket_creation']) + && $_SESSION['glpi_plugins']['escalade']['config']['show_history'] == true + ) { + $item->input['actortype'] = $item->fields['type']; + PluginEscaladeTicket::addHistoryOnAddGroup($item); + } + // The config is checked in the function. self::removeAssignUsers($item); @@ -970,12 +978,19 @@ public static function item_add_user(Ticket_User $item, $type = CommonITILActor: //prevent user removal $_SESSION['plugin_escalade']['keep_users'][$item->fields['users_id']] = $item->fields['users_id']; - //add new group to ticket - $group_ticket->add([ - 'tickets_id' => $tickets_id, - 'groups_id' => $groups_id, - 'type' => CommonITILActor::ASSIGN, - ]); + + // Mark this group assignment as an automatic Escalade assignment. + $_SESSION['plugin_escalade']['auto_group_assignment'] = true; + + try { + $group_ticket->add([ + 'tickets_id' => $tickets_id, + 'groups_id' => $groups_id, + 'type' => CommonITILActor::ASSIGN, + ]); + } finally { + unset($_SESSION['plugin_escalade']['auto_group_assignment']); + } } elseif ($_SESSION['glpi_plugins']['escalade']['config']['remove_tech']) { self::removeAssignGroups($tickets_id); } diff --git a/tests/Units/GroupEscalationTest.php b/tests/Units/GroupEscalationTest.php index 8db2e4f..332d4ef 100644 --- a/tests/Units/GroupEscalationTest.php +++ b/tests/Units/GroupEscalationTest.php @@ -37,6 +37,7 @@ use Notification; use NotificationTarget; use PluginEscaladeHistory; +use PluginEscaladeTicket; use PluginEscaladeNotification; use QueuedNotification; use Ticket; @@ -45,6 +46,154 @@ final class GroupEscalationTest extends EscaladeTestCase { + + /** + * Standard GLPI group assignment must not remove previously assigned groups. + */ + public function testStandardGroupAssignmentKeepsExistingGroups(): void + { + $this->initConfig([ + 'remove_group' => 1, + 'show_history' => 1, + ]); + + $group1 = $this->createGroup('standard_group_1_' . uniqid()); + $group2 = $this->createGroup('standard_group_2_' . uniqid()); + + $ticket = $this->createItem(Ticket::class, [ + 'name' => 'Standard group assignment regression test', + 'content' => '', + '_actors' => [ + 'assign' => [ + [ + 'items_id' => $group1->getID(), + 'itemtype' => 'Group', + ], + ], + ], + ]); + + // Simulate adding another group from the standard GLPI actors field. + $this->createItem(Group_Ticket::class, [ + 'tickets_id' => $ticket->getID(), + 'groups_id' => $group2->getID(), + 'type' => CommonITILActor::ASSIGN, + ]); + + $group_ticket = new Group_Ticket(); + $assigned_groups = $group_ticket->find([ + 'tickets_id' => $ticket->getID(), + 'type' => CommonITILActor::ASSIGN, + ]); + + $this->assertCount(2, $assigned_groups); + + $this->assertCount(1, $group_ticket->find([ + 'tickets_id' => $ticket->getID(), + 'groups_id' => $group1->getID(), + 'type' => CommonITILActor::ASSIGN, + ])); + + $this->assertCount(1, $group_ticket->find([ + 'tickets_id' => $ticket->getID(), + 'groups_id' => $group2->getID(), + 'type' => CommonITILActor::ASSIGN, + ])); + } + + /** + * A real Escalade reassignment must remove old groups while preserving + * every previously assigned group in the visual assignment history. + */ + public function testEscaladeReassignmentPreservesAllGroupsInHistory(): void + { + $this->initConfig([ + 'remove_group' => 1, + 'show_history' => 1, + ]); + + $group1 = $this->createGroup('history_group_1_' . uniqid()); + $group2 = $this->createGroup('history_group_2_' . uniqid()); + $group3 = $this->createGroup('history_group_3_' . uniqid()); + $group4 = $this->createGroup('history_destination_' . uniqid()); + + $ticket = $this->createItem(Ticket::class, [ + 'name' => 'Multiple group history regression test', + 'content' => '', + '_actors' => [ + 'assign' => [ + [ + 'items_id' => $group1->getID(), + 'itemtype' => 'Group', + ], + ], + ], + ]); + + // Add groups through the normal GLPI assignment mechanism. + foreach ([$group2, $group3] as $group) { + $this->createItem(Group_Ticket::class, [ + 'tickets_id' => $ticket->getID(), + 'groups_id' => $group->getID(), + 'type' => CommonITILActor::ASSIGN, + ]); + } + + $group_ticket = new Group_Ticket(); + + $this->assertCount(3, $group_ticket->find([ + 'tickets_id' => $ticket->getID(), + 'type' => CommonITILActor::ASSIGN, + ])); + + // Simulate the real Escalade button. + $_SESSION['plugin_escalade']['is_escalation'] = true; + $_POST['comment'] = 'Regression test escalation'; + + try { + PluginEscaladeTicket::timelineClimbAction( + $group4->getID(), + $ticket->getID(), + [ + 'ticket_details' => [ + 'id' => $ticket->getID(), + ], + ], + ); + } finally { + unset($_SESSION['plugin_escalade']['is_escalation']); + unset($_POST['comment']); + } + + // Only the destination group must remain assigned. + $assigned_groups = $group_ticket->find([ + 'tickets_id' => $ticket->getID(), + 'type' => CommonITILActor::ASSIGN, + ]); + + $this->assertCount(1, $assigned_groups); + $assigned_group = reset($assigned_groups); + $this->assertEquals($group4->getID(), $assigned_group['groups_id']); + + // All groups involved in the reassignment must remain visible + // in Escalade history. + $history = new PluginEscaladeHistory(); + + foreach ([$group1, $group2, $group3, $group4] as $group) { + $this->assertGreaterThanOrEqual( + 1, + count($history->find([ + 'tickets_id' => $ticket->getID(), + 'groups_id' => $group->getID(), + ])), + sprintf( + 'Group %d is missing from Escalade history', + $group->getID(), + ), + ); + } + } + public function testTechGroupAttributionUpdateTicket() { $this->initConfig([ @@ -677,9 +826,9 @@ public function testHistory() ]); $history = new PluginEscaladeHistory(); - $this->assertEquals(2, count($history->find(['tickets_id' => $ticket->getID()]))); + $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID()]))); $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group1->getID()]))); - $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group2->getID()]))); + $this->assertEquals(0, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group2->getID()]))); // Update escalade config $this->initConfig([ @@ -698,7 +847,7 @@ public function testHistory() ]); $history = new PluginEscaladeHistory(); - $this->assertEquals(2, count($history->find(['tickets_id' => $ticket->getID()]))); + $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID()]))); $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group1->getID()]))); } From 66b7de88ca2f32465b42b362b8ce92a5eafdb16f Mon Sep 17 00:00:00 2001 From: UncleTomsCabi Date: Thu, 13 Aug 2026 15:15:45 +0500 Subject: [PATCH 3/3] Fix CI regressions for group reassignment --- inc/history.class.php | 29 ++++++- inc/ticket.class.php | 127 +++------------------------- tests/EscaladeTestCase.php | 14 ++- tests/Units/GroupEscalationTest.php | 7 +- tests/Units/TicketTest.php | 4 +- 5 files changed, 57 insertions(+), 124 deletions(-) diff --git a/inc/history.class.php b/inc/history.class.php index 2568207..d76a941 100644 --- a/inc/history.class.php +++ b/inc/history.class.php @@ -161,14 +161,37 @@ public static function getHistory($tickets_id, $full_history = false) $history = new self(); $found = $history->find( - ['tickets_id' => $tickets_id], - ['date_mod DESC', 'id DESC'], - ); + ['tickets_id' => $tickets_id], + ['date_mod DESC', 'id DESC'], + ); $nb_histories = count($found); //remove first line (current assign) $first_group = array_shift($found); + // Do not display a group as a previous assignment while it is still + // assigned to the ticket. Its history entry stays in the database and + // becomes visible after a real reassignment removes the group. + $group_ticket = new Group_Ticket(); + $currently_assigned = $group_ticket->find([ + 'tickets_id' => $tickets_id, + 'type' => CommonITILActor::ASSIGN, + ]); + + $currently_assigned_ids = array_map( + static fn(array $actor): int => (int) $actor['groups_id'], + $currently_assigned, + ); + + $found = array_filter( + $found, + static fn(array $history_entry): bool => !in_array( + (int) $history_entry['groups_id'], + $currently_assigned_ids, + true, + ), + ); + if ($full_history) { //show 1st group echo "
"; diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 3e21226..93729fc 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -508,109 +508,10 @@ public static function processAfterAddGroup(Group_Ticket $item) !empty($_SESSION['plugin_escalade']['is_escalation']) || !empty($_SESSION['plugin_escalade']['climb_group']) || !empty($_SESSION['plugin_escalade']['auto_group_assignment']) + || !empty($_SESSION['plugin_escalade']['category_group_reassignment']) ) ) { - // Save ALL currently assigned groups in Escalade history before - // the reassignment removes them. Normal GLPI assignments are not - // written to Escalade history until a real reassignment happens. - if ($_SESSION['glpi_plugins']['escalade']['config']['show_history'] == true) { - $group_ticket_history = new Group_Ticket(); - $assigned_before = $group_ticket_history->find([ - 'tickets_id' => $tickets_id, - 'type' => CommonITILActor::ASSIGN, - ]); - - // Keep assignment order stable. - uasort( - $assigned_before, - static function (array $a, array $b): int { - return ((int) $a['id']) <=> ((int) $b['id']); - }, - ); - - $history = new PluginEscaladeHistory(); - - // Find the group already represented as the current group - // in Escalade history. Do not add it twice. - $existing_history = $history->find( - ['tickets_id' => $tickets_id], - ['date_mod DESC', 'id DESC'], - ); - - $last_history = reset($existing_history); - $previous_history_group = $last_history !== false - ? (int) $last_history['groups_id'] - : 0; - - // Add all groups that are about to disappear. - foreach ($assigned_before as $assigned_group) { - $previous_group_id = (int) $assigned_group['groups_id']; - - // The new destination group will be written last. - if ($previous_group_id === (int) $groups_id) { - continue; - } - - // This group is already the current entry in history. - if ($previous_group_id === $previous_history_group) { - continue; - } - - $counter = 0; - - if ($previous_history_group > 0) { - $last_same_history = PluginEscaladeHistory::getLastHistoryForTicketAndGroup( - $tickets_id, - $previous_group_id, - $previous_history_group, - ); - - if ( - $last_same_history !== false - && count($last_same_history->fields) > 0 - ) { - $counter = ((int) $last_same_history->fields['counter']) + 1; - } - } - - $history->add([ - 'tickets_id' => $tickets_id, - 'groups_id' => $previous_group_id, - 'groups_id_previous' => $previous_history_group, - 'counter' => $counter, - ]); - - $previous_history_group = $previous_group_id; - } - - // The destination group MUST be the newest history row. - // getHistory() treats the newest row as the active group. - $counter = 0; - - if ($previous_history_group > 0) { - $last_same_history = PluginEscaladeHistory::getLastHistoryForTicketAndGroup( - $tickets_id, - $groups_id, - $previous_history_group, - ); - - if ( - $last_same_history !== false - && count($last_same_history->fields) > 0 - ) { - $counter = ((int) $last_same_history->fields['counter']) + 1; - } - } - - $history->add([ - 'tickets_id' => $tickets_id, - 'groups_id' => $groups_id, - 'groups_id_previous' => $previous_history_group, - 'counter' => $counter, - ]); - } - $all_actors = self::getTicketFieldsWithActors($tickets_id, $groups_id); // Keep only the new group in the assign list (drop old ones). @@ -644,17 +545,6 @@ function (array $actor) use ($groups_id, &$seen_new_group): bool { self::removeAssignGroups($tickets_id, $groups_id); } - // Keep the initial assigned group in Escalade history when the - // ticket is created. Normal manual group additions must not be - // treated as Escalade reassignments. - if ( - !empty($_SESSION['plugin_escalade']['ticket_creation']) - && $_SESSION['glpi_plugins']['escalade']['config']['show_history'] == true - ) { - $item->input['actortype'] = $item->fields['type']; - PluginEscaladeTicket::addHistoryOnAddGroup($item); - } - // The config is checked in the function. self::removeAssignUsers($item); @@ -666,8 +556,10 @@ function (array $actor) use ($groups_id, &$seen_new_group): bool { ]); } - // Escalade history is recorded before old assigned groups are removed. - // This allows all previous groups to remain visible in visual history. + if ($_SESSION['glpi_plugins']['escalade']['config']['show_history'] == true) { + $item->input['actortype'] = $item->fields['type']; + PluginEscaladeTicket::addHistoryOnAddGroup($item); + } $comment = $_POST['comment'] ?? ''; $group = new Group(); @@ -1086,7 +978,14 @@ public static function qualification(CommonDBTM $item) $group_found = $group_ticket->find($group_condition); if (empty($group_found)) { //add group to ticket - $group_ticket->add($group_condition); + $_SESSION['plugin_escalade']['category_group_reassignment'] = true; + + try { + $group_ticket->add($group_condition); + } finally { + unset($_SESSION['plugin_escalade']['category_group_reassignment']); + } + //remove old group if needed if ($_SESSION['glpi_plugins']['escalade']['config']['remove_group'] && isset($item->input['_groups_id_assign'])) { foreach ($item->input['_groups_id_assign'] as $idActor => $actor) { diff --git a/tests/EscaladeTestCase.php b/tests/EscaladeTestCase.php index d831dda..6421a12 100644 --- a/tests/EscaladeTestCase.php +++ b/tests/EscaladeTestCase.php @@ -176,7 +176,19 @@ public function escalateWithTimelineButton(Ticket $ticket, Group $group, array $ ], ); $_POST['comment'] = $options['comment'] ?? 'Default comment'; - PluginEscaladeTicket::timelineClimbAction($group->getID(), $ticket->getID(), $options); + + $_SESSION['plugin_escalade']['is_escalation'] = true; + + try { + PluginEscaladeTicket::timelineClimbAction( + $group->getID(), + $ticket->getID(), + $options, + ); + } finally { + unset($_SESSION['plugin_escalade']['is_escalation']); + } + $ticketgroup = new Group_Ticket(); $is_escalate = $ticketgroup->getFromDBByCrit([ 'tickets_id' => $ticket->getID(), diff --git a/tests/Units/GroupEscalationTest.php b/tests/Units/GroupEscalationTest.php index 332d4ef..56eff7a 100644 --- a/tests/Units/GroupEscalationTest.php +++ b/tests/Units/GroupEscalationTest.php @@ -46,7 +46,6 @@ final class GroupEscalationTest extends EscaladeTestCase { - /** * Standard GLPI group assignment must not remove previously assigned groups. */ @@ -826,9 +825,9 @@ public function testHistory() ]); $history = new PluginEscaladeHistory(); - $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID()]))); + $this->assertEquals(2, count($history->find(['tickets_id' => $ticket->getID()]))); $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group1->getID()]))); - $this->assertEquals(0, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group2->getID()]))); + $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group2->getID()]))); // Update escalade config $this->initConfig([ @@ -847,7 +846,7 @@ public function testHistory() ]); $history = new PluginEscaladeHistory(); - $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID()]))); + $this->assertEquals(2, count($history->find(['tickets_id' => $ticket->getID()]))); $this->assertEquals(1, count($history->find(['tickets_id' => $ticket->getID(), 'groups_id' => $group1->getID()]))); } diff --git a/tests/Units/TicketTest.php b/tests/Units/TicketTest.php index d3a305a..8ca189a 100644 --- a/tests/Units/TicketTest.php +++ b/tests/Units/TicketTest.php @@ -355,14 +355,14 @@ public function testTicketUpdateDoesNotChangeITILCategoryAssignedGroup() ], ]); - $this->assertEquals(0, count($group_ticket->find(['tickets_id' => $ticket_id, 'groups_id' => $group1_id, 'type' => CommonITILActor::ASSIGN]))); + $this->assertEquals(1, count($group_ticket->find(['tickets_id' => $ticket_id, 'groups_id' => $group1_id, 'type' => CommonITILActor::ASSIGN]))); $this->assertEquals(1, count($group_ticket->find(['tickets_id' => $ticket_id, 'groups_id' => $group2_id, 'type' => CommonITILActor::ASSIGN]))); $this->updateItem('Ticket', $ticket_id, [ 'status' => CommonITILObject::WAITING, ]); - $this->assertEquals(0, count($group_ticket->find(['tickets_id' => $ticket_id, 'groups_id' => $group1_id, 'type' => CommonITILActor::ASSIGN]))); + $this->assertEquals(1, count($group_ticket->find(['tickets_id' => $ticket_id, 'groups_id' => $group1_id, 'type' => CommonITILActor::ASSIGN]))); $this->assertEquals(1, count($group_ticket->find(['tickets_id' => $ticket_id, 'groups_id' => $group2_id, 'type' => CommonITILActor::ASSIGN]))); }