From 1829e9112e17c72f58b1b332291090621868aa3b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 1 Apr 2020 04:30:08 +0000 Subject: [PATCH 1/5] Add error_logging in case of duplicate SAP battery. #371 --- src/Command/ImportSAPBatteryCommand.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Command/ImportSAPBatteryCommand.php b/src/Command/ImportSAPBatteryCommand.php index fcd54f7d..8ea53a1d 100644 --- a/src/Command/ImportSAPBatteryCommand.php +++ b/src/Command/ImportSAPBatteryCommand.php @@ -77,7 +77,7 @@ class ImportSAPBatteryCommand extends Command // clean up fields $clean_brand = trim($fields[0]); - $clean_sku = trim($fields[1]); + $clean_sku = strtoupper(trim($fields[1])); $clean_size = trim($fields[2]); $output->writeln("Parsing $clean_sku..."); @@ -110,11 +110,17 @@ class ImportSAPBatteryCommand extends Command // create battery entry $battery = new SAPBattery(); $battery->setID($clean_sku) - ->setSize($size_hash[$clean_size]) - ->setBrand($brand_hash[$clean_brand]); + ->setSize($this->batt_size_hash[$clean_size]) + ->setBrand($this->batt_brand_hash[$clean_brand]); $em->persist($battery); } + else + { + // TODO: different batteries but same SKU: WCHD23BL-CPN00-LX + // how to process? + error_log('Battery with that sku already exists.'); + } } $em->flush(); From c38eb147c833126fc697fcca457aab83d8af07f7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 1 Apr 2020 08:33:25 +0000 Subject: [PATCH 2/5] Add logging of duplicate entries when importing SAP batteries. #371 --- src/Command/AdjustLongLatCommand.php | 6 +- .../ComputeWarrantyExpiryDateCommand.php | 4 +- .../CreateCustomerFromWarrantyCommand.php | 4 +- src/Command/FulfillOldJobOrderCommand.php | 6 +- src/Command/FulfillPendingJobOrderCommand.php | 6 +- .../GenerateBatteryCompatibilityCommand.php | 6 +- .../GenerateWarrantyFromJobOrderCommand.php | 4 +- src/Command/ImportBatteryPriceCommand.php | 6 +- src/Command/ImportCustomerCommand.php | 4 +- src/Command/ImportLegacyJobOrderCommand.php | 6 +- src/Command/ImportOutletsCommand.php | 11 +-- src/Command/ImportPartnersCommand.php | 6 +- src/Command/ImportSAPBatteryCommand.php | 69 +++++++++++++++++-- src/Command/ImportVehicleBatteryCommand.php | 6 +- .../ImportVehicleCompatibilityCommand.php | 6 +- src/Command/MergeDuplicateVehiclesCommand.php | 6 +- src/Command/ReportRiderTime.php | 4 +- .../SetCustomerPrivacyPolicyCommand.php | 6 +- src/Command/TestRegAPNSCommand.php | 2 - .../UpdateCustomerVehicleBatteryCommand.php | 6 +- .../UpdateCustomerVehicleWarrantyCommand.php | 4 +- src/Command/UploadCleanupCommand.php | 11 +-- src/Command/UserCreateCommand.php | 11 +-- 23 files changed, 129 insertions(+), 71 deletions(-) diff --git a/src/Command/AdjustLongLatCommand.php b/src/Command/AdjustLongLatCommand.php index b7e26ad1..62405269 100644 --- a/src/Command/AdjustLongLatCommand.php +++ b/src/Command/AdjustLongLatCommand.php @@ -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(); } diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index 383370f7..cffc24ef 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -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; diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index 91684217..42b2fe73 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -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; diff --git a/src/Command/FulfillOldJobOrderCommand.php b/src/Command/FulfillOldJobOrderCommand.php index a0cabd57..dc987e8b 100644 --- a/src/Command/FulfillOldJobOrderCommand.php +++ b/src/Command/FulfillOldJobOrderCommand.php @@ -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(); } diff --git a/src/Command/FulfillPendingJobOrderCommand.php b/src/Command/FulfillPendingJobOrderCommand.php index 22180186..0c1fe7b0 100644 --- a/src/Command/FulfillPendingJobOrderCommand.php +++ b/src/Command/FulfillPendingJobOrderCommand.php @@ -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(); } diff --git a/src/Command/GenerateBatteryCompatibilityCommand.php b/src/Command/GenerateBatteryCompatibilityCommand.php index 57e20076..ec0a1843 100644 --- a/src/Command/GenerateBatteryCompatibilityCommand.php +++ b/src/Command/GenerateBatteryCompatibilityCommand.php @@ -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(); } diff --git a/src/Command/GenerateWarrantyFromJobOrderCommand.php b/src/Command/GenerateWarrantyFromJobOrderCommand.php index 86653d97..1d3f100b 100644 --- a/src/Command/GenerateWarrantyFromJobOrderCommand.php +++ b/src/Command/GenerateWarrantyFromJobOrderCommand.php @@ -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; diff --git a/src/Command/ImportBatteryPriceCommand.php b/src/Command/ImportBatteryPriceCommand.php index 02bbbea9..12fade3a 100644 --- a/src/Command/ImportBatteryPriceCommand.php +++ b/src/Command/ImportBatteryPriceCommand.php @@ -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(); diff --git a/src/Command/ImportCustomerCommand.php b/src/Command/ImportCustomerCommand.php index f6babefc..4c0e75e7 100644 --- a/src/Command/ImportCustomerCommand.php +++ b/src/Command/ImportCustomerCommand.php @@ -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(); diff --git a/src/Command/ImportLegacyJobOrderCommand.php b/src/Command/ImportLegacyJobOrderCommand.php index 7546880b..76e30d10 100644 --- a/src/Command/ImportLegacyJobOrderCommand.php +++ b/src/Command/ImportLegacyJobOrderCommand.php @@ -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(); diff --git a/src/Command/ImportOutletsCommand.php b/src/Command/ImportOutletsCommand.php index dbcb5979..1558b74e 100644 --- a/src/Command/ImportOutletsCommand.php +++ b/src/Command/ImportOutletsCommand.php @@ -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; diff --git a/src/Command/ImportPartnersCommand.php b/src/Command/ImportPartnersCommand.php index 74e02d5b..1a09df6d 100644 --- a/src/Command/ImportPartnersCommand.php +++ b/src/Command/ImportPartnersCommand.php @@ -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(); } diff --git a/src/Command/ImportSAPBatteryCommand.php b/src/Command/ImportSAPBatteryCommand.php index 8ea53a1d..9189a0e5 100644 --- a/src/Command/ImportSAPBatteryCommand.php +++ b/src/Command/ImportSAPBatteryCommand.php @@ -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); + + } } diff --git a/src/Command/ImportVehicleBatteryCommand.php b/src/Command/ImportVehicleBatteryCommand.php index 93c0bd77..c3511330 100644 --- a/src/Command/ImportVehicleBatteryCommand.php +++ b/src/Command/ImportVehicleBatteryCommand.php @@ -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 = []; diff --git a/src/Command/ImportVehicleCompatibilityCommand.php b/src/Command/ImportVehicleCompatibilityCommand.php index 29d74417..481579e1 100644 --- a/src/Command/ImportVehicleCompatibilityCommand.php +++ b/src/Command/ImportVehicleCompatibilityCommand.php @@ -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 = []; diff --git a/src/Command/MergeDuplicateVehiclesCommand.php b/src/Command/MergeDuplicateVehiclesCommand.php index a0b729cd..99bbbec4 100644 --- a/src/Command/MergeDuplicateVehiclesCommand.php +++ b/src/Command/MergeDuplicateVehiclesCommand.php @@ -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(); } diff --git a/src/Command/ReportRiderTime.php b/src/Command/ReportRiderTime.php index 77d7f94d..e8825b5b 100644 --- a/src/Command/ReportRiderTime.php +++ b/src/Command/ReportRiderTime.php @@ -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; diff --git a/src/Command/SetCustomerPrivacyPolicyCommand.php b/src/Command/SetCustomerPrivacyPolicyCommand.php index 4132fa91..e5d27617 100644 --- a/src/Command/SetCustomerPrivacyPolicyCommand.php +++ b/src/Command/SetCustomerPrivacyPolicyCommand.php @@ -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; diff --git a/src/Command/TestRegAPNSCommand.php b/src/Command/TestRegAPNSCommand.php index d9615141..52ec7d76 100644 --- a/src/Command/TestRegAPNSCommand.php +++ b/src/Command/TestRegAPNSCommand.php @@ -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; diff --git a/src/Command/UpdateCustomerVehicleBatteryCommand.php b/src/Command/UpdateCustomerVehicleBatteryCommand.php index f7e09e30..57ad1246 100644 --- a/src/Command/UpdateCustomerVehicleBatteryCommand.php +++ b/src/Command/UpdateCustomerVehicleBatteryCommand.php @@ -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(); diff --git a/src/Command/UpdateCustomerVehicleWarrantyCommand.php b/src/Command/UpdateCustomerVehicleWarrantyCommand.php index 89b6e5e0..98fec1cb 100644 --- a/src/Command/UpdateCustomerVehicleWarrantyCommand.php +++ b/src/Command/UpdateCustomerVehicleWarrantyCommand.php @@ -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; diff --git a/src/Command/UploadCleanupCommand.php b/src/Command/UploadCleanupCommand.php index 94d22c6e..ffa1828b 100644 --- a/src/Command/UploadCleanupCommand.php +++ b/src/Command/UploadCleanupCommand.php @@ -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']; diff --git a/src/Command/UserCreateCommand.php b/src/Command/UserCreateCommand.php index f0873dc1..3b10d771 100644 --- a/src/Command/UserCreateCommand.php +++ b/src/Command/UserCreateCommand.php @@ -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) From 719cccf778503efb21c4094cbba0ee9a75ea0571 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Apr 2020 03:33:02 +0000 Subject: [PATCH 3/5] Add API call to get warranties when given a list of serial numbers. #372 --- .../api-bundle/Command/TestAPICommand.php | 18 +++++++-- config/api_acl.yaml | 2 + config/routes/capi.yaml | 6 +++ src/Controller/CAPI/WarrantyController.php | 40 +++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index 7e959808..a8a2be2a 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -64,7 +64,7 @@ class TestAPICommand extends Command 'start' => '1', ]; - $api->get('/capi/warranties', $params); + //$api->get('/capi/warranties', $params); // warranty find @@ -123,7 +123,7 @@ class TestAPICommand extends Command // privacy policy $privacy_policy_id = 2; - $api->get('/capi/privacy_policy/' . $privacy_policy_id ); + //$api->get('/capi/privacy_policy/' . $privacy_policy_id ); // register new customer $params = [ @@ -137,6 +137,18 @@ class TestAPICommand extends Command 'v_condition' => 'new', 'v_fuel_type' => 'gas', ]; - $api->post('/capi/quick_registration', $params); + //$api->post('/capi/quick_registration', $params); + + // get warranties given list of serial numbers + $serial_list = [ + 'AJ34LJADR12134LKJM4', + 'AJ34LJADR12134LKJL5', + ]; + + $params = [ + 'serial_list' => $serial_list, + ]; + + $api->post('/capi/warranties_list', $params); } } diff --git a/config/api_acl.yaml b/config/api_acl.yaml index 2ff18704..a7ad72d5 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -20,6 +20,8 @@ access_keys: label: Delete - id: warranty.set.privacypolicy label: Set Privacy Policy + - id: warranty.list.serial + label: List by Serial - id: batterybrand label: Battery Brand Access acls: diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index ee3c8668..0c2e5ac1 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -108,6 +108,12 @@ capi_warranty_privacy_policy: controller: App\Controller\CAPI\WarrantyController::setPrivacyPolicy methods: [POST] +# get list of warranties given list of serials +capi_warranty_get_warranties_from_serials: + path: /capi/warranties_list + controller: App\Controller\CAPI\WarrantyController::getWarrantiesBySerialList + methods: [POST] + # customer vehicle api # find customer vehicle by id diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 83ecf74a..114f3c8c 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -502,6 +502,46 @@ class WarrantyController extends APIController } + public function getWarrantiesBySerialList(Request $req, EntityManagerInterface $em) + { + $this->denyAccessUnlessGranted('warranty.list.serial', null, 'No access.'); + + error_log('getWarrantiesBySerialList'); + // required parameters + $params = [ + 'serial_list', + ]; + + $msg = $this->checkRequiredParameters($req, $params); + error_log('msg - ' . $msg); + if ($msg) + return new APIResponse(false, $msg); + + $serial_list = $req->request->get('serial_list'); + + if (empty($serial_list)) + return new APIResponse(false, 'Empty serial numbers list.'); + + $warranty_list = []; + foreach ($serial_list as $serial) + { + $clean_serial = $this->cleanSerial($serial); + $warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]); + + if ($warr == null) + return new APIResponse(false, 'No warranty found with that serial number.', null, 404); + + $warranty_list[] = $this->generateWarrantyData($warr); + } + + + $data = [ + 'warranties' => $warranty_list, + ]; + + return new APIResponse(true, 'Warranties found.', $data); + } + protected function getCustomerFromMobile($em, $warranty) { $w_mobile = $warranty->getMobileNumber(); From 135ab10cd38c52d18a27765b6455de2f558b6e42 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Apr 2020 03:58:21 +0000 Subject: [PATCH 4/5] Add to response the list of serials with no warranties. #372 --- catalyst/api-bundle/Command/TestAPICommand.php | 3 ++- src/Controller/CAPI/WarrantyController.php | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index a8a2be2a..952b98b6 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -142,7 +142,8 @@ class TestAPICommand extends Command // get warranties given list of serial numbers $serial_list = [ 'AJ34LJADR12134LKJM4', - 'AJ34LJADR12134LKJL5', + 'AJ34LJADR12134LKJL5', + 'test', ]; $params = [ diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 114f3c8c..affdb892 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -523,20 +523,22 @@ class WarrantyController extends APIController return new APIResponse(false, 'Empty serial numbers list.'); $warranty_list = []; + $warr_not_found_list = []; foreach ($serial_list as $serial) { $clean_serial = $this->cleanSerial($serial); $warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]); if ($warr == null) - return new APIResponse(false, 'No warranty found with that serial number.', null, 404); - - $warranty_list[] = $this->generateWarrantyData($warr); + $warr_not_found_list[] = 'Warranty not found for ' . $clean_serial; + else + $warranty_list[] = $this->generateWarrantyData($warr); } $data = [ - 'warranties' => $warranty_list, + 'warranties_found' => $warranty_list, + 'warranties_not_found' => $warr_not_found_list, ]; return new APIResponse(true, 'Warranties found.', $data); From 1dac0c506e01fafe3007e31ef992e70142cc8c7d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Apr 2020 04:01:08 +0000 Subject: [PATCH 5/5] Remove message. #372 --- src/Controller/CAPI/WarrantyController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index affdb892..e5f5437e 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -530,7 +530,7 @@ class WarrantyController extends APIController $warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]); if ($warr == null) - $warr_not_found_list[] = 'Warranty not found for ' . $clean_serial; + $warr_not_found_list[] = $clean_serial; else $warranty_list[] = $this->generateWarrantyData($warr); }