2023-12-19 09:23:16 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
2023-12-19 09:42:56 -08:00
|
|
|
use \App\Helpers\Helper;
|
|
|
|
use \App\Models\Setting;
|
|
|
|
use \App\Models\User;
|
2023-12-19 09:23:16 -08:00
|
|
|
|
|
|
|
class FixLanguageDirs extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
2023-12-19 09:42:56 -08:00
|
|
|
/**
|
|
|
|
* Update the settings table
|
|
|
|
*/
|
|
|
|
$settings = Setting::getSettings();
|
2023-12-19 11:00:11 -08:00
|
|
|
if (($settings) && ($settings->locale != '')) {
|
2023-12-19 09:42:56 -08:00
|
|
|
DB::table('settings')->update(['locale' => Helper::mapLegacyLocale($settings->locale)]);
|
2023-12-19 09:23:16 -08:00
|
|
|
}
|
|
|
|
|
2023-12-19 09:42:56 -08:00
|
|
|
/**
|
|
|
|
* Update the users table
|
|
|
|
*/
|
2023-12-19 12:23:19 -08:00
|
|
|
$users = User::whereNotNull('locale')->get();
|
2023-12-19 09:42:56 -08:00
|
|
|
// 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)]);
|
|
|
|
}
|
2023-12-19 09:23:16 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
2023-12-19 11:54:04 -08:00
|
|
|
$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)]);
|
|
|
|
}
|
|
|
|
|
2023-12-19 09:23:16 -08:00
|
|
|
}
|
|
|
|
}
|