Skip to content

Commit

Permalink
fix(issue): recreate when restore ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Sep 2, 2022
1 parent 247a574 commit 2656e28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
18 changes: 7 additions & 11 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ function plugin_formcreator_hook_add_ticket(CommonDBTM $item) {
return;
}

if (isset($item->input['items_id'][PluginFormcreatorFormAnswer::getType()])) {
// the ticket is associated to a form answer
return;
}

$requester = $DB->request([
'SELECT' => 'users_id',
'FROM' => Ticket_User::getTable(),
Expand Down Expand Up @@ -482,15 +477,16 @@ function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) {

function plugin_formcreator_hook_restore_ticket(CommonDBTM $item) {
$formAnswer = new PluginFormcreatorFormAnswer();
if (! $formAnswer->getFromDbByTicket($item)) {
plugin_formcreator_hook_add_ticket($item);
if ($formAnswer->getFromDbByTicket($item)) {
$formAnswer->createIssue();
$minimalStatus = $formAnswer->getAggregatedStatus();
if ($minimalStatus !== null) {
$formAnswer->updateStatus($minimalStatus);
}
return;
}

$minimalStatus = $formAnswer->getAggregatedStatus();
if ($minimalStatus !== null) {
$formAnswer->updateStatus($minimalStatus);
}
plugin_formcreator_hook_add_ticket($item);
}

function plugin_formcreator_hook_purge_ticket(CommonDBTM $item) {
Expand Down
13 changes: 6 additions & 7 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,9 @@ public function post_addItem() {
return;
}
}
$this->createIssue();
if ($this->input['status'] != self::STATUS_REFUSED) {
$this->createIssue();
}
$minimalStatus = $formAnswer->getAggregatedStatus();
if ($minimalStatus !== null) {
$this->updateStatus($minimalStatus);
Expand Down Expand Up @@ -1346,14 +1348,9 @@ private function sendNotification() {
}
}

private function createIssue() {
public function createIssue() {
global $DB;

$issue = new PluginFormcreatorIssue();
if ($this->input['status'] == self::STATUS_REFUSED) {
return;
}

// If cannot get itemTicket from DB it happens either
// when no item exist
// or when several rows matches
Expand All @@ -1377,6 +1374,8 @@ private function createIssue() {
'items_id' => $this->getID(),
]
]);

$issue = new PluginFormcreatorIssue();
if ($rows->count() != 1) {
// There is no or several tickets for this form answer
// The issue must be created from this form answer
Expand Down

0 comments on commit 2656e28

Please sign in to comment.