From 446581160446bc15aed787657f6e50c283629dfe Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 25 Nov 2019 06:59:23 +0000 Subject: [PATCH] Add command to set warranty class to commercial for warranties with no plate numbers. #279 --- src/Command/SetWarrantyClassCommand.php | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/Command/SetWarrantyClassCommand.php diff --git a/src/Command/SetWarrantyClassCommand.php b/src/Command/SetWarrantyClassCommand.php new file mode 100644 index 00000000..5d79307d --- /dev/null +++ b/src/Command/SetWarrantyClassCommand.php @@ -0,0 +1,64 @@ +em = $em; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('warranty:setwarrantyclass') + ->setDescription('Set warranty class for warranties with no plate numbers.') + ->setHelp('Set warranty class for warranties with no plate numbers.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $total_warr = 0; + + // get all warranties + error_log('Getting warranties...'); + $warr_q = $this->em->createQuery('select w from App\Entity\Warranty w where w.plate_number = :plate') + ->setParameters(['plate' => '']); + $warranties = $warr_q->iterate(); + + $output->writeln("Processing warranties... "); + foreach($warranties as $row) + { + $warr = $row[0]; + + if ($warr->getWarrantyClass() != WarrantyClass::WTY_COMMERCIAL) + { + // set warranty class to commercial + $warr->setWarrantyClass(WarrantyClass::WTY_COMMERCIAL); + + $this->em->persist($warr); + $this->em->flush(); + + $total_warr++; + } + } + + error_log('Total warranties set: ' . $total_warr); + } + +}