mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
5e0128c9dc
Signed-off-by: snipe <snipe@snipe.net>
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use \App\Helpers\Helper;
|
|
use \App\Models\Setting;
|
|
use \App\Models\User;
|
|
|
|
class FixLanguageDirs extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up()
|
|
{
|
|
/**
|
|
* Update the settings table
|
|
*/
|
|
$settings = Setting::getSettings();
|
|
if (($settings) && ($settings->locale != '')) {
|
|
DB::table('settings')->update(['locale' => Helper::mapLegacyLocale($settings->locale)]);
|
|
}
|
|
|
|
/**
|
|
* Update the users table
|
|
*/
|
|
$users = User::whereNotNull('locale')->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::mapLegacyLocale($user->locale)]);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
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)]);
|
|
}
|
|
|
|
}
|
|
}
|