Files
Phraseanet/lib/Alchemy/Phrasea/Model/Repositories/WebhookEventDeliveryRepository.php
Aina Sitraka fc278420a4 PHRAS-3598 Webhook - Emit improvement - Count and Log errors - stop to notify endpoint in error (#4209)
* deactivate webhook when many times undelivered

* fix

* fix log
2023-01-11 14:52:22 +01:00

80 lines
2.1 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Model\Entities\ApiApplication;
use Alchemy\Phrasea\Model\Entities\WebhookEventDelivery;
use Doctrine\ORM\EntityRepository;
/**
* WebhookEventDeliveryRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class WebhookEventDeliveryRepository extends EntityRepository
{
/**
* @return WebhookEventDelivery[]
*/
public function findUndeliveredEvents()
{
$qb = $this->createQueryBuilder('e');
$qb
->where($qb->expr()->eq('e.delivered', $qb->expr()->literal(false)))
->andWhere($qb->expr()->lt('e.deliveryTries', ':nb_tries'));
$qb->setParameter(':nb_tries', WebhookEventDelivery::MAX_DELIVERY_TRIES);
return $qb->getQuery()->getResult();
}
/**
* @param $apiApplication
* @return WebhookEventDelivery[]
*/
public function findUndeliveredEventsFromLastAppUpdate(ApiApplication $apiApplication)
{
$qb = $this->createQueryBuilder('e');
$qb
->join('e.application', 'a')
->where('e.application = :app')
->andWhere($qb->expr()->eq('e.delivered', $qb->expr()->literal(false)))
->andWhere('e.deliveryTries = 3')
->andWhere('e.created > a.updated')
->setParameter(':app', $apiApplication)
;
return $qb->getQuery()->getResult();
}
/**
* @param ApiApplication $apiApplication
* @param int $count
* @return WebhookEventDelivery[]
*/
public function findLastDeliveries(ApiApplication $apiApplication, $count = 10)
{
$qb = $this->createQueryBuilder('e');
$qb
->where('e.application = :app')
->setMaxResults(max(0, (int) $count))
->orderBy('e.created', 'DESC')
->setParameters([ 'app' => $apiApplication ]);
return $qb->getQuery()->getResult();
}
}