Index: branches/5.2.x/core/units/categories/categories_item.php =================================================================== diff -u -N -r14699 -r14719 --- branches/5.2.x/core/units/categories/categories_item.php (.../categories_item.php) (revision 14699) +++ branches/5.2.x/core/units/categories/categories_item.php (.../categories_item.php) (revision 14719) @@ -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(); - - if ($this->Validate()) { - // TODO: such approach will not respect changes from CategoryEventHandler::OnBeforeItemCreate event - $this->SetDBField('ResourceId', $this->Application->NextResourceId()); - } - - // TODO: move to CategoryEventHandler::OnBeforeItemCreate - $is_admin = $this->Application->isAdminUser; - - if ((!$this->IsTempTable() && !$is_admin) || ($is_admin && !$this->GetDBField('CreatedById'))) { - $this->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); - } - - $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; - - } - - /** - * Updates previously loaded record with current item' values - * - * @access public - * @param int $id Primary Key Id to update - * @param bool $system_update - * @return bool - * @access public - */ - public function Update($id = null, $system_update = false) - { - $this->checkFilename(); - $this->generateFilename(); - - return parent::Update($id, $system_update); - } - - function buildParentPath() - { $parent_id = $this->GetDBField('ParentId'); - if ($parent_id == 0) { + if ( $parent_id == 0 ) { $parent_path = '|'; } else { - $cat_table = $this->Application->getUnitOption($this->Prefix, 'TableName'); - $sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s'; - $parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) ); + $sql = 'SELECT ParentPath + FROM ' . $this->Application->getUnitOption($this->Prefix, 'TableName') . ' WHERE + CategoryId = ' . $parent_id; + $parent_path = $this->Conn->GetOne($sql); } - return $parent_path.$this->GetID().'|'; + return $parent_path . $this->GetID() . '|'; } /** * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result * * @param string $string * @return string + * @access protected */ - function stripDisallowed($string) + protected function stripDisallowed($string) { $filenames_helper =& $this->Application->recallObject('FilenamesHelper'); /* @var $filenames_helper kFilenamesHelper */ @@ -110,22 +56,22 @@ return $this->checkAutoFilename($string); } - function checkFilename() + public function checkFilename() { - if ($this->GetDBField('AutomaticFilename')) { + if ( $this->GetDBField('AutomaticFilename') ) { // filename will be generated from scratch, don't check anything here - return ; + return; } - elseif ($this->GetDBField('Type') == PAGE_TYPE_TEMPLATE) { + elseif ( $this->GetDBField('Type') == PAGE_TYPE_TEMPLATE ) { // system page with AutomaticFilename checkbox unchecked -> compatibility with Proj-CMS <= 4.3.9 (when "/" were allowed in Filename) - return ; + return; } $filename = $this->GetDBField('Filename'); $this->SetDBField('Filename', $this->stripDisallowed($filename)); } - function checkAutoFilename($filename) + protected function checkAutoFilename($filename) { static $current_theme = null; @@ -202,9 +148,9 @@ * Generate item's filename based on it's title field value * * @return void - * @access protected + * @access public */ - protected function generateFilename() + public function generateFilename() { if ( !$this->GetDBField('AutomaticFilename') && $this->GetDBField('Filename') ) { return ; @@ -224,25 +170,30 @@ * Allows to detect if root category being edited * * @return int + * @access public */ - function IsRoot() + public function IsRoot() { return $this->Application->RecallVar('IsRootCategory_'.$this->Application->GetVar('m_wid')); } + /** * Sets correct name to Home category while editing it * * @return bool + * @access public */ - function IsNewItem() + public function IsNewItem() { - if ($this->IsRoot() && $this->Prefix == 'c') { + if ( $this->IsRoot() && $this->Prefix == 'c' ) { $title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField'); $category_name = $this->Application->Phrase(($this->Application->isAdmin ? 'la_' : 'lu_') . 'rootcategory_name'); $this->SetDBField($title_field, $category_name); + return false; } + return parent::IsNewItem(); }