Fix issues found during testing. #655

This commit is contained in:
Korina Cordero 2022-04-08 09:06:55 +00:00
parent 6cc9cddf1f
commit bc1c6110e8

View file

@ -26,11 +26,11 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
const F_V_MODEL_YEAR = 2;
const F_B_SIZE = 7;
const F_B_MODEL = 8;
const F_B_ALT_PREM_MF = 10;
const F_B_ALT_PREM_LM = 11;
const F_B_ALT_SUPER_PREM_MF = 12;
const F_B_ALT_SUPREME_MF = 13;
const F_B_ALT_PLATINUM_MF = 14;
//const F_B_ALT_PREM_MF = 10;
//const F_B_ALT_PREM_LM = 11;
//const F_B_ALT_SUPER_PREM_MF = 12;
//const F_B_ALT_SUPREME_MF = 13;
//const F_B_ALT_PLATINUM_MF = 14;
// the rest of the fields are irrelevant
protected $em;
@ -92,7 +92,9 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
{
$output->writeln("Parsing row " . $row_num . "...");
// alternate brands are not in file, so we just comment out
// get the alternate battery brand header names
/*
if ($row_num == 2)
{
$prem_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]);
@ -101,6 +103,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$supreme_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_SUPREME_MF]);
$platinum_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PLATINUM_MF]);
}
*/
// process row
$output_info[] = $this->processRow($fields, $vbrands, $row_num, $prem_mf_name, $prem_lm_name,
@ -108,10 +111,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$row_num++;
}
// print_r($b_models);
// print_r($batteries);
// save to db
// save to db the valid ones
foreach ($vbrands as $brand_name => $vbrand)
{
// vehicles
@ -140,6 +141,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$vdata['battery']->addVehicle($vehicle);
// alt_batteries
// alternate brands are not in file, so we just comment out
/*
if (isset($vdata['alt_battery_prem_mf']))
$vdata['alt_battery_prem_mf']->addVehicle($vehicle);
if (isset($vdata['alt_battery_prem_lm']))
@ -150,12 +153,14 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$vdata['alt_battery_supreme_mf']->addVehicle($vehicle);
if (isset($vdata['alt_battery_platinum_mf']))
$vdata['alt_battery_platinum_mf']->addVehicle($vehicle);
*/
}
}
$em->flush();
// write to output file
// error_log(print_r($output_info, true));
$this->outputVehicleBatteryInfo($output_file, $output_info);
fclose($fh);
@ -177,8 +182,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
// go into the vbrands array
$output_info = $this->validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel);
error_log(count($output_info));
if (!empty($output_info))
return $output_info;
@ -202,8 +205,10 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$batt_key = $this->getBatteryKey($bsize, $bmodel);
$vbrands[$brand]['vehicles'][$row_num]['battery'] = $this->batt_index[$batt_key];
// alternate brands are not in file, so we just comment out
// need to check alternate brands if battery exists
// go through the alternate fields, look for 'P'. Not kidding. It's what is in the csv file.
/*
if ($this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]) == 'P')
{
// check if we have battery for name + size combo
@ -249,6 +254,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$vbrands[$brand]['vehicles'][$row_num]['alt_battery_platinum_mf'] = $this->batt_index[$alt_batt_key];
}
}
*/
}
protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel)
@ -297,11 +303,14 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$model_year = trim($fields[SELF::F_V_MODEL_YEAR]);
$bsize = trim($fields[SELF::F_B_SIZE]);
$bmodel = trim($fields[SELF::F_B_MODEL]);
// alternate brands are not in file, so we just comment out
/*
$alt_prem_mf = trim($fields[SELF::F_B_ALT_PREM_MF]);
$alt_prem_lm = trim($fields[SELF::F_B_ALT_PREM_LM]);
$alt_super_prem_mf = trim($fields[SELF::F_B_ALT_SUPER_PREM_MF]);
$alt_supreme_mf = trim($fields[SELF::F_B_ALT_SUPREME_MF]);
$alt_platinum_mf = trim($fields[SELF::F_B_ALT_PLATINUM_MF]);
*/
return [
$mfg_name,
@ -309,11 +318,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
$model_year,
$bsize,
$bmodel,
$alt_prem_mf,
$alt_prem_lm,
$alt_super_prem_mf,
$alt_supreme_mf,
$alt_platinum_mf,
$status,
$reason
];
@ -343,7 +347,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
foreach($entries as $row)
{
fputcsv($fh, $row);
if ($row != null)
fputcsv($fh, $row);
}
fclose($fh);
@ -362,8 +367,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
if (!isset($this->v_index[$mfg_name]))
$this->v_index[$mfg_name] = [];
error_log('vehicle keys ' . $mfg_name . ' ' . $this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo());
$this->v_index[$mfg_name][$this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()] = $v;
}
}
@ -378,33 +381,9 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
// get the battery size
$bsize = $b->getSize()->getName();
error_log($bsize);
$key = $this->getBatteryKey($bsize, $b->getModel()->getName());
// check if size has /
$bsizes = [];
$pos = stripos($bsize, '/');
if ($pos == false)
{
// no '/' in size
$bsizes[] = $this->normalizeName($bsize);
}
else
{
// if yes, we need to split it.
$sizes = explode('/', $bsize);
foreach ($sizes as $size)
{
$bsizes[] = $this->normalizeName($size);
}
}
foreach ($bsizes as $battery_size)
{
error_log('Adding ' . $battery_size . ' to key');
$key = $this->getBatteryKey($battery_size, $b->getModel()->getName());
$this->batt_index[$key] = $b;
}
$this->batt_index[$key] = $b;
}
}