Index: branches/5.2.x/core/units/languages/languages_item.php =================================================================== diff -u -N -r14244 -r14572 --- branches/5.2.x/core/units/languages/languages_item.php (.../languages_item.php) (revision 14244) +++ branches/5.2.x/core/units/languages/languages_item.php (.../languages_item.php) (revision 14572) @@ -1,6 +1,6 @@ Conn->GetOne($sql) + 1; } + /** + * Set's current language as new primary and return previous primary language + * + * @param bool $reset_primary + * @param bool $admin_language + * @return int + */ function setPrimary($reset_primary = true, $admin_language = false) { + $prev_primary = false; $primary_field = $admin_language ? 'AdminInterfaceLang' : 'PrimaryLang'; + if ($reset_primary) { + $sql = 'SELECT ' . $this->IDField . ' + FROM ' . $this->TableName . ' + WHERE ' . $primary_field . ' = 1'; + $prev_primary = $this->Conn->GetOne($sql); + $sql = 'UPDATE '.$this->TableName.' SET '.$primary_field.' = 0'; $this->Conn->Query($sql); @@ -39,9 +53,38 @@ // in case, when Update method is called for this langauge object $this->SetDBField($primary_field, 1); $this->SetDBField('Enabled', 1); + + // increment serial by hand, since no Update method is called + $this->Application->incrementCacheSerial($this->Prefix); + $this->Application->incrementCacheSerial($this->Prefix, $this->GetID()); + + return $prev_primary; } /** + * Copies missing data on current language from given language + * + * @param int $from_language + */ + function copyMissingData($from_language) + { + if ( !is_numeric($from_language) || ($from_language == $this->GetID()) ) { + // invalid or same language + return ; + } + + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + + $to_language = $this->GetID(); + $this->Application->UnitConfigReader->ReReadConfigs(); + + foreach ($this->Application->UnitConfigReader->configData as $prefix => $config_data) { + $ml_helper->copyMissingData($prefix, $from_language, $to_language); + } + } + + /** * Allows to format number according to regional settings * * @param float $number