Index: branches/5.2.x/core/units/helpers/multilanguage_helper.php =================================================================== diff -u -N -r14092 -r14095 --- branches/5.2.x/core/units/helpers/multilanguage_helper.php (.../multilanguage_helper.php) (revision 14092) +++ branches/5.2.x/core/units/helpers/multilanguage_helper.php (.../multilanguage_helper.php) (revision 14095) @@ -1,6 +1,6 @@ languageCount = $this->getLanguageCount(); + static $init_made = false; + + if (!$init_made) { + $this->languagesIDs = $this->getActualLanguages(); + $this->languageCount = max( max($this->languagesIDs), 5 ); + $init_made = true; + } } /** + * Returns language ids, that can be used + * + * @return Array + */ + protected function getActualLanguages() + { + $cache_key = 'language_ids[%LangSerial%]'; + $ret = $this->Application->getCache($cache_key); + + if ($ret === false) { + $this->Conn->nextQueryCachable = true; + $sql = 'SELECT ' . $this->Application->getUnitOption('lang', 'IDField') . ' + FROM ' . $this->Application->getUnitOption('lang', 'TableName'); + $ret = $this->Conn->GetCol($sql); + + $this->Application->setCache($cache_key, $ret); + } + + return $ret; + } + + /** * Checks if language with specified id is created * * @param int $language_id * @return bool */ - function LanguageFound($language_id) + protected function LanguageFound($language_id) { return in_array($language_id, $this->languagesIDs) || $language_id <= 5; } /** - * Returns language count in system (always is divisible by 5) + * Returns list of processable languages * + * @return Array */ - function getLanguageCount() + public function getLanguages() { - if ($this->languageCount) { - return $this->languageCount; - } + static $languages = null; - $id_field = $this->Application->getUnitOption('lang', 'IDField'); - $table_name = $this->Application->getUnitOption('lang', 'TableName'); + if ( !isset($languages) ) { + $languages = Array (); + $this->initLanguageCount(); - $this->languagesIDs = $this->Conn->GetCol('SELECT '.$id_field.' FROM '.$table_name); + for ($language_id = 1; $language_id <= $this->languageCount; $language_id++) { + if ( $this->LanguageFound($language_id) ) { + $languages[] = $language_id; + } + } + } - $languages_count = $this->Conn->GetOne('SELECT MAX('.$id_field.') FROM '.$table_name); - - return max($languages_count, 5); + return $languages; } - function scanTable($mask) { $i = 0; @@ -144,6 +176,8 @@ return true; } + $this->initLanguageCount(); + $sqls = Array(); $this->readTableStructure($table_name, $refresh);