52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Repository;
|
||
|
|
||
|
use App\Entity\Cron;
|
||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||
|
use Doctrine\Persistence\ManagerRegistry;
|
||
|
|
||
|
class CronRepository extends ServiceEntityRepository
|
||
|
{
|
||
|
public function __construct(ManagerRegistry $registry)
|
||
|
{
|
||
|
parent::__construct($registry, Cron::class);
|
||
|
}
|
||
|
|
||
|
public function add(Cron $entity, bool $flush = false): void
|
||
|
{
|
||
|
$this->getEntityManager()->persist($entity);
|
||
|
|
||
|
if ($flush) {
|
||
|
$this->getEntityManager()->flush();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function remove(Cron $entity, bool $flush = false): void
|
||
|
{
|
||
|
$this->getEntityManager()->remove($entity);
|
||
|
|
||
|
if ($flush) {
|
||
|
$this->getEntityManager()->flush();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function toExec()
|
||
|
{
|
||
|
// Les commandes à executer
|
||
|
// = statut = 0 (à executer)
|
||
|
// = statut = 2 (OK) et derniere execution + interval > now et nombre d'appel = 0
|
||
|
// = statut = 3 (KO) et derniere execution + interval > now et nombre d'appel = 0
|
||
|
// = statut = 3 (KO) et nombre d'execution < nombre d'appel
|
||
|
|
||
|
|
||
|
$now=new \DateTime();
|
||
|
|
||
|
$qb = $this->createQueryBuilder('cron')
|
||
|
->Where('cron.statut=0')
|
||
|
->orWhere('(cron.statut=0 OR cron.statut=1) AND cron.nextexecdate<:now');
|
||
|
|
||
|
return $qb->getQuery()->setParameter('now',$now->format("Y-m-d H:i:s"))->getResult();
|
||
|
}
|
||
|
}
|