From acb50950a4c190a269fb1f1d74a49fa396f7677f Mon Sep 17 00:00:00 2001 From: atm-lena Date: Thu, 27 Aug 2020 11:31:48 +0200 Subject: [PATCH 01/10] Add a default message to "actioncomm_send" template --- htdocs/core/class/html.formmail.class.php | 2 ++ htdocs/langs/en_US/other.lang | 1 + htdocs/langs/fr_FR/other.lang | 1 + 3 files changed, 4 insertions(+) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index aeec45555b2..1fef9012858 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1253,6 +1253,8 @@ class FormMail extends Form $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping"); } elseif ($type_template == 'fichinter_send') { $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter"); + } elseif ($type_template == 'actioncomm_send') { + $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm"); } elseif (!empty($type_template)) { $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric"); } diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 54c0572d453..ffc74c96d3b 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -99,6 +99,7 @@ PredefinedMailContentSendShipping=__(Hello)__\n\nPlease find shipping __REF__ at PredefinedMailContentSendFichInter=__(Hello)__\n\nPlease find intervention __REF__ attached\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentLink=You can click on the link below to make your payment if it is not already done.\n\n%s\n\n PredefinedMailContentGeneric=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ +PredefinedMailContentSendActionComm=__(Hello)__\n\nEvent reminder "__EVENT_LABEL__" on __EVENT_DATE__ at __EVENT_TIME__\n__(Sincerely)__\n\n__USER_SIGNATURE__ DemoDesc=Dolibarr is a compact ERP/CRM supporting several business modules. A demo showcasing all modules makes no sense as this scenario never occurs (several hundred available). So, several demo profiles are available. ChooseYourDemoProfil=Choose the demo profile that best suits your needs... ChooseYourDemoProfilMore=...or build your own profile
(manual module selection) diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang index bd75f6c9035..729ab374319 100644 --- a/htdocs/langs/fr_FR/other.lang +++ b/htdocs/langs/fr_FR/other.lang @@ -101,6 +101,7 @@ PredefinedMailContentThirdparty=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNA PredefinedMailContentContact=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentUser=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentLink=Vous pouvez cliquer sur le lien ci-dessous pour effectuer votre paiement si ce n'est déjà fait.\n\n%s\n\n +PredefinedMailContentSendActionComm=__(Hello)__\n\nRappel événement "__EVENT_LABEL__" le __EVENT_DATE__ à __EVENT_TIME__\n__(Sincerely)__\n\n__USER_SIGNATURE__ DemoDesc=Dolibarr est un logiciel de gestion proposant plusieurs modules métiers. Une démonstration qui inclut tous ces modules n'a pas de sens car ce cas n'existe jamais (plusieurs centaines de modules disponibles). Aussi, quelques profils type de démo sont disponibles. ChooseYourDemoProfil=Veuillez choisir le profil de démonstration qui correspond le mieux à votre activité… ChooseYourDemoProfilMore=...ou construisez votre propre profil
(sélection manuelle des modules) From f57325237aea5b77db1e013d46b5965f49f39710 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Thu, 27 Aug 2020 12:30:59 +0200 Subject: [PATCH 02/10] WIP : sendEmailsReminder() --- htdocs/comm/action/class/actioncomm.class.php | 19 ++++++++++++++++++- htdocs/langs/en_US/members.lang | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 1e860217d03..f97a01f67e9 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -28,6 +28,8 @@ */ require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + /** @@ -1949,7 +1951,7 @@ class ActionComm extends CommonObject */ public function sendEmailsReminder() { - global $conf, $langs; + global $conf, $langs, $user; $error = 0; $this->output = ''; @@ -1976,6 +1978,21 @@ class ActionComm extends CommonObject // TODO Scan events of type 'email' into table llx_actioncomm_reminder with status todo, send email, then set status to done + $sql = "SELECT rowid as id, fk_email_template FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email'"; + $resql = $this->db->query($sql); + + if($resql){ + while($obj = $this->db->fetch_object($resql)){ + $formmail = new FormMail($this->db); + + $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($obj->fk_email_template)) ? $obj->fk_email_template : 0, 1, '(SendingReminderActionComm)'); + + } + } else { + $error++; + } + + // 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))."'"; $this->db->query($sql); diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 5ef946ddf67..2f126b11fdf 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -117,6 +117,7 @@ SendingEmailOnMemberValidation=Sending email on new member validation SendingEmailOnNewSubscription=Sending email on new subscription SendingReminderForExpiredSubscription=Sending reminder for expired subscriptions SendingEmailOnCancelation=Sending email on cancelation +SendingReminderActionComm=Sending reminder for agenda event # Topic of email templates YourMembershipRequestWasReceived=Your membership was received. YourMembershipWasValidated=Your membership was validated From e3ce3cbb7c6e95eb0f8d35c888d6c48855fcb2d6 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Thu, 27 Aug 2020 15:49:56 +0200 Subject: [PATCH 03/10] Function sendEmailsReminder() --- htdocs/comm/action/class/actioncomm.class.php | 96 ++++++++++++++++--- htdocs/core/lib/functions.lib.php | 7 ++ htdocs/langs/en_US/other.lang | 2 +- htdocs/langs/fr_FR/other.lang | 2 +- 4 files changed, 94 insertions(+), 13 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index f97a01f67e9..54a7fd8e2f0 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -29,6 +29,10 @@ require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncommreminder.class.php'; + + @@ -1974,30 +1978,100 @@ class ActionComm extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); - $this->db->begin(); - - // TODO Scan events of type 'email' into table llx_actioncomm_reminder with status todo, send email, then set status to done - - $sql = "SELECT rowid as id, fk_email_template FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email'"; + //Select all action comm reminder + $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email'"; $resql = $this->db->query($sql); if($resql){ while($obj = $this->db->fetch_object($resql)){ - $formmail = new FormMail($this->db); - $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($obj->fk_email_template)) ? $obj->fk_email_template : 0, 1, '(SendingReminderActionComm)'); + $actionCommReminder = new ActionCommReminder($this->db); + $res = $actionCommReminder->fetch($obj->id); + if($res < 0) { + $error++; + $this->errors[] = "Failed to load invoice ActionComm Reminder"; + } + if(!$error) + { + //Select email template + $formmail = new FormMail($this->db); + $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : 0, 1, '(SendingReminderActionComm)'); + + $res = $this->fetch($actionCommReminder->fk_actioncomm); + + if ($res > 0) + { + // PREPARE EMAIL + + // Make substitution in email content + $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this); + + complete_substitutions_array($substitutionarray, $langs, $this); + + // Content + $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray); + + //Topic + $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : $langs->trans('EventReminder'); + + // Recipient + $recipient = new User($this->db); + $res = $recipient->fetch($actionCommReminder->fk_user); + if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; + else { + $this->errors[] = "Failed to load recipient"; + $error++; + } + + // Sender + $from = $conf->global->MAIN_MAIL_EMAIL_FROM; + + // Errors Recipient + $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; + + // Mail Creation + $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', ''); + + // Sending Mail + if ($cMailFile->sendfile()) + { + $actionCommReminder->status=$actionCommReminder::STATUS_DONE; + $res = $actionCommReminder->update($user); + if($res<0) { + $this->errors[] = "Failed to update status of ActionComm Reminder"; + $error++; + } + else $nbMailSend++; + } + else + { + $errorsMsg[] = $cMailFile->error.' : '.$to; + $error++; + } + } + else + { + $error++; + } + } } } else { $error++; } + if(!$error) + { + $this->db->begin(); - // 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))."'"; - $this->db->query($sql); + // 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))."'"; + $resql = $this->db->query($sql); - $this->db->commit(); + if($resql) $this->db->commit(); + else $this->db->rollback(); + + } return $error; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 8631e0e5663..74916ec62e1 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6244,6 +6244,13 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, if (is_object($object) && $object->element == 'commande') $substitutionarray['__URL_ORDER__'] = DOL_MAIN_URL_ROOT."/commande/card.php?id=".$object->id; if (is_object($object) && $object->element == 'facture') $substitutionarray['__URL_INVOICE__'] = DOL_MAIN_URL_ROOT."/compta/facture/card.php?id=".$object->id; } + + if (is_object($object) && $object->element == 'action') + { + $substitutionarray['__EVENT_LABEL__'] = $object->label; + $substitutionarray['__EVENT_DATE__'] = dol_print_date($object->datep, '%A %d %b %Y'); + $substitutionarray['__EVENT_TIME__'] = dol_print_date($object->datep, '%H:%M:%S'); + } } } if (empty($exclude) || !in_array('objectamount', $exclude)) diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index ffc74c96d3b..4903bea90da 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -99,7 +99,7 @@ PredefinedMailContentSendShipping=__(Hello)__\n\nPlease find shipping __REF__ at PredefinedMailContentSendFichInter=__(Hello)__\n\nPlease find intervention __REF__ attached\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentLink=You can click on the link below to make your payment if it is not already done.\n\n%s\n\n PredefinedMailContentGeneric=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ -PredefinedMailContentSendActionComm=__(Hello)__\n\nEvent reminder "__EVENT_LABEL__" on __EVENT_DATE__ at __EVENT_TIME__\n__(Sincerely)__\n\n__USER_SIGNATURE__ +PredefinedMailContentSendActionComm=Event reminder "__EVENT_LABEL__" on __EVENT_DATE__ at __EVENT_TIME__

This is an automatic message, please do not reply. DemoDesc=Dolibarr is a compact ERP/CRM supporting several business modules. A demo showcasing all modules makes no sense as this scenario never occurs (several hundred available). So, several demo profiles are available. ChooseYourDemoProfil=Choose the demo profile that best suits your needs... ChooseYourDemoProfilMore=...or build your own profile
(manual module selection) diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang index 729ab374319..e666b6d6d80 100644 --- a/htdocs/langs/fr_FR/other.lang +++ b/htdocs/langs/fr_FR/other.lang @@ -101,7 +101,7 @@ PredefinedMailContentThirdparty=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNA PredefinedMailContentContact=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentUser=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentLink=Vous pouvez cliquer sur le lien ci-dessous pour effectuer votre paiement si ce n'est déjà fait.\n\n%s\n\n -PredefinedMailContentSendActionComm=__(Hello)__\n\nRappel événement "__EVENT_LABEL__" le __EVENT_DATE__ à __EVENT_TIME__\n__(Sincerely)__\n\n__USER_SIGNATURE__ +PredefinedMailContentSendActionComm=Rappel événement "__EVENT_LABEL__" le __EVENT_DATE__ à __EVENT_TIME__

Ceci est un message automatique, merci de ne pas répondre. DemoDesc=Dolibarr est un logiciel de gestion proposant plusieurs modules métiers. Une démonstration qui inclut tous ces modules n'a pas de sens car ce cas n'existe jamais (plusieurs centaines de modules disponibles). Aussi, quelques profils type de démo sont disponibles. ChooseYourDemoProfil=Veuillez choisir le profil de démonstration qui correspond le mieux à votre activité… ChooseYourDemoProfilMore=...ou construisez votre propre profil
(sélection manuelle des modules) From c0f254d10c675c8d34deed2971438683359c24b0 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Thu, 27 Aug 2020 16:03:25 +0200 Subject: [PATCH 04/10] Translation + decode --- htdocs/comm/action/class/actioncomm.class.php | 4 ++-- htdocs/langs/en_US/agenda.lang | 3 ++- htdocs/langs/fr_FR/agenda.lang | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 54a7fd8e2f0..2f99eef15c9 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1979,7 +1979,7 @@ class ActionComm extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); //Select all action comm reminder - $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email'"; + $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email' AND status = 0"; $resql = $this->db->query($sql); if($resql){ @@ -2013,7 +2013,7 @@ class ActionComm extends CommonObject $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray); //Topic - $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : $langs->trans('EventReminder'); + $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder')); // Recipient $recipient = new User($this->db); diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index bbfb143cee8..7b716d8050d 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -165,4 +165,5 @@ TimeType=Duration type ReminderType=Callback type AddReminder=Create an automatic reminder notification for this event ErrorReminderActionCommCreation=Error creating the reminder notification for this event -BrowserPush=Browser Notification \ No newline at end of file +BrowserPush=Browser Notification +EventReminder=Event Reminder \ No newline at end of file diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang index 80d1c953e0b..e53af5f75be 100644 --- a/htdocs/langs/fr_FR/agenda.lang +++ b/htdocs/langs/fr_FR/agenda.lang @@ -164,3 +164,4 @@ ReminderType=Type de rappel AddReminder=Créer une notification de rappel automatique pour cet évènement ErrorReminderActionCommCreation=Erreur lors de la création de la notification de rappel de cet événement BrowserPush=Notification navigateur +EventReminder=Rappel événement From 6562334f7b2138941f22af5fc182773201d99126 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Fri, 28 Aug 2020 09:37:18 +0200 Subject: [PATCH 05/10] FIX sendEmailsReminder() function --- htdocs/comm/action/class/actioncomm.class.php | 99 ++++++++++--------- 1 file changed, 53 insertions(+), 46 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 2f99eef15c9..2bf5af2599e 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1994,66 +1994,73 @@ class ActionComm extends CommonObject if(!$error) { - //Select email template - $formmail = new FormMail($this->db); - $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : 0, 1, '(SendingReminderActionComm)'); - $res = $this->fetch($actionCommReminder->fk_actioncomm); - - if ($res > 0) + if ($actionCommReminder->dateremind <= dol_now()) { - // PREPARE EMAIL - // Make substitution in email content - $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this); + //Select email template + $formmail = new FormMail($this->db); + $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : 0, 1, '(SendingReminderActionComm)'); - complete_substitutions_array($substitutionarray, $langs, $this); + $res = $this->fetch($actionCommReminder->fk_actioncomm); - // Content - $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray); - - //Topic - $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder')); - - // Recipient - $recipient = new User($this->db); - $res = $recipient->fetch($actionCommReminder->fk_user); - if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; - else { - $this->errors[] = "Failed to load recipient"; - $error++; - } - - // Sender - $from = $conf->global->MAIN_MAIL_EMAIL_FROM; - - // Errors Recipient - $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; - - // Mail Creation - $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', ''); - - // Sending Mail - if ($cMailFile->sendfile()) + if ($res > 0) { - $actionCommReminder->status=$actionCommReminder::STATUS_DONE; - $res = $actionCommReminder->update($user); - if($res<0) { - $this->errors[] = "Failed to update status of ActionComm Reminder"; + // PREPARE EMAIL + + // Make substitution in email content + $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this); + + complete_substitutions_array($substitutionarray, $langs, $this); + + // Content + $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray); + + //Topic + $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder')); + + // Recipient + $recipient = new User($this->db); + $res = $recipient->fetch($actionCommReminder->fk_user); + if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; + else + { + $this->errors[] = "Failed to load recipient"; + $error++; + } + + // Sender + $from = $conf->global->MAIN_MAIL_EMAIL_FROM; + + // Errors Recipient + $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; + + // Mail Creation + $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', ''); + + // Sending Mail + if ($cMailFile->sendfile()) + { + $actionCommReminder->status = $actionCommReminder::STATUS_DONE; + $res = $actionCommReminder->update($user); + if ($res < 0) + { + $this->errors[] = "Failed to update status of ActionComm Reminder"; + $error++; + } + else $nbMailSend++; + } + else + { + $errorsMsg[] = $cMailFile->error.' : '.$to; $error++; } - else $nbMailSend++; } else { - $errorsMsg[] = $cMailFile->error.' : '.$to; $error++; } } - else - { - $error++; - } } } } else { From 13f91f1de89ce41dbff233f3434c59ffb2cd4dbe Mon Sep 17 00:00:00 2001 From: atm-lena Date: Tue, 1 Sep 2020 09:41:59 +0200 Subject: [PATCH 06/10] FIX getEmailTemplat() in sendEmailsReminder() reminder function --- htdocs/comm/action/class/actioncomm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 9273352d2f5..e5686263878 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -2005,7 +2005,7 @@ class ActionComm extends CommonObject //Select email template $formmail = new FormMail($this->db); - $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : 0, 1, '(SendingReminderActionComm)'); + $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1); $res = $this->fetch($actionCommReminder->fk_actioncomm); From b747f6285ebf2158ddbb72bafcfe099b96968116 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Tue, 1 Sep 2020 10:01:59 +0200 Subject: [PATCH 07/10] Errors management --- htdocs/comm/action/class/actioncomm.class.php | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index e5686263878..54b0b1f634e 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1983,7 +1983,9 @@ class ActionComm extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); - //Select all action comm reminder + $this->db->begin(); + + //Select all action comm reminder $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email' AND status = 0"; $resql = $this->db->query($sql); @@ -1994,7 +1996,7 @@ class ActionComm extends CommonObject $res = $actionCommReminder->fetch($obj->id); if($res < 0) { $error++; - $this->errors[] = "Failed to load invoice ActionComm Reminder"; + $errorsMsg[] = "Failed to load invoice ActionComm Reminder"; } if(!$error) @@ -2030,12 +2032,16 @@ class ActionComm extends CommonObject if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; else { - $this->errors[] = "Failed to load recipient"; + $errorsMsg[] = "Failed to load recipient"; $error++; } // Sender $from = $conf->global->MAIN_MAIL_EMAIL_FROM; + if(empty($from)) { + $errorsMsg[] = "Failed to load recipient"; + $error++; + } // Errors Recipient $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; @@ -2050,7 +2056,7 @@ class ActionComm extends CommonObject $res = $actionCommReminder->update($user); if ($res < 0) { - $this->errors[] = "Failed to update status of ActionComm Reminder"; + $errorsMsg[] = "Failed to update status of ActionComm Reminder"; $error++; } else $nbMailSend++; @@ -2074,18 +2080,23 @@ class ActionComm extends CommonObject if(!$error) { - $this->db->begin(); - // 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))."'"; $resql = $this->db->query($sql); - if($resql) $this->db->commit(); - else $this->db->rollback(); + if(!$resql) $error ++; } - return $error; + if(!$error) { + $this->db->commit(); + return 0; + } + else { + $this->db->rollback(); + return end($errorsMsg); + } + } /** From 86c6ef23e352f7d51a4833453b0c31b4dfef9a7d Mon Sep 17 00:00:00 2001 From: atm-lena Date: Tue, 1 Sep 2020 10:05:55 +0200 Subject: [PATCH 08/10] Errors management v2 --- htdocs/comm/action/class/actioncomm.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 54b0b1f634e..c91ac1a1abe 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -2084,7 +2084,10 @@ class ActionComm extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE dateremind < '".$this->db->jdate($now - (3600 * 24 * 32))."'"; $resql = $this->db->query($sql); - if(!$resql) $error ++; + if(!$resql) { + $errorsMsg[] = 'Failed to delete old reminders'; + $error ++; + } } @@ -2094,7 +2097,7 @@ class ActionComm extends CommonObject } else { $this->db->rollback(); - return end($errorsMsg); + return (!empty($errorsMsg)) ? end($errorsMsg) : $error; } } From 763515a4ca3613d4446a432657807831dcdc1d24 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 1 Sep 2020 08:17:19 +0000 Subject: [PATCH 09/10] Fixing style errors. --- htdocs/comm/action/class/actioncomm.class.php | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index c91ac1a1abe..aaf160b9ec1 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1989,22 +1989,19 @@ class ActionComm extends CommonObject $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email' AND status = 0"; $resql = $this->db->query($sql); - if($resql){ - while($obj = $this->db->fetch_object($resql)){ - + if ($resql){ + while ($obj = $this->db->fetch_object($resql)){ $actionCommReminder = new ActionCommReminder($this->db); $res = $actionCommReminder->fetch($obj->id); - if($res < 0) { + if ($res < 0) { $error++; $errorsMsg[] = "Failed to load invoice ActionComm Reminder"; } - if(!$error) + if (!$error) { - if ($actionCommReminder->dateremind <= dol_now()) { - //Select email template $formmail = new FormMail($this->db); $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1); @@ -2030,15 +2027,14 @@ class ActionComm extends CommonObject $recipient = new User($this->db); $res = $recipient->fetch($actionCommReminder->fk_user); if ($res > 0 && !empty($recipient->email)) $to = $recipient->email; - else - { + else { $errorsMsg[] = "Failed to load recipient"; $error++; } // Sender $from = $conf->global->MAIN_MAIL_EMAIL_FROM; - if(empty($from)) { + if (empty($from)) { $errorsMsg[] = "Failed to load recipient"; $error++; } @@ -2061,14 +2057,12 @@ class ActionComm extends CommonObject } else $nbMailSend++; } - else - { + else { $errorsMsg[] = $cMailFile->error.' : '.$to; $error++; } } - else - { + else { $error++; } } @@ -2078,20 +2072,19 @@ class ActionComm extends CommonObject $error++; } - if(!$error) + if (!$error) { // 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))."'"; $resql = $this->db->query($sql); - if(!$resql) { + if (!$resql) { $errorsMsg[] = 'Failed to delete old reminders'; $error ++; } - } - if(!$error) { + if (!$error) { $this->db->commit(); return 0; } From a626b252bd3a54f61d3c7a58d9da4166d007840b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 1 Sep 2020 15:33:02 +0200 Subject: [PATCH 10/10] Optimize code --- htdocs/comm/action/class/actioncomm.class.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index aaf160b9ec1..fd41a9eadf4 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1986,12 +1986,17 @@ class ActionComm extends CommonObject $this->db->begin(); //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"; + $sql .= " WHERE typeremind = 'email' AND status = 0"; + $sql .= " AND dateremind <= '".$this->db->idate(dol_now())."'"; + $sql .= $this->db->order("dateremind", "ASC"); $resql = $this->db->query($sql); - if ($resql){ - while ($obj = $this->db->fetch_object($resql)){ - $actionCommReminder = new ActionCommReminder($this->db); + if ($resql) { + $formmail = new FormMail($this->db); + $actionCommReminder = new ActionCommReminder($this->db); + + while ($obj = $this->db->fetch_object($resql)){ $res = $actionCommReminder->fetch($obj->id); if ($res < 0) { $error++; @@ -2000,14 +2005,11 @@ class ActionComm extends CommonObject if (!$error) { - if ($actionCommReminder->dateremind <= dol_now()) - { //Select email template - $formmail = new FormMail($this->db); $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1); + // Load event $res = $this->fetch($actionCommReminder->fk_actioncomm); - if ($res > 0) { // PREPARE EMAIL @@ -2065,7 +2067,6 @@ class ActionComm extends CommonObject else { $error++; } - } } } } else { @@ -2075,7 +2076,8 @@ class ActionComm extends CommonObject if (!$error) { // 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"; + $sql .= " WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32))."'"; $resql = $this->db->query($sql); if (!$resql) {