Merge branch '655-import-yokohama-vehicle-battery-compatibility' into 'master'

Modify script to create vehicle if vehicle does not exist. Modify length of make in Vehicle. #655

Closes #655

See merge request jankstudio/resq!769
This commit is contained in:
Kendrick Chan 2022-04-11 03:06:51 +00:00
commit ab2ca02227
2 changed files with 65 additions and 6 deletions

View file

@ -62,6 +62,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$csv_file = $input->getArgument('input_file');
$output_file = $input->getArgument('output_file');
$this->populateVehicleManufacturerIndex();
$this->populateVehicleIndex();
$this->populateBatteryIndex();
@ -260,6 +261,23 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel)
{
$output_info = [];
// check if manufacturer is blank
if (empty($brand))
{
$message = 'No manufacturer provided.';
$output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $output_info;
}
// check if make is blank
if (empty($make))
{
$message = 'No make provided.';
$output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $output_info;
}
// process model year data
if ($model == 'NONE')
{
@ -277,12 +295,42 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$m_year_to = 0;
}
// get manufacturer or make one
if (!isset($this->vmfg_index[$brand]))
{
// manufacturer
$mfg = new VehicleManufacturer();
$mfg->setName($brand);
$this->em->persist($mfg);
}
else
{
$mfg = $this->vmfg_index[$brand];
}
if (!isset($this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)]))
{
$message = 'Invalid vehicle';
$output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $output_info;
// vehicle
$vehicle = new Vehicle();
$vehicle->setManufacturer($mfg)
->setMake($make)
->setModelYearFrom($m_year_from)
->setModelYearTo($m_year_to);
$this->em->persist($vehicle);
}
else
{
$vehicle = $this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)];
}
// save to db new manufacturer and vehicle
$this->em->flush();
// add the vehicle manufacturer to hash
$this->vmfg_index[$brand] = $mfg;
// add the new vehicle to hash
$this->v_index[$brand][$make . '|' . $m_year_from . '|' . $m_year_to] = $vehicle;
// recommended battery
$batt_key = $this->getBatteryKey($bsize, $bmodel);
@ -354,16 +402,27 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
fclose($fh);
}
protected function populateVehicleManufacturerIndex()
{
$vmfgs = $this->em->getRepository(VehicleManufacturer::class)->findAll();
$this->vmfg_index = [];
foreach ($vmfgs as $vmfg)
{
$mfg_name = $this->normalizeName($vmfg->getName());
$this->vmfg_index[$mfg_name] = $vmfg;
}
}
protected function populateVehicleIndex()
{
$vs = $this->em->getRepository(Vehicle::class)->findAll();
$this->v_index = [];
$this->vmfg_index = [];
foreach ($vs as $v)
{
$mfg_name = $this->normalizeName($v->getManufacturer()->getName());
$this->vmfg_index[$mfg_name] = $v->getManufacturer();
if (!isset($this->v_index[$mfg_name]))
$this->v_index[$mfg_name] = [];

View file

@ -36,7 +36,7 @@ class Vehicle
// make
/**
* @ORM\Column(type="string", length=80)
* @ORM\Column(type="string", length=110)
* @Assert\NotBlank()
*/
protected $make;