Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix injection of `values in entity tabs` when injecting an `entity`
- Fix `pdffont` field error for users
- Move `Notepads` search options to the Black List option
- Fix the SQL error: `Column ‘...’ cannot be null in the query`


### Added
Expand Down
8 changes: 7 additions & 1 deletion inc/commoninjectionlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,13 @@ private function setValueForItemtype($itemtype, $field, $value, $fromdb = false)
}
} else { // First value
if (empty($value)) {
$this->values[$itemtype][$field] = "NULL";
if (isForeignKeyField($field) || (strpos($field, 'is_') !== false)) {
// If the field is an id, we set it to 0
$this->values[$itemtype][$field] = self::DROPDOWN_EMPTY_VALUE;
} else {
// Else we set it to NULL
$this->values[$itemtype][$field] = self::EMPTY_VALUE;
}
} else {
$this->values[$itemtype][$field] = $value;
}
Expand Down
72 changes: 57 additions & 15 deletions inc/networkequipmentinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ public function connectedTo()


/**
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions()
**/
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions()
**/
public function getOptions($primary_type = '')
{

$tab = Search::getOptions(get_parent_class($this));

//Specific to location
//Specific to location
$tab[3]['linkfield'] = 'locations_id';

//Virtual type : need to be processed at the end !
//Virtual type : need to be processed at the end !
$tab[200]['table'] = 'glpi_networkequipments';
$tab[200]['field'] = 'nb_ports';
$tab[200]['name'] = __('Number of ports', 'datainjection');
Expand All @@ -76,17 +76,38 @@ public function getOptions($primary_type = '')
$tab[200]['linkfield'] = 'nb_ports';
$tab[200]['injectable'] = PluginDatainjectionCommonInjectionLib::FIELD_VIRTUAL;

//Remove some options because some fields cannot be imported
//Remove some options because some fields cannot be imported
$blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this));
$notimportable = [
41, 43, 44, 45, 46, 48, 61, 63, 64, 91, 92, 93
41,
43,
44,
45,
46,
48,
61,
63,
64,
91,
92,
93
];

$options['ignore_fields'] = array_merge($blacklist, $notimportable);

$options['displaytype'] = ["dropdown" => [3, 4, 11, 23, 31, 32, 33,
40, 49, 71
],
$options['displaytype'] = [
"dropdown" => [
3,
4,
11,
23,
31,
32,
33,
40,
49,
71
],
"bool" => [86],
"user" => [24, 70],
"multiline_text" => [16, 90]
Expand All @@ -97,8 +118,8 @@ public function getOptions($primary_type = '')


/**
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::addOrUpdateObject()
**/
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::addOrUpdateObject()
**/
public function addOrUpdateObject($values = [], $options = [])
{

Expand All @@ -109,10 +130,10 @@ public function addOrUpdateObject($values = [], $options = [])


/**
* @param array $values
* @param boolean $add (true by default)
* @param array|null $rights array
*/
* @param array $values
* @param boolean $add (true by default)
* @param array|null $rights array
*/
public function processAfterInsertOrUpdate($values, $add = true, $rights = [])
{

Expand All @@ -135,4 +156,25 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = [])
}
}
}

/**
* @param array $values array
**/
public function reformat(&$values = [])
{

foreach (
['cpu'] as $int
) {
if (
isset($values['NetworkEquipment'][$int])
&& (
$values['NetworkEquipment'][$int] == PluginDatainjectionCommonInjectionLib::EMPTY_VALUE
|| $values['NetworkEquipment'][$int] === 'NULL'
)
) {
$values['NetworkEquipment'][$int] = 0;
}
}
}
}