More log into notify class

This commit is contained in:
Laurent Destailleur 2014-09-04 14:38:30 +02:00
parent 5aaba31c6a
commit 32fd2e03ce

View File

@ -147,104 +147,116 @@ class Notify
else $sql.= " AND a.code = '".$action."'"; // New usage else $sql.= " AND a.code = '".$action."'"; // New usage
$sql .= " AND s.rowid = ".$socid; $sql .= " AND s.rowid = ".$socid;
dol_syslog("Notify::send", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$i = 0;
while ($i < $num) // For each notification couple defined (third party/actioncode) if ($num > 0)
{ {
$obj = $this->db->fetch_object($result); $i = 0;
while ($i < $num) // For each notification couple defined (third party/actioncode)
{
$obj = $this->db->fetch_object($result);
$sendto = $obj->firstname . " " . $obj->lastname . " <".$obj->email.">"; $sendto = $obj->firstname . " " . $obj->lastname . " <".$obj->email.">";
$actiondefid = $obj->adid; $actiondefid = $obj->adid;
if (dol_strlen($sendto)) if (dol_strlen($obj->email))
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$application=($conf->global->MAIN_APPLICATION_TITLE?$conf->global->MAIN_APPLICATION_TITLE:'Dolibarr ERP/CRM'); $application=($conf->global->MAIN_APPLICATION_TITLE?$conf->global->MAIN_APPLICATION_TITLE:'Dolibarr ERP/CRM');
$subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification"); $subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification");
$message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
$message.= "\n"; $message.= "\n";
$message.= $texte; $message.= $texte;
// Add link // Add link
$link=''; $link='';
switch($objet_type) switch($objet_type)
{ {
case 'ficheinter': case 'ficheinter':
$link='/fichinter/fiche.php?id='.$objet_id; $link='/fichinter/fiche.php?id='.$objet_id;
break; break;
case 'propal': case 'propal':
$link='/comm/propal.php?id='.$objet_id; $link='/comm/propal.php?id='.$objet_id;
break; break;
case 'facture': case 'facture':
$link='/compta/facture.php?facid='.$objet_id; $link='/compta/facture.php?facid='.$objet_id;
break; break;
case 'order': case 'order':
$link='/commande/fiche.php?id='.$objet_id; $link='/commande/fiche.php?id='.$objet_id;
break; break;
case 'order_supplier': case 'order_supplier':
$link='/fourn/commande/fiche.php?id='.$objet_id; $link='/fourn/commande/fiche.php?id='.$objet_id;
break; break;
} }
// Define $urlwithroot // Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
if ($link) $message.="\n".$urlwithroot.$link; if ($link) $message.="\n".$urlwithroot.$link;
$filename = basename($file); $filename = basename($file);
$mimefile=dol_mimetype($file); $mimefile=dol_mimetype($file);
$msgishtml=0; $msgishtml=0;
$replyto = $conf->notification->email_from; $replyto = $conf->notification->email_from;
$mailfile = new CMailFile( $mailfile = new CMailFile(
$subject, $subject,
$sendto, $sendto,
$replyto, $replyto,
$message, $message,
array($file), array($file),
array($mimefile), array($mimefile),
array($filename[count($filename)-1]), array($filename[count($filename)-1]),
'', '',
'', '',
0, 0,
$msgishtml $msgishtml
); );
if ($mailfile->sendfile()) if ($mailfile->sendfile())
{ {
$now=dol_now(); $now=dol_now();
$sendto = htmlentities($sendto); $sendto = htmlentities($sendto);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate($now)."', ".$actiondefid.", ".$obj->cid.", '".$objet_type."', ".$objet_id.", '".$this->db->escape($obj->email)."')"; $sql.= " VALUES ('".$this->db->idate($now)."', ".$actiondefid.", ".$obj->cid.", '".$objet_type."', ".$objet_id.", '".$this->db->escape($obj->email)."')";
dol_syslog("Notify::send", LOG_DEBUG); dol_syslog("Notify::send", LOG_DEBUG);
if (! $this->db->query($sql) ) if (! $this->db->query($sql) )
{ {
dol_print_error($this->db); dol_print_error($this->db);
} }
} }
else else
{ {
$this->error=$mailfile->error; $this->error=$mailfile->error;
//dol_syslog("Notify::send ".$this->error, LOG_ERR); //dol_syslog("Notify::send ".$this->error, LOG_ERR);
} }
} }
$i++; else
{
dol_syslog("No notification sent for ".$sendto." because email is empty");
}
$i++;
}
return $i;
} }
return $i; else
{
dol_syslog("No notification sent, nothing into notification setup for the thirdparty socid = ".$socid);
return 0;
}
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
return -1; return -1;
} }