Skip to content

Commit

Permalink
fix(issue): loss of issue on automatic action
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jan 22, 2021
1 parent 3266fc9 commit f6a33ad
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 9 deletions.
2 changes: 1 addition & 1 deletion front/targetticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
$use_notification = ($_POST['use_notification'] == 0) ? 0 : 1;
$targetTicket_actor = new PluginFormcreatorTarget_Actor();
$targetTicket_actor->add([
'itemtype' => $targetticket->getType(),
'itemtype' => $targetticket->getType(),
'items_id' => $id,
'actor_role' => $_POST['actor_role'],
'actor_type' => $_POST['actor_type'],
Expand Down
18 changes: 11 additions & 7 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,17 @@ public static function getSyncIssuesRequest() : AbstractQuery {
],
[
'TABLE' => new QuerySubquery([
'SELECT' => ['users_id', $ticketFk],
'DISTINCT' => true,
'FROM' => $ticketUserTable,
'WHERE' => [
'type' => CommonITILActor::REQUESTER,
],
'ORDER' => ['id ASC'],
'SELECT' => '*',
'FROM' => new QuerySubquery([
'SELECT' => ['users_id', $ticketFk],
'DISTINCT' => true,
'FROM' => $ticketUserTable,
'WHERE' => [
'type' => CommonITILActor::REQUESTER,
],
'ORDER' => ['id ASC'],
], 'inner_glpi_tickets_users'),
'GROUPBY' => 'tickets_id'
], 'glpi_tickets_users'),
'FKEY' => [
$ticketTable => 'id',
Expand Down
99 changes: 98 additions & 1 deletion tests/3-unit/PluginFormcreatorIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,43 @@ public function providerGetsyncIssuesRequest_simpleFormanswers() {
];
}

public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() {
$form = $this->getForm();
$targetTicket1 = new \PluginFormcreatorTargetTicket();
$targetTicket1->add([
'plugin_formcreator_forms_id' => $form->getID(),
'name' => 'foo',
]);
$this->boolean($targetTicket1->isNewItem())->isFalse();

$formAnswer = new \PluginFormcreatorFormAnswer();
$formAnswer->add([
'plugin_formcreator_forms_id' => $form->getID(),
]);
$this->boolean($formAnswer->isNewItem())->isFalse();
$formAnswer->getFromDB($formAnswer->getID());
$ticket = array_shift($formAnswer->targetList);
$this->object($ticket)->isInstanceOf(\Ticket::getType());

return [
'formAnswerWithOneTicket' => [
'item' => $ticket,
'expected' => [
'sub_itemtype' => \Ticket::getType(),
'original_id' => $ticket->getID(),
'display_id' => 't_' . $ticket->getID(),
'name' => $ticket->fields['name'],
'status' => $ticket->fields['status'],
'requester_id' => $ticket->fields['users_id_recipient'],
'date_creation' => $ticket->fields['date'],
'date_mod' => $ticket->fields['date_mod'],
'users_id_validator' => '0',
'groups_id_validator' => '0',
],
],
];
}

public function providerGetSyncIssuesRequest_formAnswerWithSeveralTickets() {
$form = $this->getForm();
$targetTicket1 = new \PluginFormcreatorTargetTicket();
Expand Down Expand Up @@ -285,14 +322,74 @@ public function providerGetsyncIssuesRequest_validatedTicket() {
];
}

public function providerGetSyncIssuesRequest_FormAnswerWithSeveralRequesters() {
$form = $this->getForm();
$targetTicket1 = new \PluginFormcreatorTargetTicket();
$targetTicket1->add([
'plugin_formcreator_forms_id' => $form->getID(),
'name' => 'foo',
]);
$this->boolean($targetTicket1->isNewItem())->isFalse();

$actor1 = new \PluginFormcreatorTarget_Actor();
$actor1->add([
'itemtype' => $targetTicket1->getType(),
'items_id' => $targetTicket1->getID(),
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON,
'actor_type' => \CommonITILActor::REQUESTER,
'actor_value' => 3,
'use_notification' => '1',
]);
$this->boolean($actor1->isNewItem())->isFalse();
$actor2 = new \PluginFormcreatorTarget_Actor();
$actor2->add([
'itemtype' => $targetTicket1->getType(),
'items_id' => $targetTicket1->getID(),
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON,
'actor_type' => \CommonITILActor::REQUESTER,
'actor_value' => 5,
'use_notification' => '1',
]);
$this->boolean($actor2->isNewItem())->isFalse();

$formAnswer = new \PluginFormcreatorFormAnswer();
$formAnswer->add([
'plugin_formcreator_forms_id' => $form->getID(),
]);
$this->boolean($formAnswer->isNewItem())->isFalse();
$formAnswer->getFromDB($formAnswer->getID());

$ticket = array_shift($formAnswer->targetList);
$this->object($ticket)->isInstanceOf(\Ticket::getType());
return [
'formAnswerWithSeveralRequesters' => [
'item' => $ticket,
'expected' => [
'sub_itemtype' => \Ticket::getType(),
'original_id' => $ticket->getID(),
'display_id' => 't_' . $ticket->getID(),
'name' => $ticket->fields['name'],
'status' => $ticket->fields['status'],
'requester_id' => $ticket->fields['users_id_recipient'],
'date_creation' => $ticket->fields['date'],
'date_mod' => $ticket->fields['date_mod'],
'users_id_validator' => '0',
'groups_id_validator' => '0',
],
],
];
}

public function providerGetSyncIssuesRequest() {
return array_merge(
$this->providerGetsyncIssuesRequest_simpleTicket(),
$this->providerGetsyncIssuesRequest_simpleFormanswers(),
$this->providerGetSyncIssuesRequest_formAnswerWithOneTicket(),
$this->providerGetSyncIssuesRequest_formAnswerWithSeveralTickets(),
$this->providerGetSyncIssuesRequest_formanswerUnderValidation(),
$this->providerGetsyncIssuesRequest_ticketUnderValidation(),
$this->providerGetsyncIssuesRequest_validatedTicket()
$this->providerGetsyncIssuesRequest_validatedTicket(),
$this->providerGetSyncIssuesRequest_FormAnswerWithSeveralRequesters()
);
}

Expand Down

0 comments on commit f6a33ad

Please sign in to comment.