Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -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 ) {