From 434bd357234b57eb9fbb2fa8d765432e3f7d0169 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 15 Dec 2022 09:11:08 +0100 Subject: [PATCH] fix(issue): follow entity change on ticket transfer --- hook.php | 35 +++++++++++++++++++++++++++++++++++ setup.php | 3 +++ 2 files changed, 38 insertions(+) diff --git a/hook.php b/hook.php index c69ab52ca..7a9737457 100644 --- a/hook.php +++ b/hook.php @@ -716,3 +716,38 @@ function plugin_formcreator_hook_update_user(CommonDBTM $item) { } } } + +function plugin_formcreator_transfer(array $options) { + if ($options['type'] != Ticket::class) { + return; + } + + if ($options['id'] == $options['newID']) { + $issue = new PluginFormcreatorIssue(); + if (!$issue->getFromDbByCrit([ + 'itemtype' => $options['type'], + 'items_id' => $options['id'], + ])) { + // No matching issue found + return; + } + $issue->update([ + 'id' => $issue->getID(), + 'entities_id' => $options['entities_id'], + ]); + } else { + $item_ticket = new Item_Ticket(); + if (!$item_ticket->getFromDBByCrit([ + 'itemtype' => PluginFormcreatorFormAnswer::class, + 'tickets_id' => $options['id'], + ])) { + // No matching form answer found + return; + } + $item_ticket->add([ + 'itemtype' => PluginFormcreatorFormAnswer::class, + 'items_id' => $item_ticket->fields['items_id'], + 'tickets_id' => $options['newID'], + ]); + } +} \ No newline at end of file diff --git a/setup.php b/setup.php index c35e9df64..5b62bbb9f 100644 --- a/setup.php +++ b/setup.php @@ -305,6 +305,9 @@ function plugin_formcreator_permanent_hook(): void { ]; // hook to add custom actions on a ticket in service catalog $PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['formcreator'] = 'plugin_formcreator_timelineActions'; + + $PLUGIN_HOOKS[Hooks::ITEM_TRANSFER]['formcreator'] = 'plugin_formcreator_transfer'; + } /**