Index: branches/5.0.x/core/install/upgrades.php =================================================================== diff -u -N -r12734 -r12808 --- branches/5.0.x/core/install/upgrades.php (.../upgrades.php) (revision 12734) +++ branches/5.0.x/core/install/upgrades.php (.../upgrades.php) (revision 12808) @@ -1,6 +1,6 @@ Conn->Query($sql); } + + /** + * Update to 5.0.2-B2 + * + * @param string $mode when called mode {before, after) + */ + function Upgrade_5_0_2_B2($mode) + { + if ($mode == 'after') { + // scan theme to fill Theme.TemplateAliases and ThemeFiles.TemplateAlias fields + $this->_toolkit->rebuildThemes(); + + $sql = 'SELECT TemplateAliases, ThemeId + FROM ' . TABLE_PREFIX . 'Theme + WHERE (Enabled = 1) AND (TemplateAliases <> "")'; + $template_aliases = $this->Conn->GetCol($sql, 'ThemeId'); + + $all_template_aliases = Array (); // reversed alias (from real template to alias) + + foreach ($template_aliases as $theme_id => $theme_template_aliases) { + $theme_template_aliases = unserialize($theme_template_aliases); + + if (!$theme_template_aliases) { + continue; + } + + $all_template_aliases = array_merge($all_template_aliases, array_flip($theme_template_aliases)); + } + + $default_design_replaced = false; + $default_design = trim($this->Application->ConfigValue('cms_DefaultDesign'), '/'); + + foreach ($all_template_aliases as $from_template => $to_alias) { + // replace default design in configuration variable (when matches alias) + if ($from_template == $default_design) { + // specific alias matched + $sql = 'UPDATE ' . TABLE_PREFIX . 'ConfigurationValues + SET VariableValue = ' . $this->Conn->qstr($to_alias) . ' + WHERE VariableName = "cms_DefaultDesign"'; + $this->Conn->Query($sql); + + $default_design_replaced = true; + } + + // replace Category.Template and Category.CachedTemplate fields (when matches alias) + $sql = 'UPDATE ' . TABLE_PREFIX . 'Category + SET Template = ' . $this->Conn->qstr($to_alias) . ' + WHERE Template IN (' . $this->Conn->qstr('/' . $from_template) . ',' . $this->Conn->qstr($from_template) . ')'; + $this->Conn->Query($sql); + + $sql = 'UPDATE ' . TABLE_PREFIX . 'Category + SET CachedTemplate = ' . $this->Conn->qstr($to_alias) . ' + WHERE CachedTemplate IN (' . $this->Conn->qstr('/' . $from_template) . ',' . $this->Conn->qstr($from_template) . ')'; + $this->Conn->Query($sql); + } + + if (!$default_design_replaced) { + // in case if current default design template doesn't + // match any of aliases, then set it to #default_design# + $sql = 'UPDATE ' . TABLE_PREFIX . 'ConfigurationValues + SET VariableValue = "#default_design#" + WHERE VariableName = "cms_DefaultDesign"'; + $this->Conn->Query($sql); + } + + // replace data in category custom fields used for category item template storage + $mod_rewrite_helper =& $this->Application->recallObject('ModRewriteHelper'); + /* @var $mod_rewrite_helper kModRewriteHelper */ + + foreach ($this->Application->ModuleInfo as $module_name => $module_info) { + $custom_field_id = $mod_rewrite_helper->getItemTemplateCustomField($module_info['Var']); + + if (!$custom_field_id) { + continue; + } + + foreach ($all_template_aliases as $from_template => $to_alias) { + $sql = 'UPDATE ' . TABLE_PREFIX . 'CategoryCustomData + SET l1_cust_' . $custom_field_id . ' = ' . $this->Conn->qstr($to_alias) . ' + WHERE l1_cust_' . $custom_field_id . ' = ' . $this->Conn->qstr($from_template); + $this->Conn->Query($sql); + } + } + + } + } } \ No newline at end of file