From fa0e763665d9e2f1ec6c07d1922577a24bf445c5 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:46:54 +0200 Subject: [PATCH] fix(core) relationship of problem and device lost when category is changed --- src/CommonDBTM.php | 7 +++++-- src/CommonITILObject.php | 6 +++++- src/Problem.php | 2 +- src/Ticket.php | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/CommonDBTM.php b/src/CommonDBTM.php index 27a3da5db9f..eced58dd17e 100644 --- a/src/CommonDBTM.php +++ b/src/CommonDBTM.php @@ -1170,7 +1170,6 @@ protected function restoreInput(array $default = []) if (isset($_SESSION['saveInput'][$this->getType()])) { $saved = Html::cleanPostForTextArea($_SESSION['saveInput'][$this->getType()]); - // clear saved data when restored (only need once) $this->clearSavedInput(); @@ -2742,6 +2741,8 @@ public function initForm($ID, array $options = []) // Restore saved input or template data $input = $this->restoreInput($this->fields); + var_dump($input); + exit; // If entity assign force current entity to manage recursive templates if ($this->isEntityAssign()) { @@ -2752,7 +2753,9 @@ public function initForm($ID, array $options = []) $this->check(-1, CREATE, $input); } else if ($this->isNewID($ID)) { // Restore saved input if available - $input = $this->restoreInput($options); + $input = $this->restoreInput($options + ['_add_fromitem' => "_add_fromitem"]); + /*var_dump($input); + exit;*/ // Create item $this->check(-1, CREATE, $input); } else { diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php index f2827cb5208..c4a53d78dd6 100644 --- a/src/CommonITILObject.php +++ b/src/CommonITILObject.php @@ -565,6 +565,11 @@ protected function restoreInputAndDefaults($ID, array &$options, ?array $overrid // Set default options if ($force_set_defaults || static::isNewID($ID)) { + if (isset($options['_from_itemtype']) && isset($options['_from_items_id'])) { + if (!isset($default_values['_add_fromitem'])) { + $default_values['_add_fromitem'] = '_add_fromitem'; + } + } foreach ($default_values as $key => $val) { if (!isset($options[$key])) { if (isset($options['_saved'][$key])) { @@ -586,7 +591,6 @@ public function showForm($ID, array $options = []) if (!static::canView()) { return false; } - $this->restoreInputAndDefaults($ID, $options); $canupdate = !$ID || (Session::getCurrentInterface() == "central" && $this->canUpdateItem()); diff --git a/src/Problem.php b/src/Problem.php index 3ae55ed2571..523008e6596 100644 --- a/src/Problem.php +++ b/src/Problem.php @@ -1388,7 +1388,7 @@ public static function showListForItem(CommonDBTM $item, $withtemplate = 0) echo "
"; Html::showSimpleForm( Problem::getFormURL(), - '_add_fromitem', + '', __('New problem for this item...'), [ '_from_itemtype' => $item->getType(), diff --git a/src/Ticket.php b/src/Ticket.php index f6a42856145..f55fd74b344 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -5498,7 +5498,8 @@ public static function showListForItem(CommonDBTM $item, $withtemplate = 0) Ticket::getFormURL(), '_add_fromitem', __('New ticket for this item...'), - ['itemtype' => $item->getType(), + [ + 'itemtype' => $item->getType(), 'items_id' => $item->getID() ] );