From 3182b326bca08b84fc3b0d5b4dc073e5ebfd14e7 Mon Sep 17 00:00:00 2001 From: Giovanny Rodriguez Date: Mon, 11 May 2026 11:20:58 -0500 Subject: [PATCH 1/3] Replace task with followup on ticket transfer and unify content Transfer logging used TicketTask (task) which is intended for work to be done. ITILFollowup (followup) is the correct type to record an event that already happened. Also consolidates entity, group, and justification into a single followup instead of relying on fragmented string concatenation, and guards the group/justification sections with !empty() so they only appear when actually set. Co-Authored-By: Claude Sonnet 4.6 --- src/Ticket.php | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Ticket.php b/src/Ticket.php index dae70ea..7f7540d 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -42,10 +42,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')) { @@ -633,25 +632,25 @@ public function launchTicketTransfer($params) } } - $groupText = "

$justification"; + $content = __("Transfer 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' => __( - "Transfer to", - "transferticketentity" - ) . " $theEntity " . $groupText + 'content' => $content, ]); $ticket = new \Ticket(); From ca5e9b015eb66aa6b0b9625a24602443e60fef9d Mon Sep 17 00:00:00 2001 From: Giovanny Rodriguez Date: Mon, 25 May 2026 09:30:24 -0500 Subject: [PATCH 2/3] Add configurable log type (followup or task) per entity Admins can now choose per destination entity whether the transfer is logged as a followup (default) or as a task. The choice is stored in a new log_type column (0=followup, 1=task). A migration guard adds the column on existing installations via ALTER TABLE. Co-Authored-By: Claude Sonnet 4.6 --- hook.php | 6 ++++++ src/Entity.php | 9 ++++++++- src/Ticket.php | 28 ++++++++++++++++++++-------- templates/config.html.twig | 16 ++++++++++++++++ 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/hook.php b/hook.php index 4c48a38..c572721 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 215f0f5..e878e99 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,7 +218,10 @@ public function showFormMcv($item) 'entities_id' => $item->getID(), 'availableCategories' => $availableCategories, 'checkMandatoryCategory' => $checkMandatoryCategory, - ], + 'log_type_options' => [ + 0 => __('Followup', 'transferticketentity'), + 1 => __('Task', 'transferticketentity'), + ], ); return true; @@ -264,6 +270,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 7f7540d..a504223 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -45,6 +45,8 @@ use Session; use Ticket_User; use ITILFollowup; +use Planning; +use TicketTask; use TicketTemplateMandatoryField; if (!defined('GLPI_ROOT')) { @@ -644,14 +646,24 @@ public function launchTicketTransfer($params) $content .= "

" . $justification; } - // Log the transfer as a followup - $followup = new ITILFollowup(); - $followup->add([ - 'itemtype' => \Ticket::class, - 'items_id' => $params['id_ticket'], - 'is_private' => true, - 'content' => $content, - ]); + // 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 4e70990..c3817db 100644 --- a/templates/config.html.twig +++ b/templates/config.html.twig @@ -86,6 +86,22 @@ along with Reports. If not, see . ) }} +
+ +
+ {% do call('Dropdown::showFromArray', [ + 'log_type', + log_type_options, + { + 'multiple': false, + 'value': item.fields['log_type']|default(0), + } + ]) %} +
+
+ {# Bloc catégorie #}
From 66737e290de3eeba4b7971adf6dbff0d18f1e1db Mon Sep 17 00:00:00 2001 From: Giovanny Rodriguez Date: Mon, 25 May 2026 09:47:14 -0500 Subject: [PATCH 3/3] Fix unclosed array bracket in Entity showFormMcv --- src/Entity.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Entity.php b/src/Entity.php index e878e99..a07a94f 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -222,6 +222,7 @@ public function showFormMcv($item) 0 => __('Followup', 'transferticketentity'), 1 => __('Task', 'transferticketentity'), ], + ], ); return true;