Index: branches/5.1.x/core/units/helpers/themes_helper.php =================================================================== diff -u -N -r13487 -r13545 --- branches/5.1.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 13487) +++ branches/5.1.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 13545) @@ -1,6 +1,6 @@ Application->recallObject('LanguageImportHelper'); - /* @var $language_import_helper LanguageImportHelper */ + $this->installThemeLanguagePack($theme_path); - foreach ($this->Application->ModuleInfo as $module_name => $module_info) { - if ($module_name == 'In-Portal') { - continue; - } - - $lang_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/english.lang'; - - if (file_exists($lang_file)) { - $language_import_helper->performImport($lang_file, '|0|', '', LANG_SKIP_EXISTING); - } - } - $fields_hash = Array ( 'LanguagePackInstalled' => 1, ); $this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $theme_id); } - // get template aliases from "/_install/theme.xml" files in theme + $fields_hash = Array ( + 'TemplateAliases' => serialize( $this->getTemplateAliases($theme_id, $theme_path) ), + ); + + $this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $theme_id); + + return $theme_id; + } + + /** + * Installs module(-s) language pack for given theme + * + * @param string $theme_path + * @param string $module_name + */ + function installThemeLanguagePack($theme_path, $module_name = false) + { + if ($module_name === false) { + $modules = $this->Application->ModuleInfo; + } + else { + $modules = Array ($module_name => $this->Application->ModuleInfo[$module_name]); + } + + $language_import_helper =& $this->Application->recallObject('LanguageImportHelper'); + /* @var $language_import_helper LanguageImportHelper */ + + foreach ($modules as $module_name => $module_info) { + if ($module_name == 'In-Portal') { + continue; + } + + $lang_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/english.lang'; + + if (file_exists($lang_file)) { + $language_import_helper->performImport($lang_file, '|0|', '', LANG_SKIP_EXISTING); + } + } + } + + /** + * Returns template aliases from "/_install/theme.xml" files in theme + * + * @param int $theme_id + * @param string $theme_path + */ + function getTemplateAliases($theme_id, $theme_path) + { $template_aliases = Array (); $xml_parser =& $this->Application->recallObject('kXMLHelper'); @@ -191,13 +225,37 @@ } } - $fields_hash = Array ( - 'TemplateAliases' => serialize($template_aliases), - ); + return $template_aliases; + } - $this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $theme_id); + /** + * Installs given module language pack and refreshed it from all themes + * + * @param string $module_name + */ + function syncronizeModule($module_name) + { + $sql = 'SELECT `Name`, ThemeId + FROM ' . TABLE_PREFIX . 'Theme'; + $themes = $this->Conn->GetCol($sql, 'ThemeId'); - return $theme_id; + if (!$themes) { + return ; + } + + foreach ($themes as $theme_id => $theme_name) { + $theme_path = $this->themesFolder . '/' . $theme_name; + + // install language pack + $this->installThemeLanguagePack($theme_path, $module_name); + + // update TemplateAliases mapping + $fields_hash = Array ( + 'TemplateAliases' => serialize( $this->getTemplateAliases($theme_id, $theme_path) ), + ); + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'Theme', 'ThemeId = ' . $theme_id); + } } /**