Skip to content

Commit ab9f642

Browse files
committed
Merge branch 'release/2.8.1'
2 parents e79d891 + 13d01f5 commit ab9f642

23 files changed

+841
-460
lines changed

composer.lock

Lines changed: 122 additions & 263 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datainjection.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<author>Xavier Caillaud</author>
2929
</authors>
3030
<versions>
31+
<version>
32+
<num>2.8.1</num>
33+
<compatibility>~9.5.0</compatibility>
34+
<download_url>https://github.com/pluginsGLPI/datainjection/releases/download/2.8.1/glpi-datainjection-2.8.1.tar.bz2</download_url>
35+
</version>
3136
<version>
3237
<num>2.8.0</num>
3338
<compatibility>~9.5.0</compatibility>

inc/commoninjectionlib.class.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,12 @@ private function manageFieldValues() {
502502
foreach ($data as $field => $value) {
503503
if (!in_array($field, $blacklisted_fields)) {
504504
$searchOption = self::findSearchOption($searchOptions, $field);
505-
$this->getFieldValue($injectionClass, $itemtype, $searchOption, $field, $value);
505+
//searchoption relation type is already manage by manageRelations()
506+
//skip it
507+
if ((isset($searchOption['displaytype']) && $searchOption['displaytype'] != 'relation')
508+
|| !isset($searchOption['displaytype'])) {
509+
$this->getFieldValue($injectionClass, $itemtype, $searchOption, $field, $value);
510+
}
506511
}
507512
}
508513

@@ -1627,9 +1632,6 @@ private function manageRelations() {
16271632
null, $option['relationclass'], $option, $option['linkfield'],
16281633
$value, true
16291634
);
1630-
1631-
//Remove the old option
1632-
$this->unsetValue($itemtype, $option['linkfield']);
16331635
}
16341636
}
16351637
}

inc/entityinjection.class.php

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,62 @@ function addOrUpdateObject($values = [], $options = []) {
8787
}
8888

8989

