From 833c7685e18a3f415efdd6b2f73a077086d2a6d1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 17:32:38 +0100 Subject: [PATCH] Hook 'maildao' was renamed into 'mail' into the method sendfile that send emails, and method was renamed from 'doaction' into 'sendMail'. To process task #4875 #7969 in several steps. --- ChangeLog | 10 ++++++++++ htdocs/core/actions_sendmails.inc.php | 20 +++++++++---------- htdocs/core/class/CMailFile.class.php | 26 +++++++++++++++++++------ htdocs/core/class/hookmanager.class.php | 10 ++++++---- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2cf9f178a16..43fecf4d2e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,16 @@ English Dolibarr ChangeLog -------------------------------------------------------------- + +***** ChangeLog for 8.0.0 compared to 7.0.0 ***** + +WARNING: + +Following changes may create regressions for some external modules, but were necessary to make Dolibarr better: +* Hook 'maildao' was renamed into 'mail' into the method sendfile that send emails, and method was renamed from + 'doaction' into 'sendMail'. + + ***** ChangeLog for 7.0.0 compared to 6.0.5 ***** For users: NEW: When payment is registered, PDF of invoices are also regenerated so payments diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index eea69e37c13..962d00ee4b8 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -106,7 +106,6 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $subject='';$actionmsg='';$actionmsg2=''; - if (! empty($conf->dolimail->enabled)) $langs->load("dolimail@dolimail"); $langs->load('mails'); if (is_object($object)) @@ -321,6 +320,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // Feature to push mail sent into Sent folder + /* This code must be now included into the hook mail, method sendMailAfter if (! empty($conf->dolimail->enabled)) { $mailfromid = explode("#", $_POST['frommail'],3); // $_POST['frommail'] = 'aaa#Sent# ' // TODO Use a better way to define Sent dir. @@ -329,7 +329,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO { $mbid = $mailfromid[1]; - /*IMAP Postbox*/ + // IMAP Postbox $mailboxconfig = new IMAP($db); $mailboxconfig->fetch($mbid); if ($mailboxconfig->mailbox_imap_host) $ref=$mailboxconfig->get_ref(); @@ -361,6 +361,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } } } + */ // Make substitution in email content $substitutionarray=getCommonSubstitutionArray($langs, 0, null, $object); @@ -393,7 +394,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $result=$mailfile->sendfile(); if ($result) { - // FIXME This must be moved into the trigger for action $trigger_name + // Two hooks are available into method $mailfile->sendfile, so dedicated code is no more required + /* if (! empty($conf->dolimail->enabled)) { $mid = (GETPOST('mid','int') ? GETPOST('mid','int') : 0); // Original mail id is set ? @@ -411,7 +413,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if ($movemail) setEventMessages($langs->trans("MailMovedToImapFolder",$folder), null, 'mesgs'); else setEventMessages($langs->trans("MailMovedToImapFolder_Warning",$folder), null, 'warnings'); } - } + }*/ // Initialisation of datas if (is_object($object)) @@ -446,12 +448,10 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // This avoid sending mail twice if going out and then back to page $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); setEventMessages($mesg, null, 'mesgs'); - if ($conf->dolimail->enabled) - { - header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').'&'.($paramname2?$paramname2:'mid').'='.$parm2val); - exit; - } - header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'')); + + $moreparam=''; + if (isset($paramname2) || isset($paramval2)) $moreparam.= '&'.($paramname2?$paramname2:'mid').'='.$paramval2; + header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').$moreparam); exit; } else diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index d9469c11559..32d795db528 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -482,7 +482,7 @@ class CMailFile /** - * Send mail that was prepared by constructor + * Send mail that was prepared by constructor. * * @return boolean True if mail sent, false otherwise */ @@ -499,15 +499,21 @@ class CMailFile { require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($db); - $hookmanager->initHooks(array('maildao')); - $reshook = $hookmanager->executeHooks('doactions', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if (! empty($reshook)) + $hookmanager->initHooks(array('mail')); + + $parameters=array(); $action=''; + $reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) { - $this->error = "Error in hook maildao doactions " . $reshook; + $this->error = "Error in hook maildao sendMail " . $reshook; dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR); return $reshook; } + if ($reshook == 1) // Hook replace standard code + { + return true; + } // Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10; @@ -760,13 +766,21 @@ class CMailFile } else { - // Send mail method not correctly defined // -------------------------------------- return 'Bad value for sendmode'; } + $parameters=array(); $action=''; + $reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) + { + $this->error = "Error in hook maildao sendMailAfter " . $reshook; + dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR); + + return $reshook; + } } else { diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 31833c113b4..1a19e313e08 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -139,6 +139,9 @@ class HookManager 'addMoreMassActions', 'addSearchEntry', 'addStatisticLine', + 'createDictionaryFieldList', + 'editDictionaryFieldlist', + 'getFormMail', 'deleteFile', 'doActions', 'doMassActions', @@ -175,10 +178,9 @@ class HookManager 'formatEvent', 'printObjectLine', 'printObjectSubLine', - 'createDictionaryFieldList', - 'editDictionaryFieldlist', - 'getFormMail', - 'showLinkToObjectBlock' + 'showLinkToObjectBlock', + 'sendMail', + 'sendMailAfter' ) )) $hooktype='addreplace';