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:
commit
ab2ca02227
2 changed files with 65 additions and 6 deletions
|
|
@ -62,6 +62,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
|
||||||
$csv_file = $input->getArgument('input_file');
|
$csv_file = $input->getArgument('input_file');
|
||||||
$output_file = $input->getArgument('output_file');
|
$output_file = $input->getArgument('output_file');
|
||||||
|
|
||||||
|
$this->populateVehicleManufacturerIndex();
|
||||||
$this->populateVehicleIndex();
|
$this->populateVehicleIndex();
|
||||||
$this->populateBatteryIndex();
|
$this->populateBatteryIndex();
|
||||||
|
|
||||||
|
|
@ -260,6 +261,23 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
|
||||||
protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel)
|
protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel)
|
||||||
{
|
{
|
||||||
$output_info = [];
|
$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
|
// process model year data
|
||||||
if ($model == 'NONE')
|
if ($model == 'NONE')
|
||||||
{
|
{
|
||||||
|
|
@ -277,12 +295,42 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
|
||||||
$m_year_to = 0;
|
$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)]))
|
if (!isset($this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)]))
|
||||||
{
|
{
|
||||||
$message = 'Invalid vehicle';
|
// vehicle
|
||||||
$output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message);
|
$vehicle = new Vehicle();
|
||||||
return $output_info;
|
$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
|
// recommended battery
|
||||||
$batt_key = $this->getBatteryKey($bsize, $bmodel);
|
$batt_key = $this->getBatteryKey($bsize, $bmodel);
|
||||||
|
|
@ -354,16 +402,27 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
|
||||||
fclose($fh);
|
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()
|
protected function populateVehicleIndex()
|
||||||
{
|
{
|
||||||
$vs = $this->em->getRepository(Vehicle::class)->findAll();
|
$vs = $this->em->getRepository(Vehicle::class)->findAll();
|
||||||
|
|
||||||
$this->v_index = [];
|
$this->v_index = [];
|
||||||
$this->vmfg_index = [];
|
|
||||||
foreach ($vs as $v)
|
foreach ($vs as $v)
|
||||||
{
|
{
|
||||||
$mfg_name = $this->normalizeName($v->getManufacturer()->getName());
|
$mfg_name = $this->normalizeName($v->getManufacturer()->getName());
|
||||||
$this->vmfg_index[$mfg_name] = $v->getManufacturer();
|
|
||||||
if (!isset($this->v_index[$mfg_name]))
|
if (!isset($this->v_index[$mfg_name]))
|
||||||
$this->v_index[$mfg_name] = [];
|
$this->v_index[$mfg_name] = [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class Vehicle
|
||||||
|
|
||||||
// make
|
// make
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=110)
|
||||||
* @Assert\NotBlank()
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $make;
|
protected $make;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue