Skip to content

Commit

Permalink
fix(issue): cancel ticket with simplified service catalog
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Jun 19, 2020
1 parent 333fefe commit b46b64f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
50 changes: 26 additions & 24 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,33 +387,35 @@ function plugin_formcreator_hook_update_ticket(CommonDBTM $item) {
function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) {
global $DB;

if ($item instanceof Ticket) {
$id = $item->getID();
if (!($item instanceof Ticket)) {
return;
}

// mark formanswers as deleted
$iterator = $DB->request([
'SELECT' => ['id'],
'FROM' => Item_Ticket::getTable(),
'WHERE' => [
'itemtype' => 'PluginFormcreatorFormAnswer',
'tickets_id' => $id,
]
]);
foreach ($iterator as $row) {
$form_answer = new PluginFormcreatorFormAnswer();
$form_answer->update([
'id' => $row['id'],
'is_deleted' => 1,
]);
}
$id = $item->getID();

// delete issue
$issue = new PluginFormcreatorIssue();
$issue->deleteByCriteria([
'display_id' => "t_$id",
'sub_itemtype' => 'Ticket'
], 1);
// mark formanswers as deleted
$iterator = $DB->request([
'SELECT' => ['id'],
'FROM' => Item_Ticket::getTable(),
'WHERE' => [
'itemtype' => 'PluginFormcreatorFormAnswer',
'tickets_id' => $id,
]
]);
foreach ($iterator as $row) {
$form_answer = new PluginFormcreatorFormAnswer();
$form_answer->update([
'id' => $row['id'],
'is_deleted' => 1,
]);
}

// delete issue
$issue = new PluginFormcreatorIssue();
$issue->deleteByCriteria([
'display_id' => "t_$id",
'sub_itemtype' => 'Ticket'
], 1);
}

function plugin_formcreator_hook_restore_ticket(CommonDBTM $item) {
Expand Down
6 changes: 4 additions & 2 deletions js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,10 @@ function plugin_formcreator_cancelMyTicket(id) {
url: rootDoc + '/plugins/formcreator/ajax/cancelticket.php',
data: {id: id},
type: "POST",
dataType: "json"
dataType: "text"
}).done(function(response) {
reloadTab;
window.location.replace(rootDoc + '/plugins/formcreator/front/issue.php?reset=reset');
}).error(function(response) {
alert("<?php echo __('Failed to cancel the ticket', 'formcreator'); ?>");
});
}

0 comments on commit b46b64f

Please sign in to comment.