Ticket 325 : Update civility field to comply with Teddy Guichard 's request

This commit is contained in:
Jérémy Munsch 2021-09-15 15:29:19 +02:00
parent 993a334b1d
commit 7e94de27e3
3 changed files with 78 additions and 8 deletions

View file

@ -5,25 +5,22 @@ namespace App\Enums;
use Kwaadpepper\Enum\BaseEnumRoutable;
/**
* @method static self mlle()
* @method static self mme()
* @method static self m()
* @method static self mme()
*/
final class ContactFormCivility extends BaseEnumRoutable
{
protected static function values(): array
{
return [
'mlle' => 1,
'mme' => 2,
'm' => 3
'm' => 1,
'mme' => 2
];
}
protected static function labels(): array
{
return [
'mlle' => __('Mlle'),
'mme' => __('Mme'),
'm' => __('M')
];

View file

@ -7,7 +7,6 @@ use App\Exceptions\AbortRowImportException;
use App\Models\Order;
use App\Models\OrderSellItem;
use App\Models\SellItem;
use App\Models\SellItems;
use Illuminate\Support\Str;
use Database\migrations\LeGaulois2016Migration;
@ -46,7 +45,7 @@ class MigrateLegaulois2016BoutiqueTables extends LeGaulois2016Migration
'address' => 'boutique_commande_adresse',
'postcode' => 'boutique_commande_cp',
'civility' => [
'default' => ContactFormCivility::mlle(),
'default' => ContactFormCivility::mme(),
'name' => ''
],
'ref' => [

View file

@ -0,0 +1,74 @@
<?php
use App\Enums\ContactFormCivility;
use App\Models\DeliveryAddress;
use App\Models\Order;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
class UpdateCivilityEnum extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$orders = DB::table((new Order())->getTable())->select(['id', 'civility'])->get();
foreach ($orders as $order) {
switch ($order->civility) {
case 1:
$order->civility = ContactFormCivility::mme()->value;
break;
case 3:
$order->civility = ContactFormCivility::m()->value;
break;
}
DB::table((new Order())->getTable())
->where('id', $order->id)
->update(['civility' => $order->civility]);
}
$deliveryAddresses = DB::table((new DeliveryAddress())->getTable())->select(['id', 'civility'])->get();
foreach ($deliveryAddresses as $deliveryAddress) {
switch ($deliveryAddress->civility) {
case 1:
$deliveryAddress->civility = ContactFormCivility::mme()->value;
break;
case 3:
$deliveryAddress->civility = ContactFormCivility::m()->value;
break;
}
DB::table((new DeliveryAddress())->getTable())
->where('id', $deliveryAddress->id)
->update(['civility' => $deliveryAddress->civility]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$orders = DB::table((new Order())->getTable())->select(['id', 'civility'])->get();
foreach ($orders as $order) {
if ($order->civility === ContactFormCivility::m()->value) {
$order->civility = 3;
DB::table((new Order())->getTable())
->where('id', $order->id)
->update(['civility' => $order->civility]);
}
}
$deliveryAddresses = DB::table((new DeliveryAddress())->getTable())->select(['id', 'civility'])->get();
foreach ($deliveryAddresses as $deliveryAddress) {
if ($order->civility === ContactFormCivility::m()->value) {
$deliveryAddress->civility = 3;
DB::table((new DeliveryAddress())->getTable())
->where('id', $deliveryAddress->id)
->update(['civility' => $deliveryAddress->civility]);
}
}
}
}