Skip to content

Commit

Permalink
fix: cannot delete a ticket from service catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Aug 10, 2022
1 parent ba6ed88 commit acec9bb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 49 deletions.
1 change: 1 addition & 0 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public function display($options = []) {
if (!class_exists($itemtype)) {
Html::displayNotFoundError();
}
/** @var CommonDBTM $item */
$item = new $itemtype();
if (!$item->getFromDB($this->fields['items_id'])) {
Html::displayNotFoundError();
Expand Down
104 changes: 55 additions & 49 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,62 +425,68 @@ function plugin_formcreator_redirect() {
return;
}

if (!plugin_formcreator_replaceHelpdesk()) {
return;
}

if (strpos($_SERVER['REQUEST_URI'], "front/ticket.form.php") !== false) {
if (!isset($_POST['update']) && plugin_formcreator_replaceHelpdesk()) {
$decodedUrl = [];
$openItilFollowup = '';
if (isset($_GET['_openfollowup'])) {
$openItilFollowup = '&_openfollowup=1';
}
if (isset($_SERVER['QUERY_STRING'])) {
parse_str($_SERVER['QUERY_STRING'], $decodedUrl);
if (isset($decodedUrl['forcetab'])) {
Session::setActiveTab(Ticket::class, $decodedUrl['forcetab']);
}
}
if (!isset($_GET['id'])) {
// invalid url
Html::redirect($CFG_GLPI["root_doc"]);
}
if (isset($_POST['update']) || isset($_POST['delete'])) {
return;
}

// When an ticket has a matching issue (it means that the ticket is the only generated ticket)
$issue = new PluginFormcreatorIssue();
$issues = $issue->find([
'itemtype' => Ticket::class,
'items_id' => (int) $_GET['id']
]);
if (count($issues) == 1) {
$issueId = array_pop($issues)['id'];
$issue->getFromDB($issueId);
Html::redirect($issue->getFormURLWithID($issue->getID()) . $openItilFollowup);
$decodedUrl = [];
$openItilFollowup = '';
if (isset($_GET['_openfollowup'])) {
$openItilFollowup = '&_openfollowup=1';
}
if (isset($_SERVER['QUERY_STRING'])) {
parse_str($_SERVER['QUERY_STRING'], $decodedUrl);
if (isset($decodedUrl['forcetab'])) {
Session::setActiveTab(Ticket::class, $decodedUrl['forcetab']);
}
}
if (!isset($_GET['id'])) {
// invalid url
Html::redirect($CFG_GLPI["root_doc"]);
}

// When no or several tickets matches an issue, rely use the Form Answer
$itemTicket = new Item_Ticket();
$itemTicket->getFromDBByCrit([
'itemtype' => PluginFormcreatorFormAnswer::class,
'tickets_id' => (int) $_GET['id']
]);
if ($itemTicket->isNewItem()) {
// No formanswer found
Html::displayNotFoundError();
}
// When an ticket has a matching issue (it means that the ticket is the only generated ticket)
$issue = new PluginFormcreatorIssue();
$issues = $issue->find([
'itemtype' => Ticket::class,
'items_id' => (int) $_GET['id']
]);
if (count($issues) == 1) {
$issueId = array_pop($issues)['id'];
$issue->getFromDB($issueId);
Html::redirect($issue->getFormURLWithID($issue->getID()) . $openItilFollowup);
}

$issue->getFromDBByCrit([
'itemtype' => PluginFormcreatorFormAnswer::class,
'items_id' => $itemTicket->fields['items_id']
]);
if ($issue->isNewItem()) {
// No formanswer found
Html::displayNotFoundError();
}
$ticket = Ticket::getById($itemTicket->fields['tickets_id']);
if ($ticket === false) {
Html::redirect($issue->getFormURLWithID($itemTicket->fields['items_id']) . $openItilFollowup);
}
// When no or several tickets matches an issue, rely use the Form Answer
$itemTicket = new Item_Ticket();
$itemTicket->getFromDBByCrit([
'itemtype' => PluginFormcreatorFormAnswer::class,
'tickets_id' => (int) $_GET['id']
]);
if ($itemTicket->isNewItem()) {
// No formanswer found
Html::displayNotFoundError();
}

Html::redirect($issue->getFormURLWithID($issue->getID()) . '&tickets_id=' . $itemTicket->fields['tickets_id']);
$issue->getFromDBByCrit([
'itemtype' => PluginFormcreatorFormAnswer::class,
'items_id' => $itemTicket->fields['items_id']
]);
if ($issue->isNewItem()) {
// No formanswer found
Html::displayNotFoundError();
}
$ticket = Ticket::getById($itemTicket->fields['tickets_id']);
if ($ticket === false) {
Html::redirect($issue->getFormURLWithID($itemTicket->fields['items_id']) . $openItilFollowup);
}

Html::redirect($issue->getFormURLWithID($issue->getID()) . '&tickets_id=' . $itemTicket->fields['tickets_id']);
}
}

Expand Down

0 comments on commit acec9bb

Please sign in to comment.