Skip to content

Commit

Permalink
Merge branch 'release/2.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Oct 27, 2020
2 parents e79d891 + 13d01f5 commit ab9f642
Show file tree
Hide file tree
Showing 23 changed files with 841 additions and 460 deletions.
385 changes: 122 additions & 263 deletions composer.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions datainjection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<author>Xavier Caillaud</author>
</authors>
<versions>
<version>
<num>2.8.1</num>
<compatibility>~9.5.0</compatibility>
<download_url>https://github.com/pluginsGLPI/datainjection/releases/download/2.8.1/glpi-datainjection-2.8.1.tar.bz2</download_url>
</version>
<version>
<num>2.8.0</num>
<compatibility>~9.5.0</compatibility>
Expand Down
10 changes: 6 additions & 4 deletions inc/commoninjectionlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,12 @@ private function manageFieldValues() {
foreach ($data as $field => $value) {
if (!in_array($field, $blacklisted_fields)) {
$searchOption = self::findSearchOption($searchOptions, $field);
$this->getFieldValue($injectionClass, $itemtype, $searchOption, $field, $value);
//searchoption relation type is already manage by manageRelations()
//skip it
if ((isset($searchOption['displaytype']) && $searchOption['displaytype'] != 'relation')
|| !isset($searchOption['displaytype'])) {
$this->getFieldValue($injectionClass, $itemtype, $searchOption, $field, $value);
}
}
}

Expand Down Expand Up @@ -1627,9 +1632,6 @@ private function manageRelations() {
null, $option['relationclass'], $option, $option['linkfield'],
$value, true
);

//Remove the old option
$this->unsetValue($itemtype, $option['linkfield']);
}
}
}
Expand Down
81 changes: 65 additions & 16 deletions inc/entityinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,62 @@ function addOrUpdateObject($values = [], $options = []) {
}


public static function getRootEntityName() {
$root = new Entity();
$root->getFromDb(0);

return $root->fields['name'];
}


/**
* @param $input array
* @param $add (true by default)
* @param $rights array
**/
function customimport($input = [], $add = true, $rights = []) {

if (!isset($input['completename']) || empty($input['completename'])) {
return -1;
}

$em = new Entity();

// Search for exisiting entity
$search = $input['completename'];

// Check if search start by root entity
$root = self::getRootEntityName();
if (strpos($search, $root) !== 0) {
$search = "$root > $search";
}

$results = $em->find(['completename' => $search]);

if (count($results)) {
$ent = array_pop($results);
return $this->updateExistingEntity($ent['id'], $input);
} else {
return $this->importEntity($input);
}
}

