From 4c9e6e19970651ca0b9cd12156f8102e778886aa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Apr 2023 14:33:23 +0200 Subject: [PATCH] Fix opt-out email --- htdocs/comm/mailing/cibles.php | 4 ++-- htdocs/comm/mailing/class/mailing.class.php | 2 +- .../modules/mailings/modules_mailings.php | 24 +++++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 38550b62422..8586c25b3dd 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -265,7 +265,7 @@ if ($object->fetch($id) >= 0) { $morehtmlright = ''; $nbtry = $nbok = 0; - if ($object->statut == 2 || $object->statut == 3) { + if ($object->statut == $object::STATUS_SENTPARTIALY || $object->statut == $object::STATUS_SENTCOMPLETELY) { $nbtry = $object->countNbOfTargets('alreadysent'); $nbko = $object->countNbOfTargets('alreadysentko'); $nbok = ($nbtry - $nbko); @@ -767,7 +767,7 @@ if ($object->fetch($id) >= 0) { print ''; // Status of recipient sending email (Warning != status of emailing) - if ($obj->statut == 0) { + if ($obj->statut == $object::STATUS_DRAFT) { // Date sent print ''; diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 9ad466f9671..451478e8058 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -905,7 +905,7 @@ class Mailing extends CommonObject /** - * Return the label of a given status of a recipient + * Return the label of a given status of a recipient * TODO Add class mailin_target.class.php * * @param int $status Id status diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index b99d012f6a9..8ab6184c9a3 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -158,7 +158,7 @@ class MailingTargets // This can't be abstract as it is used for some method $nb = $obj->nb; $sql = "UPDATE ".MAIN_DB_PREFIX."mailing"; - $sql .= " SET nbemail = ".$nb." WHERE rowid = ".((int) $mailing_id); + $sql .= " SET nbemail = ".((int) $nb)." WHERE rowid = ".((int) $mailing_id); if (!$this->db->query($sql)) { dol_syslog($this->db->error()); $this->error = $this->db->error(); @@ -171,11 +171,11 @@ class MailingTargets // This can't be abstract as it is used for some method } /** - * Add a list of targets int the database + * Add a list of targets into the database * * @param int $mailing_id Id of emailing * @param array $cibles Array with targets - * @return int < 0 si erreur, nb ajout si ok + * @return int < 0 if error, nb added if OK */ public function addTargetsToDatabase($mailing_id, $cibles) { @@ -241,16 +241,20 @@ class MailingTargets // This can't be abstract as it is used for some method $result=$this->db->query($sql); */ - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; - $sql .= " SET statut=3"; - $sql .= " WHERE fk_mailing = ".((int) $mailing_id)." AND email IN (SELECT mu.email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe AS mu WHERE mu.entity IN ('".getEntity('mailing')."'))"; + if (empty($this->evenunsubscribe)) { + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; + $sql .= " SET statut = 3"; + $sql .= " WHERE fk_mailing = ".((int) $mailing_id); + $sql .= " AND EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = email and mu.entity = ".((int) $conf->entity).")"; - dol_syslog(__METHOD__.":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG); - $result = $this->db->query($sql); - if (!$result) { - dol_print_error($this->db); + dol_syslog(__METHOD__.":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG); + $result = $this->db->query($sql); + if (!$result) { + dol_print_error($this->db); + } } + // Update nb of recipient into emailing record $this->update_nb($mailing_id); $this->db->commit();