Skip to content

Commit

Permalink
fix(issue): update issue status on ticket validation update
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Oct 20, 2020
1 parent 636d674 commit 5db55f6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
29 changes: 29 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ public static function cancelMyTicket($id) {

/**
* Get the status to set for an issue matching a ticket
* Tightly related to SQL query in SyncIssues automatic actions
*
* Conversion matrix
*
* Validation Status
* +-------------+---------+---------+----------+
* |NULL or NONE | WAITING | REFUSED | ACCEPTED |
* + ---------+-------------+---------+---------+----------+
* T S | INCOMING | T V V T
* i t | ASSIGNED | T V V T
* c a | PLANNED | T V V T
* k t | WAITING | T V V T
* e u | SOLVED | T V T T
* t s | CLOSED | T V T T
*
* T = status picked from Ticket
* V = status picked ce qfrom Validation
*
* @param Ticket $item
* @return integer
*/
Expand All @@ -242,6 +260,17 @@ public static function getTicketStatusForIssue(Ticket $item) {
$user = 0;
if (!$ticketValidation->isNewItem()) {
$user = $ticketValidation->fields['users_id_validate'];
switch ($ticketValidation->fields['status']) {
case CommonITILValidation::WAITING:
$status = PluginFormcreatorFormAnswer::STATUS_WAITING;
break;

case CommonITILValidation::REFUSED:
if ($item->fields['status'] != Ticket::SOLVED && $item->fields['status'] != Ticket::CLOSED) {
$status = PluginFormcreatorFormAnswer::STATUS_REFUSED;
}
break;
}
}

return ['status' => $status, 'user' => $user];
Expand Down
17 changes: 16 additions & 1 deletion inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static function cronSyncIssues(CronTask $task) {
$formAnswerTable = PluginFormcreatorFormAnswer::getTable();
$itemTicketTable = Item_Ticket::getTable();
$ticketFk = Ticket::getForeignKeyField();
// The columns status of the 2nd part of the UNNION statement
// must match the same logic as PluginFormcreatorCommon::getTicketStatusForIssue()
// @see PluginFormcreatorCommon::getTicketStatusForIssue()
$query1 = new QuerySubQuery([
'SELECT' => [
new QueryExpression('NULL as `id`'),
Expand Down Expand Up @@ -127,7 +130,19 @@ public static function cronSyncIssues(CronTask $task) {
new QueryExpression("CONCAT('t_', `$ticketTable`.`id`) as `display_id`"),
"$ticketTable.id as original_id",
new QueryExpression("'" . Ticket::getType() . "' as `sub_itemtype`"),
new QueryExpression("IF(`$ticketValidationTable`.`status` IS NULL,`$ticketTable`.`status`, IF(`$ticketValidationTable`.`status` = 2, 101, IF(`$ticketValidationTable`.`status` = 3, `$ticketTable`.`status`, 102))) AS `status`"),
new QueryExpression("IF(`$ticketValidationTable`.`status` IS NULL,
`$ticketTable`.`status`,
IF(`$ticketValidationTable`.`status` IN ('1', '3'),
`$ticketTable`.`status`,
IF(`$ticketTable`.`status` IN ('5', '6') AND `$ticketValidationTable`.`status` = '4',
`$ticketTable`.`status`,
IF(`$ticketValidationTable`.`status` = '" . CommonITILValidation::WAITING . "',
'" . PluginFormcreatorFormAnswer::STATUS_WAITING . "',
'" . PluginFormcreatorFormAnswer::STATUS_REFUSED . "'
)
)
)
) AS `status`"),
$ticketTable => [
'date as date_creation',
'date_mod as date_mod',
Expand Down

0 comments on commit 5db55f6

Please sign in to comment.