From 385eee465eb2e76220ae6d4ad7292d5d4e52a995 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 17 Sep 2020 15:53:01 +0200 Subject: [PATCH] fix(issue): handle deletion of validation Signed-off-by: Thierry Bugier --- hook.php | 4 ++++ inc/common.class.php | 15 +++++++++++---- inc/issue.class.php | 1 + setup.php | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hook.php b/hook.php index b48c8f311..ba402567e 100644 --- a/hook.php +++ b/hook.php @@ -467,6 +467,10 @@ function plugin_formcreator_hook_update_ticketvalidation(CommonDBTM $item) { $issue->update(['status' => $status['status']] + $issue->fields); } +function plugin_formcreator_hook_purge_ticketvalidation(CommonDBTM $item) { + plugin_formcreator_hook_update_ticketvalidation($item); +} + function plugin_formcreator_dynamicReport($params) { switch ($params['item_type']) { case PluginFormcreatorFormAnswer::class; diff --git a/inc/common.class.php b/inc/common.class.php index 3aa86e04c..1cc328e5b 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -230,16 +230,23 @@ public static function cancelMyTicket($id) { * t s | CLOSED | T V T T * * T = status picked from Ticket - * V = status picked ce qfrom Validation + * V = status picked from Validation * * @param Ticket $item * @return integer */ public static function getTicketStatusForIssue(Ticket $item) { - $ticketValidation = new TicketValidation(); - $ticketValidation->getFromDBByCrit([ + $ticketValidations = (new TicketValidation())->find([ 'tickets_id' => $item->getID(), - ]); + ], [ + 'timeline_position ASC' + ], 1); + $ticketValidation = new TicketValidation(); + if (count($ticketValidations)) { + $row = array_shift($ticketValidation); + $ticketValidation->getFromDB($row['id']); + } + $status = $item->fields['status']; $user = 0; if (!$ticketValidation->isNewItem()) { diff --git a/inc/issue.class.php b/inc/issue.class.php index 8a12e2315..671728557 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -160,6 +160,7 @@ public static function cronSyncIssues(CronTask $task) { $DB->query("INSERT INTO `$table` SELECT * FROM ($query) as `dt`"); $volume = 1; } + Toolbox::logError("Plugin Formcreator: Automatic action SyncIssue detected an inconsticency. Issues were rebuilt."); } } $task->setVolume($volume); diff --git a/setup.php b/setup.php index 16ffe2692..f47ea95c8 100644 --- a/setup.php +++ b/setup.php @@ -157,6 +157,9 @@ function plugin_init_formcreator() { $PLUGIN_HOOKS['item_update']['formcreator'] = [ TicketValidation::class => 'plugin_formcreator_hook_update_ticketvalidation' ]; + $PLUGIN_HOOKS['item_purge']['formcreator'] = [ + TicketValidation::class => 'plugin_formcreator_hook_purge_ticketvalidation' + ]; $PLUGIN_HOOKS['pre_item_purge']['formcreator'] = [ PluginFormcreatorTargetTicket::class => 'plugin_formcreator_hook_pre_purge_targetTicket', PluginFormcreatorTargetChange::class => 'plugin_formcreator_hook_pre_purge_targetChange'