/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::addOrUpdateObject() **/ function addOrUpdateObject($values = array(), $options = array()) { $lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options); $lib->processAddOrUpdate(); return $lib->getInjectionResults(); }
/** * Add a value to the fields to inject * * @param $fields_toinject the fields * @param $searchOptions options related to the itemtype to inject * @param $mapping the mapping which matches the field * @param $value the value for this field, as readed from the CSV file * @param $several array of all fields which can be mapping more than one time * in the model * @return nothing **/ function addValueToInject(&$fields_toinject, $searchOptions, $mapping, $value, $several = array()) { // Option will be found only for "main" type. $option = PluginDatainjectionCommonInjectionLib::findSearchOption($searchOptions, $mapping->getValue()); $return_value = $value; if ($option['displaytype'] == 'multiline_text' && in_array($mapping->getValue(), $several) && $value != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE) { $return_value = ''; if (isset($fields_toinject[$mapping->getItemtype()][$mapping->getValue()])) { $return_value .= $fields_toinject[$mapping->getItemtype()][$mapping->getValue()]; } $return_value .= $mapping->getMappingName() . "=" . $value . "\n"; } $fields_toinject[$mapping->getItemtype()][$mapping->getValue()] = $return_value; }
/** * @param $models_id **/ static function prepareLogResults($models_id) { $results = Toolbox::stripslashes_deep(json_decode(PluginDatainjectionSession::getParam('results'), true)); $todisplay = array(); $model = new self(); $model->getFromDB($models_id); if (!empty($results)) { foreach ($results as $result) { $tmp = array('line' => $result['line'], 'status' => $result['status'], 'check_sumnary' => PluginDatainjectionCommonInjectionLib::getLogLabel(PluginDatainjectionCommonInjectionLib::SUCCESS), 'check_message' => PluginDatainjectionCommonInjectionLib::getLogLabel(PluginDatainjectionCommonInjectionLib::SUCCESS), 'type' => __('Undetermined', 'datainjection'), 'status_message' => PluginDatainjectionCommonInjectionLib::getLogLabel($result['status']), 'itemtype' => $model->fields['itemtype'], 'url' => '', 'item' => ''); if (isset($result[PluginDatainjectionCommonInjectionLib::ACTION_CHECK])) { $check_infos = $result[PluginDatainjectionCommonInjectionLib::ACTION_CHECK]; $tmp['check_status'] = $check_infos['status']; $tmp['check_sumnary'] = PluginDatainjectionCommonInjectionLib::getLogLabel($check_infos['status']); $tmp['check_message'] = ''; $first = true; foreach ($check_infos as $key => $val) { if ($key !== 'status' && $val[0] != PluginDatainjectionCommonInjectionLib::SUCCESS) { $tmp['check_message'] .= ($first ? '' : "\n") . sprintf(__('%1$s (%2$s)'), PluginDatainjectionCommonInjectionLib::getLogLabel($val[0]), $val[1]); $first = false; } } } //Store the action type (add/update) if (isset($result['type'])) { $tmp['type'] = PluginDatainjectionCommonInjectionLib::getActionLabel($result['type']); } if (isset($result[$model->fields['itemtype']])) { $tmp['item'] = $result[$model->fields['itemtype']]; $url = Toolbox::getItemTypeFormURL($model->fields['itemtype']) . "?id=" . $result[$model->fields['itemtype']]; $tmp['url'] = "<a href='" . $url . "'>" . $result[$model->fields['itemtype']] . "</a>"; } if ($result['status'] == PluginDatainjectionCommonInjectionLib::SUCCESS) { $todisplay[PluginDatainjectionCommonInjectionLib::SUCCESS][] = $tmp; } else { $todisplay[PluginDatainjectionCommonInjectionLib::FAILED][] = $tmp; } } } return $todisplay; }
/** * @param $info PluginDatainjectionInfo object * @param $value **/ static function keepInfo(PluginDatainjectionInfo $info, $value) { $itemtype = $info->getInfosType(); $injectionClass = PluginDatainjectionCommonInjectionLib::getInjectionClassInstance($itemtype); $options = $injectionClass->getOptions($itemtype); $option = PluginDatainjectionCommonInjectionLib::findSearchOption($options, $info->getValue()); if ($option) { switch ($option['displaytype']) { default: case 'text': case 'multiline_text': if ($value != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE) { return true; } return false; case 'dropdown': case 'user': case 'contact': if ($value != PluginDatainjectionCommonInjectionLib::DROPDOWN_EMPTY_VALUE) { return true; } return false; } } }
/** * @param $options array **/ static function getUsedMappingsOrInfos($options = array()) { global $DB; $p['itemtype'] = self::NO_VALUE; $p['primary_type'] = ''; $p['mapping_or_info'] = array(); $p['called_by'] = ''; $p['need_decode'] = true; foreach ($options as $key => $value) { $p[$key] = $value; } if ($p['need_decode']) { $mapping_or_info = json_decode(Toolbox::stripslashes_deep($options['mapping_or_info']), true); } else { $mapping_or_info = $options['mapping_or_info']; } $used = array(); $table = $p['called_by'] == 'PluginDatainjectionMapping' ? "glpi_plugin_datainjection_mappings" : "glpi_plugin_datainjection_infos"; $datas = getAllDatasFromTable($table, "`models_id` = '" . $mapping_or_info['models_id'] . "'"); $injectionClass = PluginDatainjectionCommonInjectionLib::getInjectionClassInstance($p['itemtype']); $options = $injectionClass->getOptions(); foreach ($datas as $data) { if ($data['value'] != self::NO_VALUE) { foreach ($options as $option) { if (isset($option['table']) && $option['table'] == getItemTypeForTable($data['itemtype']) && $option['linkfield'] == $data['value'] && $option['displaytype'] != 'multiline_text' && $mapping_or_info['value'] != $data['value']) { $used[$option['linkfield']] = $option['linkfield']; break; } } } } return $used; }