90+
public static function getRootEntityName() {
91+
$root = new Entity();
92+
$root->getFromDb(0);
93+
94+
return $root->fields['name'];
95+
}
96+
97+
9098
/**
9199
* @param $input array
92100
* @param $add (true by default)
93101
* @param $rights array
94102
**/
95103
function customimport($input = [], $add = true, $rights = []) {
96-
97104
if (!isset($input['completename']) || empty($input['completename'])) {
98105
return -1;
99106
}
100107

108+
$em = new Entity();
109+
110+
// Search for exisiting entity
111+
$search = $input['completename'];
112+
113+
// Check if search start by root entity
114+
$root = self::getRootEntityName();
115+
if (strpos($search, $root) !== 0) {
116+
$search = "$root > $search";
117+
}
118+
119+
$results = $em->find(['completename' => $search]);
120+
121+
if (count($results)) {
122+
$ent = array_pop($results);
123+
return $this->updateExistingEntity($ent['id'], $input);
124+
} else {
125+
return $this->importEntity($input);
126+
}
127+
}
128+
129+
public function importEntity($input) {
130+
$em = new Entity();
131+
101132
// Import a full tree from completename
102133
$names = explode('>', $input['completename']);
103-
$fk = $this->getForeignKeyField();
104134
$i = count($names);
105135
$parent = 0;
106-
$entity = new Entity();
107136
$level = 0;
108137

138+
// Remove root entity if specified
139+
if (strcmp(trim($names[0]), trim(self::getRootEntityName())) === 0) {
140+
unset($names[0]);
141+
}
142+
109143
foreach ($names as $name) {
110144
$name = trim($name);
145+
111146
$i--;
112147
$level++;
113148
if (empty($name)) {
@@ -127,23 +162,37 @@ function customimport($input = [], $add = true, $rights = []) {
127162
$tmp['level'] = $level;
128163
$tmp['entities_id'] = $parent;
129164

130-
//Does the entity alread exists ?
165+
// Does the entity alread exists ?
131166
$results = getAllDataFromTable(
132-
'glpi_entities',
133-
['name' => $name, 'entities_id' => $parent]
167+
'glpi_entities',
168+
['name' => $name, 'entities_id' => $parent]
134169
);
135-
//Entity doesn't exists => create it
170+
171+
// Entity doesn't exists => create it
136172
if (empty($results)) {
137-
$parent = CommonDropdown::import($tmp);
173+
$parent = $em->import($tmp);
138174
} else {
139-
//Entity already exists, use the ID as parent
140-
$ent = array_pop($results);
141-
$parent = $ent['id'];
175+
// Entity already exists, use the ID as parent
176+
$ent = array_pop($results);
177+
$parent = $ent['id'];
142178
}
143179
}
180+
144181
return $parent;
145182
}
146183

184+
public function updateExistingEntity($id, $input) {
185+
$em = new Entity();
186+
187+
// Update entity
188+
$input['id'] = $id;
189+
unset($input['completename']);
190+
unset($input['entities_id']);
191+
$em->update($input);
192+
193+
return $id;
194+
}
195+
147196

148197
/**
149198
* @param $injectionClass
@@ -156,16 +205,16 @@ function customDataAlreadyInDB($injectionClass, $values, $options) {
156205
return false;
157206
}
158207
$results = getAllDataFromTable(
159-
'glpi_entities',
160-
['completename' => $values['completename']]
208+
'glpi_entities',
209+
['completename' => $values['completename']]
161210
);
162211

163212
if (empty($results)) {
164-
return false;
213+
return false;
165214
}
166215

167-
$ent = array_pop($results);
168-
return $ent['id'];
216+
$ent = array_pop($results);
217+
return $ent['id'];
169218
}
170219

171220
}

locales/cs_CZ.mo

41 Bytes
Binary file not shown.

locales/cs_CZ.po

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
#
66
# Translators:
77
# Cédric Anne, 2018
8-
# David Stepan <stepand@tiscali.cz>, 2018
98
# Pavel Borecki <pavel.borecki@gmail.com>, 2019
9+
# David Stepan <stepand@tiscali.cz>, 2020
1010
#
1111
#, fuzzy
1212
msgid ""
1313
msgstr ""
1414
"Project-Id-Version: PACKAGE VERSION\n"
1515
"Report-Msgid-Bugs-To: \n"
16-
"POT-Creation-Date: 2020-07-10 10:45+0000\n"
16+
"POT-Creation-Date: 2020-10-27 14:24+0000\n"
1717
"PO-Revision-Date: 2018-06-21 12:57+0000\n"
18-
"Last-Translator: Pavel Borecki <pavel.borecki@gmail.com>, 2019\n"
18+
"Last-Translator: David Stepan <stepand@tiscali.cz>, 2020\n"
1919
"Language-Team: Czech (Czech Republic) (https://www.transifex.com/teclib/teams/28042/cs_CZ/)\n"
2020
"MIME-Version: 1.0\n"
2121
"Content-Type: text/plain; charset=UTF-8\n"
@@ -242,7 +242,7 @@ msgstr "Do souboru"
242242
msgid "From the model"
243243
msgstr "Ze šablony"
244244

245-
#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1957
245+
#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1959
246246
msgid "Undetermined"
247247
msgstr "Nespecifikováno"
248248

@@ -391,7 +391,7 @@ msgstr "Tato entita vám není přístupná"
391391

392392
#: inc/computerinjection.class.php:72
393393
msgid "Antivirus name"
394-
msgstr ""
394+
msgstr "Název antiviru"
395395

396396
#: inc/modelcsv.class.php:160
397397
msgid "Specific file format options"
@@ -429,50 +429,50 @@ msgstr "-------Zvolte tabulku-------"
429429
msgid "-------Choose a field-------"
430430
msgstr "-------Zvolte kolonku-------"
431431

432-
#: inc/commoninjectionlib.class.php:1874
432+
#: inc/commoninjectionlib.class.php:1876
433433
msgid "Add from CSV file"
434434
msgstr "Přidat z CSV souboru"
435435

436-
#: inc/commoninjectionlib.class.php:1876
436+
#: inc/commoninjectionlib.class.php:1878
437437
msgid "Update from CSV file"
438438
msgstr "Aktualizovat z CSV souboru"
439439

440-
#: inc/commoninjectionlib.class.php:1917
440+
#: inc/commoninjectionlib.class.php:1919
441441
msgid "No right to import data"
442442
msgstr "Nemáte oprávnění importovat data"
443443

444-
#: inc/commoninjectionlib.class.php:1921
444+
#: inc/commoninjectionlib.class.php:1923
445445
msgid "No right to update data"
446446
msgstr "Nemáte oprávnění aktualizovat data"
447447

448-
#: inc/commoninjectionlib.class.php:1925
448+
#: inc/commoninjectionlib.class.php:1927
449449
msgid "Size of the inserted value is to expansive"
450450
msgstr "Velikost vkládané hodnoty je příliš obsáhlá"
451451

452-
#: inc/commoninjectionlib.class.php:1929
452+
#: inc/commoninjectionlib.class.php:1931
453453
msgid "Import not allowed"
454454
msgstr "Import není dovolen"
455455

456-
#: inc/commoninjectionlib.class.php:1933
456+
#: inc/commoninjectionlib.class.php:1935
457457
msgid "Import failed"
458458
msgstr "Import se nezdařil"
459459

460-
#: inc/commoninjectionlib.class.php:1937
460+
#: inc/commoninjectionlib.class.php:1939
461461
msgid "At least one mandatory field is not present"
462462
msgstr "Přinejmenším jedna povinná kolonka není vyplněná"
463463

464-
#: inc/commoninjectionlib.class.php:1941
464+
#: inc/commoninjectionlib.class.php:1943
465465
msgid "Data to insert are correct"
466466
msgstr "Data pro vložení jsou v pořádku"
467467

468-
#: inc/commoninjectionlib.class.php:1945
468+
#: inc/commoninjectionlib.class.php:1947
469469
msgid "One data is not the good type"
470470
msgstr "Jedna data nejsou správného typu"
471471

472-
#: inc/commoninjectionlib.class.php:1949
472+
#: inc/commoninjectionlib.class.php:1951
473473
msgid "Warning"
474474
msgstr "Varování"
475475

476-
#: inc/commoninjectionlib.class.php:1953
476+
#: inc/commoninjectionlib.class.php:1955
477477
msgid "Data not found"
478478
msgstr "Data nebyla nalezena"

locales/datainjection.pot

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-07-10 10:45+0000\n"
11+
"POT-Creation-Date: 2020-10-27 14:24+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -229,7 +229,7 @@ msgstr ""
229229
msgid "From the model"
230230
msgstr ""
231231

232-
#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1957
232+
#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1959
233233
msgid "Undetermined"
234234
msgstr ""
235235

@@ -416,50 +416,50 @@ msgstr ""
416416
msgid "-------Choose a field-------"
417417
msgstr ""
418418

419-
#: inc/commoninjectionlib.class.php:1874
419+
#: inc/commoninjectionlib.class.php:1876
420420
msgid "Add from CSV file"
421421
msgstr ""
422422

423-
#: inc/commoninjectionlib.class.php:1876
423+
#: inc/commoninjectionlib.class.php:1878
424424
msgid "Update from CSV file"
425425
msgstr ""
426426

427-
#: inc/commoninjectionlib.class.php:1917
427+
#: inc/commoninjectionlib.class.php:1919
428428
msgid "No right to import data"
429429
msgstr ""
430430

431-
#: inc/commoninjectionlib.class.php:1921
431+
#: inc/commoninjectionlib.class.php:1923
432432
msgid "No right to update data"
433433
msgstr ""
434434

435-
#: inc/commoninjectionlib.class.php:1925
435+
#: inc/commoninjectionlib.class.php:1927
436436
msgid "Size of the inserted value is to expansive"
437437
msgstr ""
438438

439-
#: inc/commoninjectionlib.class.php:1929
439+
#: inc/commoninjectionlib.class.php:1931
440440
msgid "Import not allowed"
441441
msgstr ""
442442

443-
#: inc/commoninjectionlib.class.php:1933
443+
#: inc/commoninjectionlib.class.php:1935
444444
msgid "Import failed"
445445
msgstr ""
446446

447-
#: inc/commoninjectionlib.class.php:1937
447+
#: inc/commoninjectionlib.class.php:1939
448448
msgid "At least one mandatory field is not present"
449449
msgstr ""
450450

451-
#: inc/commoninjectionlib.class.php:1941
451+
#: inc/commoninjectionlib.class.php:1943
452452
msgid "Data to insert are correct"
453453
msgstr ""
454454

455-
#: inc/commoninjectionlib.class.php:1945
455+
#: inc/commoninjectionlib.class.php:1947
456456
msgid "One data is not the good type"
457457
msgstr ""
458458

459-
#: inc/commoninjectionlib.class.php:1949
459+
#: inc/commoninjectionlib.class.php:1951
460460
msgid "Warning"
461461
msgstr ""
462462

463-
#: inc/commoninjectionlib.class.php:1953
463+
#: inc/commoninjectionlib.class.php:1955
464464
msgid "Data not found"
465465
msgstr ""

locales/en_GB.mo

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)