From 24fb59a9693f0b1d99d006b5df276ea076dd13df Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 2 Oct 2025 15:40:41 +0200 Subject: [PATCH 1/3] Fix tag deletion before escalation --- inc/ticket.class.php | 69 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 0aac77e..9b8716a 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -39,6 +39,30 @@ class PluginEscaladeTicket { public const MANAGED_BY_CORE = -1; // Status managed by core, not by plugin + /** + * Preserve existing tags when updating a ticket + * This prevents tags from being removed during escalation operations + * + * @param int $tickets_id The ticket ID + * @param array $update_data The update data array (passed by reference) + * @return void + */ + private static function preserveExistingTags(int $tickets_id, array &$update_data): void + { + // Preserve existing tags if Tag plugin is active + if (Plugin::isPluginActive('tag') && class_exists('PluginTagTagItem')) { + $tag_item = new PluginTagTagItem(); + $existing_tags = $tag_item->find([ + 'items_id' => $tickets_id, + 'itemtype' => 'Ticket' + ]); + if (!empty($existing_tags)) { + $tag_ids = array_column($existing_tags, 'plugin_tag_tags_id'); + $update_data['_plugin_tag_tag_values'] = $tag_ids; + } + } + } + public static function pre_item_update(CommonDBTM $item) { // Only process escalation logic if we're dealing with actor assignments @@ -615,14 +639,20 @@ public static function climb_group($tickets_id, $groups_id, $no_redirect = false '

' . sprintf(__('Escalation to the group %s.', 'escalade'), Sanitizer::unsanitize($group->getName())) . '


', ), ]); - $ticket = new Ticket(); - $ticket->update([ + + $update_data = [ 'id' => $tickets_id, '_itil_assign' => [ 'groups_id' => $groups_id, '_type' => 'group', ], - ]); + ]; + + // Preserve existing tags + self::preserveExistingTags($tickets_id, $update_data); + + $ticket = new Ticket(); + $ticket->update($update_data); } if (!$no_redirect) { @@ -1081,14 +1111,19 @@ public static function assign_me($tickets_id) ]); if (empty($found)) { - $ticket = new Ticket(); - $ticket->update([ + $update_data = [ 'id' => $tickets_id, '_itil_assign' => [ 'users_id' => $_SESSION['glpiID'], '_type' => 'user', ], - ]); + ]; + + // Preserve existing tags + self::preserveExistingTags($tickets_id, $update_data); + + $ticket = new Ticket(); + $ticket->update($update_data); } } @@ -1306,16 +1341,20 @@ public static function timelineClimbAction(int $group_id, int $tickets_id, array if ($_SESSION['glpi_plugins']['escalade']['config']['ticket_last_status'] != -1) { $_form_object['status'] = $_SESSION['glpi_plugins']['escalade']['config']['ticket_last_status']; } + + $update_data = $options['ticket_details'] + [ + '_actors' => PluginEscaladeTicket::getTicketFieldsWithActors($tickets_id, $group_id), + '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added + 'actortype' => CommonITILActor::ASSIGN, + 'groups_id' => $group_id, + '_form_object' => $_form_object, + ]; + + // Preserve existing tags + self::preserveExistingTags($tickets_id, $update_data); + $updates_ticket = new Ticket(); - $updates_ticket->update( - $options['ticket_details'] + [ - '_actors' => PluginEscaladeTicket::getTicketFieldsWithActors($tickets_id, $group_id), - '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added - 'actortype' => CommonITILActor::ASSIGN, - 'groups_id' => $group_id, - '_form_object' => $_form_object, - ], - ); + $updates_ticket->update($update_data); } } } From 73264a4cdea36d34b9a7ad28dd1664d9ac9b9a50 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 2 Oct 2025 15:42:27 +0200 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb036dc..495b59a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] +## Fixed + +- Fix `tag` deletion before escalation using `Escalate button` + ## [2.9.18] - 2025-30-09 ### Fixed From c3884e59f956edeec711b40241bb54cb4aa30cfb Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 2 Oct 2025 17:17:27 +0200 Subject: [PATCH 3/3] Fix php-cs --- inc/ticket.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 9b8716a..9c09894 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -54,7 +54,7 @@ private static function preserveExistingTags(int $tickets_id, array &$update_dat $tag_item = new PluginTagTagItem(); $existing_tags = $tag_item->find([ 'items_id' => $tickets_id, - 'itemtype' => 'Ticket' + 'itemtype' => 'Ticket', ]); if (!empty($existing_tags)) { $tag_ids = array_column($existing_tags, 'plugin_tag_tags_id'); @@ -639,7 +639,7 @@ public static function climb_group($tickets_id, $groups_id, $no_redirect = false '

' . sprintf(__('Escalation to the group %s.', 'escalade'), Sanitizer::unsanitize($group->getName())) . '


', ), ]); - + $update_data = [ 'id' => $tickets_id, '_itil_assign' => [ @@ -647,10 +647,10 @@ public static function climb_group($tickets_id, $groups_id, $no_redirect = false '_type' => 'group', ], ]; - + // Preserve existing tags self::preserveExistingTags($tickets_id, $update_data); - + $ticket = new Ticket(); $ticket->update($update_data); } @@ -1118,10 +1118,10 @@ public static function assign_me($tickets_id) '_type' => 'user', ], ]; - + // Preserve existing tags self::preserveExistingTags($tickets_id, $update_data); - + $ticket = new Ticket(); $ticket->update($update_data); } @@ -1341,7 +1341,7 @@ public static function timelineClimbAction(int $group_id, int $tickets_id, array if ($_SESSION['glpi_plugins']['escalade']['config']['ticket_last_status'] != -1) { $_form_object['status'] = $_SESSION['glpi_plugins']['escalade']['config']['ticket_last_status']; } - + $update_data = $options['ticket_details'] + [ '_actors' => PluginEscaladeTicket::getTicketFieldsWithActors($tickets_id, $group_id), '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added @@ -1349,10 +1349,10 @@ public static function timelineClimbAction(int $group_id, int $tickets_id, array 'groups_id' => $group_id, '_form_object' => $_form_object, ]; - + // Preserve existing tags self::preserveExistingTags($tickets_id, $update_data); - + $updates_ticket = new Ticket(); $updates_ticket->update($update_data); }