Index: branches/5.2.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r14572 -r14585 --- branches/5.2.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 14572) +++ branches/5.2.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 14585) @@ -1,6 +1,6 @@ FieldValues[$field]); } if (!$res) { - $this->SetError($field, 'bad_type', null, $params['type']); + $this->SetError($field, 'bad_type', null, Array ($params['type'])); } } return $res; @@ -898,7 +898,7 @@ $res = $res && mb_strlen($val) >= $params['min_len']; } if (!$res) { - $error_params = Array (getArrayValue($params, 'min_len'), getArrayValue($params, 'max_len')); + $error_params = Array (getArrayValue($params, 'min_len'), getArrayValue($params, 'max_len'), mb_strlen($val)); $this->SetError($field, 'length_out_of_range', null, $error_params); return $res; } @@ -1574,19 +1574,37 @@ return true; } - $cdata_key = rtrim($this->Prefix.'-cdata.'.$this->Special, '.'); - $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true, 'populate_ml_fields' => true)); + $cdata_key = rtrim($this->Prefix . '-cdata.' . $this->Special, '.'); + $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true)); + /* @var $cdata kDBItem */ + $resource_id = $this->GetDBField('ResourceId'); $cdata->Load($resource_id, 'ResourceId'); $cdata->SetDBField('ResourceId', $resource_id); $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); /* @var $ml_formatter kMultiLanguage */ + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + foreach ($this->customFields as $custom_id => $custom_name) { - $force_primary = isset($cdata->Fields['cust_'.$custom_id]['force_primary']) && $cdata->Fields['cust_'.$custom_id]['force_primary']; - $cdata->SetDBField($ml_formatter->LangFieldName('cust_'.$custom_id, $force_primary), $this->GetDBField('cust_'.$custom_name)); + $field_options = $cdata->GetFieldOptions('cust_' . $custom_id); + $force_primary = isset($field_options['force_primary']) && $field_options['force_primary']; + + if ($force_primary) { + $cdata->SetDBField($ml_formatter->LangFieldName('cust_' . $custom_id, true), $this->GetDBField('cust_' . $custom_name)); + } + else { + for ($language_id = 1; $language_id <= $ml_helper->languageCount; $language_id++) { + if (!$ml_helper->LanguageFound($language_id)) { + continue; + } + + $cdata->SetDBField('l' . $language_id . '_cust_' . $custom_id, $this->GetDBField('l' . $language_id . '_cust_' . $custom_name)); + } + } } return $cdata->isLoaded() ? $cdata->Update() : $cdata->Create();