Skip to content

Commit

Permalink
fix(migration): update template fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B committed Apr 25, 2024
1 parent 4741bfa commit 385f99d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Migration.php
Expand Up @@ -1716,6 +1716,25 @@ private function migrateSearchOptions()
'itemtype' => $itemtype,
'num' => $old_search_opt
]);

// Update template fields
if (is_a($itemtype, 'CommonITILObject', true)) {
$tables = [
'glpi_' . strtolower($itemtype) . 'templatehiddenfields',
'glpi_' . strtolower($itemtype) . 'templatemandatoryfields',
'glpi_' . strtolower($itemtype) . 'templatepredefinedfields',
];
foreach ($tables as $table) {
if (!$DB->tableExists($table)) {
continue;
}
$DB->updateOrDie($table, [
'field' => $new_search_opt
], [
'field' => $old_search_opt
]);
}
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/units/Migration.php
Expand Up @@ -1151,6 +1151,9 @@ public function testChangeSearchOption()

$this->migration->changeSearchOption('Computer', 40, 100);
$this->migration->changeSearchOption('Printer', 20, 10);
$this->migration->changeSearchOption('Ticket', 1, 1001);

$this->calling($this->db)->tableExists = true;

$this->output(
function () {
Expand All @@ -1162,6 +1165,10 @@ function () {
"UPDATE `glpi_displaypreferences` SET `num` = '100' WHERE `itemtype` = 'Computer' AND `num` = '40'",
"DELETE `glpi_displaypreferences` FROM `glpi_displaypreferences` WHERE `id` IN ('12', '156', '421')",
"UPDATE `glpi_displaypreferences` SET `num` = '10' WHERE `itemtype` = 'Printer' AND `num` = '20'",
"UPDATE `glpi_displaypreferences` SET `num` = '1001' WHERE `itemtype` = 'Ticket' AND `num` = '1'",
"UPDATE `glpi_tickettemplatehiddenfields` SET `field` = '1001' WHERE `field` = '1'",
"UPDATE `glpi_tickettemplatemandatoryfields` SET `field` = '1001' WHERE `field` = '1'",
"UPDATE `glpi_tickettemplatepredefinedfields` SET `field` = '1001' WHERE `field` = '1'",
"UPDATE `glpi_savedsearches` SET `query` = 'is_deleted=0&as_map=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=100&criteria%5B0%5D%5Bsearchtype%5D=contains&criteria%5B0%5D%5Bvalue%5D=LT1&criteria%5B1%5D%5Blink%5D=AND&criteria%5B1%5D%5Bitemtype%5D=Budget&criteria%5B1%5D%5Bmeta%5D=1&criteria%5B1%5D%5Bfield%5D=4&criteria%5B1%5D%5Bsearchtype%5D=contains&criteria%5B1%5D%5Bvalue%5D=&search=Search&itemtype=Computer' WHERE `id` = '1'",
"UPDATE `glpi_savedsearches` SET `query` = 'is_deleted=0&as_map=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=40&criteria%5B0%5D%5Bsearchtype%5D=contains&criteria%5B0%5D%5Bvalue%5D=LT1&criteria%5B1%5D%5Blink%5D=AND&criteria%5B1%5D%5Bitemtype%5D=Computer&criteria%5B1%5D%5Bmeta%5D=1&criteria%5B1%5D%5Bfield%5D=100&criteria%5B1%5D%5Bsearchtype%5D=contains&criteria%5B1%5D%5Bvalue%5D=&search=Search&itemtype=Computer' WHERE `id` = '2'",
]);
Expand Down

0 comments on commit 385f99d

Please sign in to comment.