1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Mark Scherer |
4
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
5
|
|
|
*/ |
6
|
|
|
namespace Queue\Mailer\Transport; |
7
|
|
|
|
8
|
|
|
use Cake\Mailer\AbstractTransport; |
9
|
|
|
use Cake\Mailer\Email; |
10
|
|
|
use Cake\ORM\TableRegistry; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Send mail using Queue plugin |
14
|
|
|
*/ |
15
|
|
|
class SimpleQueueTransport extends AbstractTransport |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Send mail |
20
|
|
|
* |
21
|
|
|
* @param \Cake\Mailer\Email $email Email |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
public function send(Email $email) |
25
|
|
|
{ |
26
|
|
|
if (!empty($this->_config['queue'])) { |
27
|
|
|
$this->_config = $this->_config['queue'] + $this->_config; |
28
|
|
|
$email->setConfig((array)$this->_config['queue'] + [ |
29
|
|
|
'queue' => [] |
30
|
|
|
]); |
31
|
|
|
unset($this->_config['queue']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$settings = [ |
35
|
|
|
'from' => [ |
36
|
|
|
$email->getFrom() |
37
|
|
|
], |
38
|
|
|
'to' => [ |
39
|
|
|
$email->getTo() |
40
|
|
|
], |
41
|
|
|
'cc' => [ |
42
|
|
|
$email->getCc() |
43
|
|
|
], |
44
|
|
|
'bcc' => [ |
45
|
|
|
$email->getBcc() |
46
|
|
|
], |
47
|
|
|
'charset' => [ |
48
|
|
|
$email->getCharset() |
49
|
|
|
], |
50
|
|
|
'replyTo' => [ |
51
|
|
|
$email->getReplyTo() |
52
|
|
|
], |
53
|
|
|
'readReceipt' => [ |
54
|
|
|
$email->getReadReceipt() |
55
|
|
|
], |
56
|
|
|
'returnPath' => [ |
57
|
|
|
$email->getReturnPath() |
58
|
|
|
], |
59
|
|
|
'messageId' => [ |
60
|
|
|
$email->getMessageId() |
61
|
|
|
], |
62
|
|
|
'domain' => [ |
63
|
|
|
$email->getDomain() |
64
|
|
|
], |
65
|
|
|
'headers' => [ |
66
|
|
|
$email->getHeaders() |
67
|
|
|
], |
68
|
|
|
'headerCharset' => [ |
69
|
|
|
$email->getHeaderCharset() |
70
|
|
|
], |
71
|
|
|
'theme' => [ |
72
|
|
|
$email->viewBuilder()->getTheme() |
73
|
|
|
], |
74
|
|
|
'profile' => [ |
75
|
|
|
$email->getProfile() |
76
|
|
|
], |
77
|
|
|
'emailFormat' => [ |
78
|
|
|
$email->getEmailFormat() |
79
|
|
|
], |
80
|
|
|
'subject' => method_exists($email, 'getOriginalSubject') ? [ |
81
|
|
|
$email->getOriginalSubject() |
82
|
|
|
] : [ |
83
|
|
|
$email->getSubject() |
84
|
|
|
], |
85
|
|
|
'transport' => [ |
86
|
|
|
$this->_config['transport'] |
87
|
|
|
], |
88
|
|
|
'attachments' => [ |
89
|
|
|
$email->getAttachments() |
90
|
|
|
], |
91
|
|
|
'template' => [ |
92
|
|
|
$email->viewBuilder()->getTemplate() |
93
|
|
|
], |
94
|
|
|
'layout' => [ |
95
|
|
|
$email->viewBuilder()->getLayout() |
96
|
|
|
], |
97
|
|
|
'viewVars' => [ |
98
|
|
|
$email->getViewVars() |
99
|
|
|
] |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
foreach ($settings as $setting => $value) { |
103
|
|
|
if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) { |
104
|
|
|
unset($settings[$setting]); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$QueuedJobs = $this->getQueuedJobsModel(); |
109
|
|
|
$result = $QueuedJobs->createJob('Email', [ |
110
|
|
|
'settings' => $settings |
111
|
|
|
]); |
112
|
|
|
$result['headers'] = ''; |
113
|
|
|
$result['message'] = ''; |
114
|
|
|
|
115
|
|
|
return $result->toArray(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* |
120
|
|
|
* @return \Queue\Model\Table\QueuedTasksTable |
121
|
|
|
*/ |
122
|
|
|
protected function getQueuedJobsModel() |
123
|
|
|
{ |
124
|
|
|
/** @var \Queue\Model\Table\QueuedTasksTable $table */ |
125
|
|
|
$table = TableRegistry::getTableLocator()->get('Queue.QueuedTasks'); |
126
|
|
|
|
127
|
|
|
return $table; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|