diff --git a/code/Newsletter/NewsletterEmailProcess.php b/code/Newsletter/NewsletterEmailProcess.php index b270850d..04773d7f 100755 --- a/code/Newsletter/NewsletterEmailProcess.php +++ b/code/Newsletter/NewsletterEmailProcess.php @@ -8,7 +8,12 @@ class NewsletterEmailProcess extends BatchProcess { protected $nlType; protected $messageID; - function __construct( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $only_to_unsent = 0) { + /** + * Set up a Newsletter Email Process + * + * @recipients A DataObject containing the addresses of the recipients of this newsletter + */ + function __construct( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $recipients) { $this->subject = $subject; $this->body = $body; @@ -16,14 +21,8 @@ class NewsletterEmailProcess extends BatchProcess { $this->newsletter = $newsletter; $this->nlType = $nlType; $this->messageID = $messageID; - - $groupID = $nlType->GroupID; - // Allow sending to only those who have not already received it. - if (0 == $only_to_unsent) { - parent::__construct( DataObject::get( 'Member', "`GroupID`='$groupID'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`" ) ); - } else { - parent::__construct( $newsletter->UnsentSubscribers() ); - } + + parent::__construct( $recipients ); } diff --git a/code/NewsletterAdmin.php b/code/NewsletterAdmin.php index dcb2bdcd..3e4d4a2a 100755 --- a/code/NewsletterAdmin.php +++ b/code/NewsletterAdmin.php @@ -440,12 +440,17 @@ class NewsletterAdmin extends LeftAndMain { } break; case "List": - echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID ); - break; + // Send to the entire mailing list. + $groupID = $nlType->GroupID; + echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, + DataObject::get( 'Member', "`GroupID`='$groupID'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`" ) + ); + break; case "Unsent": + // Send to only those who have not already been sent this newsletter. $only_to_unsent = 1; - echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, $only_to_unsent); - break; + echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, $newsletter->UnsentSubscribers()); + break; } return FormResponse::respond(); @@ -457,8 +462,8 @@ class NewsletterAdmin extends LeftAndMain { $email->send(); } - static function sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $only_to_unsent = 0) { - $emailProcess = new NewsletterEmailProcess( $subject, $body, $from, $newsletter, $nlType, $messageID, $only_to_unsent); + static function sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $recipients) { + $emailProcess = new NewsletterEmailProcess( $subject, $body, $from, $newsletter, $nlType, $messageID, $recipients); return $emailProcess->start(); }