Skip to content

Commit

Permalink
fix(core) relationship of problem and device lost when category is ch…
Browse files Browse the repository at this point in the history
…anged
  • Loading branch information
Lainow committed Oct 9, 2023
1 parent d2358bd commit fa0e763
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/CommonDBTM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()) {
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/Problem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ public static function showListForItem(CommonDBTM $item, $withtemplate = 0)
echo "<div class='firstbloc'>";
Html::showSimpleForm(
Problem::getFormURL(),
'_add_fromitem',
'',
__('New problem for this item...'),
[
'_from_itemtype' => $item->getType(),
Expand Down
3 changes: 2 additions & 1 deletion src/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]
);
Expand Down

0 comments on commit fa0e763

Please sign in to comment.