Skip to content

Commit

Permalink
Ensure item type is set in rule_matched hook; fixes pluginsGLPI#136
Browse files Browse the repository at this point in the history
Also fix Container::updateFieldsValues() parameters order
to get not required at the end
  • Loading branch information
trasher committed Jan 11, 2017
1 parent 0f4d459 commit c8347da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion front/container.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Html::back();

} else if (isset($_POST["update_fields_values"])) {
$container->updateFieldsValues($_REQUEST, false, $_REQUEST['itemtype']);
$container->updateFieldsValues($_REQUEST, $_REQUEST['itemtype'], false);
Html::back();

} else {
Expand Down
11 changes: 8 additions & 3 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ function plugin_fields_rule_matched($params) {
$agent->getFromDB($agents_id);

// update current field
$container->updateFieldsValues(array('plugin_fields_containers_id' => $data['id'],
$field => $value,
'items_id' => $agent->fields['computers_id']));
$container->updateFieldsValues(
array(
'plugin_fields_containers_id' => $data['id'],
$field => $value,
'items_id' => $agent->fields['computers_id']
),
Computer::getType()
);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,10 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
/**
* Insert values submited by fields container
* @param array $data data posted
* @param boolean $massiveaction Is a massive action
* @return boolean
*/
function updateFieldsValues($data, $massiveaction = false, $itemtype) {
function updateFieldsValues($data, $itemtype, $massiveaction = false) {
global $DB;

if (self::validateValues($data, $itemtype, $massiveaction) === false) {
Expand Down Expand Up @@ -1040,7 +1041,7 @@ static function postItemAdd(CommonDBTM $item) {
$data['items_id'] = $item->getID();
//update data
$container = new self();
if ($container->updateFieldsValues($data, isset($_REQUEST['massiveaction']), $item->getType())) {
if ($container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))) {
return true;
}
}
Expand All @@ -1061,7 +1062,7 @@ static function preItemUpdate(CommonDBTM $item) {
$data = $item->plugin_fields_data;
//update data
$container = new self();
if (count($data) == 0 || $container->updateFieldsValues($data, isset($_REQUEST['massiveaction']), $item->getType())) {
if (count($data) == 0 || $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))) {
return true;
}
return $item->input = array();
Expand Down

0 comments on commit c8347da

Please sign in to comment.