Index: branches/RC/core/units/categories/categories_item.php =================================================================== diff -u -r10920 -r11368 --- branches/RC/core/units/categories/categories_item.php (.../categories_item.php) (revision 10920) +++ branches/RC/core/units/categories/categories_item.php (.../categories_item.php) (revision 11368) @@ -2,14 +2,17 @@ class CategoriesItem extends kDBItem { - function Create($force_id=false, $system_create=false) + function Create($force_id = false, $system_create = false) { $this->checkFilename(); $this->generateFilename(); - if (!$this->Validate()) return false; + if ($this->Validate()) { + // TODO: such approach will not respect changes from CategoryEventHandler::OnBeforeItemCreate event + $this->SetDBField('ResourceId', $this->Application->NextResourceId()); + } - $this->SetDBField('ResourceId', $this->Application->NextResourceId()); + // TODO: move to CategoryEventHandler::OnBeforeItemCreate $this->SetDBField('CreatedById', $this->Application->RecallVar('user_id') ); $this->SetDBField('CreatedOn_date', adodb_mktime() ); $this->SetDBField('CreatedOn_time', adodb_mktime() ); @@ -18,24 +21,26 @@ $this->SetDBField('ParentId', $parent_category); $ret = parent::Create($force_id, $system_create); + if ($ret) { + // TODO: move to CategoryEventHandler::OnAfterItemCreate method $sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s'; $parent_path = $this->buildParentPath(); $this->Conn->Query( sprintf($sql, $this->TableName, $this->Conn->qstr($parent_path), $this->GetID() ) ); $this->SetDBField('ParentPath', $parent_path); } + return $ret; } - function Update($id=null, $system_update=false) + function Update($id=null, $system_update = false) { $this->checkFilename(); $this->generateFilename(); - $ret = parent::Update($id, $system_update); - return $ret; + return parent::Update($id, $system_update); } function buildParentPath() @@ -53,7 +58,7 @@ return $parent_path.$this->GetID().'|'; } - + /** * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result * @@ -85,7 +90,7 @@ if(!$filename) return $filename; $escape_char = $this->Application->ConfigValue('FilenameSpecialCharReplacement'); - + $item_id = !$this->GetID() ? 0 : $this->GetID(); $check_in_parent_cat_only = $item_id ? ' AND ParentId = '.$this->GetDBField('ParentId') : '';