Skip to content

Commit b46b64f

Browse files
committed
fix(issue): cancel ticket with simplified service catalog
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 333fefe commit b46b64f

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

hook.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -387,33 +387,35 @@ function plugin_formcreator_hook_update_ticket(CommonDBTM $item) {
387387
function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) {
388388
global $DB;
389389

390-
if ($item instanceof Ticket) {
391-
$id = $item->getID();
390+
if (!($item instanceof Ticket)) {
391+
return;
392+
}
392393

393-
// mark formanswers as deleted
394-
$iterator = $DB->request([
395-
'SELECT' => ['id'],
396-
'FROM' => Item_Ticket::getTable(),
397-
'WHERE' => [
398-
'itemtype' => 'PluginFormcreatorFormAnswer',
399-
'tickets_id' => $id,
400-
]
401-
]);
402-
foreach ($iterator as $row) {
403-
$form_answer = new PluginFormcreatorFormAnswer();
404-
$form_answer->update([
405-
'id' => $row['id'],
406-
'is_deleted' => 1,
407-
]);
408-
}
394+
$id = $item->getID();
409395

410-
// delete issue
411-
$issue = new PluginFormcreatorIssue();
412-
$issue->deleteByCriteria([
413-
'display_id' => "t_$id",
414-
'sub_itemtype' => 'Ticket'
415-
], 1);
396+
// mark formanswers as deleted
397+
$iterator = $DB->request([
398+
'SELECT' => ['id'],
399+
'FROM' => Item_Ticket::getTable(),
400+
'WHERE' => [
401+
'itemtype' => 'PluginFormcreatorFormAnswer',
402+
'tickets_id' => $id,
403+
]
404+
]);
405+
foreach ($iterator as $row) {
406+
$form_answer = new PluginFormcreatorFormAnswer();
407+
$form_answer->update([
408+
'id' => $row['id'],
409+
'is_deleted' => 1,
410+
]);
416411
}
412+
413+
// delete issue
414+
$issue = new PluginFormcreatorIssue();
415+
$issue->deleteByCriteria([
416+
'display_id' => "t_$id",
417+
'sub_itemtype' => 'Ticket'
418+
], 1);
417419
}
418420

419421
function plugin_formcreator_hook_restore_ticket(CommonDBTM $item) {

js/scripts.js.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,8 +1335,10 @@ function plugin_formcreator_cancelMyTicket(id) {
13351335
url: rootDoc + '/plugins/formcreator/ajax/cancelticket.php',
13361336
data: {id: id},
13371337
type: "POST",
1338-
dataType: "json"
1338+
dataType: "text"
13391339
}).done(function(response) {
1340-
reloadTab;
1340+
window.location.replace(rootDoc + '/plugins/formcreator/front/issue.php?reset=reset');
1341+
}).error(function(response) {
1342+
alert("<?php echo __('Failed to cancel the ticket', 'formcreator'); ?>");
13411343
});
13421344
}

0 commit comments

Comments
 (0)