@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | public function queueMessage(Swift_Mime_Message $message) |
66 | 66 | { |
67 | 67 | $email = new Email(); |
68 | - $email->setFromEmail(implode('; ', array_keys($message->getFrom())) ); |
|
68 | + $email->setFromEmail(implode('; ', array_keys($message->getFrom()))); |
|
69 | 69 | |
70 | - if($message->getTo() !== null ){ |
|
71 | - $email->setToEmail(implode('; ', array_keys($message->getTo())) ); |
|
70 | + if ($message->getTo() !== null) { |
|
71 | + $email->setToEmail(implode('; ', array_keys($message->getTo()))); |
|
72 | 72 | } |
73 | - if($message->getCc() !== null ){ |
|
74 | - $email->setCcEmail(implode('; ', array_keys($message->getCc())) ); |
|
73 | + if ($message->getCc() !== null) { |
|
74 | + $email->setCcEmail(implode('; ', array_keys($message->getCc()))); |
|
75 | 75 | } |
76 | - if($message->getBcc() !== null ){ |
|
77 | - $email->setBccEmail(implode('; ', array_keys($message->getBcc())) ); |
|
76 | + if ($message->getBcc() !== null) { |
|
77 | + $email->setBccEmail(implode('; ', array_keys($message->getBcc()))); |
|
78 | 78 | } |
79 | - if($message->getReplyTo() !== null ){ |
|
80 | - $email->setReplyToEmail(implode('; ', array_keys($message->getReplyTo())) ); |
|
79 | + if ($message->getReplyTo() !== null) { |
|
80 | + $email->setReplyToEmail(implode('; ', array_keys($message->getReplyTo()))); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $email->setBody($message->getBody()); |
@@ -105,17 +105,17 @@ discard block |
||
105 | 105 | $count = 0; |
106 | 106 | $emails = $this->repository->getEmailQueue($this->getMessageLimit()); |
107 | 107 | |
108 | - foreach($emails as $email){ |
|
108 | + foreach ($emails as $email) { |
|
109 | 109 | /*@var $message \Swift_Mime_Message */ |
110 | 110 | $message = $email->getMessage(); |
111 | - try{ |
|
112 | - $count+= $transport->send($message, $failedRecipients); |
|
113 | - if($count > 0){ |
|
111 | + try { |
|
112 | + $count += $transport->send($message, $failedRecipients); |
|
113 | + if ($count > 0) { |
|
114 | 114 | $this->repository->markCompleteSending($email); |
115 | - }else{ |
|
115 | + }else { |
|
116 | 116 | throw new \Swift_SwiftException('The email was not sent.'); |
117 | 117 | } |
118 | - }catch(\Swift_SwiftException $ex){ |
|
118 | + }catch (\Swift_SwiftException $ex) { |
|
119 | 119 | $this->repository->markFailedSending($email, $ex); |
120 | 120 | } |
121 | 121 | } |
@@ -112,10 +112,10 @@ |
||
112 | 112 | $count+= $transport->send($message, $failedRecipients); |
113 | 113 | if($count > 0){ |
114 | 114 | $this->repository->markCompleteSending($email); |
115 | - }else{ |
|
115 | + } else{ |
|
116 | 116 | throw new \Swift_SwiftException('The email was not sent.'); |
117 | 117 | } |
118 | - }catch(\Swift_SwiftException $ex){ |
|
118 | + } catch(\Swift_SwiftException $ex){ |
|
119 | 119 | $this->repository->markFailedSending($email, $ex); |
120 | 120 | } |
121 | 121 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Rafael |
|
5 | - * Date: 02/05/2015 |
|
6 | - * Time: 22:16 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Rafael |
|
5 | + * Date: 02/05/2015 |
|
6 | + * Time: 22:16 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Citrax\Bundle\DatabaseSwiftMailerBundle\Spool; |
10 | 10 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class EmailRepository extends EntityRepository |
14 | 14 | { |
15 | - public function addEmail(Email $email){ |
|
15 | + public function addEmail(Email $email) { |
|
16 | 16 | $em = $this->getEntityManager(); |
17 | 17 | $email->setStatus(Email::STATUS_READY); |
18 | 18 | $email->setRetries(0); |
@@ -20,31 +20,31 @@ discard block |
||
20 | 20 | $em->flush(); |
21 | 21 | } |
22 | 22 | |
23 | - public function getAllEmails(){ |
|
23 | + public function getAllEmails() { |
|
24 | 24 | $qb = $this->createQueryBuilder('e'); |
25 | 25 | |
26 | - $qb->addOrderBy('e.createdAt','DESC'); |
|
26 | + $qb->addOrderBy('e.createdAt', 'DESC'); |
|
27 | 27 | return $qb->getQuery(); |
28 | 28 | } |
29 | 29 | |
30 | - public function getEmailQueue($limit = 100){ |
|
30 | + public function getEmailQueue($limit = 100) { |
|
31 | 31 | $qb = $this->createQueryBuilder('e'); |
32 | 32 | |
33 | - $qb->where($qb->expr()->eq('e.status',':status'))->setParameter(':status' ,Email::STATUS_READY); |
|
34 | - $qb->orWhere($qb->expr()->eq('e.status',':status_1'))->setParameter(':status_1' ,Email::STATUS_FAILED); |
|
35 | - $qb->andWhere($qb->expr()->lt('e.retries',':retries'))->setParameter(':retries',10); |
|
33 | + $qb->where($qb->expr()->eq('e.status', ':status'))->setParameter(':status', Email::STATUS_READY); |
|
34 | + $qb->orWhere($qb->expr()->eq('e.status', ':status_1'))->setParameter(':status_1', Email::STATUS_FAILED); |
|
35 | + $qb->andWhere($qb->expr()->lt('e.retries', ':retries'))->setParameter(':retries', 10); |
|
36 | 36 | |
37 | 37 | |
38 | - $qb->addOrderBy('e.retries','ASC'); |
|
39 | - $qb->addOrderBy('e.createdAt','ASC'); |
|
40 | - if(empty($limit) === false){ |
|
38 | + $qb->addOrderBy('e.retries', 'ASC'); |
|
39 | + $qb->addOrderBy('e.createdAt', 'ASC'); |
|
40 | + if (empty($limit) === false) { |
|
41 | 41 | $qb->setMaxResults($limit); |
42 | 42 | } |
43 | 43 | |
44 | 44 | return $qb->getQuery()->getResult(); |
45 | 45 | } |
46 | 46 | |
47 | - public function markFailedSending(Email $email, \Exception $ex){ |
|
47 | + public function markFailedSending(Email $email, \Exception $ex) { |
|
48 | 48 | $email->setErrorMessage($ex->getMessage()); |
49 | 49 | $email->setStatus(Email::STATUS_FAILED); |
50 | 50 | $email->setRetries($email->getRetries()+1); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $em->flush(); |
54 | 54 | } |
55 | 55 | |
56 | - public function markCompleteSending(Email $email){ |
|
56 | + public function markCompleteSending(Email $email) { |
|
57 | 57 | $email->setStatus(Email::STATUS_COMPLETE); |
58 | 58 | $email->setSentAt(new \DateTime()); |
59 | 59 | $email->setErrorMessage(''); |