Add logging of duplicate entries when importing SAP batteries. #371

This commit is contained in:
Korina Cordero 2020-04-01 08:33:25 +00:00
parent 1829e9112e
commit c38eb147c8
23 changed files with 129 additions and 71 deletions

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\JobOrder;
@ -17,9 +17,9 @@ class AdjustLongLatCommand extends Command
{
protected $em;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
parent::__construct();
}

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Battery;
@ -18,7 +18,7 @@ class ComputeWarrantyExpiryDateCommand extends Command
protected $em;
protected $wh;
public function __construct(ObjectManager $em, WarrantyHandler $wh)
public function __construct(EntityManagerInterface $em, WarrantyHandler $wh)
{
$this->em = $em;
$this->wh = $wh;

View file

@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Warranty;
use App\Entity\Customer;
@ -33,7 +33,7 @@ class CreateCustomerFromWarrantyCommand extends Command
protected $cvu_mfg_id;
protected $cvu_brand_id;
public function __construct(ObjectManager $em, $cvu_mfg_id, $cvu_brand_id)
public function __construct(EntityManagerInterface $em, $cvu_mfg_id, $cvu_brand_id)
{
$this->em = $em;

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\JobOrder;
use App\Entity\JOEvent;
@ -22,9 +22,9 @@ class FulfillOldJobOrderCommand extends Command
{
protected $em;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
parent::__construct();
}

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\JobOrder;
use App\Entity\JOEvent;
@ -22,9 +22,9 @@ class FulfillPendingJobOrderCommand extends Command
{
protected $em;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
parent::__construct();
}

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\VehicleManufacturer;
use App\Entity\Vehicle;
@ -21,9 +21,9 @@ class GenerateBatteryCompatibilityCommand extends Command
protected $em;
protected $vmfg_index;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
parent::__construct();
}

View file

@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\JobOrder;
use App\Entity\Warranty;
@ -25,7 +25,7 @@ class GenerateWarrantyFromJobOrderCommand extends Command
protected $sapbatt_hash;
protected $warranties_hash;
public function __construct(ObjectManager $em)
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use DateTime;
@ -30,9 +30,9 @@ class ImportBatteryPriceCommand extends Command
protected $em;
protected $size_index;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
$this->size_index = [];
parent::__construct();

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use DateTime;
@ -49,7 +49,7 @@ class ImportCustomerCommand extends Command
protected $mfg_index;
protected $vehicle_index;
public function __construct(ObjectManager $em)
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
$this->populateMfgIndex();

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Warranty;
use App\Entity\Battery;
@ -44,9 +44,9 @@ class ImportLegacyJobOrderCommand extends Command
protected $row_max_field_size;
protected $data_max_field_size;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
$this->loadBatteryModels();
$this->loadBatterySizes();

View file

@ -7,7 +7,8 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Outlet;
use App\Entity\Hub;
@ -17,11 +18,11 @@ use DateTime;
class ImportOutletsCommand extends Command
{
private $object_manager;
private $em;
public function __construct(ObjectManager $om, ValidatorInterface $validator)
public function __construct(EntityManagerInterface $em, ValidatorInterface $validator)
{
$this->object_manager = $om;
$this->em = $em;
$this->validator = $validator;
parent::__construct();
@ -60,7 +61,7 @@ class ImportOutletsCommand extends Command
}
// get entity manager
$em = $this->object_manager;
$em = $this->em;
// row counter
$row = 1;

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use DateTime;
@ -34,9 +34,9 @@ class ImportPartnersCommand extends Command
protected $em;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
parent::__construct();
}

View file

@ -7,7 +7,8 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\SAPBattery;
use App\Entity\SAPBatteryBrand;
@ -22,7 +23,7 @@ class ImportSAPBatteryCommand extends Command
private $batt_size_hash;
private $batt_brand_hash;
public function __construct(ObjectManager $em)
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
$this->initBatteryHash();
@ -37,12 +38,14 @@ class ImportSAPBatteryCommand extends Command
$this->setName('sap_battery:import')
->setDescription('Import a CSV file with SAP battery data.')
->setHelp('Creates SAP battery data entries off imported CSV.')
->addArgument('file', InputArgument::REQUIRED, 'Path to the CSV file.');
->addArgument('file', InputArgument::REQUIRED, 'Path to the CSV file.')
->addArgument('output_file', InputArgument::REQUIRED, 'Path to the output CSV file.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$csv_file = $input->getArgument('file');
$report_file = $input->getArgument('output_file');
// CSV column order:
// 0 - brand
@ -68,6 +71,9 @@ class ImportSAPBatteryCommand extends Command
// has error?
$has_error = false;
$dupe_brands = [];
$dupe_sizes = [];
$dupe_batteries = [];
// loop through rows and build hashes
while (($fields = fgetcsv($handle)) !== false)
{
@ -92,6 +98,11 @@ class ImportSAPBatteryCommand extends Command
$this->batt_brand_hash[$clean_brand] = $brand;
}
else
{
// add to duplicate list
$dupe_brands[] = $clean_brand;
}
// size hash
if (!isset($this->batt_size_hash[$clean_size]))
@ -103,6 +114,10 @@ class ImportSAPBatteryCommand extends Command
$this->batt_size_hash[$clean_size] = $size;
}
else
{
$dupe_sizes[] = $clean_size;
}
// battery hash
if (!isset($this->battery_hash[$clean_sku]))
@ -117,13 +132,19 @@ class ImportSAPBatteryCommand extends Command
}
else
{
// TODO: different batteries but same SKU: WCHD23BL-CPN00-LX
// how to process?
error_log('Battery with that sku already exists.');
$dupe_batteries[] = $clean_sku;
}
}
$em->flush();
// write dupes report
if ((count($dupe_brands) > 0) ||
(count($dupe_sizes) > 0) ||
(count($dupe_batteries) > 0))
{
$this->writeDupeReport($report_file, $dupe_brands, $dupe_sizes, $dupe_batteries);
}
}
protected function initBatteryHash()
@ -152,4 +173,40 @@ class ImportSAPBatteryCommand extends Command
foreach ($brands as $brand)
$this->batt_brand_hash[$brand->getName()] = $brand;
}
protected function writeDupeReport($report_file, $brands, $sizes, $batts)
{
try
{
$fh = fopen($report_file, "w");
}
catch (Exception $e)
{
throw new Exception('The file "' . $report_file . '" could be opened.');
}
fputs($fh, 'Brands not added: ' . "\n");
foreach ($brands as $brand)
{
fputs($fh, $brand, strlen($brand));
fputs($fh, "\n");
}
fputs($fh, 'Sizes not added: ' . "\n");
foreach ($sizes as $size)
{
fputs($fh, $size, strlen($size));
fputs($fh, "\n");
}
fputs($fh, 'SKUs not added: ' . "\n");
foreach ($batts as $batt)
{
fputs($fh, $batt, strlen($batt));
fputs($fh, "\n");
}
fclose($fh);
}
}

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use DateTime;
@ -35,9 +35,9 @@ class ImportVehicleBatteryCommand extends Command
protected $batt_index;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
$this->vmfg_index = [];
$this->v_index = [];
$this->batt_index = [];

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use DateTime;
@ -28,9 +28,9 @@ class ImportVehicleCompatibilityCommand extends Command
protected $bsize_index;
protected $b_index;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
$this->vmfg_index = [];
$this->v_index = [];
$this->b_index = [];

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Vehicle;
@ -15,9 +15,9 @@ class MergeDuplicateVehiclesCommand extends Command
{
protected $em;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
parent::__construct();
}

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use DateTime;
@ -21,7 +21,7 @@ class ReportRiderTime extends Command
protected $jo_index;
protected $filtered_jo_index;
public function __construct(ObjectManager $em)
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;

