Skip to content

Commit 7d50cd7

Browse files
authored
Merge pull request #28 from BBrunekreeft/master
Remove obsolete database fields
2 parents e09361b + c7b04a4 commit 7d50cd7

File tree

4 files changed

+43
-41
lines changed

4 files changed

+43
-41
lines changed

MailQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function process()
9191

9292
$success = true;
9393

94-
$items = Queue::find()->where(['and', ['sent_time' => NULL], ['!=', 'to', 'a:0:{}'], ['<', 'attempts', $this->maxAttempts], ['<=', 'time_to_send', date('Y-m-d H:i:s')]])->orderBy(['created_at' => SORT_ASC])->limit($this->mailsPerRound);
94+
$items = Queue::find()->where(['and', ['sent_time' => NULL], ['<', 'attempts', $this->maxAttempts], ['<=', 'time_to_send', date('Y-m-d H:i:s')]])->orderBy(['created_at' => SORT_ASC])->limit($this->mailsPerRound);
9595
foreach ($items->each() as $item) {
9696
if ($message = $item->toMessage()) {
9797
$attributes = ['attempts', 'last_attempt_time'];

Message.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,11 @@ public function queue($time_to_send = 'now')
3131

3232
$item = new Queue();
3333

34-
$item->from = serialize($this->from);
35-
$item->to = serialize($this->getTo());
36-
$item->cc = serialize($this->getCc());
37-
$item->bcc = serialize($this->getBcc());
38-
$item->reply_to = serialize($this->getReplyTo());
39-
$item->charset = $this->getCharset();
4034
$item->subject = $this->getSubject();
4135
$item->attempts = 0;
4236
$item->swift_message = base64_encode(serialize($this));
4337
$item->time_to_send = date('Y-m-d H:i:s', $time_to_send);
4438

45-
$parts = $this->getSwiftMessage()->getChildren();
46-
// if message has no parts, use message
47-
if ( !is_array($parts) || !sizeof($parts) ) {
48-
$parts = [ $this->getSwiftMessage() ];
49-
}
50-
51-
foreach( $parts as $part ) {
52-
if( !( $part instanceof \Swift_Mime_Attachment ) ) {
53-
/* @var $part \Swift_Mime_MimeEntity */
54-
switch( $part->getContentType() ) {
55-
case 'text/html':
56-
$item->html_body = $part->getBody();
57-
break;
58-
case 'text/plain':
59-
$item->text_body = $part->getBody();
60-
break;
61-
}
62-
63-
if( !$item->charset ) {
64-
$item->charset = $part->getCharset();
65-
}
66-
}
67-
}
68-
6939
return $item->save();
7040
}
7141
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use yii\db\Migration;
4+
use nterms\mailqueue\MailQueue;
5+
6+
/**
7+
* Handles adding swift_message to table `mail_queue`.
8+
*/
9+
class m170217_124201_drop_obsolete_columns_from_mail_queue_table extends Migration
10+
{
11+
/**
12+
* @inheritdoc
13+
*/
14+
public function up()
15+
{
16+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'from');
17+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'to');
18+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'cc');
19+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'bcc');
20+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'html_body');
21+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'text_body');
22+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'reply_to');
23+
$this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'charset');
24+
}
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
public function down()
30+
{
31+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'from', 'text');
32+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'to', 'text');
33+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'cc', 'text');
34+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'bcc', 'text');
35+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'html_body', 'text');
36+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'text_body', 'text');
37+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'reply_to', 'text');
38+
$this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'charset', 'string');
39+
}
40+
}

models/Queue.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,13 @@
1010
/**
1111
* This is the model class for table "{{%mail_queue}}".
1212
*
13-
* @property string $from
14-
* @property string $to
15-
* @property string $cc
16-
* @property string $bcc
1713
* @property string $subject
18-
* @property string $html_body
19-
* @property string $text_body
20-
* @property string $reply_to
21-
* @property string $charset
2214
* @property integer $created_at
2315
* @property integer $attempts
2416
* @property integer $last_attempt_time
2517
* @property integer $sent_time
2618
* @property string $time_to_send
27-
* @property string swift_message
19+
* @property string $swift_message
2820
*/
2921
class Queue extends ActiveRecord
3022
{
@@ -61,7 +53,7 @@ public function rules()
6153
return [
6254
[['created_at', 'attempts', 'last_attempt_time', 'sent_time'], 'integer'],
6355
[['time_to_send', 'swift_message'], 'required'],
64-
[['to', 'cc', 'bcc', 'subject', 'html_body', 'text_body', 'charset'], 'safe'],
56+
[['subject'], 'safe'],
6557
];
6658
}
6759

0 commit comments

Comments
 (0)