Index: branches/RC/core/kernel/utility/temp_handler.php =================================================================== diff -u -r9643 -r10294 --- branches/RC/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 9643) +++ branches/RC/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 10294) @@ -602,6 +602,7 @@ $query = 'DELETE FROM '.$this->GetTempName($master['TableName']).' WHERE '.$master['IdField'].' = 0'; $this->Conn->Query($query); + $this->UpdateChangeLogForeignKeys($master, $live_ids[$an_id], $an_id); } } @@ -636,8 +637,31 @@ return $this->savedIDs[ $master['Prefix'] ]; } + + function UpdateChangeLogForeignKeys($master, $live_id, $temp_id) + { + $main_prefix = $this->Application->GetTopmostPrefix($master['Prefix']); + $ses_var_name = $main_prefix.'_changes_'.$this->Application->GetTopmostWid($this->Prefix); + $changes = $this->Application->RecallVar($ses_var_name); + $changes = $changes ? unserialize($changes) : array(); + + foreach ($changes as $key => $rec) { + if ($rec['Prefix'] == $master['Prefix']) { + if ($rec['ItemId'] == $temp_id) { + $changes[$key]['ItemId'] = $live_id; + } + } + if ($rec['MasterPrefix'] == $master['Prefix']) { + if ($rec['MasterId'] == $temp_id) { + $changes[$key]['MasterId'] = $live_id; + } + } + } + $this->Application->StoreVar($ses_var_name, serialize($changes)); + } function UpdateForeignKeys($master, $live_id, $temp_id) { + $this->UpdateChangeLogForeignKeys($master, $live_id, $temp_id); foreach ($master['SubTables'] as $sub_table) { $foreign_key_field = is_array($sub_table['ForeignKey']) ? getArrayValue($sub_table, 'ForeignKey', $master['Prefix']) : $sub_table['ForeignKey']; if (!$foreign_key_field) return;