Index: branches/5.1.x/core/units/helpers/menu_helper.php =================================================================== diff -u -N -r13951 -r13987 --- branches/5.1.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 13951) +++ branches/5.1.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 13987) @@ -114,7 +114,7 @@ static $root_path = null; if (!$root_cat) { - $root_cat = $this->Application->ModuleInfo['Core']['RootCat']; + $root_cat = $this->Application->getBaseCategory(); $cache_key = 'parent_paths[%CIDSerial:' . $root_cat . '%]'; $root_path = $this->Application->getCache($cache_key); @@ -176,7 +176,7 @@ $cat = $this_category->GetDBField('ParentId'); } elseif ($cat == 0) { - $cat = $this->Application->ModuleInfo['Core']['RootCat']; + $cat = $this->Application->getBaseCategory(); } return $cat; Index: branches/5.1.x/core/units/helpers/category_helper.php =================================================================== diff -u -N -r13955 -r13987 --- branches/5.1.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 13955) +++ branches/5.1.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 13987) @@ -1,6 +1,6 @@ Application->findModule('Name', 'Core', 'RootCat'); // 0; + $block_params['cat_id'] = $this->Application->getBaseCategory(); $block_params['no_editing'] = 1; $block_params['current'] = $current_category == $block_params['cat_id'] ? 1 : 0; $block_params['separator'] = $params['separator']; @@ -305,7 +305,7 @@ $category_data = $this->Conn->GetRow($sql); $cached_path = Array (); - $skip_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $skip_category = $this->Application->getBaseCategory(); if ($category_data) { $category_names = explode('&|&', $category_data[$navbar_field]); @@ -457,7 +457,7 @@ $language_count = $ml_helper->getLanguageCount(); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); $data = $this->_getChildren($root_category, $language_count); if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { @@ -552,7 +552,7 @@ $data = $this->_getStructureTree(); $theme_id = (int)$themes_helper->getCurrentThemeId(); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); $this->_primaryLanguageId = $this->Application->GetDefaultLanguageId(); $this->_structureTree = $this->_printChildren($data, $root_category, $this->Application->GetVar('m_lang'), $theme_id); Index: branches/5.1.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r13984 -r13987 --- branches/5.1.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 13984) +++ branches/5.1.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 13987) @@ -1,6 +1,6 @@ Application->GetVar($event->getPrefixSpecial() . '_id'); - $home_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $home_category = $this->Application->getBaseCategory(); $this->Application->StoreVar('IsRootCategory_'.$this->Application->GetVar('m_wid'), ($category_id === '0') || ($category_id == $home_category)); @@ -291,7 +291,7 @@ if ("$parent_cat_id" == '0') { // replace "0" category with "Content" category id (this way template - $parent_cat_id = $this->Application->findModule('Name', 'Core', 'RootCat'); + $parent_cat_id = $this->Application->getBaseCategory(); } if ("$parent_cat_id" != 'any') { @@ -758,7 +758,7 @@ // 2. preset template $category_id = $this->Application->GetVar('m_cat_id'); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); if ($category_id == $root_category) { $object->SetDBField('Template', $this->_getDefaultDesign()); } @@ -1589,7 +1589,7 @@ $this->_saveTitleField($object, 'Title'); $this->_saveTitleField($object, 'MenuTitle'); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); if (($object->GetDBField('ParentId') == $root_category) && ($object->GetDBField('Template') == CATEGORY_TEMPLATE_INHERIT)) { $object->SetError('Template', 'no_inherit'); @@ -1672,7 +1672,7 @@ $theme_id = $this->_getCurrentThemeId(); } - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); $page_category = $this->Application->GetVar('m_cat_id'); if (!$page_category) { $page_category = $root_category; @@ -1869,7 +1869,7 @@ $settings = $site_config_helper->getSettings(); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); // set root category $section_ajustments = $this->Application->getUnitOption($event->Prefix, 'SectionAdjustments'); Index: branches/5.1.x/core/install/install_toolkit.php =================================================================== diff -u -N -r13956 -r13987 --- branches/5.1.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 13956) +++ branches/5.1.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 13987) @@ -1,6 +1,6 @@ 'Content/' . $name, ); - $category_fields['ParentId'] = $this->Application->findModule('Name', 'Core', 'RootCat'); + $category_fields['ParentId'] = $this->Application->getBaseCategory(); if (isset($category_template)) { $category_fields['Template'] = $category_template; Index: branches/5.1.x/core/units/helpers/cat_dbitem_export_helper.php =================================================================== diff -u -N -r13569 -r13987 --- branches/5.1.x/core/units/helpers/cat_dbitem_export_helper.php (.../cat_dbitem_export_helper.php) (revision 13569) +++ branches/5.1.x/core/units/helpers/cat_dbitem_export_helper.php (.../cat_dbitem_export_helper.php) (revision 13987) @@ -1,6 +1,6 @@ Application->GetVar('m_cat_id'); $parent_path = $this->Conn->GetOne($sql); $parent_path = explode('|', substr($parent_path, 1, -1)); - if ($parent_path && $parent_path[0] == $this->Application->findModule('Name', 'Core', 'RootCat')) { + if ($parent_path && $parent_path[0] == $this->Application->getBaseCategory()) { array_shift($parent_path); } Index: branches/5.1.x/core/kernel/application.php =================================================================== diff -u -N -r13905 -r13987 --- branches/5.1.x/core/kernel/application.php (.../application.php) (revision 13905) +++ branches/5.1.x/core/kernel/application.php (.../application.php) (revision 13987) @@ -1,6 +1,6 @@ recallObject('PermissionsHelper'); /* @var $perm_helper kPermissionsHelper */ - if ($perm_helper->CheckUserPermission($user, 'CATEGORY.MODIFY', 0, $this->ModuleInfo['Core']['RootCat'])) { + if ($perm_helper->CheckUserPermission($user, 'CATEGORY.MODIFY', 0, $this->getBaseCategory())) { // user can edit cms blocks $editing_mode = $this->GetVar('editing_mode'); define('EDITING_MODE', $editing_mode ? $editing_mode : EDITING_MODE_BROWSE); @@ -3232,4 +3232,18 @@ return false; } + /** + * Base category of all categories + * Usually replaced category, with ID = 0 in category-related operations. + * + * @return int + */ + function getBaseCategory() + { + // same, what $this->findModule('Name', 'Core', 'RootCat') does + // don't cache while IS_INSTALL, because of kInstallToolkit::createModuleCategory and upgrade + + return $this->ModuleInfo['Core']['RootCat']; + } + } \ No newline at end of file Index: branches/5.1.x/core/units/content/content_eh.php =================================================================== diff -u -N -r13086 -r13987 --- branches/5.1.x/core/units/content/content_eh.php (.../content_eh.php) (revision 13086) +++ branches/5.1.x/core/units/content/content_eh.php (.../content_eh.php) (revision 13987) @@ -1,6 +1,6 @@ Application->RecallVar('user_id'); // user can change top category - $top_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $top_category = $this->Application->getBaseCategory(); $perm_status = $perm_helper->CheckUserPermission($user_id, 'CATEGORY.MODIFY', 0, $top_category); return $perm_helper->finalizePermissionCheck($event, $perm_status); Index: branches/5.1.x/core/units/categories/categories_tag_processor.php =================================================================== diff -u -N -r13951 -r13987 --- branches/5.1.x/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 13951) +++ branches/5.1.x/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 13987) @@ -1,6 +1,6 @@ Application->findModule('Name', 'Core', 'RootCat'); - } - - return $root_category; + return $this->Application->getBaseCategory(); } /** @@ -620,7 +614,7 @@ */ function ModuleRootCategory($params) { - return $this->Application->GetVar('m_cat_id') == $this->HomeCategory($params); + return $this->Application->GetVar('m_cat_id') == $this->Application->getBaseCategory(); } function CatalogItemCount($params) Index: branches/5.1.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r13581 -r13987 --- branches/5.1.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 13581) +++ branches/5.1.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 13987) @@ -1,6 +1,6 @@ Application->findModule('Name', 'Core', 'RootCat'); + $parent_cat_id = $this->Application->getBaseCategory(); } if ((string)$parent_cat_id != 'any') { @@ -2047,7 +2047,7 @@ */ function OnResetSettings(&$event) { - $this->Application->StoreVar('ImportCategory', $this->Application->findModule('Name', 'Core', 'RootCat')); + $this->Application->StoreVar('ImportCategory', $this->Application->getBaseCategory()); } function OnCancelAction(&$event) Index: branches/5.1.x/core/units/admin/admin_tag_processor.php =================================================================== diff -u -N -r13750 -r13987 --- branches/5.1.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 13750) +++ branches/5.1.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 13987) @@ -1,6 +1,6 @@ Application->findModule('Name', 'Core', 'RootCat'); + $params['m_cat_id'] = $this->Application->getBaseCategory(); $default_params = Array('no_amp' => 1, 'pass' => 'all,'.$params['prefix']); unset($params['prefix']); @@ -766,7 +766,7 @@ if (isset($params['m_opener']) && $params['m_opener'] == 'r') { // front-end link for highlighting purposes $vars['t'] = 'index'; - $vars['m_cat_id'] = $this->Application->findModule('Name', 'Core', 'RootCat'); + $vars['m_cat_id'] = $this->Application->getBaseCategory(); } unset($recursion_templates[ array_search('index', $recursion_templates)]); Index: branches/5.1.x/core/units/helpers/permissions_helper.php =================================================================== diff -u -N -r13584 -r13987 --- branches/5.1.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 13584) +++ branches/5.1.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 13987) @@ -1,6 +1,6 @@ Application->GetVar('m_cat_id'); + } + if ($type == 1) { // "system" permission are always checked per "Home" category (ID = 0) $cat_id = 0; } - - if (!isset($cat_id)) { - $cat_id = $this->Application->GetVar('m_cat_id'); + elseif ("$cat_id" === "0") { + $cat_id = $this->Application->getBaseCategory(); } // perm cache is build only based on records in db, that's why if permission is not explicitly denied, then @@ -612,7 +615,7 @@ $cat_hierarchy = $this->Conn->GetOne($sql); if ($cat_hierarchy === false) { // category was deleted, but refrence to it stays in other tables -> data integrity is broken - $cat_hierarchy = '|' . $this->Application->findModule('Name', 'Core', 'RootCat') . '|'; + $cat_hierarchy = '|' . $this->Application->getBaseCategory() . '|'; } }