Skip to content

Commit

Permalink
Merge pull request #29003 from bradley-jarvis/fix-email-sendscript
Browse files Browse the repository at this point in the history
FIX broken send mail script
  • Loading branch information
eldy authored Mar 21, 2024
2 parents b5804ae + 9d31390 commit 16c9393
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions scripts/emailings/mailing-send.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
$login = '';
}

$max = 0;
$max = -1;

if (isset($argv[3]) || !empty($argv[3])) {
$max = $argv[3];
Expand Down Expand Up @@ -108,7 +108,7 @@
}

// We get list of emailing id to process
$sql = "SELECT m.rowid";
$sql = "SELECT m.rowid, m.statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
$sql .= " WHERE m.statut IN (1,2)";
if ($id != 'all') {
Expand All @@ -122,12 +122,18 @@
$j = 0;

if ($num) {
for ($j = 0; $j < $num; $j++) {
for ($j = 0; $j < $num && $max != 0; $j++) {
$obj = $db->fetch_object($resql);

dol_syslog("Process mailing with id ".$obj->rowid);
print "Process mailing with id ".$obj->rowid."\n";

if ($obj->status == 1) {
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut = 2 WHERE rowid = ".((int) $obj->rowid);
$result_sql = $db->query($sql);
dol_syslog("Started mailing campaign ".$obj->rowid, LOG_DEBUG);
}

$emailing = new Mailing($db);
$emailing->fetch($obj->rowid);

Expand Down Expand Up @@ -188,6 +194,7 @@
$now = dol_now();

$obj = $db->fetch_object($resql2);
$max--;

// sendto en RFC2822
$sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">");
Expand Down Expand Up @@ -408,25 +415,16 @@
$i++;
}
} else {
$mesg = "Emailing id ".$id." has no recipient to target";
//$mesg = "Emailing id ".$id." has no recipient to target";
print $mesg."\n";
dol_syslog($mesg, LOG_ERR);
}

// Loop finished, set global statut of mail
$statut = 2;
if (!$nbko) {
$statut = 3;
}

$sqlenddate = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".((int) $statut)." WHERE rowid=".((int) $id);
// Loop finished, set global statut of mail
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=3 WHERE rowid=".$obj->rowid;
$result_sql = $db->query($sql);

dol_syslog("update global status", LOG_DEBUG);
print "Update status of emailing id ".$id." to ".$statut."\n";
$resqlenddate = $db->query($sqlenddate);
if (!$resqlenddate) {
dol_print_error($db);
$error++;
dol_syslog("update global status", LOG_DEBUG);
print "Update status of emailing id ".$id." to ".$statut."\n";
}
} else {
dol_print_error($db);
Expand Down

0 comments on commit 16c9393

Please sign in to comment.