Avoid adding unsubscribed contacts in mailing list

Add an sql criterion to exclude unsubscribed email adresses from count of contacts (function getNbOfRecipients) and avoid their inclusion in mailing lists (function add_to_target)
This commit is contained in:
simicar29 2020-01-07 16:13:48 +01:00 committed by GitHub
parent f05873201c
commit 7e29e57aff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,6 +105,8 @@ class mailing_contacts1 extends MailingTargets
$sql.= " WHERE c.entity IN (".getEntity('socpeople').")";
$sql.= " AND c.email != ''"; // Note that null != '' is false
$sql.= " AND c.no_email = 0";
$sql .= " AND (SELECT count(*) FROM ". MAIN_DB_PREFIX . "mailing_unsubscribe WHERE email = c.email) = 0";
// exclude unsubscribed users
$sql.= " AND c.statut = 1";
// The request must return a field called "nb" to be understandable by parent::getNbOfRecipients
@ -384,6 +386,8 @@ class mailing_contacts1 extends MailingTargets
$sql.= " WHERE sp.entity IN (".getEntity('socpeople').")";
$sql.= " AND sp.email <> ''";
$sql.= " AND sp.no_email = 0";
$sql .= " AND (SELECT count(*) FROM ". MAIN_DB_PREFIX . "mailing_unsubscribe WHERE email = sp.email) = 0";
// Exclude unsubscribed email adresses
$sql.= " AND sp.statut = 1";
$sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
// Filter on category