Index: trunk/core/units/general/helpers/filenames_helper.php =================================================================== diff -u -N -r5505 -r5509 --- trunk/core/units/general/helpers/filenames_helper.php (.../filenames_helper.php) (revision 5505) +++ trunk/core/units/general/helpers/filenames_helper.php (.../filenames_helper.php) (revision 5509) @@ -27,10 +27,10 @@ $item_id = !$item_id ? 0 : $item_id; if ($table == TABLE_PREFIX.'CategoryItems') { - $table = $this->Application->IsTempTable($table) ? $this->Application->GetLiveName($table) : $table; - $item_tmp_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetTempName($table).' WHERE ItemResourceId = '.$item_id); - $item_live_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id); - $item_categories = array_unique(array_merge($item_tmp_categories, $item_live_categories)); + $item_categories_cur = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id); + $item_categories_live = $this->Application->IsTempTable($table) ? $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetLiveName($table).' WHERE ItemResourceId = '.$item_id) : array(); + + $item_categories = array_unique(array_merge($item_categories_cur, $item_categories_live)); if (!$item_categories) { $item_categories = array($this->Application->GetVar('m_cat_id')); // this may happen when creating new item } @@ -40,13 +40,18 @@ $cat_filter = ''; } - // check temp table + // check current table (temp or live) $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter; $found_temp_ids = $this->Conn->GetCol($sql_temp); - // check live table - $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter; - $found_live_ids = $this->Conn->GetCol($sql_live); + // check live table if current is temp + if ( $this->Application->IsTempTable($table) ) { + $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter; + $found_live_ids = $this->Conn->GetCol($sql_live); + } + else { + $found_live_ids = array(); + } $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) ); @@ -63,10 +68,14 @@ } // check live & temp table - $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter; - $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter; - 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 ) + $sql_cur = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter; + $sql_live = $this->Application->IsTempTable($table) ? 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter : false; + while ( $this->Conn->GetOne( sprintf($sql_cur, $this->Conn->qstr($filename.$append)) ) > 0 || + ( $sql_live + && + ( $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 ) + ) + ) { if (substr($append, -1) == 'z') $append .= 'a'; $append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 );