Index: trunk/kernel/include/item.php =================================================================== diff -u -N -r3261 -r3268 --- trunk/kernel/include/item.php (.../item.php) (revision 3261) +++ trunk/kernel/include/item.php (.../item.php) (revision 3268) @@ -1131,14 +1131,14 @@ $found_item_ids = $db->GetCol($sql); $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); - $duplicates_found = (count($found_item_ids) > 1); + $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $this->UniqueId()); if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number { - $append = $duplicates_found ? 'a' : ''; + $append = $duplicates_found ? '_a' : ''; if($has_page) { $filename = $rets[1].'_'.$rets[2]; - $append = $rets[3] ? $rets[3] : 'a'; + $append = $rets[3] ? $rets[3] : '_a'; } $sql = 'SELECT '.$this->IdField().' FROM '.$this->tablename.' WHERE (Filename = %s) AND ('.$this->IdField().' != '.$this->UniqueId().')'; Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -N -r3261 -r3268 --- trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3261) +++ trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3268) @@ -214,8 +214,10 @@ function checkAutoFilename($filename) { - if(!$filename || is_null( $this->GetID() ) ) return $filename; - + if(!$filename) return $filename; + + $item_id = !$this->GetID() ? 0 : $this->GetID(); + // check temp table $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename); $found_temp_ids = $this->Conn->GetCol($sql_temp); @@ -228,19 +230,19 @@ $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); - $duplicates_found = (count($found_item_ids) > 1); + $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id); if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number { - $append = $duplicates_found ? 'a' : ''; + $append = $duplicates_found ? '_a' : ''; if($has_page) { $filename = $rets[1].'_'.$rets[2]; - $append = $rets[3] ? $rets[3] : 'a'; + $append = $rets[3] ? $rets[3] : '_a'; } // check live & temp table - $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$this->GetID().')'; - $sql_live = 'SELECT '.$this->IDField.' FROM '.kTempTablesHandler::GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$this->GetID().')'; + $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; + $sql_live = 'SELECT '.$this->IDField.' FROM '.kTempTablesHandler::GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 || $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 ) { Index: trunk/kernel/units/general/cat_dbitem.php =================================================================== diff -u -N -r3261 -r3268 --- trunk/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3261) +++ trunk/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3268) @@ -214,8 +214,10 @@ function checkAutoFilename($filename) { - if(!$filename || is_null( $this->GetID() ) ) return $filename; - + if(!$filename) return $filename; + + $item_id = !$this->GetID() ? 0 : $this->GetID(); + // check temp table $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename); $found_temp_ids = $this->Conn->GetCol($sql_temp); @@ -228,19 +230,19 @@ $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); - $duplicates_found = (count($found_item_ids) > 1); + $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id); if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number { - $append = $duplicates_found ? 'a' : ''; + $append = $duplicates_found ? '_a' : ''; if($has_page) { $filename = $rets[1].'_'.$rets[2]; - $append = $rets[3] ? $rets[3] : 'a'; + $append = $rets[3] ? $rets[3] : '_a'; } // check live & temp table - $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$this->GetID().')'; - $sql_live = 'SELECT '.$this->IDField.' FROM '.kTempTablesHandler::GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$this->GetID().')'; + $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; + $sql_live = 'SELECT '.$this->IDField.' FROM '.kTempTablesHandler::GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 || $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 ) { Index: trunk/kernel/include/category.php =================================================================== diff -u -N -r3255 -r3268 --- trunk/kernel/include/category.php (.../category.php) (revision 3255) +++ trunk/kernel/include/category.php (.../category.php) (revision 3268) @@ -59,15 +59,17 @@ $db =& GetADODBConnection(); $sql = 'SELECT CategoryId FROM '.$this->tablename.' WHERE (Filename = '.$db->qstr($filename).') AND (ParentId = '.$m_var_list['cat'].')'; - $category_id = $db->GetOne($sql); + $found_category_ids = $db->GetCol($sql); $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); - if( ($category_id != $this->UniqueId()) || $has_page ) // other category has same filename as ours OR we have filename, that ends with _number + + $duplicates_found = (count($found_category_ids) > 1) || ($found_category_ids && $found_category_ids[0] != $this->UniqueId()); + if ($duplicates_found || $has_page) { - $append = $category_id ? 'a' : ''; + $append = $duplicates_found ? '_a' : ''; if($has_page) { $filename = $rets[1].'_'.$rets[2]; - $append = $rets[3] ? $rets[3] : 'a'; + $append = $rets[3] ? $rets[3] : '_a'; } $sql = 'SELECT CategoryId FROM '.$this->tablename.' WHERE (Filename = %s) AND (CategoryId != '.$this->UniqueId().') AND (ParentId = '.$m_var_list['cat'].')'; Index: trunk/kernel/include/itemdb.php =================================================================== diff -u -N -r2882 -r3268 --- trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 2882) +++ trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 3268) @@ -106,6 +106,9 @@ function SetUniqueId($value) { $var = $this->IdField(); + + if( $this->UsingTempTable() ) $value = $this->UniqueId(); + $this->Set($var, $value); }