Index: branches/5.2.x/core/units/categories/categories_item.php =================================================================== diff -u -N -r14244 -r14585 --- branches/5.2.x/core/units/categories/categories_item.php (.../categories_item.php) (revision 14244) +++ branches/5.2.x/core/units/categories/categories_item.php (.../categories_item.php) (revision 14585) @@ -1,6 +1,6 @@ GetDBField('ParentId') > 0 ? $this->GetDBField('ParentId') : $this->Application->GetVar('m_cat_id'); + $this->SetDBField('ParentId', $parent_category); + $this->checkFilename(); $this->generateFilename(); @@ -33,9 +37,6 @@ $this->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); } - $parent_category = $this->GetDBField('ParentId') > 0 ? $this->GetDBField('ParentId') : $this->Application->GetVar('m_cat_id'); - $this->SetDBField('ParentId', $parent_category); - $ret = parent::Create($force_id, $system_create); if ($ret) { @@ -131,26 +132,25 @@ $item_theme = $current_theme; } - $unique_clause = '(Filename = %s) AND (ThemeId = ' . $item_theme . ' OR ThemeId = 0)'; - $check_in_parent_cat_only = $item_id ? ' AND ParentId = ' . $this->GetDBField('ParentId') : ''; + $unique_clause = '(Filename = %s) AND (ThemeId = ' . $item_theme . ' OR ThemeId = 0) AND (ParentId = ' . $this->GetDBField('ParentId') . ')'; + $sql_mask = ' SELECT ' . $this->IDField . ' + FROM %s + WHERE ' . sprintf($unique_clause, $this->Conn->qstr($filename)); + // check temp table - $sql_temp = ' SELECT ' . $this->IDField . ' - FROM ' . $this->TableName . ' - WHERE ' . sprintf($unique_clause, $this->Conn->qstr($filename)) . $check_in_parent_cat_only; + $sql_temp = sprintf($sql_mask, $this->TableName); $found_temp_ids = $this->Conn->GetCol($sql_temp); // check live table - $sql_live = ' SELECT ' . $this->IDField . ' - FROM ' . $this->Application->GetLiveName($this->TableName) . ' - WHERE ' . sprintf($unique_clause, $this->Conn->qstr($filename)) . $check_in_parent_cat_only; + $sql_live = sprintf($sql_mask, $this->Application->GetLiveName($this->TableName)); $found_live_ids = $this->Conn->GetCol($sql_live); $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) ); $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); - $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 ? $escape_char . 'a' : ''; if ($has_page) { @@ -162,6 +162,7 @@ $sql_temp = ' SELECT ' . $this->IDField . ' FROM ' . $this->TableName . ' WHERE ' . $unique_clause . ' AND (' . $this->IDField . ' != ' . $item_id . ')'; + $sql_live = ' SELECT ' . $this->IDField . ' FROM ' . $this->Application->GetLiveName($this->TableName) . ' WHERE ' . $unique_clause . ' AND (' . $this->IDField . ' != ' . $item_id . ')';