Source of file SendRecipientQueue.php
Size: 2,686 Bytes - Last Modified: 2021-12-23T10:33:22+00:00
/var/www/docs.ssmods.com/process/src/src/Model/SendRecipientQueue.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 | <?php namespace SilverStripe\Newsletter\Model; use SilverStripe\ORM\DataObject; use SilverStripe\Newsletter\Control\Email\NewsletterEmail; class SendRecipientQueue extends DataObject { private static $db = [ "Status" => "Enum('Scheduled, InProgress, Sent, Failed, Bounced, BlackListed', 'Scheduled')", "RetryCount" => "Int(0)" ]; private static $has_one = [ "Newsletter" => Newsletter::class, "Recipient" => Recipient::class ]; private static $summary_fields = [ "Status", "Newsletter.Subject", "Recipient.Email", "RetryCount", "LastEdited", ]; private static $default_sort = [ 'LastEdited DESC' ]; private static $table_name = 'SendRecipientQueue'; public function canCreate($member = null, $context = []) { // can only be created by PHP return false; } public function canEdit($member = null) { return false; } /** * @param boolean $includeRelations */ public function fieldLabels($includeRelations = true) { $labels = parent::fieldLabels($includeRelations); $labels["Status"] = _t('Newsletter.FieldStatus', "Status"); $labels["Recipient.Email"] = _t('Newsletter.FieldEmail', "Email"); $labels["RetryCount"] = _t('Newsletter.FieldRetryCount', "Retry Count"); $labels["LastEdited"] = _t('Newsletter.FieldLastEdited', "Last Edited"); return $labels; } /** * */ public function send() { $recipient = $this->Recipient(); $newsletter = $this->Newsletter(); if (!$recipient || !$newsletter) { $this->Status = 'Failed'; $this->write(); return; } if ($recipient && empty($recipient->Blacklisted) && $recipient->Verified) { $email = NewsletterEmail::create( $newsletter, $recipient ); if (!empty($newsletter->ReplyTo)) { $email->setReplyTo($newsletter->ReplyTo); } try { $success = $email->send(); } catch (Exception $e) { $tsuccess = false; } if ($success) { $this->Status = 'Sent'; $recipient->ReceivedCount = $recipient->ReceivedCount + 1; } else { $this->Status = 'Failed'; $recipient->BouncedCount = $recipient->BouncedCount + 1; } $recipient->write(); } else { $this->Status = 'BlackListed'; } $this->write(); } } |