New: Better error management for add/remove of memeber into mailman.

This commit is contained in:
Laurent Destailleur 2013-03-30 18:04:33 +01:00
parent 1eec85da9d
commit 000fe2c864
7 changed files with 81 additions and 16 deletions

View File

@ -41,6 +41,10 @@ class Adherent extends CommonObject
public $table_element='adherent';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $error;
var $errors;
var $mesgs;
var $id;
var $ref;
var $civilite_id;
@ -1370,10 +1374,10 @@ class Adherent extends CommonObject
*/
function add_to_abo()
{
global $conf;
global $conf,$langs;
include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
$mailmanspip=new MailmanSpip($db);
$mailmanspip=new MailmanSpip($this->db);
$err=0;
@ -1386,6 +1390,16 @@ class Adherent extends CommonObject
$this->error=$mailmanspip->error;
$err+=1;
}
foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail)
{
$langs->load("errors");
$this->errors[]=$langs->trans("ErrorFailedToAddToMailmanList",$tmpemail,$tmplist);
}
foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail)
{
$langs->load("mailmanspip");
$this->mesgs[]=$langs->trans("SuccessToAddToMailmanList",$tmpemail,$tmplist);
}
}
// spip
@ -1400,11 +1414,10 @@ class Adherent extends CommonObject
}
if ($err)
{
// error
return -$err;
}
else
{
{
return 1;
}
}
@ -1418,10 +1431,10 @@ class Adherent extends CommonObject
*/
function del_to_abo()
{
global $conf;
global $conf,$langs;
include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
$mailmanspip=new MailmanSpip($db);
$mailmanspip=new MailmanSpip($this->db);
$err=0;
@ -1431,8 +1444,20 @@ class Adherent extends CommonObject
$result=$mailmanspip->del_to_mailman($this);
if ($result < 0)
{
$this->error=$mailmanspip->error;
$err+=1;
}
foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail)
{
$langs->load("errors");
$this->errors[]=$langs->trans("ErrorFailedToRemoveToMailmanList",$tmpemail,$tmplist);
}
foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail)
{
$langs->load("mailmanspip");
$this->mesgs[]=$langs->trans("SuccessToRemoveToMailmanList",$tmpemail,$tmplist);
}
}
if ($conf->global->ADHERENT_USE_SPIP && ! empty($conf->mailmanspip->enabled))

View File

@ -356,15 +356,24 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
{
if ($object->oldcopy->del_to_abo() < 0)
{
// error
$errmsgs[]= $langs->trans("FailedToCleanMailmanList").': '.$object->error."<br>\n";
if (! empty($object->oldcopy->error)) setEventMessage($langs->trans("ErrorFailedToRemoveToMailmanList").': '.$object->oldcopy->error, 'errors');
setEventMessage($object->oldcopy->errors, 'errors');
}
else
{
setEventMessage($object->oldcopy->mesgs,'mesgs');
}
}
if ($object->add_to_abo() < 0) // We add subscription if new email or new type (new type may means more mailing-list to subscribe)
// We add subscription if new email or new type (new type may means more mailing-list to subscribe)
if ($object->add_to_abo() < 0)
{
if (! empty($object->error)) setEventMessage($langs->trans("ErrorFailedToAddToMailmanList").': '.$object->error, 'errors');
setEventMessage($object->errors, 'errors');
}
else
{
// error
$errmsgs[]= $langs->trans("FailedToAddToMailmanList").': '.$object->error."<br>\n";
}
setEventMessage($object->mesgs, 'mesgs');
}
}
$rowid=$object->id;

View File

@ -114,7 +114,8 @@ ErrNoZipEngine=No engine to unzip %s file in this PHP
ErrorFileMustBeADolibarrPackage=The file %s must be a Dolibarr zip package
ErrorFileRequired=It takes a package Dolibarr file
ErrorPhpCurlNotInstalled=The PHP CURL is not installed, this is essential to talk with Paypal
ErrorFailedToAddToMailmanList=Failed to add record to Mailman list or SPIP base
ErrorFailedToAddToMailmanList=Failed to add record %s to Mailman list %s or SPIP base
ErrorFailedToRemoveToMailmanList=Failed to remove record %s to Mailman list %s or SPIP base
ErrorNewValueCantMatchOldValue=New value can't be equal to old one
ErrorFailedToValidatePasswordReset=Failed to reinit password. May be the reinit was already done (this link can be used only one time). If not, try to restart the reinit process.

