@@ -39,6 +39,30 @@ class PluginEscaladeTicket
3939{
4040 public const MANAGED_BY_CORE = -1 ; // Status managed by core, not by plugin
4141
42+ /**
43+ * Preserve existing tags when updating a ticket
44+ * This prevents tags from being removed during escalation operations
45+ *
46+ * @param int $tickets_id The ticket ID
47+ * @param array $update_data The update data array (passed by reference)
48+ * @return void
49+ */
50+ private static function preserveExistingTags (int $ tickets_id , array &$ update_data ): void
51+ {
52+ // Preserve existing tags if Tag plugin is active
53+ if (Plugin::isPluginActive ('tag ' ) && class_exists ('PluginTagTagItem ' )) {
54+ $ tag_item = new PluginTagTagItem ();
55+ $ existing_tags = $ tag_item ->find ([
56+ 'items_id ' => $ tickets_id ,
57+ 'itemtype ' => 'Ticket ' ,
58+ ]);
59+ if (!empty ($ existing_tags )) {
60+ $ tag_ids = array_column ($ existing_tags , 'plugin_tag_tags_id ' );
61+ $ update_data ['_plugin_tag_tag_values ' ] = $ tag_ids ;
62+ }
63+ }
64+ }
65+
4266 public static function pre_item_update (CommonDBTM $ item )
4367 {
4468 // Only process escalation logic if we're dealing with actor assignments
@@ -670,6 +694,10 @@ public static function climb_group($tickets_id, $groups_id, $no_redirect = false
670694 $ update_data ['_groups_id_observer ' ] = array_column ($ observer_groups , 'groups_id ' );
671695 }
672696
697+ // Preserve existing tags
698+ self ::preserveExistingTags ($ tickets_id , $ update_data );
699+
700+ $ ticket = new Ticket ();
673701 $ ticket ->update ($ update_data );
674702 }
675703
@@ -1129,14 +1157,19 @@ public static function assign_me($tickets_id)
11291157 ]);
11301158
11311159 if (empty ($ found )) {
1132- $ ticket = new Ticket ();
1133- $ ticket ->update ([
1160+ $ update_data = [
11341161 'id ' => $ tickets_id ,
11351162 '_itil_assign ' => [
11361163 'users_id ' => $ _SESSION ['glpiID ' ],
11371164 '_type ' => 'user ' ,
11381165 ],
1139- ]);
1166+ ];
1167+
1168+ // Preserve existing tags
1169+ self ::preserveExistingTags ($ tickets_id , $ update_data );
1170+
1171+ $ ticket = new Ticket ();
1172+ $ ticket ->update ($ update_data );
11401173 }
11411174 }
11421175
@@ -1354,16 +1387,20 @@ public static function timelineClimbAction(int $group_id, int $tickets_id, array
13541387 if ($ _SESSION ['glpi_plugins ' ]['escalade ' ]['config ' ]['ticket_last_status ' ] != -1 ) {
13551388 $ _form_object ['status ' ] = $ _SESSION ['glpi_plugins ' ]['escalade ' ]['config ' ]['ticket_last_status ' ];
13561389 }
1390+
1391+ $ update_data = $ options ['ticket_details ' ] + [
1392+ '_actors ' => PluginEscaladeTicket::getTicketFieldsWithActors ($ tickets_id , $ group_id ),
1393+ '_plugin_escalade_no_history ' => true , // Prevent a duplicated task to be added
1394+ 'actortype ' => CommonITILActor::ASSIGN ,
1395+ 'groups_id ' => $ group_id ,
1396+ '_form_object ' => $ _form_object ,
1397+ ];
1398+
1399+ // Preserve existing tags
1400+ self ::preserveExistingTags ($ tickets_id , $ update_data );
1401+
13571402 $ updates_ticket = new Ticket ();
1358- $ updates_ticket ->update (
1359- $ options ['ticket_details ' ] + [
1360- '_actors ' => PluginEscaladeTicket::getTicketFieldsWithActors ($ tickets_id , $ group_id ),
1361- '_plugin_escalade_no_history ' => true , // Prevent a duplicated task to be added
1362- 'actortype ' => CommonITILActor::ASSIGN ,
1363- 'groups_id ' => $ group_id ,
1364- '_form_object ' => $ _form_object ,
1365- ],
1366- );
1403+ $ updates_ticket ->update ($ update_data );
13671404 }
13681405 }
13691406}
0 commit comments