<?php
namespace App\Command\Watches;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use App\Entity\V2\Watch;
class DelayResponseCommand extends ContainerAwareCommand
{
protected static $defaultName = 'app:watches-delay';
private $em;
public function __construct(\Doctrine\ORM\EntityManagerInterface $em)
{
$this->em = $em;
parent::__construct();
}
protected function configure()
{
$this
->setDescription("Met à jour le statut si pas de réponse au bout de 72 heures et 48 heures pour le paiement")
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->autoDelayResponse($output);
$output->writeln( ( new \DateTime('now', new \DateTimeZone('Europe/Paris')) )->format('d-m-Y H:i:s') . ":ok");
}
/**
* Garde sans réponse
*/
private function autoDelayResponse($output): void
{
//HOST 3 jours
$now = new \DateTime('now');
$qb = $this->em->getRepository(Watch::class)->createQueryBuilder('w')
->select('w')
->where(":now > DATE_ADD(w.status_one, :day, 'DAY')")
->andWhere("w.status = :status")
->andWhere("w.active = 1")
->andWhere("w.deleted_at is NULL")
->setParameter('day', 3)
->setParameter('now', $now)
->setParameter('status', '100');
$watches = $qb->getQuery()->getResult();
foreach ($watches as $key => $watch) {
$watch->setStatus(120);
$msg = ( " Garde " . $watch->getId() . " en 120 ");
$output->writeln($msg);
$this->em->flush();
}
//MASTER 2 jours
$qb = $this->em->getRepository(Watch::class)->createQueryBuilder('w')
->select('w')
->where(":now > DATE_ADD(w.status_two, :day, 'DAY')")
->andWhere("w.status = :status")
->andWhere("w.active = 1")
->andWhere("w.deleted_at is NULL")
->setParameter('day', 2)
->setParameter('now', $now)
->setParameter('status', '200');
$watches = $qb->getQuery()->getResult();
foreach ($watches as $key => $watch) {
$watch->setStatus(202);
$msg = ( " Garde " . $watch->getId() . " en 202 ");
$output->writeln($msg);
$this->em->flush();
}
}
}