forked from nterms/yii2-mailqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.php
43 lines (35 loc) · 983 Bytes
/
Message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Message.php
* @author Saranga Abeykoon http://nterms.com
*/
namespace nterms\mailqueue;
use Yii;
use nterms\mailqueue\models\Queue;
/**
* Extends `yii\swiftmailer\Message` to enable queuing.
*
* @see http://www.yiiframework.com/doc-2.0/yii-swiftmailer-message.html
*/
class Message extends \yii\swiftmailer\Message
{
public $queueItemClass;
/**
* Enqueue the message storing it in database.
*
* @param timestamp $time_to_send
* @return boolean true on success, false otherwise
*/
public function queue($time_to_send = 'now')
{
if($time_to_send == 'now') {
$time_to_send = time();
}
$item = Yii::createObject($this->queueItemClass);
$item->subject = $this->getSubject();
$item->attempts = 0;
$item->swift_message = base64_encode(serialize($this));
$item->time_to_send = date('Y-m-d H:i:s', $time_to_send);
return $item->save();
}
}