diff --git a/hook.php b/hook.php
index 0990704..820e4ed 100644
--- a/hook.php
+++ b/hook.php
@@ -55,6 +55,7 @@ function plugin_transferticketentity_install()
`allow_transfer` BOOLEAN NOT NULL DEFAULT 0,
`keep_category` BOOLEAN NOT NULL DEFAULT 0,
`itilcategories_id` INT {$default_key_sign},
+ `log_type` TINYINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
FOREIGN KEY (`entities_id`) REFERENCES `glpi_entities` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
@@ -62,6 +63,11 @@ function plugin_transferticketentity_install()
$DB->doQuery($query);
}
+ if (!$DB->fieldExists('glpi_plugin_transferticketentity_entities_settings', 'log_type')) {
+ $DB->doQuery("ALTER TABLE `glpi_plugin_transferticketentity_entities_settings`
+ ADD COLUMN `log_type` TINYINT NOT NULL DEFAULT 0");
+ }
+
return true;
}
diff --git a/src/Entity.php b/src/Entity.php
index a4d248d..9a714dd 100644
--- a/src/Entity.php
+++ b/src/Entity.php
@@ -82,6 +82,7 @@ public function prepareInputForAdd($input)
'allow_transfer',
'keep_category',
'itilcategories_id',
+ 'log_type',
]));
}
@@ -95,6 +96,7 @@ public function prepareInputForUpdate($input)
'allow_transfer',
'keep_category',
'itilcategories_id',
+ 'log_type',
]));
}
@@ -201,6 +203,7 @@ public function showFormMcv($item)
$checkRights->fields['allow_transfer'] = 0;
$checkRights->fields['keep_category'] = 0;
$checkRights->fields['itilcategories_id'] = 0;
+ $checkRights->fields['log_type'] = 0;
}
$target = self::getFormURL();
@@ -215,6 +218,10 @@ public function showFormMcv($item)
'entities_id' => $item->getID(),
'availableCategories' => $availableCategories,
'checkMandatoryCategory' => $checkMandatoryCategory,
+ 'log_type_options' => [
+ 0 => __('Followup', 'transferticketentity'),
+ 1 => __('Task', 'transferticketentity'),
+ ],
],
);
@@ -264,6 +271,7 @@ public static function checkEntityRight($params)
$array['allow_transfer'] = $data['allow_transfer'];
$array['keep_category'] = $data['keep_category'];
$array['itilcategories_id'] = $data['itilcategories_id'];
+ $array['log_type'] = $data['log_type'] ?? 0;
}
return $array;
diff --git a/src/Ticket.php b/src/Ticket.php
index 4dee33c..64440bd 100644
--- a/src/Ticket.php
+++ b/src/Ticket.php
@@ -41,9 +41,10 @@
use Group_Ticket;
use Group_User;
use Html;
-use Planning;
use Session;
use Ticket_User;
+use ITILFollowup;
+use Planning;
use TicketTask;
use TicketTemplateMandatoryField;
@@ -550,7 +551,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 +559,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,26 +633,36 @@ 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'],
- 'is_private' => true,
- 'state' => Planning::INFO,
- 'content' => __(
- "Escalation to",
- "transferticketentity"
- ) . " $theEntity " . $groupText
- ]);
+ if (!empty($justification)) {
+ $content .= "
" . $justification;
+ }
+
+ // Log the transfer as a followup or task depending on entity configuration
+ if (($checkEntityRight['log_type'] ?? 0) == 1) {
+ $task = new TicketTask();
+ $task->add([
+ 'tickets_id' => $params['id_ticket'],
+ 'is_private' => true,
+ 'state' => Planning::INFO,
+ 'content' => $content,
+ ]);
+ } else {
+ $followup = new ITILFollowup();
+ $followup->add([
+ 'itemtype' => \Ticket::class,
+ 'items_id' => $params['id_ticket'],
+ 'is_private' => true,
+ 'content' => $content,
+ ]);
+ }
$ticket = new \Ticket();
$ticket->getFromDB($params['id_ticket']);
diff --git a/templates/config.html.twig b/templates/config.html.twig
index 4ce53f6..dcf3d66 100644
--- a/templates/config.html.twig
+++ b/templates/config.html.twig
@@ -85,6 +85,22 @@
) }}
+