Index: branches/5.2.x/core/kernel/utility/temp_handler.php =================================================================== diff -u -N -r14657 -r14699 --- branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 14657) +++ branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 14699) @@ -1,6 +1,6 @@ GetTempName($table), - $table); + $sql = 'CREATE TABLE ' . $this->GetTempName($table) . ' + SELECT * + FROM ' . $table . ' + WHERE 0'; - $this->Conn->Query($query); + $this->Conn->Query($sql); } function BuildTables($prefix, $ids) @@ -281,7 +282,9 @@ foreach ($ids as $id) { $mode = 'create'; - if ( $cloned_ids = getArrayValue($this->AlreadyProcessed, $master['TableName']) ) { + $cloned_ids = getArrayValue($this->AlreadyProcessed, $master['TableName']); + + if ( $cloned_ids ) { // if we have already cloned the id, replace it with cloned id and set mode to update // update mode is needed to update second ForeignKey for items cloned by first ForeignKey if ( getArrayValue($cloned_ids, $id) ) { @@ -494,7 +497,9 @@ $parent_key_field = $master['IdField']; } - if ( $cached = getArrayValue($this->FKeysCache, $master['TableName'].'.'.$parent_key_field) ) { + $cached = getArrayValue($this->FKeysCache, $master['TableName'].'.'.$parent_key_field); + + if ( $cached ) { if ( array_key_exists(serialize($live_id), $cached) ) { list($live_foreign_key, $temp_foreign_key) = $cached[serialize($live_id)]; if ($mode == 1) { @@ -866,10 +871,12 @@ function DropTempTable($table) { - if( in_array($table, $this->DroppedTables) ) return false; - $query = sprintf("DROP TABLE IF EXISTS %s", - $this->GetTempName($table) - ); + if ( in_array($table, $this->DroppedTables) ) { + return false; + } + + $query = 'DROP TABLE IF EXISTS ' . $this->GetTempName($table); + array_push($this->DroppedTables, $table); $this->DroppedTables = array_unique($this->DroppedTables); $this->Conn->Query($query);