Skip to content

Commit

Permalink
fix(object lock): duplicate keys in search options
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored Dec 18, 2023
1 parent 1221d33 commit 8d8f4d2
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 deletions.
72 changes: 72 additions & 0 deletions install/migrations/update_10.0.11_to_10.0.12.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2023 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* 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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2023 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* @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);
}
}
}
4 changes: 2 additions & 2 deletions src/ObjectLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -612,7 +612,7 @@ public static function rawSearchOptionsToAdd($itemtype)
];

$tab[] = [
'id' => '206',
'id' => '208',
'table' => getTableForItemType('ObjectLock'),
'field' => 'date',
'datatype' => 'datetime',
Expand Down
8 changes: 7 additions & 1 deletion tests/functional/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
Expand Down

0 comments on commit 8d8f4d2

Please sign in to comment.