Index: branches/5.1.x/core/kernel/utility/temp_handler.php =================================================================== diff -u -N -r13086 -r13161 --- branches/5.1.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 13086) +++ branches/5.1.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 13161) @@ -1,6 +1,6 @@ GetTempName($master['TableName']).' WHERE '.$master['IdField'].' = 0'; $this->Conn->Query($query); + $this->UpdateChangeLogForeignKeys($master, $live_ids[$an_id], $an_id); } } @@ -677,23 +678,33 @@ 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); + if ($live_id == $temp_id) { + return ; + } + + $prefix = $master['Prefix']; + $main_prefix = $this->Application->GetTopmostPrefix($prefix); + $ses_var_name = $main_prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); $changes = $this->Application->RecallVar($ses_var_name); - $changes = $changes ? unserialize($changes) : array(); + $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['Prefix'] == $prefix && $rec['ItemId'] == $temp_id) { + // main item change log record + $changes[$key]['ItemId'] = $live_id; } - if ($rec['MasterPrefix'] == $master['Prefix']) { - if ($rec['MasterId'] == $temp_id) { - $changes[$key]['MasterId'] = $live_id; - } + + if ($rec['MasterPrefix'] == $prefix && $rec['MasterId'] == $temp_id) { + // sub item change log record + $changes[$key]['MasterId'] = $live_id; } + + if (in_array($prefix, $rec['ParentPrefix']) && $rec['ParentId'][$prefix] == $temp_id) { + // parent item change log record + $changes[$key]['ParentId'][$prefix] = $live_id; + } } + $this->Application->StoreVar($ses_var_name, serialize($changes)); }