refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User\User;
|
||||
use App\Helpers\CountriesHelper;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class DefaultTemperatureScale extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('temperature_scale')->default('celsius')->change();
|
||||
});
|
||||
|
||||
$country = null;
|
||||
$currentLocale = null;
|
||||
User::orderBy('locale')->chunkById(200, function ($users) use ($country, $currentLocale) {
|
||||
foreach ($users as $user) {
|
||||
if ($user->locale != $currentLocale || $country == null) {
|
||||
$country = CountriesHelper::getCountryFromLocale($user->locale);
|
||||
$currentLocale = $user->locale;
|
||||
}
|
||||
|
||||
if ($country !== null) {
|
||||
switch ($country->getIsoAlpha2()) {
|
||||
case 'US':
|
||||
case 'BZ':
|
||||
case 'KY':
|
||||
$user->temperature_scale = 'fahrenheit';
|
||||
break;
|
||||
default:
|
||||
$user->temperature_scale = 'celsius';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$user->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user