Skip to content

Commit

Permalink
Fix counting of scheduled pending recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Dec 10, 2024
1 parent 35ed35f commit 8f889f0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Release Notes for Campaign

## 3.5.8 - 2024-12-09
## 3.5.8 - Unreleased

### Fixed

- Fixed the calculation of the pending recipient count for scheduled sendouts ([#505](https://github.com/putyourlightson/craft-campaign/issues/505)).
- Fixed a bug in which pending sendouts did not have a status colour assigned ([#507](https://github.com/putyourlightson/craft-campaign/issues/507)).

## 3.5.7 - 2024-11-29
Expand Down
27 changes: 7 additions & 20 deletions src/services/SendoutsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public function getPendingRecipients(SendoutElement $sendout, int $limit = null)
*/
public function getPendingRecipientCount(SendoutElement $sendout): int
{
if ($sendout->sendoutType === 'regular') {
// Count live contacts only (not drafts).
if ($sendout->sendoutType === 'regular' || $sendout->sendoutType === 'scheduled') {
$count = ContactElement::find()
->id($this->getPendingRecipientsStandardIds($sendout))
->count();
Expand Down Expand Up @@ -403,8 +402,8 @@ public function sendNotification(SendoutElement $sendout): void

if ($sendout->sendStatus == SendoutElement::STATUS_SENT) {
$subject = Craft::t('campaign', 'Sending completed: {title}', $variables);
$htmlBody = Craft::t('campaign', 'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!!', $variables);
$plaintextBody = Craft::t('campaign', 'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!!', $variables);
$htmlBody = Craft::t('campaign', 'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!', $variables);
$plaintextBody = Craft::t('campaign', 'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!', $variables);
} else {
$subject = Craft::t('campaign', 'Sending failed: {title}', $variables);
$htmlBody = Craft::t('campaign', 'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” failed after {sendAttempts} send attempt(s). Please check that your <a href="{emailSettingsUrl}">Campaign email settings</a> are correctly configured and check the error in the Craft log.', $variables);
Expand Down Expand Up @@ -584,17 +583,6 @@ private function getSentRecipientsQuery(SendoutElement $sendout, bool $todayOnly
return $query;
}

/**
* Returns the standard sendout’s base query condition.
*/
private function getPendingRecipientsStandardBaseCondition(SendoutElement $sendout): array
{
return [
'mailingListId' => $sendout->mailingListIds,
'subscriptionStatus' => 'subscribed',
];
}

/**
* Returns the standard sendout’s pending recipient contact IDs.
*
Expand All @@ -604,12 +592,13 @@ private function getPendingRecipientsStandardIds(SendoutElement $sendout): array
{
App::maxPowerCaptain();

$baseCondition = $this->getPendingRecipientsStandardBaseCondition($sendout);

// Get contacts subscribed to sendout’s mailing lists
$query = ContactMailingListRecord::find()
->select(['contactId'])
->where($baseCondition);
->andWhere([
'mailingListId' => $sendout->mailingListIds,
'subscriptionStatus' => 'subscribed',
]);

// Ensure contacts have not complained, bounced, or been blocked (in contact record)
$query->innerJoin(ContactRecord::tableName() . ' contact', '[[contact.id]] = [[contactId]]')
Expand Down Expand Up @@ -653,7 +642,6 @@ private function getPendingRecipientsStandardIds(SendoutElement $sendout): array
*/
private function getPendingRecipientsStandard(SendoutElement $sendout, int $limit = null): array
{
$baseCondition = $this->getPendingRecipientsStandardBaseCondition($sendout);
$contactIds = $this->getPendingRecipientsStandardIds($sendout);

if ($limit !== null) {
Expand All @@ -664,7 +652,6 @@ private function getPendingRecipientsStandard(SendoutElement $sendout, int $limi
$recipients = ContactMailingListRecord::find()
->select(['contactId', 'mailingListId' => 'MIN([[mailingListId]])', 'subscribed' => 'MIN([[subscribed]])'])
->groupBy(['contactId'])
->where($baseCondition)
->andWhere(['contactId' => $contactIds])
->orderBy(['contactId' => SORT_ASC])
->asArray()
Expand Down
4 changes: 2 additions & 2 deletions src/translations/de/campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@
'Sending failed. Please check your email settings and the error in the logs.' => 'Senden fehlgeschlagen. Bitte überprüfen Sie Ihre E-Mail-Einstellungen und den Fehler-Log.',
'Sending' => 'Sende',
'Sending of the sendout “{title}” [{sendoutUrl}] failed after {sendAttempts} send attempt(s). Please check that your Campaign email settings [{emailSettingsUrl}] are correctly configured and check the error in the Craft log.' => 'Senden der Sendung “{title}” [{sendoutUrl}] nach {sendAttempts} Versuchen fehlgeschlagen. Bitte stellen Sie sicher, dass Ihre Campaign-E-Mail-Einstellungen [{emailSettingsUrl}] richtig konfiguriert sind und prüfen Sie die Craft-Fehler-Logs.',
'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!!' => 'Senden der Sendung “{title}” [{sendoutUrl}] erfolgreich beendet!!',
'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!' => 'Senden der Sendung “{title}” [{sendoutUrl}] erfolgreich beendet!',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” failed after {sendAttempts} send attempt(s). Please check that your <a href="{emailSettingsUrl}">Campaign email settings</a> are correctly configured and check the error in the Craft log.' => 'Senden der Sendung “<a href="{sendoutUrl}">{title}</a>” nach {sendAttempts} Versuchen fehlgeschlagen. Bitte stellen Sie sicher, dass Ihre <a href="{emailSettingsUrl}">Campaign-E-Mail-Einstellungen</a> richtig konfiguriert sind und prüfen Sie die Craft-Fehler-Logs.',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!!' => 'Senden der Sendung “<a href="{sendoutUrl}">{title}</a>” erfolgreich beendet!!',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!' => 'Senden der Sendung “<a href="{sendoutUrl}">{title}</a>” erfolgreich beendet!',
'Sendout' => 'Sendung',
'sendout' => 'Sendung',
'Sendout Activated!' => 'Sendung aktiviert!',
Expand Down
4 changes: 2 additions & 2 deletions src/translations/en/campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@
'Sending failed. Please check your email settings and the error in the logs.' => '',
'Sending' => '',
'Sending of the sendout “{title}” [{sendoutUrl}] failed after {sendAttempts} send attempt(s). Please check that your Campaign email settings [{emailSettingsUrl}] are correctly configured and check the error in the Craft log.' => '',
'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!!' => '',
'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!' => '',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” failed after {sendAttempts} send attempt(s). Please check that your <a href="{emailSettingsUrl}">Campaign email settings</a> are correctly configured and check the error in the Craft log.' => '',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!!' => '',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!' => '',
'Sendout' => '',
'sendout' => '',
'Sendout Activated!' => '',
Expand Down
4 changes: 2 additions & 2 deletions src/translations/fr/campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@
'Sending failed. Please check your email settings and the error in the logs.' => 'Échec de l’envoi. Veuillez vérifiez les réglages de vos emails et les erreurs dans les logs.',
'Sending' => 'Envoi en cours',
'Sending of the sendout “{title}” [{sendoutUrl}] failed after {sendAttempts} send attempt(s). Please check that your Campaign email settings [{emailSettingsUrl}] are correctly configured and check the error in the Craft log.' => 'L’envoi de la campagne “{title}” [{sendoutUrl}] a échoué après {sendAttempts} tentative(s) d’envoi. Veuillez vérifier que les réglages de messagerie de votre newsletter [{emailSettingsUrl}] sont correctement configurés et vérifiez l’erreur dans les journaux.',
'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!!' => 'L’envoi de la campagne “{title}” [{sendoutUrl}] est un succès !',
'Sending of the sendout “{title}” [{sendoutUrl}] has been successfully completed!' => 'L’envoi de la campagne “{title}” [{sendoutUrl}] est un succès !',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” failed after {sendAttempts} send attempt(s). Please check that your <a href="{emailSettingsUrl}">Campaign email settings</a> are correctly configured and check the error in the Craft log.' => 'L’envoi de la campagne “<a href="{sendoutUrl}">{title}</a>” a échoué après {sendAttempts} tentative(s) d’envoi. Veuillez vérifier que vos <a href="{emailSettingsUrl}">réglages de campagne</a> sont correctement configurés et vérifiez l’erreur dans les journaux.',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!!' => 'L’envoi de la campagne “<a href="{sendoutUrl}">{title}</a>” est un succès !',
'Sending of the sendout “<a href="{sendoutUrl}">{title}</a>” has been successfully completed!' => 'L’envoi de la campagne “<a href="{sendoutUrl}">{title}</a>” est un succès !',
'Sendout' => 'Campagne',
'sendout' => 'campagne',
'Sendout Activated!' => 'L’envoi est en cours !',
Expand Down

0 comments on commit 8f889f0

Please sign in to comment.