Fix opt-out email

This commit is contained in:
Laurent Destailleur 2023-04-09 14:33:23 +02:00
parent f081768baa
commit 4c9e6e1997
3 changed files with 17 additions and 13 deletions

View File

@ -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 '</td>';
// Status of recipient sending email (Warning != status of emailing)
if ($obj->statut == 0) {
if ($obj->statut == $object::STATUS_DRAFT) {
// Date sent
print '<td align="center"></td>';

View File

@ -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

View File

@ -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();