mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Added back-migration for Big Locale Refactoring
This commit is contained in:
parent
70b8b7e4be
commit
82dd601661
|
@ -1342,15 +1342,8 @@ class Helper
|
|||
* @param $language_code
|
||||
* @return string []
|
||||
*/
|
||||
public static function mapLegacyLocale($language_code = null)
|
||||
{
|
||||
|
||||
if (strlen($language_code) > 4) {
|
||||
return $language_code;
|
||||
}
|
||||
|
||||
$languages = [
|
||||
'af' => 'af-ZA', // Afrikaans
|
||||
public static $language_map = ['af' => 'af-ZA', // Afrikaans
|
||||
'am' => 'am-ET', // Amharic
|
||||
'ar' => 'ar-SA', // Arabic
|
||||
'bg' => 'bg-BG', // Bulgarian
|
||||
|
@ -1399,7 +1392,15 @@ class Helper
|
|||
'zu' => 'zu-ZA', // Zulu
|
||||
];
|
||||
|
||||
foreach ($languages as $legacy => $new) {
|
||||
|
||||
public static function mapLegacyLocale($language_code = null)
|
||||
{
|
||||
|
||||
if (strlen($language_code) > 4) {
|
||||
return $language_code;
|
||||
}
|
||||
|
||||
foreach (self::$language_map as $legacy => $new) {
|
||||
if ($language_code == $legacy) {
|
||||
\Log::debug('Current language is '.$legacy.', using '.$new.' instead');
|
||||
return $new;
|
||||
|
@ -1407,4 +1408,17 @@ class Helper
|
|||
}
|
||||
}
|
||||
|
||||
public static function mapBackToLegacyLocale($new_locale = null)
|
||||
{
|
||||
if (strlen($new_locale) <= 4) {
|
||||
return $new_locale; //"new locale" apparently wasn't quite so new
|
||||
}
|
||||
$legacy_locale = array_search($new_locale,self::$language_map);
|
||||
|
||||
if($legacy_locale !== false) {
|
||||
return $legacy_locale;
|
||||
}
|
||||
return $new_locale; // better that you have some weird locale that doesn't fit into our mappings anywhere than 'void'
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,19 @@ class FixLanguageDirs extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
$settings = Setting::getSettings();
|
||||
if (($settings) && ($settings->locale != '')) {
|
||||
DB::table('settings')->update(['locale' => Helper::mapBackToLegacyLocale($settings->locale)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the users table
|
||||
*/
|
||||
$users = User::whereNotNull('locale')->whereNull('deleted_at')->get();
|
||||
// Skip the model in case the validation rules have changed
|
||||
foreach ($users as $user) {
|
||||
DB::table('users')->where('id', $user->id)->update(['locale' => Helper::mapBackToLegacyLocale($user->locale)]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue