Skip to content

Commit 7a6867c

Browse files
f0xx16lorenzo
authored andcommitted
attachment-support and bugfixing (#16)
* added attachments-support * send mail bugfix * added null => true in migration
1 parent bcd5e85 commit 7a6867c

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
use Migrations\AbstractMigration;
3+
4+
class AddAttachmentsToEmailQueue extends AbstractMigration
5+
{
6+
/**
7+
* Change Method.
8+
*
9+
* More information on this method is available here:
10+
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
11+
* @return void
12+
*/
13+
public function change()
14+
{
15+
$table = $this->table('email_queue');
16+
$table->addColumn('attachments', 'text', [
17+
'default' => null,
18+
'null' => true,
19+
]);
20+
$table->update();
21+
}
22+
}

src/Model/Table/EmailQueueTable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function enqueue($to, array $data, array $options = [])
6161
'headers' => [],
6262
'template_vars' => $data,
6363
'config' => 'default',
64+
'attachments' => []
6465
];
6566

6667
$email = $options + $defaults;
@@ -174,7 +175,8 @@ protected function _initializeSchema(Schema $schema)
174175
$type = Configure::read('EmailQueue.serialization_type') ?: 'email_queue.serialize';
175176
$schema->columnType('template_vars', $type);
176177
$schema->columnType('headers', $type);
177-
178+
$schema->columnType('attachments', $type);
179+
178180
return $schema;
179181
}
180182
}

src/Shell/PreviewShell.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public function preview($e)
4848
$theme = empty($e['theme']) ? '' : (string) $e['theme'];
4949

5050
$email = new Email($configName);
51+
52+
if (!empty($e['attachments'])) {
53+
$email->attachments($e['attachments']);
54+
}
55+
5156
$email->transport('Debug')
5257
->to($e['email'])
5358
->subject($e['subject'])

src/Shell/SenderShell.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function main()
6363

6464
$count = count($emails);
6565
foreach ($emails as $e) {
66-
$configName = $e->layout === 'default' ? $this->params['config'] : $e->config;
67-
$template = $e->layout === 'default' ? $this->params['template'] : $e->template;
66+
$configName = $e->config === 'default' ? $this->params['config'] : $e->config;
67+
$template = $e->template === 'default' ? $this->params['template'] : $e->template;
6868
$layout = $e->layout === 'default' ? $this->params['layout'] : $e->layout;
6969
$headers = empty($e->headers) ? array() : (array) $e->headers;
7070
$theme = empty($e->theme) ? '' : (string) $e->theme;
@@ -82,7 +82,11 @@ public function main()
8282
$from = key($email->from());
8383
$transport->config(['additionalParameters' => "-f $from"]);
8484
}
85-
85+
86+
if (!empty($e->attachments)) {
87+
$email->attachments($e->attachments);
88+
}
89+
8690
$sent = $email
8791
->to($e->email)
8892
->subject($e->subject)

0 commit comments

Comments
 (0)