Index: branches/5.2.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r16001 -r16016 --- branches/5.2.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 16001) +++ branches/5.2.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 16016) @@ -1,6 +1,6 @@ getRequestProtectedFields($hash); + if ( $skip_fields ) { $set_fields = array_diff($set_fields, $skip_fields); } @@ -319,23 +319,42 @@ } /** + * Returns fields, that are not allowed to be changed from request. + * + * @param array $fields_hash Fields hash. + * + * @return array + */ + protected function getRequestProtectedFields(array $fields_hash) + { + // don't allow changing ID + $fields = Array (); + $fields[] = $this->Application->getUnitOption($this->Prefix, 'IDField'); + + $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); + + if ( $parent_prefix && $this->isLoaded() && !$this->Application->isAdmin ) { + // don't allow changing foreign key of existing item from request + $foreign_key = $this->Application->getUnitOption($this->Prefix, 'ForeignKey'); + $fields[] = is_array($foreign_key) ? $foreign_key[$parent_prefix] : $foreign_key; + } + + return $fields; + } + + /** * Sets object fields from $hash array * @param Array $hash - * @param Array|null $skip_fields * @param Array|null $set_fields * @return void * @access public */ - public function SetDBFieldsFromHash($hash, $skip_fields = Array (), $set_fields = Array ()) + public function SetDBFieldsFromHash($hash, $set_fields = Array ()) { if ( !$set_fields ) { $set_fields = array_keys($hash); } - if ( $skip_fields ) { - $set_fields = array_diff($set_fields, $skip_fields); - } - $set_fields = array_intersect($set_fields, array_keys($this->Fields)); foreach ($set_fields as $field_name) { @@ -1575,4 +1594,4 @@ return array_shift($status_fields); } -} \ No newline at end of file +}