Skip to content

Commit 1995852

Browse files
authored
Fix location completename update (#565)
* Fix location completename update * Update changelog * Fix header * Fix phpcs and rector
1 parent 04c5e2c commit 1995852

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## [UNRELEASED]
8+
## [unreleased] -
99

1010
### Fixed
1111

12+
- Fix `name` and `locations_id` when updating the `completename`
1213
- Fix user field updates and email import
1314

1415
## [2.15.2] - 2025-11-25

inc/commoninjectionlib.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr
16481648

16491649
if (!empty($option) && self::isFieldADropdown($option['displaytype']) && $value == self::EMPTY_VALUE) {
16501650
//If field is a dropdown and value is '', then replace it by 0
1651-
continue;
1651+
$toinject[$key] = 0;
16521652
} else {
16531653
// Skip empty values for fields that cannot accept empty strings during updates
16541654
// Check if the field is nullable using the injection class method

inc/locationinjection.class.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,36 @@
3030

3131

3232

33+
/**
34+
* -------------------------------------------------------------------------
35+
* DataInjection plugin for GLPI
36+
* -------------------------------------------------------------------------
37+
*
38+
* LICENSE
39+
*
40+
* This file is part of DataInjection.
41+
*
42+
* DataInjection is free software; you can redistribute it and/or modify
43+
* it under the terms of the GNU General Public License as published by
44+
* the Free Software Foundation; either version 2 of the License, or
45+
* (at your option) any later version.
46+
*
47+
* DataInjection is distributed in the hope that it will be useful,
48+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
49+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50+
* GNU General Public License for more details.
51+
*
52+
* You should have received a copy of the GNU General Public License
53+
* along with DataInjection. If not, see <http://www.gnu.org/licenses/>.
54+
* -------------------------------------------------------------------------
55+
* @copyright Copyright (C) 2007-2023 by DataInjection plugin team.
56+
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
57+
* @link https://github.com/pluginsGLPI/datainjection
58+
* -------------------------------------------------------------------------
59+
*/
60+
61+
62+
3363
class PluginDatainjectionLocationInjection extends Location implements PluginDatainjectionInjectionInterface
3464
{
3565
public static function getTable($classname = null)
@@ -83,9 +113,20 @@ public function getOptions($primary_type = '')
83113
**/
84114
public function addOrUpdateObject($values = [], $options = [])
85115
{
86-
116+
$values = $this->fixLocationTreeStructure($values);
87117
$lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options);
88118
$lib->processAddOrUpdate();
89119
return $lib->getInjectionResults();
90120
}
121+
122+
public function fixLocationTreeStructure($values)
123+
{
124+
if (isset($values['Location']['completename']) && !isset($values['Location']['name']) && !str_contains($values['Location']['completename'], '>')) {
125+
$values['Location']['name'] = trim($values['Location']['completename']);
126+
$values['Location']['locations_id'] = '0';
127+
$values['Location']['ancestors_cache'] = '[]';
128+
}
129+
130+
return $values;
131+
}
91132
}

0 commit comments

Comments
 (0)