diff --git a/install/migrations/update_10.0.11_to_10.0.12.php b/install/migrations/update_10.0.11_to_10.0.12.php new file mode 100644 index 00000000000..76acd917e3c --- /dev/null +++ b/install/migrations/update_10.0.11_to_10.0.12.php @@ -0,0 +1,72 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * Update from 10.0.11 to 10.0.12 + * + * @return bool for success (will die for most error) + **/ +function update10011to10012() +{ + /** + * @var \DBmysql $DB + * @var \Migration $migration + */ + global $DB, $migration; + + $updateresult = true; + $ADDTODISPLAYPREF = []; + $DELFROMDISPLAYPREF = []; + $update_dir = __DIR__ . '/update_10.0.11_to_10.0.12/'; + + //TRANS: %s is the number of new version + $migration->displayTitle(sprintf(__('Update to %s'), '10.0.12')); + $migration->setVersion('10.0.12'); + + $update_scripts = scandir($update_dir); + foreach ($update_scripts as $update_script) { + if (preg_match('/\.php$/', $update_script) !== 1) { + continue; + } + require $update_dir . $update_script; + } + + // ************ Keep it at the end ************** + $migration->updateDisplayPrefs($ADDTODISPLAYPREF, $DELFROMDISPLAYPREF); + + $migration->executeMigration(); + + return $updateresult; +} diff --git a/install/migrations/update_10.0.11_to_10.0.12/duplicate_searchopt_fixes.php b/install/migrations/update_10.0.11_to_10.0.12/duplicate_searchopt_fixes.php new file mode 100644 index 00000000000..4b4f8d3bff0 --- /dev/null +++ b/install/migrations/update_10.0.11_to_10.0.12/duplicate_searchopt_fixes.php @@ -0,0 +1,55 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * @var \DBmysql $DB + * @var \Migration $migration + */ + +$iterator = $DB->request('glpi_configs', ['name' => 'lock_use_lock_item']); +$lock_use_lock_item = $iterator->current()['value'] ?? false; + +if ($lock_use_lock_item) { + $iterator = $DB->request('glpi_configs', ['name' => 'lock_item_list']); + $lock_item_list = $iterator->current()['value'] ?? ''; + $lock_item_list = json_decode($lock_item_list); + + if (is_array($lock_item_list)) { + foreach ($lock_item_list as $itemtype) { + $migration->changeSearchOption($itemtype, 205, 207); + $migration->changeSearchOption($itemtype, 206, 208); + } + } +} diff --git a/src/ObjectLock.php b/src/ObjectLock.php index 3b1275b7a95..800a90c01b4 100644 --- a/src/ObjectLock.php +++ b/src/ObjectLock.php @@ -594,7 +594,7 @@ public static function rawSearchOptionsToAdd($itemtype) && in_array($itemtype, $CFG_GLPI['lock_item_list']) ) { $tab[] = [ - 'id' => '205', + 'id' => '207', 'table' => 'glpi_users', 'field' => 'name', 'datatype' => 'dropdown', @@ -612,7 +612,7 @@ public static function rawSearchOptionsToAdd($itemtype) ]; $tab[] = [ - 'id' => '206', + 'id' => '208', 'table' => getTableForItemType('ObjectLock'), 'field' => 'date', 'datatype' => 'datetime', diff --git a/tests/functional/Search.php b/tests/functional/Search.php index 6bf13b0570c..d31619e7f5f 100644 --- a/tests/functional/Search.php +++ b/tests/functional/Search.php @@ -52,7 +52,7 @@ class Search extends DbTestCase { private function doSearch($itemtype, $params, array $forcedisplay = []) { - global $DEBUG_SQL; + global $DEBUG_SQL, $CFG_GLPI; // check param itemtype exists (to avoid search errors) if ($itemtype !== 'AllAssets') { @@ -64,6 +64,12 @@ private function doSearch($itemtype, $params, array $forcedisplay = []) $this->login(); } + // force item lock + if (in_array($itemtype, $CFG_GLPI['lock_lockable_objects'])) { + $CFG_GLPI["lock_use_lock_item"] = 1; + $CFG_GLPI["lock_item_list"] = [$itemtype]; + } + // force session in debug mode (to store & retrieve sql errors) $glpi_use_mode = $_SESSION['glpi_use_mode']; $_SESSION['glpi_use_mode'] = \Session::DEBUG_MODE;