Index: branches/5.1.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r13161 -r13168 --- branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 13161) +++ branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 13168) @@ -1,6 +1,6 @@ values hash to load item by * @param string $id_field_name Optional parameter to load item by given Id field + * @param bool $cachable cache this query result based on it's prefix serial * @return bool True if item has been loaded, false otherwise */ - function Load($id, $id_field_name = null) + function Load($id, $id_field_name = null, $cachable = false) { if ( isset($id_field_name) ) { $this->SetIDField($id_field_name); // set new IDField @@ -385,8 +386,25 @@ } $q = $this->GetSelectSQL() . ' WHERE ' . $keys_sql; - $field_values = $this->Conn->GetRow($q); + if ($cachable && $this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + $serial_name = $this->Application->incrementCacheSerial($this->Prefix == 'st' ? 'c' : $this->Prefix, isset($id_field_name) ? null : $id, false); + $cache_key = 'kDBItem::Load_' . crc32(serialize($id) . '-' . $this->IDField) . '[%' . $serial_name . '%]'; + $field_values = $this->Application->getCache($cache_key, false); + + if ($field_values === false) { + $field_values = $this->Conn->GetRow($q); + + if ($field_values !== false) { + // only cache, when data was retrieved + $this->Application->setCache($cache_key, $field_values); + } + } + } + else { + $field_values = $this->Conn->GetRow($q); + } + if ($field_values) { $this->FieldValues = array_merge_recursive2($this->FieldValues, $field_values); $this->OriginalFieldValues = $this->FieldValues; @@ -1082,8 +1100,22 @@ } if (in_array($this->Prefix, $rec['ParentPrefix']) && $rec['ParentId'][$this->Prefix] == $this->GetID()) { - // change log record of given item's sub item + // change log record of given item's sub item -> update changed id's in dependent fields $changes[$key]['ParentId'][$this->Prefix] = $new_id; + + if (array_key_exists('DependentFields', $rec)) { + // these are fields from table of $rec['Prefix'] table! + // when one of dependent fields goes into idfield of it's parent item, that was changed + $parent_table_key = $this->Application->getUnitOption($rec['Prefix'], 'ParentTableKey'); + $parent_table_key = is_array($parent_table_key) ? $parent_table_key[$this->Prefix] : $parent_table_key; + + if ($parent_table_key == $this->IDField) { + $foreign_key = $this->Application->getUnitOption($rec['Prefix'], 'ForeignKey'); + $foreign_key = is_array($foreign_key) ? $foreign_key[$this->Prefix] : $foreign_key; + + $changes[$key]['DependentFields'][$foreign_key] = $new_id; + } + } } } } @@ -1162,19 +1194,24 @@ // sub item // collect foreign key values (for serial reset) $foreign_keys = $this->Application->getUnitOption($this->Prefix, 'ForeignKey'); - $fields_hash['ParentId'] = $fields_hash['ParentPrefix'] = Array (); + $dependent_fields = $fields_hash['ParentId'] = $fields_hash['ParentPrefix'] = Array (); if (is_array($foreign_keys)) { foreach ($foreign_keys as $prefix => $field_name) { + $dependent_fields[$field_name] = $this->GetDBField($field_name); $fields_hash['ParentPrefix'][] = $prefix; $fields_hash['ParentId'][$prefix] = $this->getParentId($prefix); } } else { + $dependent_fields[$foreign_keys] = $this->GetDBField($foreign_keys); $fields_hash['ParentPrefix'] = Array ( $this->Application->getUnitOption($this->Prefix, 'ParentPrefix') ); $fields_hash['ParentId'][ $fields_hash['ParentPrefix'][0] ] = $this->getParentId('auto'); } + $fields_hash['DependentFields'] = $dependent_fields; + + // works only, when main item is present in url, when subitem is changed $master_id = $this->Application->GetVar($main_prefix . '_id');