Skip to content

Commit 434bd35

Browse files
committed
fix(issue): follow entity change on ticket transfer
1 parent c3d03b5 commit 434bd35

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

hook.php

+35
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,38 @@ function plugin_formcreator_hook_update_user(CommonDBTM $item) {
716716
}
717717
}
718718
}
719+
720+
function plugin_formcreator_transfer(array $options) {
721+
if ($options['type'] != Ticket::class) {
722+
return;
723+
}
724+
725+
if ($options['id'] == $options['newID']) {
726+
$issue = new PluginFormcreatorIssue();
727+
if (!$issue->getFromDbByCrit([
728+
'itemtype' => $options['type'],
729+
'items_id' => $options['id'],
730+
])) {
731+
// No matching issue found
732+
return;
733+
}
734+
$issue->update([
735+
'id' => $issue->getID(),
736+
'entities_id' => $options['entities_id'],
737+
]);
738+
} else {
739+
$item_ticket = new Item_Ticket();
740+
if (!$item_ticket->getFromDBByCrit([
741+
'itemtype' => PluginFormcreatorFormAnswer::class,
742+
'tickets_id' => $options['id'],
743+
])) {
744+
// No matching form answer found
745+
return;
746+
}
747+
$item_ticket->add([
748+
'itemtype' => PluginFormcreatorFormAnswer::class,
749+
'items_id' => $item_ticket->fields['items_id'],
750+
'tickets_id' => $options['newID'],
751+
]);
752+
}
753+
}

setup.php

+3
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ function plugin_formcreator_permanent_hook(): void {
305305
];
306306
// hook to add custom actions on a ticket in service catalog
307307
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['formcreator'] = 'plugin_formcreator_timelineActions';
308+
309+
$PLUGIN_HOOKS[Hooks::ITEM_TRANSFER]['formcreator'] = 'plugin_formcreator_transfer';
310+
308311
}
309312

310313
/**

0 commit comments

Comments
 (0)