1 | <?php |
||
12 | class AzineMailgunService { |
||
13 | /** |
||
14 | * @var ManagerRegistry |
||
15 | */ |
||
16 | private $managerRegistry; |
||
17 | |||
18 | 3 | public function __construct(ManagerRegistry $managerRegistry) { |
|
21 | |||
22 | /** |
||
23 | * Deletes all MailgunEvents that are older than the ageLimit |
||
24 | * @param \DateTime $ageLimit |
||
25 | * @return int |
||
26 | */ |
||
27 | 1 | public function removeOldEventEntries(\DateTime $ageLimit) { |
|
30 | |||
31 | /** |
||
32 | * Deletes all MailgunEvents of the given type(s) that are older than the ageLimit |
||
33 | * |
||
34 | * Possible Types are: |
||
35 | * |
||
36 | * Event-Type Description |
||
37 | * --------------------------------------------------------------------- |
||
38 | * accepted Mailgun accepted the request to send/forward the email and the message has been placed in queue. |
||
39 | * rejected Mailgun rejected the request to send/forward the email. |
||
40 | * delivered Mailgun sent the email and it was accepted by the recipient email server. |
||
41 | * failed Mailgun could not deliver the email to the recipient email server. |
||
42 | * opened The email recipient opened the email and enabled image viewing. Open tracking must be enabled in the Mailgun control panel, and the CNAME record must be pointing to mailgun.org. |
||
43 | * clicked The email recipient clicked on a link in the email. Click tracking must be enabled in the Mailgun control panel, and the CNAME record must be pointing to mailgun.org. |
||
44 | * unsubscribed The email recipient clicked on the unsubscribe link. Unsubscribe tracking must be enabled in the Mailgun control panel. |
||
45 | * complained The email recipient clicked on the spam complaint button within their email client. Feedback loops enable the notification to be received by Mailgun. |
||
46 | * stored Mailgun has stored an incoming message |
||
47 | * |
||
48 | * @param string|array of string|null $type |
||
49 | * @param \DateTime $ageLimit |
||
50 | * @return integer number of deleted records |
||
51 | */ |
||
52 | 3 | public function removeEvents($type = null, \DateTime $ageLimit) { |
|
53 | 3 | $qb = $this->getManager()->createQueryBuilder()->delete("Azine\MailgunWebhooksBundle\Entity\MailgunEvent", "e")->andWhere("e.timestamp < :age") |
|
54 | 3 | ->setParameter("age", $ageLimit->getTimestamp()); |
|
55 | |||
56 | 3 | if (is_string($type)) { |
|
57 | 1 | $qb->andWhere("e.event = :type")->setParameter("type", $type); |
|
58 | 2 | } elseif (is_array($type)) { |
|
59 | 1 | $qb->andWhere("e.event in (:type)")->setParameter("type", $type); |
|
60 | } |
||
61 | |||
62 | 3 | return $qb->getQuery()->execute(); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Delete all MailgunEvents that match the given criteria (added as "andWhere" clauses). |
||
67 | * |
||
68 | * @param array $criteria |
||
69 | * @return \Doctrine\ORM\mixed |
||
70 | */ |
||
71 | public function removeEventsBy(array $criteria) |
||
72 | { |
||
73 | $qb = $this->getManager()->createQueryBuilder() |
||
74 | ->delete("Azine\MailgunWebhooksBundle\Entity\MailgunEvent", "e"); |
||
75 | foreach ($criteria as $field => $value){ |
||
76 | if($value == null){ |
||
77 | $qb->andWhere("e.$field is null"); |
||
78 | |||
79 | } else { |
||
80 | $qb->andWhere("e.$field = :$field") |
||
81 | ->setParameter($field, $value); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return $qb->getQuery()->execute(); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @return EntityManager |
||
90 | */ |
||
91 | 3 | private function getManager() { |
|
94 | } |
||
95 |