Index: branches/5.2.x/core/kernel/utility/temp_handler.php =================================================================== diff -u -N -r15012 -r15055 --- branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 15012) +++ branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 15055) @@ -1,6 +1,6 @@ Tables; - if( strpos($prefix,'.') !== false ) list($prefix,$special) = explode('.', $prefix, 2); + if ( !$ids ) { + return; + } - $prefix_special = rtrim($prefix.'.'.$special, '.'); + if ( !isset($master) ) { + $master = $this->Tables; + } + if ( strpos($prefix, '.') !== false ) { + list($prefix, $special) = explode('.', $prefix, 2); + } + + $prefix_special = rtrim($prefix . '.' . $special, '.'); + //recalling by different name, because we may get kDBList, if we recall just by prefix - $recall_prefix = $prefix_special.($special ? '' : '.').'-item'; - $object =& $this->Application->recallObject($recall_prefix, $prefix, Array('skip_autoload' => true, 'parent_event' => &$this->parentEvent)); + $recall_prefix = $prefix_special . ($special ? '' : '.') . '-item'; + $object =& $this->Application->recallObject($recall_prefix, $prefix, Array ('skip_autoload' => true, 'parent_event' => &$this->parentEvent)); /* @var $object kDBItem */ - foreach ($ids as $id) - { + foreach ($ids as $id) { $object->Load($id); $original_values = $object->GetFieldValues(); - if( !$object->Delete($id) ) continue; + if ( !$object->Delete($id) ) { + continue; + } + if ( is_array(getArrayValue($master, 'SubTables')) ) { - foreach($master['SubTables'] as $sub_table) { - if (!getArrayValue($sub_table, 'AutoDelete')) continue; + foreach ($master['SubTables'] as $sub_table) { + if ( !getArrayValue($sub_table, 'AutoDelete') ) { + continue; + } + $sub_TableName = $object->IsTempTable() ? $this->GetTempName($sub_table['TableName']) : $sub_table['TableName']; $foreign_key_field = is_array($sub_table['ForeignKey']) ? getArrayValue($sub_table, 'ForeignKey', $master['Prefix']) : $sub_table['ForeignKey']; $parent_key_field = is_array($sub_table['ParentTableKey']) ? getArrayValue($sub_table, 'ParentTableKey', $master['Prefix']) : $sub_table['ParentTableKey']; - if (!$foreign_key_field || !$parent_key_field) continue; + if ( !$foreign_key_field || !$parent_key_field ) { + continue; + } - $query = 'SELECT '.$sub_table['IdField'].' FROM '.$sub_TableName.' - WHERE '.$foreign_key_field.' = '.$original_values[$parent_key_field]; + $sql = 'SELECT ' . $sub_table['IdField'] . ' + FROM ' . $sub_TableName . ' + WHERE ' . $foreign_key_field . ' = ' . $original_values[$parent_key_field]; + $sub_ids = $this->Conn->GetCol($sql); - $sub_ids = $this->Conn->GetCol($query); - $parent_key = $object->GetDBField(is_array($sub_table['ParentTableKey']) ? $sub_table['ParentTableKey'][$prefix] : $sub_table['ParentTableKey']); $this->DeleteItems($sub_table['Prefix'], $special, $sub_ids, $sub_table, $parent_key);