|
30 | 30 |
|
31 | 31 |
|
32 | 32 |
|
| 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 | + |
33 | 63 | class PluginDatainjectionLocationInjection extends Location implements PluginDatainjectionInjectionInterface |
34 | 64 | { |
35 | 65 | public static function getTable($classname = null) |
@@ -83,9 +113,20 @@ public function getOptions($primary_type = '') |
83 | 113 | **/ |
84 | 114 | public function addOrUpdateObject($values = [], $options = []) |
85 | 115 | { |
86 | | - |
| 116 | + $values = $this->fixLocationTreeStructure($values); |
87 | 117 | $lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options); |
88 | 118 | $lib->processAddOrUpdate(); |
89 | 119 | return $lib->getInjectionResults(); |
90 | 120 | } |
| 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 | + } |
91 | 132 | } |
0 commit comments