Skip to content

Commit 5db55f6

Browse files
committed
fix(issue): update issue status on ticket validation update
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 636d674 commit 5db55f6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

inc/common.class.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ public static function cancelMyTicket($id) {
230230

231231
/**
232232
* Get the status to set for an issue matching a ticket
233+
* Tightly related to SQL query in SyncIssues automatic actions
234+
*
235+
* Conversion matrix
236+
*
237+
* Validation Status
238+
* +-------------+---------+---------+----------+
239+
* |NULL or NONE | WAITING | REFUSED | ACCEPTED |
240+
* + ---------+-------------+---------+---------+----------+
241+
* T S | INCOMING | T V V T
242+
* i t | ASSIGNED | T V V T
243+
* c a | PLANNED | T V V T
244+
* k t | WAITING | T V V T
245+
* e u | SOLVED | T V T T
246+
* t s | CLOSED | T V T T
247+
*
248+
* T = status picked from Ticket
249+
* V = status picked ce qfrom Validation
250+
*
233251
* @param Ticket $item
234252
* @return integer
235253
*/
@@ -242,6 +260,17 @@ public static function getTicketStatusForIssue(Ticket $item) {
242260
$user = 0;
243261
if (!$ticketValidation->isNewItem()) {
244262
$user = $ticketValidation->fields['users_id_validate'];
263+
switch ($ticketValidation->fields['status']) {
264+
case CommonITILValidation::WAITING:
265+
$status = PluginFormcreatorFormAnswer::STATUS_WAITING;
266+
break;
267+
268+
case CommonITILValidation::REFUSED:
269+
if ($item->fields['status'] != Ticket::SOLVED && $item->fields['status'] != Ticket::CLOSED) {
270+
$status = PluginFormcreatorFormAnswer::STATUS_REFUSED;
271+
}
272+
break;
273+
}
245274
}
246275

247276
return ['status' => $status, 'user' => $user];

inc/issue.class.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public static function cronSyncIssues(CronTask $task) {
7575
$formAnswerTable = PluginFormcreatorFormAnswer::getTable();
7676
$itemTicketTable = Item_Ticket::getTable();
7777
$ticketFk = Ticket::getForeignKeyField();
78+
// The columns status of the 2nd part of the UNNION statement
79+
// must match the same logic as PluginFormcreatorCommon::getTicketStatusForIssue()
80+
// @see PluginFormcreatorCommon::getTicketStatusForIssue()
7881
$query1 = new QuerySubQuery([
7982
'SELECT' => [
8083
new QueryExpression('NULL as `id`'),
@@ -127,7 +130,19 @@ public static function cronSyncIssues(CronTask $task) {
127130
new QueryExpression("CONCAT('t_', `$ticketTable`.`id`) as `display_id`"),
128131
"$ticketTable.id as original_id",
129132
new QueryExpression("'" . Ticket::getType() . "' as `sub_itemtype`"),
130-
new QueryExpression("IF(`$ticketValidationTable`.`status` IS NULL,`$ticketTable`.`status`, IF(`$ticketValidationTable`.`status` = 2, 101, IF(`$ticketValidationTable`.`status` = 3, `$ticketTable`.`status`, 102))) AS `status`"),
133+
new QueryExpression("IF(`$ticketValidationTable`.`status` IS NULL,
134+
`$ticketTable`.`status`,
135+
IF(`$ticketValidationTable`.`status` IN ('1', '3'),
136+
`$ticketTable`.`status`,
137+
IF(`$ticketTable`.`status` IN ('5', '6') AND `$ticketValidationTable`.`status` = '4',
138+
`$ticketTable`.`status`,
139+
IF(`$ticketValidationTable`.`status` = '" . CommonITILValidation::WAITING . "',
140+
'" . PluginFormcreatorFormAnswer::STATUS_WAITING . "',
141+
'" . PluginFormcreatorFormAnswer::STATUS_REFUSED . "'
142+
)
143+
)
144+
)
145+
) AS `status`"),
131146
$ticketTable => [
132147
'date as date_creation',
133148
'date_mod as date_mod',

0 commit comments

Comments
 (0)