WIP: Resolve "Warranties with no plate number set to commercial" #1136

Draft
korina.cordero wants to merge 2 commits from 279-warranties-with-no-plate-number-set-to-commercial into master

View file

@ -0,0 +1,64 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use App\Entity\Warranty;
use App\Ramcar\WarrantyClass;
class SetWarrantyClassCommand extends Command
{
protected $em;
public function __construct(ObjectManager $em)
{
$this->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);
}
}