Errors management

This commit is contained in:
atm-lena 2020-09-01 10:01:59 +02:00
parent d2ed43d913
commit b747f6285e

View File

@ -1983,6 +1983,8 @@ class ActionComm extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$this->db->begin();
//Select all action comm reminder //Select all action comm reminder
$sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email' AND status = 0"; $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email' AND status = 0";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -1994,7 +1996,7 @@ class ActionComm extends CommonObject
$res = $actionCommReminder->fetch($obj->id); $res = $actionCommReminder->fetch($obj->id);
if($res < 0) { if($res < 0) {
$error++; $error++;
$this->errors[] = "Failed to load invoice ActionComm Reminder"; $errorsMsg[] = "Failed to load invoice ActionComm Reminder";
} }
if(!$error) if(!$error)
@ -2030,12 +2032,16 @@ class ActionComm extends CommonObject
if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; if ($res > 0 && !empty($recipient->email)) $to = $recipient->email;
else else
{ {
$this->errors[] = "Failed to load recipient"; $errorsMsg[] = "Failed to load recipient";
$error++; $error++;
} }
// Sender // Sender
$from = $conf->global->MAIN_MAIL_EMAIL_FROM; $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
if(empty($from)) {
$errorsMsg[] = "Failed to load recipient";
$error++;
}
// Errors Recipient // Errors Recipient
$errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
@ -2050,7 +2056,7 @@ class ActionComm extends CommonObject
$res = $actionCommReminder->update($user); $res = $actionCommReminder->update($user);
if ($res < 0) if ($res < 0)
{ {
$this->errors[] = "Failed to update status of ActionComm Reminder"; $errorsMsg[] = "Failed to update status of ActionComm Reminder";
$error++; $error++;
} }
else $nbMailSend++; else $nbMailSend++;
@ -2074,18 +2080,23 @@ class ActionComm extends CommonObject
if(!$error) if(!$error)
{ {
$this->db->begin();
// Delete also very old past events (we do not keep more than 1 month record in past) // Delete also very old past events (we do not keep more than 1 month record in past)
$sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE dateremind < '".$this->db->jdate($now - (3600 * 24 * 32))."'"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE dateremind < '".$this->db->jdate($now - (3600 * 24 * 32))."'";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if($resql) $this->db->commit(); if(!$resql) $error ++;
else $this->db->rollback();
} }
return $error; if(!$error) {
$this->db->commit();
return 0;
}
else {
$this->db->rollback();
return end($errorsMsg);
}
} }
/** /**