From 6bde277fefc5dc2bb011d3e55ef424ce03083836 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 20 Nov 2019 02:01:41 +0000 Subject: [PATCH] Fix syntax errors. #274 --- .../CreateCustomerFromWarrantyCommand.php | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index 992cf2db..94f3b725 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -15,6 +15,9 @@ use App\Entity\CustomerVehicle; use App\Entity\VehicleManufacturer; use App\Entity\Vehicle; +use App\Ramcar\FuelType; +use App\Ramcar\VehicleStatusCondition; + class CreateCustomerFromWarrantyCommand extends Command { protected $em; @@ -24,8 +27,6 @@ class CreateCustomerFromWarrantyCommand extends Command { $this->em = $em; - $this->loadCustomers(); - parent::__construct(); } @@ -35,9 +36,10 @@ class CreateCustomerFromWarrantyCommand extends Command ->setDescription('Create customers from existing warranties.') ->setHelp('Creates customers from existing warranties.'); } - protected function execute(InputInterface $input, OutputInterface $output) { + // load all customers + $this->loadCustomers(); // get all warranties $warranties = $this->em->getRepository(Warranty::class)->findAll(); @@ -68,14 +70,11 @@ class CreateCustomerFromWarrantyCommand extends Command // set values for new customer vehicle $w_plate_number = $warr->getPlateNumber(); - $default_cv_color = 'White'; - // TODO: add checking that default manufacturer is not null - $default_manufacturer = $this->em->getRepository(VehicleManufacturer::class)->findBy(['name' =>'Unknown']); - if (empty($default_manufacturer)) + $default_vehicle = $this->em->getRepository(Vehicle::class)->findBy(['name' =>'Unknown']); + if (empty($default_vehicle)) { - $output->writeln("Need to add manufacturer with Unknown name"); + $output->writeln("Need to add vehicle with manufacturer name Unknown and make name Unknown"); } - $default_make = 'Unknown'; // search cust_index for numbers in mobile_array foreach ($w_mobile_array as $w_mobile_num) { @@ -105,8 +104,7 @@ class CreateCustomerFromWarrantyCommand extends Command } } // add customer vehicle to existing customer with unknown manufacturer and make - $this->createCustomerVehicle($customer, $default_manufacturer, - $default_make, $w_plate_number, $default_cv_color); + $this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number); } $cust_found = true; } @@ -125,13 +123,12 @@ class CreateCustomerFromWarrantyCommand extends Command $this->em->persist($cust); - $this->createCustomerVehicle($cust, $default_manufacturer, - $default_make, $w_plate_number, $default_cv_color); + $this->createCustomerVehicle($cust, $default_vehicle, $w_plate_number); } } } - } + } protected function loadCustomers() { @@ -146,20 +143,17 @@ class CreateCustomerFromWarrantyCommand extends Command } } - protected function createCustomerVehicle(Customer $cust, $manufacturer, $make, - $plate_number, $color) + protected function createCustomerVehicle(Customer $cust, $vehicle, $plate_number) { $new_cv = new CustomerVehicle(); - // get manufacturer and make with name 'unknown' - - // TODO: remove the assert not blank for color and model year $new_cv->setCustomer($cust) ->setPlateNumber($plate_number) - ->setModelYear(0) - ->setColor($color) ->setStatusCondition(VehicleStatusCondition::BRAND_NEW) ->setFuelType(FuelType::GAS) ->setVehicle($vehicle); - } + + $this->em->persist($new_cv); + $this->em->flush(); + } }