diff --git a/src/Ticket.php b/src/Ticket.php
index 4dee33c..1b491d6 100644
--- a/src/Ticket.php
+++ b/src/Ticket.php
@@ -41,10 +41,9 @@
use Group_Ticket;
use Group_User;
use Html;
-use Planning;
use Session;
use Ticket_User;
-use TicketTask;
+use ITILFollowup;
use TicketTemplateMandatoryField;
if (!defined('GLPI_ROOT')) {
@@ -550,7 +549,7 @@ public function launchTicketTransfer($params)
'entities_id' => $params['entity_choice'],
];
- if ($params['group_choice'] && $params['group_choice'] > 0) {
+ if (!empty($params['group_choice']) && $params['group_choice'] > 0) {
$ticket_status = ['status' => CommonITILObject::ASSIGNED];
$ticket_update = array_merge($ticket_update, $ticket_status);
} else {
@@ -558,20 +557,19 @@ public function launchTicketTransfer($params)
$ticket_update = array_merge($ticket_update, $ticket_status);
}
- // In case keep_category is at yes and category doesn't exist, reset category's ticket
- if ($checkEntityRight['keep_category'] && !$checkExistingCategory) {
- $ticket_category = ['itilcategories_id' => 0];
- $ticket_update = array_merge($ticket_update, $ticket_category);
- }
-
- if (!$checkEntityRight['keep_category']) {
- if ($checkEntityRight['itilcategories_id'] == null) {
- $ticket_category = ['itilcategories_id' => 0];
+ if ($checkEntityRight['keep_category']) {
+ if ($checkExistingCategory) {
+ // Explicitly include the current category so GLPI does not reset it on entity change
+ $currentTicket = new \Ticket();
+ $currentTicket->getFromDB($params['id_ticket']);
+ $ticket_category = ['itilcategories_id' => $currentTicket->fields['itilcategories_id']];
} else {
- $ticket_category = ['itilcategories_id' => $checkEntityRight['itilcategories_id']];
+ $ticket_category = ['itilcategories_id' => 0];
}
- $ticket_update = array_merge($ticket_update, $ticket_category);
+ } else {
+ $ticket_category = ['itilcategories_id' => $checkEntityRight['itilcategories_id'] ?? 0];
}
+ $ticket_update = array_merge($ticket_update, $ticket_category);
// If category is mandatory with GLPIs template and category will be null
if ($ticket_category['itilcategories_id'] == 0
@@ -633,25 +631,25 @@ public function launchTicketTransfer($params)
}
}
- $groupText = "
$justification";
+ $content = __("Escalation to", "transferticketentity") . " $theEntity";
- if (isset($params['group_choice'])
- && $params['group_choice'] > 0) {
+ if (!empty($params['group_choice']) && $params['group_choice'] > 0) {
$group = new Group();
- $group->getfromDB($params['group_choice']);
- $groupText = __("in the group", "transferticketentity") ." ". $group->getName() ."\n
$justification";
+ $group->getFromDB($params['group_choice']);
+ $content .= " " . __("in the group", "transferticketentity") . " " . $group->getName();
}
- // Log the transfer in a task
- $task = new TicketTask();
- $task->add([
- 'tickets_id' => $params['id_ticket'],
+ if (!empty($justification)) {
+ $content .= "
" . $justification;
+ }
+
+ // Log the transfer as a followup
+ $followup = new ITILFollowup();
+ $followup->add([
+ 'itemtype' => \Ticket::class,
+ 'items_id' => $params['id_ticket'],
'is_private' => true,
- 'state' => Planning::INFO,
- 'content' => __(
- "Escalation to",
- "transferticketentity"
- ) . " $theEntity " . $groupText
+ 'content' => $content,
]);
$ticket = new \Ticket();