diff --git "a/ui/include/classes/import/converters/CImportDataNormalizer.php" "b/ui/include/classes/import/converters/CImportDataNormalizer.php" index b0a57683de..30a50eb3d7 100644 --- "a/ui/include/classes/import/converters/CImportDataNormalizer.php" +++ "b/ui/include/classes/import/converters/CImportDataNormalizer.php" @@ -34,7 +34,7 @@ class CImportDataNormalizer { public function normalize($data) { $data['zabbix_export'] = $this->normalizeArrayKeys($data['zabbix_export'], $this->rules); - $data['zabbix_export'] = $this->normalizeStrings($data['zabbix_export']); + $data['zabbix_export'] = $this->normalizeStrings($data['zabbix_export'], $this->rules); return $data; } @@ -80,13 +80,34 @@ class CImportDataNormalizer { * Add CR to string type fields. * * @param mixed $data Import data. + * @param array $rules Schema rules. * * @return mixed */ - protected function normalizeStrings($data) { - if ($this->rules['type'] & XML_STRING) { + protected function normalizeStrings($data, array $rules) { + if ($rules['type'] & XML_ARRAY) { + foreach ($rules['rules'] as $tag => $tag_rules) { + if (array_key_exists('ex_rules', $tag_rules)) { + $tag_rules = call_user_func($tag_rules['ex_rules'], $data); + } + + if (array_key_exists($tag, $data)) { + $data[$tag] = $this->normalizeStrings($data[$tag], $tag_rules); + } + } + } + elseif ($rules['type'] & XML_INDEXED_ARRAY) { + $prefix = $rules['prefix']; + + if (is_array($data)) { + foreach ($data as $tag => $value) { + $data[$tag] = $this->normalizeStrings($value, $rules['rules'][$prefix]); + } + } + } + elseif ($rules['type'] & XML_STRING) { $data = str_replace("\r\n", "\n", $data); - $data = (array_key_exists('flags', $this->rules) && $this->rules['flags'] & self::EOL_LF) + $data = (array_key_exists('flags', $rules) && $rules['flags'] & self::EOL_LF) ? $data : str_replace("\n", "\r\n", $data); }