/** * Add a new locale to a multi-lang db, setting * its values to the current default locale. * * @param $locale string the new locale to add * @param $source string the locale to copy from * @return void */ function addLocale($locale, $source) { // get the current supported locales $domain =& new CRM_Core_DAO_Domain(); $domain->find(true); $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); // break early if the locale is already supported if (in_array($locale, $locales)) { return; } $dao =& new CRM_Core_DAO(); // build the required SQL queries $columns =& CRM_Core_I18n_SchemaStructure::columns(); $indices =& CRM_Core_I18n_SchemaStructure::indices(); $queries = array(); foreach ($columns as $table => $hash) { // add new columns foreach ($hash as $column => $type) { $queries[] = "ALTER TABLE {$table} ADD {$column}_{$locale} {$type}"; $queries[] = "UPDATE {$table} SET {$column}_{$locale} = {$column}_{$source}"; } // add view $queries[] = self::createViewQuery($locale, $table, $dao); // add new indices $queries = array_merge($queries, self::createIndexQueries($locale, $table)); } // add triggers $queries = array_merge($queries, self::createTriggerQueries($locales, $locale)); // execute the queries without i18n rewriting foreach ($queries as $query) { $dao->query($query, false); } // update civicrm_domain.locales $locales[] = $locale; $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, $locales); $domain->save(); }
/** * Add a new locale to a multi-lang db, setting * its values to the current default locale. * * @param $locale string the new locale to add * @param $source string the locale to copy from * * @return void */ static function addLocale($locale, $source) { // get the current supported locales $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); // break early if the locale is already supported if (in_array($locale, $locales)) { return; } $dao = new CRM_Core_DAO(); // build the required SQL queries $columns = CRM_Core_I18n_SchemaStructure::columns(); $indices = CRM_Core_I18n_SchemaStructure::indices(); $queries = array(); foreach ($columns as $table => $hash) { // add new columns foreach ($hash as $column => $type) { // CRM-7854: skip existing columns if (CRM_Core_DAO::checkFieldExists($table, "{$column}_{$locale}", FALSE)) { continue; } $queries[] = "ALTER TABLE {$table} ADD {$column}_{$locale} {$type}"; $queries[] = "UPDATE {$table} SET {$column}_{$locale} = {$column}_{$source}"; } // add view $queries[] = self::createViewQuery($locale, $table, $dao); // add new indices $queries = array_merge($queries, array_values(self::createIndexQueries($locale, $table))); } // execute the queries without i18n rewriting foreach ($queries as $query) { $dao->query($query, FALSE); } // update civicrm_domain.locales $locales[] = $locale; $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, $locales); $domain->save(); // invoke the meta trigger creation call CRM_Core_DAO::triggerRebuild(); }