public function importEntity($input) {
$em = new Entity();

// Import a full tree from completename
$names = explode('>', $input['completename']);
$fk = $this->getForeignKeyField();
$i = count($names);
$parent = 0;
$entity = new Entity();
$level = 0;

// Remove root entity if specified
if (strcmp(trim($names[0]), trim(self::getRootEntityName())) === 0) {
unset($names[0]);
}

foreach ($names as $name) {
$name = trim($name);

$i--;
$level++;
if (empty($name)) {
Expand All @@ -127,23 +162,37 @@ function customimport($input = [], $add = true, $rights = []) {
$tmp['level'] = $level;
$tmp['entities_id'] = $parent;

//Does the entity alread exists ?
// Does the entity alread exists ?
$results = getAllDataFromTable(
'glpi_entities',
['name' => $name, 'entities_id' => $parent]
'glpi_entities',
['name' => $name, 'entities_id' => $parent]
);
//Entity doesn't exists => create it

// Entity doesn't exists => create it
if (empty($results)) {
$parent = CommonDropdown::import($tmp);
$parent = $em->import($tmp);
} else {
//Entity already exists, use the ID as parent
$ent = array_pop($results);
$parent = $ent['id'];
// Entity already exists, use the ID as parent
$ent = array_pop($results);
$parent = $ent['id'];
}
}

return $parent;
}

public function updateExistingEntity($id, $input) {
$em = new Entity();

// Update entity
$input['id'] = $id;
unset($input['completename']);
unset($input['entities_id']);
$em->update($input);

return $id;
}


/**
* @param $injectionClass
Expand All @@ -156,16 +205,16 @@ function customDataAlreadyInDB($injectionClass, $values, $options) {
return false;
}
$results = getAllDataFromTable(
'glpi_entities',
['completename' => $values['completename']]
'glpi_entities',
['completename' => $values['completename']]
);

if (empty($results)) {
return false;
return false;
}

$ent = array_pop($results);
return $ent['id'];
$ent = array_pop($results);
return $ent['id'];
}

}
Binary file modified locales/cs_CZ.mo
Binary file not shown.
34 changes: 17 additions & 17 deletions locales/cs_CZ.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#
# Translators:
# Cédric Anne, 2018
# David Stepan <[email protected]>, 2018
# Pavel Borecki <[email protected]>, 2019
# David Stepan <[email protected]>, 2020
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-07-10 10:45+0000\n"
"POT-Creation-Date: 2020-10-27 14:24+0000\n"
"PO-Revision-Date: 2018-06-21 12:57+0000\n"
"Last-Translator: Pavel Borecki <[email protected]>, 2019\n"
"Last-Translator: David Stepan <[email protected]>, 2020\n"
"Language-Team: Czech (Czech Republic) (https://www.transifex.com/teclib/teams/28042/cs_CZ/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -242,7 +242,7 @@ msgstr "Do souboru"
msgid "From the model"
msgstr "Ze šablony"

#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1957
#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1959
msgid "Undetermined"
msgstr "Nespecifikováno"

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

#: inc/computerinjection.class.php:72
msgid "Antivirus name"
msgstr ""
msgstr "Název antiviru"

#: inc/modelcsv.class.php:160
msgid "Specific file format options"
Expand Down Expand Up @@ -429,50 +429,50 @@ msgstr "-------Zvolte tabulku-------"
msgid "-------Choose a field-------"
msgstr "-------Zvolte kolonku-------"

#: inc/commoninjectionlib.class.php:1874
#: inc/commoninjectionlib.class.php:1876
msgid "Add from CSV file"
msgstr "Přidat z CSV souboru"

#: inc/commoninjectionlib.class.php:1876
#: inc/commoninjectionlib.class.php:1878
msgid "Update from CSV file"
msgstr "Aktualizovat z CSV souboru"

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

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

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

#: inc/commoninjectionlib.class.php:1929
#: inc/commoninjectionlib.class.php:1931
msgid "Import not allowed"
msgstr "Import není dovolen"

#: inc/commoninjectionlib.class.php:1933
#: inc/commoninjectionlib.class.php:1935
msgid "Import failed"
msgstr "Import se nezdařil"

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

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

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

#: inc/commoninjectionlib.class.php:1949
#: inc/commoninjectionlib.class.php:1951
msgid "Warning"
msgstr "Varování"

#: inc/commoninjectionlib.class.php:1953
#: inc/commoninjectionlib.class.php:1955
msgid "Data not found"
msgstr "Data nebyla nalezena"
28 changes: 14 additions & 14 deletions locales/datainjection.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-07-10 10:45+0000\n"
"POT-Creation-Date: 2020-10-27 14:24+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -229,7 +229,7 @@ msgstr ""
msgid "From the model"
msgstr ""

#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1957
#: inc/model.class.php:1371 inc/commoninjectionlib.class.php:1959
msgid "Undetermined"
msgstr ""

Expand Down Expand Up @@ -416,50 +416,50 @@ msgstr ""
msgid "-------Choose a field-------"
msgstr ""

#: inc/commoninjectionlib.class.php:1874
#: inc/commoninjectionlib.class.php:1876
msgid "Add from CSV file"
msgstr ""

#: inc/commoninjectionlib.class.php:1876
#: inc/commoninjectionlib.class.php:1878
msgid "Update from CSV file"
msgstr ""

#: inc/commoninjectionlib.class.php:1917
#: inc/commoninjectionlib.class.php:1919
msgid "No right to import data"
msgstr ""

#: inc/commoninjectionlib.class.php:1921
#: inc/commoninjectionlib.class.php:1923
msgid "No right to update data"
msgstr ""

#: inc/commoninjectionlib.class.php:1925
#: inc/commoninjectionlib.class.php:1927
msgid "Size of the inserted value is to expansive"
msgstr ""

#: inc/commoninjectionlib.class.php:1929
#: inc/commoninjectionlib.class.php:1931
msgid "Import not allowed"
msgstr ""

#: inc/commoninjectionlib.class.php:1933
#: inc/commoninjectionlib.class.php:1935
msgid "Import failed"
msgstr ""

#: inc/commoninjectionlib.class.php:1937
#: inc/commoninjectionlib.class.php:1939
msgid "At least one mandatory field is not present"
msgstr ""

#: inc/commoninjectionlib.class.php:1941
#: inc/commoninjectionlib.class.php:1943
msgid "Data to insert are correct"
msgstr ""

#: inc/commoninjectionlib.class.php:1945
#: inc/commoninjectionlib.class.php:1947
msgid "One data is not the good type"
msgstr ""

#: inc/commoninjectionlib.class.php:1949
#: inc/commoninjectionlib.class.php:1951
msgid "Warning"
msgstr ""

#: inc/commoninjectionlib.class.php:1953
#: inc/commoninjectionlib.class.php:1955
msgid "Data not found"
msgstr ""
Binary file modified locales/en_GB.mo
Binary file not shown.
Loading

0 comments on commit ab9f642

Please sign in to comment.