From 9fa77509328a2cbf6a1474ae86759c8a9c32fe35 Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Fri, 17 Feb 2017 12:37:21 +0100 Subject: [PATCH 1/5] Removed obsolete fields Fields from, to, cc, bcc, html_body, text_body, reply_to and charset are not used anymore. Subject field is kept for informational purpose. --- models/Queue.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/models/Queue.php b/models/Queue.php index f51f3e1..d0a1a68 100644 --- a/models/Queue.php +++ b/models/Queue.php @@ -10,15 +10,7 @@ /** * This is the model class for table "{{%mail_queue}}". * - * @property string $from - * @property string $to - * @property string $cc - * @property string $bcc * @property string $subject - * @property string $html_body - * @property string $text_body - * @property string $reply_to - * @property string $charset * @property integer $created_at * @property integer $attempts * @property integer $last_attempt_time @@ -61,7 +53,7 @@ public function rules() return [ [['created_at', 'attempts', 'last_attempt_time', 'sent_time'], 'integer'], [['time_to_send', 'swift_message'], 'required'], - [['to', 'cc', 'bcc', 'subject', 'html_body', 'text_body', 'charset'], 'safe'], + [['subject'], 'safe'], ]; } From 3c756f6c5fd8d80735bc0cebbbd73e49f59b2119 Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Fri, 17 Feb 2017 12:40:09 +0100 Subject: [PATCH 2/5] Removed obsolete fields Fields from, to, cc, bcc, html_body, text_body, reply_to and charset are not used anymore. --- Message.php | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/Message.php b/Message.php index 0d74a22..2ced2d0 100644 --- a/Message.php +++ b/Message.php @@ -31,41 +31,11 @@ public function queue($time_to_send = 'now') $item = new Queue(); - $item->from = serialize($this->from); - $item->to = serialize($this->getTo()); - $item->cc = serialize($this->getCc()); - $item->bcc = serialize($this->getBcc()); - $item->reply_to = serialize($this->getReplyTo()); - $item->charset = $this->getCharset(); $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); - $parts = $this->getSwiftMessage()->getChildren(); - // if message has no parts, use message - if ( !is_array($parts) || !sizeof($parts) ) { - $parts = [ $this->getSwiftMessage() ]; - } - - foreach( $parts as $part ) { - if( !( $part instanceof \Swift_Mime_Attachment ) ) { - /* @var $part \Swift_Mime_MimeEntity */ - switch( $part->getContentType() ) { - case 'text/html': - $item->html_body = $part->getBody(); - break; - case 'text/plain': - $item->text_body = $part->getBody(); - break; - } - - if( !$item->charset ) { - $item->charset = $part->getCharset(); - } - } - } - return $item->save(); } } From 50c29ca2bde13b429c90e18e55c698ee09bc54a0 Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Fri, 17 Feb 2017 12:47:14 +0100 Subject: [PATCH 3/5] Create m170217_124201_drop_obsolete_columns_from_mail_queue_table --- ...rop_obsolete_columns_from_mail_queue_table | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 migrations/m170217_124201_drop_obsolete_columns_from_mail_queue_table diff --git a/migrations/m170217_124201_drop_obsolete_columns_from_mail_queue_table b/migrations/m170217_124201_drop_obsolete_columns_from_mail_queue_table new file mode 100644 index 0000000..cbe8084 --- /dev/null +++ b/migrations/m170217_124201_drop_obsolete_columns_from_mail_queue_table @@ -0,0 +1,40 @@ +dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'from'); + $this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'to'); + $this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'cc'); + $this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'bcc'); + $this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'html_body'); + $this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'text_body'); + $this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'reply_to'); + $this->dropColumn(Yii::$app->get(MailQueue::NAME)->table, 'charset'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'from', 'text'); + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'to', 'text'); + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'cc', 'text'); + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'bcc', 'text'); + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'html_body', 'text'); + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'text_body', 'text'); + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'reply_to', 'text'); + $this->addColumn(Yii::$app->get(MailQueue::NAME)->table, 'charset', 'string'); + } +} From 6c410699454196ba3fb3ca87870463b47d298cde Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Fri, 17 Feb 2017 12:50:45 +0100 Subject: [PATCH 4/5] added missing $ in comments --- models/Queue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/Queue.php b/models/Queue.php index d0a1a68..269d196 100644 --- a/models/Queue.php +++ b/models/Queue.php @@ -16,7 +16,7 @@ * @property integer $last_attempt_time * @property integer $sent_time * @property string $time_to_send - * @property string swift_message + * @property string $swift_message */ class Queue extends ActiveRecord { From c7b04a439a7f7879d7d463082335da870c01bec8 Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Fri, 17 Feb 2017 12:58:44 +0100 Subject: [PATCH 5/5] Don't use obsolete `to` field in query --- MailQueue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MailQueue.php b/MailQueue.php index 7cb8763..4069fe3 100644 --- a/MailQueue.php +++ b/MailQueue.php @@ -91,7 +91,7 @@ public function process() $success = true; - $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); + $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); foreach ($items->each() as $item) { if ($message = $item->toMessage()) { $attributes = ['attempts', 'last_attempt_time'];