View file

@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Customer;
use App\Entity\PrivacyPolicy;
@ -22,10 +22,10 @@ class SetCustomerPrivacyPolicyCommand extends Command
private $policy_third_party_id;
private $policy_mobile_id;
public function __construct(ObjectManager $om, $policy_promo,
public function __construct(EntityManagerInterface $em, $policy_promo,
$policy_third_party, $policy_mobile)
{
$this->em = $om;
$this->em = $em;
$this->policy_promo_id = $policy_promo;
$this->policy_third_party_id = $policy_third_party;

View file

@ -7,8 +7,6 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use App\Service\APNSClient;
use DateTime;

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\JobOrder;
@ -18,9 +18,9 @@ class UpdateCustomerVehicleBatteryCommand extends Command
protected $em;
protected $custvehicle_hash;
public function __construct(ObjectManager $om)
public function __construct(EntityManagerInterface $em)
{
$this->em = $om;
$this->em = $em;
$this->custvehicle_hash = [];
parent::__construct();

View file

@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Warranty;
use App\Entity\CustomerVehicle;
@ -19,7 +19,7 @@ class UpdateCustomerVehicleWarrantyCommand extends Command
protected $em;
protected $wh;
public function __construct(ObjectManager $em, WarrantyHandler $wh)
public function __construct(EntityManagerInterface $em, WarrantyHandler $wh)
{
$this->em = $em;
$this->wh = $wh;

View file

@ -7,7 +7,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Rider;
use App\Entity\Battery;
@ -18,11 +19,11 @@ use DirectoryIterator;
class UploadCleanupCommand extends Command
{
private $encoder_factory;
private $object_manager;
private $em;
public function __construct(ObjectManager $om, Filesystem $fs, FileUploader $uploader)
public function __construct(EntityManagerInterface $em, Filesystem $fs, FileUploader $uploader)
{
$this->object_manager = $om;
$this->em = $em;
$this->filesystem = $fs;
$this->uploader = $uploader;
@ -41,7 +42,7 @@ class UploadCleanupCommand extends Command
$output->writeln('Retrieving file whitelist...');
// get all image filenames
$em = $this->object_manager;
$em = $this->em;
$riders = $em->getRepository(Rider::class)->findAll();
$whitelist = ['.gitkeep'];

View file

@ -8,7 +8,8 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\User;
use App\Entity\Role;
@ -16,12 +17,12 @@ use App\Entity\Role;
class UserCreateCommand extends Command
{
private $encoder_factory;
private $object_manager;
private $em;
public function __construct(EncoderFactoryInterface $ef, ObjectManager $om)
public function __construct(EncoderFactoryInterface $ef, EntityManagerInterface $em)
{
$this->encoder_factory = $ef;
$this->object_manager = $om;
$this->em = $em;
parent::__construct();
}
@ -49,7 +50,7 @@ class UserCreateCommand extends Command
// get entity manager
// $em = $this->getContainer()->get('doctrine')->getEntityManager();
$em = $this->object_manager;
$em = $this->em;
// build user
$user->setUsername($username)