Index: trunk/core/kernel/utility/temp_handler.php =================================================================== diff -u -N -r2800 -r3073 --- trunk/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 2800) +++ trunk/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 3073) @@ -142,11 +142,16 @@ 'AutoDelete' => $this->Application->getUnitOption($prefix,'AutoDelete'), 'TableId' => $this->TableIdCounter++, ); - $this->FinalRefs[$tmp['TableName']] = $tmp['TableId']; + $this->FinalRefs[ $tmp['TableName'] ] = $tmp['TableId']; + $constrain = $this->Application->getUnitOption($prefix,'Constrain'); - if ($constrain) $tmp['Constrain'] = $constrain; - + if ($constrain) + { + $tmp['Constrain'] = $constrain; + $this->FinalRefs[ $tmp['TableName'].$tmp['Constrain'] ] = $tmp['TableId']; + } + $SubItems = $this->Application->getUnitOption($prefix,'SubItems'); $same_sub_counter = 1; if( is_array($SubItems) ) @@ -433,7 +438,7 @@ } if ( getArrayValue($master, 'SubTables') ) { - if( in_array($table_sig, $this->CopiedTables) ) continue; + if( in_array($table_sig, $this->CopiedTables) || $this->FinalRefs[$table_sig] != $master['TableId'] ) return; foreach($current_ids AS $id) { @@ -477,7 +482,7 @@ // when all of ids in current master has been processed, copy all sub-tables data $this->CopySubTablesToLive($master, $current_ids); } - elseif( !in_array($table_sig, $this->CopiedTables) ) { //If current master doesn't have sub-tables - we could use mass operations + elseif( !in_array($table_sig, $this->CopiedTables) && ($this->FinalRefs[$table_sig] == $master['TableId']) ) { //If current master doesn't have sub-tables - we could use mass operations // We don't need to delete items from live here, as it get deleted in the beggining of the method for MasterTable // or in parent table processing for sub-tables $this->RaiseEvent('OnBeforeCopyToLive', $master['Prefix'], $current_ids); @@ -510,7 +515,7 @@ } } - if ($this->FinalRefs[$master['TableName']] != $master['TableId']) return; + if ($this->FinalRefs[ $master['TableName'] ] != $master['TableId']) return; /*if ( is_array(getArrayValue($master, 'ForeignKey')) ) { //if multiple ForeignKeys if ( $master['ForeignKey'][$parent_prefix] != end($master['ForeignKey']) ) { Index: trunk/core/units/general/brackets.php =================================================================== diff -u -N -r2320 -r3073 --- trunk/core/units/general/brackets.php (.../brackets.php) (revision 2320) +++ trunk/core/units/general/brackets.php (.../brackets.php) (revision 3073) @@ -126,38 +126,38 @@ $object =& $event->getObject(); $linked_info = $object->getLinkedInfo(); - $stored_ids = $this->Conn->GetCol('SELECT '.$object->IDField.' FROM '.$object->TableName.' WHERE '.$linked_info['ParentTableKey'].' = '.$linked_info['ParentId']); + $stored_ids = $this->Conn->GetCol('SELECT '.$object->IDField.' FROM '.$object->TableName.' WHERE '.$linked_info['ForeignKey'].' = '.$linked_info['ParentId']); uasort($items_info, Array(&$this, 'compareBrackets') ); foreach ($items_info as $item_id => $values) { if (in_array($item_id, $stored_ids)) { //if it's already exist - $object->SetDefaultValues(); - $object->Load($item_id); - $object->SetFieldsFromHash($values); - if (!$object->Validate()) { - unset($stored_ids[array_search($item_id, $stored_ids)]); - $event->redirect = false; - continue; + $object->SetDefaultValues(); + $object->Load($item_id); + $object->SetFieldsFromHash($values); + if (!$object->Validate()) { + unset($stored_ids[array_search($item_id, $stored_ids)]); + $event->redirect = false; + continue; + } + if( $object->Update($item_id) ) + { + $event->status = erSUCCESS; + } + else + { + $event->status = erFAIL; + $event->redirect = false; + break; + } + unset( $stored_ids[ array_search($item_id, $stored_ids) ] ); } - if( $object->Update($item_id) ) - { - $event->status = erSUCCESS; - } - else - { - $event->status = erFAIL; - $event->redirect = false; - break; - } - unset( $stored_ids[ array_search($item_id, $stored_ids) ] ); - } else { $object->SetDefaultValues(); $object->SetFieldsFromHash($values); - $object->SetDBField($linked_info['ParentTableKey'], $linked_info['ParentId']); + $object->SetDBField($linked_info['ForeignKey'], $linked_info['ParentId']); if( $object->Create() ) { @@ -168,7 +168,8 @@ } // delete - foreach ($stored_ids as $stored_id){ + foreach ($stored_ids as $stored_id) + { $this->Conn->Query('DELETE FROM '.$object->TableName.' WHERE '.$object->IDField.' = '.$stored_id); } @@ -226,7 +227,7 @@ $linked_info = $object->getLinkedInfo(); $sql = 'SELECT %s FROM %s WHERE %s = %s'; - $ids = $this->Conn->GetCol( sprintf($sql, $object->IDField, $object->TableName, $linked_info['ParentTableKey'], $linked_info['ParentId']) ); + $ids = $this->Conn->GetCol( sprintf($sql, $object->IDField, $object->TableName, $linked_info['ForeignKey'], $linked_info['ParentId']) ); if( is_array($ids) ) { usort($ids, Array(&$this, 'sortBracketIDs') ); Index: trunk/kernel/units/general/brackets.php =================================================================== diff -u -N -r2320 -r3073 --- trunk/kernel/units/general/brackets.php (.../brackets.php) (revision 2320) +++ trunk/kernel/units/general/brackets.php (.../brackets.php) (revision 3073) @@ -126,38 +126,38 @@ $object =& $event->getObject(); $linked_info = $object->getLinkedInfo(); - $stored_ids = $this->Conn->GetCol('SELECT '.$object->IDField.' FROM '.$object->TableName.' WHERE '.$linked_info['ParentTableKey'].' = '.$linked_info['ParentId']); + $stored_ids = $this->Conn->GetCol('SELECT '.$object->IDField.' FROM '.$object->TableName.' WHERE '.$linked_info['ForeignKey'].' = '.$linked_info['ParentId']); uasort($items_info, Array(&$this, 'compareBrackets') ); foreach ($items_info as $item_id => $values) { if (in_array($item_id, $stored_ids)) { //if it's already exist - $object->SetDefaultValues(); - $object->Load($item_id); - $object->SetFieldsFromHash($values); - if (!$object->Validate()) { - unset($stored_ids[array_search($item_id, $stored_ids)]); - $event->redirect = false; - continue; + $object->SetDefaultValues(); + $object->Load($item_id); + $object->SetFieldsFromHash($values); + if (!$object->Validate()) { + unset($stored_ids[array_search($item_id, $stored_ids)]); + $event->redirect = false; + continue; + } + if( $object->Update($item_id) ) + { + $event->status = erSUCCESS; + } + else + { + $event->status = erFAIL; + $event->redirect = false; + break; + } + unset( $stored_ids[ array_search($item_id, $stored_ids) ] ); } - if( $object->Update($item_id) ) - { - $event->status = erSUCCESS; - } - else - { - $event->status = erFAIL; - $event->redirect = false; - break; - } - unset( $stored_ids[ array_search($item_id, $stored_ids) ] ); - } else { $object->SetDefaultValues(); $object->SetFieldsFromHash($values); - $object->SetDBField($linked_info['ParentTableKey'], $linked_info['ParentId']); + $object->SetDBField($linked_info['ForeignKey'], $linked_info['ParentId']); if( $object->Create() ) { @@ -168,7 +168,8 @@ } // delete - foreach ($stored_ids as $stored_id){ + foreach ($stored_ids as $stored_id) + { $this->Conn->Query('DELETE FROM '.$object->TableName.' WHERE '.$object->IDField.' = '.$stored_id); } @@ -226,7 +227,7 @@ $linked_info = $object->getLinkedInfo(); $sql = 'SELECT %s FROM %s WHERE %s = %s'; - $ids = $this->Conn->GetCol( sprintf($sql, $object->IDField, $object->TableName, $linked_info['ParentTableKey'], $linked_info['ParentId']) ); + $ids = $this->Conn->GetCol( sprintf($sql, $object->IDField, $object->TableName, $linked_info['ForeignKey'], $linked_info['ParentId']) ); if( is_array($ids) ) { usort($ids, Array(&$this, 'sortBracketIDs') );