Skip to content

Commit a03be50

Browse files
committed
Email: log message-id out to a separate column
1 parent 88754ea commit a03be50

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

app/HMS/Entities/Email.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,34 @@ class Email
4747
*/
4848
protected $role;
4949

50+
/**
51+
* @var string
52+
*/
53+
protected $messageId;
54+
5055
/**
5156
* Create a new email record.
5257
*
5358
* @param array $toAddress Array of to adddress in format [ email => name]
5459
* @param string $subject
5560
* @param string $body
5661
* @param string $fullString
62+
* @param string $messageId
5763
*/
5864
public function __construct(
5965
array $toAddress,
6066
string $subject,
6167
string $body,
62-
string $fullString
68+
string $fullString,
69+
string $messageId
6370
) {
6471
$this->toAddress = $toAddress;
6572
$this->subject = $subject;
6673
$this->body = $body;
6774
$this->fullString = $fullString;
6875
$this->users = new ArrayCollection();
6976
$this->sentAt = Carbon::now();
77+
$this->messageId = $messageId;
7078
}
7179

7280
/**
@@ -232,4 +240,24 @@ public function setRole(?Role $role): self
232240

233241
return $this;
234242
}
243+
244+
/**
245+
* @return string
246+
*/
247+
public function getMessageId()
248+
{
249+
return $this->messageId;
250+
}
251+
252+
/**
253+
* @param string $messageId
254+
*
255+
* @return self
256+
*/
257+
public function setMessageId($messageId)
258+
{
259+
$this->messageId = $messageId;
260+
261+
return $this;
262+
}
235263
}

app/HMS/Mappings/HMS.Entities.Email.dcm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ HMS\Entities\Email:
2424
gedmo:
2525
timestampable:
2626
on: create
27+
messageId:
28+
type: string
2729
manyToOne:
2830
role:
2931
targetEntity: Role

app/Listeners/LogSentMessage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ public function __construct(
5151
public function handle(MessageSending $event)
5252
{
5353
// grab the various bits of info from the Swift_Message
54+
$messageId = $event->message->getHeaders()->get('message-id')->getId();
5455
$toAddresses = $event->message->getHeaders()->get('to')->getNameAddresses();
5556
$subject = $event->message->getHeaders()->get('subject')->getValue();
5657
$body = $event->message->getBody();
5758
$fullString = $event->message->toString();
5859

59-
$email = new Email($toAddresses, $subject, $body, $fullString);
60+
$email = new Email($toAddresses, $subject, $body, $fullString, $messageId);
6061

6162
// now work out the asscications for the users / roles
6263
foreach ($toAddresses as $address => $name) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Database\Migrations;
4+
5+
use Doctrine\Migrations\AbstractMigration;
6+
use Doctrine\DBAL\Schema\Schema as Schema;
7+
8+
class Version20190712235148_alter_email_add_message_id extends AbstractMigration
9+
{
10+
/**
11+
* @param Schema $schema
12+
*/
13+
public function up(Schema $schema)
14+
{
15+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
16+
17+
$this->addSql('ALTER TABLE emails ADD message_id VARCHAR(255) NOT NULL');
18+
}
19+
20+
/**
21+
* @param Schema $schema
22+
*/
23+
public function down(Schema $schema)
24+
{
25+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
26+
27+
$this->addSql('ALTER TABLE emails DROP message_id');
28+
}
29+
}

0 commit comments

Comments
 (0)