diff --git a/app/Enums/ContactFormCivility.php b/app/Enums/ContactFormCivility.php index bf136a58..86eaee7b 100644 --- a/app/Enums/ContactFormCivility.php +++ b/app/Enums/ContactFormCivility.php @@ -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') ]; diff --git a/database/migrations/2021_02_24_151849_migrate_legaulois2016_boutique_tables.php b/database/migrations/2021_02_24_151849_migrate_legaulois2016_boutique_tables.php index a1704224..39bec60b 100644 --- a/database/migrations/2021_02_24_151849_migrate_legaulois2016_boutique_tables.php +++ b/database/migrations/2021_02_24_151849_migrate_legaulois2016_boutique_tables.php @@ -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' => [ diff --git a/database/migrations/2021_09_15_145739_update_civility_enum.php b/database/migrations/2021_09_15_145739_update_civility_enum.php new file mode 100644 index 00000000..84bb1579 --- /dev/null +++ b/database/migrations/2021_09_15_145739_update_civility_enum.php @@ -0,0 +1,74 @@ +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]); + } + } + } +}