diff --git a/src/services/SendoutsService.php b/src/services/SendoutsService.php index ee27ed45..ce08ad13 100755 --- a/src/services/SendoutsService.php +++ b/src/services/SendoutsService.php @@ -130,7 +130,13 @@ public function getPendingRecipients(SendoutElement $sendout): array */ public function getPendingRecipientCount(SendoutElement $sendout): int { - return count($this->getPendingRecipients($sendout)) - $sendout->failures; + if ($sendout->sendoutType === 'regular') { + $count = count($this->_getPendingRecipientsStandardIds($sendout)); + } else { + $count = count($this->getPendingRecipients($sendout)); + } + + return $count - $sendout->failures; } /** @@ -588,16 +594,24 @@ private function _getSentRecipientsQuery(SendoutElement $sendout, bool $todayOnl } /** - * Returns the standard sendout's pending contact IDs. + * Returns the standard sendout’s base query condition. */ - private function _getPendingRecipientsStandard(SendoutElement $sendout): array + private function _getPendingRecipientsStandardBaseCondition(SendoutElement $sendout): array { - App::maxPowerCaptain(); - - $baseCondition = [ + return [ 'mailingListId' => $sendout->mailingListIds, 'subscriptionStatus' => 'subscribed', ]; + } + + /** + * Returns the standard sendout’s pending contact IDs. + */ + private function _getPendingRecipientsStandardIds(SendoutElement $sendout): array + { + App::maxPowerCaptain(); + + $baseCondition = $this->_getPendingRecipientsStandardBaseCondition($sendout); // Get contacts subscribed to sendout's mailing lists $query = ContactMailingListRecord::find() @@ -633,6 +647,19 @@ private function _getPendingRecipientsStandard(SendoutElement $sendout): array } } + return $contactIds; + } + + /** + * Returns the standard sendout’s pending contacts. + */ + private function _getPendingRecipientsStandard(SendoutElement $sendout): array + { + App::maxPowerCaptain(); + + $baseCondition = $this->_getPendingRecipientsStandardBaseCondition($sendout); + $contactIds = $this->_getPendingRecipientsStandardIds($sendout); + // Get recipients as array return ContactMailingListRecord::find() ->select(['contactId', 'min([[mailingListId]]) as mailingListId', 'min([[subscribed]]) as subscribed'])