From f29ed4b045bf1bf5185284645c48bd566511dafd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Nov 2020 17:49:23 +0100 Subject: [PATCH] Fix limit to send emails --- scripts/emailings/mailing-send.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index d4c915c3b72..b4354e086b5 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -39,14 +39,20 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } if (!isset($argv[1]) || !$argv[1]) { - print "Usage: ".$script_file." (ID_MAILING|all)\n"; + print "Usage: ".$script_file." (ID_MAILING|all) [userloginforsignature] [maxnbofemails]\n"; exit(-1); } + $id = $argv[1]; -if (isset($argv[2]) || !empty($argv[2])) - $login = $argv[2]; + +if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2]; else $login = ''; +$max = 0; + +if (isset($argv[3]) || !empty($argv[3])) $max = $argv[3]; + + require_once $path."../../htdocs/master.inc.php"; require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"; require_once DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php"; @@ -113,9 +119,13 @@ if ($resql) { // ou envoyes en erreur (statut=-1) $sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag"; $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; - $sql2 .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id; - if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0) { + $sql2 .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".((int) $id); + if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0 && empty($max)) { $sql2 .= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI; + } elseif ($conf->global->MAILING_LIMIT_SENDBYCLI > 0 && $max > 0) { + $sql2 .= " LIMIT ".min($conf->global->MAILING_LIMIT_SENDBYCLI, $max); + } elseif ($max > 0) { + $sql2 .= " LIMIT ".$max; } $resql2 = $db->query($sql2); @@ -128,7 +138,7 @@ if ($resql) { $now = dol_now(); // Positionne date debut envoi - $sqlstartdate = "UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id; + $sqlstartdate = "UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".((int) $id); $resqlstartdate = $db->query($sqlstartdate); if (!$resqlstartdate) { dol_print_error($db);