Spaces:
No application file
No application file
File size: 2,037 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
<?php
namespace Mautic\WebhookBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<WebhookQueue>
*/
class WebhookQueueRepository extends CommonRepository
{
/**
* Deletes all the webhook queues by ID.
*
* @param $idList array of webhookqueue IDs
*/
public function deleteQueuesById(array $idList): void
{
// don't process the list if there are no items in it
if (!count($idList)) {
return;
}
$qb = $this->_em->getConnection()->createQueryBuilder();
$qb->delete(MAUTIC_TABLE_PREFIX.'webhook_queue')
->where(
$qb->expr()->in('id', $idList)
)
->executeStatement();
}
/**
* Gets a count of the webhook queues filtered by the webhook id.
*
* @param $id int (for Webhooks)
*
* @deprecated Use exists() instead
*/
public function getQueueCountByWebhookId($id): int
{
// if no id was sent (the hook was deleted) then return a count of 0
if (!$id) {
return 0;
}
$qb = $this->_em->getConnection()->createQueryBuilder();
return (int) $qb->select('count(*) as webhook_count')
->from(MAUTIC_TABLE_PREFIX.'webhook_queue', $this->getTableAlias())
->where($this->getTableAlias().'.webhook_id = :id')
->setParameter('id', $id)
->executeQuery()
->fetchOne();
}
/**
* Check if there is webhook to process.
*/
public function exists(int $id): bool
{
$qb = $this->_em->getConnection()->createQueryBuilder();
$result = $qb->select($this->getTableAlias().'.id')
->from(MAUTIC_TABLE_PREFIX.'webhook_queue', $this->getTableAlias())
->where($this->getTableAlias().'.webhook_id = :id')
->setParameter('id', $id)
->setMaxResults(1)
->executeQuery()
->fetchOne();
return (bool) $result;
}
}
|