Skip to content

Commit

Permalink
Fixed issue with getQueueMessages where DBAL date comparisons date/ti…
Browse files Browse the repository at this point in the history
…me must be in UTC
  • Loading branch information
alanhartless committed Sep 30, 2016
1 parent 20333ba commit b4af26f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions app/bundles/CoreBundle/Entity/MessageQueueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,33 @@ public function findMessage($channel,$channelId,$leadId)
return $results;
}

public function getQueuedMessages($channel = null, $channelId = null) {
public function getQueuedMessages($channel = null, $channelId = null)
{

$scheduledDate = new \DateTime();
$scheduledDate = new \DateTime('now', new \DateTimeZone('UTC'));

$q = $this->getEntityManager()->getConnection()->createQueryBuilder()
->select('mq.id,mq.channel, mq.channel_id as channelId, mq.lead_id as lead, mq.options')
->from(MAUTIC_TABLE_PREFIX . 'message_queue', 'mq');
->from(MAUTIC_TABLE_PREFIX.'message_queue', 'mq');

$exp = $q->where( $q->expr()->eq('mq.success' ,':success'))
->andWhere($q->expr()->lt('mq.attempts','mq.max_attempts'))
->andWhere($q->expr()->gt('mq.scheduled_date', ':scheduledDate'))
->andWhere($q->expr()->lt('mq.scheduled_date', ':scheduledDateEnd'))
$q->where($q->expr()->eq('mq.success', ':success'))
->andWhere($q->expr()->lt('mq.attempts', 'mq.max_attempts'))
->andWhere('mq.scheduled_date BETWEEN :scheduledDate AND :scheduledDateEnd')
->setParameter('success', false, 'boolean')
->setParameter('scheduledDate',$scheduledDate->format('Y-m-d 00:00:00'))
->setParameter('scheduledDateEnd',$scheduledDate->format('Y-m-d 23:59:59'));
->setParameter('scheduledDate', $scheduledDate->format('Y-m-d 00:00:00'))
->setParameter('scheduledDateEnd', $scheduledDate->format('Y-m-d 23:59:59'));
$q->orderBy('priority,scheduled_date', 'ASC');
$results= $q->execute($exp)

if ($channel) {
$q->andWhere($q->expr()->eq('mq.channel', ':channel'))
->setParameter('channel', $channel);

if ($channelId) {
$q->andWhere($q->expr()->eq('mq.channel_id', (int) $channelId));
}
}

$results = $q->execute()
->fetchAll();

return $results;
Expand Down

0 comments on commit b4af26f

Please sign in to comment.