View File

@ -23,4 +23,6 @@ AddIntoSpipError=Failed to add the user in SPIP
DeleteIntoSpip=Remove from SPIP
DeleteIntoSpipConfirmation=Are you sure you want to remove this member from SPIP?
DeleteIntoSpipError=Failed to suppress the user from SPIP
SPIPConnectionFailed=Failed to connect to SPIP
SPIPConnectionFailed=Failed to connect to SPIP
SuccessToAddToMailmanList=Add of %s to mailman list %s or SPIP database done
SuccessToRemoveToMailmanList=Removal of %s from mailman list %s or SPIP database done

View File

@ -115,7 +115,8 @@ ErrNoZipEngine=Pas de moteur pour décompresser le fichier %s dans ce PHP
ErrorFileMustBeADolibarrPackage=Le fichier doit être un package Dolibarr
ErrorFileRequired=Il faut un fichier de package Dolibarr
ErrorPhpCurlNotInstalled=L'extension PHP CURL n'est pas installée, ceci est indispensable pour dialoguer avec Paypal.
ErrorFailedToAddToMailmanList=Echec de l'ajout à une liste Mailman ou base SPIP
ErrorFailedToAddToMailmanList=Echec de l'ajout de %s à la liste Mailman %s ou base SPIP
ErrorFailedToRemoveToMailmanList=Echec de la suppression de %s de la liste Mailman %s ou base SPIP
ErrorNewValueCantMatchOldValue=La nouvelle valeur ne peut être égale à l'ancienne
ErrorFailedToValidatePasswordReset=Echec de la réinitialisation du mot de passe. Il est possible que ce lien ait déjà été utilisé (l'utilisation de ce lien ne fonctionne qu'une fois). Si ce n'est pas le cas, essayer de recommencer le processus de réinit de mot de passe depuis le début.

View File

@ -23,3 +23,6 @@ DeleteIntoSpip=Supprimer de spip
DeleteIntoSpipConfirmation=Êtes-vous sur de vouloir effacer cet adhérent de SPIP?
DeleteIntoSpipError=Échec de la suppression de l'utilisateur de SPIP
SPIPConnectionFailed=Échec de connexion à SPIP
SuccessToAddToMailmanList=Ajout de %s à la liste Mailman %s ou base SPIP réalisé
SuccessToRemoveToMailmanList=Suppression de %s de la liste Mailman %s ou base SPIP réalisé

View File

@ -40,6 +40,11 @@ class MailmanSpip
var $db;
var $error;
var $mladded_ok;
var $mladded_ko;
var $mlremoved_ok;
var $mlremoved_ko;
/**
* Constructor
@ -299,6 +304,9 @@ class MailmanSpip
dol_syslog(get_class($this)."::add_to_mailman");
$this->mladded_ok=array();
$this->mladded_ko=array();
if (! function_exists("curl_init"))
{
$langs->load("errors");
@ -335,13 +343,15 @@ class MailmanSpip
if ($result === false)
{
$this->mladded_ko[$list]=$object->email;
return -2;
}
else $this->mladded_ok[$list]=$object->email;
}
return count($lists);
}
else
{
{
$this->error="ADHERENT_MAILMAN_URL not defined";
return -1;
}
@ -359,6 +369,18 @@ class MailmanSpip
{
global $conf,$langs,$user;
dol_syslog(get_class($this)."::del_to_mailman");
$this->mlremoved_ok=array();
$this->mlremoved_ko=array();
if (! function_exists("curl_init"))
{
$langs->load("errors");
$this->error=$langs->trans("ErrorFunctionNotAvailableInPHP","curl_init");
return -1;
}
if (! empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL))
{
if ($listes=='' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS))
@ -388,8 +410,10 @@ class MailmanSpip
if ($result === false)
{
$this->mlremoved_ko[$list]=$object->email;
return -2;
}
else $this->mlremoved_ok[$list]=$object->email;
}
return count($lists);
}