Add command to set warranty class to commercial for warranties with no plate numbers. #279
This commit is contained in:
parent
3babcd765f
commit
4465811604
1 changed files with 64 additions and 0 deletions
64
src/Command/SetWarrantyClassCommand.php
Normal file
64
src/Command/SetWarrantyClassCommand.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue