Index: branches/RC/core/install/upgrades.php =================================================================== diff -u -r11599 -r11610 --- branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 11599) +++ branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 11610) @@ -686,17 +686,84 @@ } /** + * Returns module root category + * + * @param string $module_name + * @return int + */ + function _getRootCategory($module_name) + { + // don't cache anything here (like in static variables), because database value is changed on the fly !!! + $sql = 'SELECT RootCat + FROM ' . TABLE_PREFIX . 'Modules + WHERE LOWER(Name) = ' . $this->Conn->qstr( strtolower($module_name) ); + $root_category = $this->Conn->GetOne($sql); + + // put to cache too, because CategoriesEventHandler::_prepareAutoPage uses kApplication::findModule + $this->Application->ModuleInfo[$module_name]['Name'] = $module_name; + $this->Application->ModuleInfo[$module_name]['RootCat'] = $root_category; + + return $root_category; + } + + /** * Move all categories (except "Content") from "Home" to "Content" category and hide them from menu * */ function _restructureCatalog() { - $root_category = $this->Application->findModule('Name', 'Proj-CMS', 'RootCat'); + $root_category = $this->_getRootCategory('Core'); - $sql = 'UPDATE ' . TABLE_PREFIX . 'Category - SET IsMenu = 0, ParentId = ' . $root_category . ' + $sql = 'SELECT CategoryId + FROM ' . TABLE_PREFIX . 'Category WHERE ParentId = 0 AND CategoryId <> ' . $root_category; - $this->Conn->Query($sql); + $top_categories = $this->Conn->GetCol($sql); + + if ($top_categories) { + // hide all categories located outside "Content" category from menu + $sql = 'UPDATE ' . TABLE_PREFIX . 'Category + SET IsMenu = 0 + WHERE (ParentPath LIKE "|' . implode('|%") OR (ParentPath LIKE "|', $top_categories) . '|%")'; + $this->Conn->Query($sql); + + // move all top level categories under "Content" category and make them visible in menu + $sql = 'UPDATE ' . TABLE_PREFIX . 'Category + SET IsMenu = 1, ParentId = ' . $root_category . ' + WHERE ParentId = 0 AND CategoryId <> ' . $root_category; + $this->Conn->Query($sql); + } + + // make sure, that all categories have valid value for Priority field + + $priority_helper =& $this->Application->recallObject('PriorityHelper'); + /* @var $priority_helper kPriorityHelper */ + + $event = new kEvent('c:OnListBuild'); + + // update all categories, because they are all under "Content" category now + $sql = 'SELECT CategoryId + FROM ' . TABLE_PREFIX . 'Category'; + $categories = $this->Conn->GetCol($sql); + + foreach ($categories as $category_id) { + $priority_helper->recalculatePriorities($event, 'ParentId = ' . $category_id); + } + + // create initial theme structure in Category table + $this->_toolkit->rebuildThemes(); + + // make sure, that all system templates have ThemeId set (only possible during platform project upgrade) + $sql = 'SELECT ThemeId + FROM ' . TABLE_PREFIX . 'Theme + WHERE PrimaryTheme = 1'; + $primary_theme_id = $this->Conn->GetOne($sql); + + if ($primary_theme_id) { + $sql = 'UPDATE ' . TABLE_PREFIX . 'Category + SET ThemeId = ' . $primary_theme_id . ' + WHERE IsSystem = 1 AND ThemeId = 0'; + $this->Conn->Query($sql); + } } /** @@ -742,6 +809,56 @@ function _createProjCMSTables() { + // 0. make sure, that Content category exists + $root_category = $this->_getRootCategory('Proj-CMS'); + if ($root_category) { + // proj-cms module found -> remove it + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Modules + WHERE Name = "Proj-CMS"'; + $this->Conn->Query($sql); + unset($this->Application->ModuleInfo['Proj-CMS']); + + // unhide all structure categories + $sql = 'UPDATE ' . TABLE_PREFIX . 'Category + SET Status = 1 + WHERE (Status = 4) AND (CategoryId <> ' . $root_category . ')'; + $this->Conn->Query($sql); + } else { + $root_category = $this->_getRootCategory('In-Edit'); + if ($root_category) { + // in-edit module found -> remove it + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Modules + WHERE Name = "In-Edit"'; + $this->Conn->Query($sql); + unset($this->Application->ModuleInfo['In-Edit']); + + // hide root category of In-Edit and set it's fields + $fields_hash = Array ( + 'l1_Name' => 'Content', 'Filename' => 'Content', 'AutomaticFilename' => 0, + 'l1_Description' => 'Content', 'Status' => 4, + ); + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'Category', 'CategoryId = ' . $root_category); + } + } + + if (!$root_category) { + // create "Content" category when Proj-CMS/In-Edit module was not installed before + // use direct sql here, because category table structure doesn't yet match table structure in object + + $fields_hash = Array ( + 'l1_Name' => 'Content', 'Filename' => 'Content', 'AutomaticFilename' => 0, + 'l1_Description' => 'Content', 'Status' => 4, + ); + + $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'Category'); + + $root_category = $this->Conn->getInsertID(); + } + + $this->_toolkit->deleteCache(); + $this->_toolkit->SetModuleRootCategory('Core', $root_category); + // 1. process "Category" table $structure = $this->Conn->Query('DESCRIBE ' . TABLE_PREFIX . 'Category', 'Field'); if (!array_key_exists('Template', $structure)) { @@ -855,7 +972,7 @@ $sql = "INSERT INTO " . TABLE_PREFIX . "ConfigurationAdmin VALUES ('cms_DefaultDesign', 'la_Text_General', 'la_prompt_DefaultDesignTemplate', 'text', NULL, NULL, 10.29, 0, 0)"; $this->Conn->Query($sql); - $sql = "INSERT INTO " . TABLE_PREFIX . "ConfigurationValues VALUES (DEFAULT, 'cms_DefaultDesign', '/platform/designs/default_design.des', 'In-Portal', 'in-portal:configure_categories')"; + $sql = "INSERT INTO " . TABLE_PREFIX . "ConfigurationValues VALUES (DEFAULT, 'cms_DefaultDesign', '/platform/designs/general', 'In-Portal', 'in-portal:configure_categories')"; $this->Conn->Query($sql); } }