src/App/Entity/EmailDeliveryNotification.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Utility\GuidUtility;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Exception;
  7. use ReflectionClass;
  8. /**
  9. * @ORM\Entity
  10. *
  11. * @ORM\Table(
  12. * name="email_delivery_notifications",
  13. * indexes={
  14. *
  15. * @ORM\Index(name="users_id_mail_sent_at_idx", columns={"users_id", "mail_sent_at"}),
  16. * @ORM\Index(name="email_mail_sent_at_idx", columns={"email", "mail_sent_at"}),
  17. * @ORM\Index(name="notification_type_mail_sent_at_idx", columns={"notification_type", "mail_sent_at"}),
  18. * @ORM\Index(name="mail_sent_at_idx", columns={"mail_sent_at"})
  19. * }
  20. * )
  21. */
  22. class EmailDeliveryNotification
  23. {
  24. public const NOTIFICATION_TYPE_DELIVERY = 0;
  25. public const NOTIFICATION_TYPE_BOUNCE = 1;
  26. public const NOTIFICATION_TYPE_COMPLAINT = 2;
  27. /**
  28. * @var string
  29. *
  30. * @ORM\GeneratedValue(strategy="CUSTOM")
  31. *
  32. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  33. *
  34. * @ORM\Column(name="id", type="guid")
  35. *
  36. * @ORM\Id
  37. */
  38. protected $id;
  39. public function setId(string $id): void
  40. {
  41. GuidUtility::validOrThrow($id);
  42. $this->id = $id;
  43. }
  44. public function getId()
  45. {
  46. return $this->id;
  47. }
  48. /**
  49. * @var User
  50. *
  51. * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="emailDeliveryNotifications")
  52. *
  53. * @ORM\JoinColumn(name="users_id", onDelete="CASCADE", nullable=true)
  54. */
  55. protected $user;
  56. public function getUser(): ?User
  57. {
  58. return $this->user;
  59. }
  60. public function setUser(?User $user = null): void
  61. {
  62. $this->user = $user;
  63. }
  64. /**
  65. * @var int
  66. *
  67. * @ORM\Column(name="notification_type", type="smallint", nullable=false)
  68. */
  69. protected $notificationType;
  70. /**
  71. * @throws Exception
  72. */
  73. public function setNotificationType(int $notificationType): void
  74. {
  75. $refl = new ReflectionClass(EmailDeliveryNotification::class);
  76. $constants = $refl->getConstants();
  77. $found = false;
  78. foreach ($constants as $constantName => $constantValue) {
  79. if (substr($constantName, 0, 18) === 'NOTIFICATION_TYPE_' && $constantValue === $notificationType) {
  80. $found = true;
  81. }
  82. }
  83. if (!$found) {
  84. throw new Exception('Value ' . $notificationType . ' not allowed for notificationType.');
  85. }
  86. $this->notificationType = $notificationType;
  87. }
  88. public function getNotificationType(): int
  89. {
  90. return $this->notificationType;
  91. }
  92. /**
  93. * @var int
  94. *
  95. * @ORM\Column(name="email", type="string", length=255, nullable=false)
  96. */
  97. protected $email;
  98. /**
  99. * @throws Exception
  100. */
  101. public function setEmail(string $email): void
  102. {
  103. $this->email = $email;
  104. }
  105. public function getEmail(): string
  106. {
  107. return $this->email;
  108. }
  109. /**
  110. * @ORM\Column(name="smtp_message", type="string", length=8192, nullable=false)
  111. */
  112. protected $smtpMessage;
  113. /**
  114. * @throws Exception
  115. */
  116. public function setSmtpMessage(string $smtpMessage): void
  117. {
  118. $this->smtpMessage = $smtpMessage;
  119. }
  120. public function getSmtpMessage(): string
  121. {
  122. return $this->smtpMessage;
  123. }
  124. /**
  125. * @ORM\Column(name="mail_message_id", type="string", length=2014, nullable=false)
  126. */
  127. protected $mailMessageId;
  128. /**
  129. * @throws Exception
  130. */
  131. public function setMailMessageId(string $mailMessageId): void
  132. {
  133. $this->mailMessageId = $mailMessageId;
  134. }
  135. public function getMailMessageId(): string
  136. {
  137. return $this->mailMessageId;
  138. }
  139. /**
  140. * @var DateTime
  141. *
  142. * @ORM\Column(name="notification_received_at", type="datetime", nullable=false)
  143. */
  144. protected $notificationReceivedAt;
  145. public function setNotificationReceivedAt(DateTime $notificationReceivedAt): void
  146. {
  147. $this->notificationReceivedAt = $notificationReceivedAt;
  148. }
  149. public function getNotificationReceivedAt(): DateTime
  150. {
  151. return $this->notificationReceivedAt;
  152. }
  153. /**
  154. * @var DateTime
  155. *
  156. * @ORM\Column(name="mail_sent_at", type="datetime", nullable=false)
  157. */
  158. protected $mailSentAt;
  159. public function setMailSentAt(DateTime $mailSentAt): void
  160. {
  161. $this->mailSentAt = $mailSentAt;
  162. }
  163. public function getMailSentAt(): DateTime
  164. {
  165. return $this->mailSentAt;
  166. }
  167. /**
  168. * @var DateTime
  169. *
  170. * @ORM\Column(name="delivery_event_occured_at", type="datetime", nullable=false)
  171. */
  172. protected $deliveryEventOccuredAt;
  173. public function setDeliveryEventOccuredAt(DateTime $deliveryEventOccuredAt): void
  174. {
  175. $this->deliveryEventOccuredAt = $deliveryEventOccuredAt;
  176. }
  177. public function getDeliveryEventOccuredAt(): DateTime
  178. {
  179. return $this->deliveryEventOccuredAt;
  180. }
  181. /**
  182. * @ORM\Column(name="subject", type="text", length=4096, nullable=true)
  183. */
  184. protected $subject;
  185. /**
  186. * @throws Exception
  187. */
  188. public function setSubject(string $subject)
  189. {
  190. $this->subject = $subject;
  191. }
  192. public function getSubject()
  193. {
  194. return $this->subject;
  195. }
  196. /**
  197. * @ORM\Column(name="raw_notification_message", type="text", length=8192, nullable=false)
  198. */
  199. protected $rawNotificationMessage;
  200. /**
  201. * @throws Exception
  202. */
  203. public function setRawNotificationMessage(string $rawNotificationMessage)
  204. {
  205. if (is_null(json_decode($rawNotificationMessage))) {
  206. throw new Exception('rawNotificationMessage must be valid JSON, but ' . $rawNotificationMessage . ' is not.');
  207. }
  208. $this->rawNotificationMessage = $rawNotificationMessage;
  209. }
  210. public function getRawNotificationMessage()
  211. {
  212. return $this->rawNotificationMessage;
  213. }
  214. }