FIX Bad error management into trigger of mailmanspip

This commit is contained in:
Laurent Destailleur 2016-06-25 18:48:50 +02:00
parent a8ba8e612a
commit f021a8ca31
6 changed files with 25 additions and 21 deletions

View File

@ -404,11 +404,7 @@ if (empty($reshook))
}
else
{
if ($object->error) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}

View File

@ -509,7 +509,7 @@ class Adherent extends CommonObject
if (! $error && $nbrowsaffected) // If something has change in main data
{
// Update information on linked user if it is an update
if ($this->user_id > 0 && ! $nosyncuser)
if (! $error && $this->user_id > 0 && ! $nosyncuser)
{
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
@ -552,7 +552,7 @@ class Adherent extends CommonObject
}
// Update information on linked thirdparty if it is an update
if ($this->fk_soc > 0 && ! $nosyncthirdparty)
if (! $error && $this->fk_soc > 0 && ! $nosyncthirdparty)
{
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
@ -1423,9 +1423,10 @@ class Adherent extends CommonObject
$err=0;
// mailman
if (! empty($conf->global->ADHERENT_USE_MAILMAN))
if (! empty($conf->global->ADHERENT_USE_MAILMAN) && ! empty($conf->mailmanspip->enabled))
{
$result=$mailmanspip->add_to_mailman($this);
if ($result < 0)
{
if (! empty($mailmanspip->error)) $this->errors[]=$mailmanspip->error;
@ -1444,7 +1445,7 @@ class Adherent extends CommonObject
}
// spip
if ($conf->global->ADHERENT_USE_SPIP && ! empty($conf->mailmanspip->enabled))
if (! empty($conf->global->ADHERENT_USE_SPIP) && ! empty($conf->mailmanspip->enabled))
{
$result=$mailmanspip->add_to_spip($this);
if ($result < 0)
@ -1458,7 +1459,7 @@ class Adherent extends CommonObject
return -$err;
}
else
{
{
return 1;
}
}

View File

@ -3998,14 +3998,13 @@ abstract class CommonObject
{
if (!empty($this->errors))
{
$this->errors=array_merge($this->errors,$interface->errors);
$this->errors=array_unique(array_merge($this->errors,$interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice.
}
else
{
$this->errors=$interface->errors;
}
}
return $result;
}

View File

@ -191,10 +191,12 @@ class Interfaces
if ($result < 0)
{
// Action KO
//dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($objMod->errors), LOG_ERR);
$nbtotal++;
$nbko++;
if (! empty($objMod->errors)) $this->errors=array_merge($this->errors,$objMod->errors);
else if (! empty($objMod->error)) $this->errors[]=$objMod->error;
//dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($this->errors), LOG_ERR);
}
}
else
@ -205,7 +207,7 @@ class Interfaces
if ($nbko)
{
dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR);
dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko." - Nb of error string returned in this->errors = ".count($this->errors), LOG_ERR);
return -$nbko;
}
else

View File

@ -54,6 +54,7 @@ $mode = GETPOST('mode','alpha');
$confirm = GETPOST('confirm','alpha');
$subaction = GETPOST('subaction','alpha');
$group = GETPOST("group","int",3);
$cancel = GETPOST('cancel');
// Define value to know what current user can do on users
$canadduser=(! empty($user->admin) || $user->rights->user->user->creer);
@ -299,7 +300,8 @@ if (empty($reshook)) {
}
}
if ($action == 'update' && !$_POST["cancel"]) {
if ($action == 'update' && ! $cancel)
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if ($caneditfield) // Case we can edit all field
@ -395,7 +397,7 @@ if (empty($reshook)) {
if (!$error) {
$ret = $object->update($user);
if ($ret < 0) {
$error ++;
$error++;
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
setEventMessages($langs->trans("ErrorLoginAlreadyExists", $object->login), null, 'errors');

View File

@ -1332,14 +1332,14 @@ class User extends CommonObject
// If user is linked to a member, remove old link to this member
if ($this->fk_member > 0)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->fk_member;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
dol_syslog(get_class($this)."::update remove link with member. We will recreate it later", LOG_DEBUG);
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->fk_member;
$resql = $this->db->query($sql);
if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
}
// Set link to user
dol_syslog(get_class($this)."::update set link with member", LOG_DEBUG);
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member =".($this->fk_member>0?$this->fk_member:'null')." where rowid = ".$this->id;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
@ -1347,6 +1347,8 @@ class User extends CommonObject
{
if ($this->fk_member > 0 && ! $nosyncmember)
{
dol_syslog(get_class($this)."::update user is linked with a member. We try to update member too.", LOG_DEBUG);
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
// This user is linked with a member, so we also update members informations
@ -1374,16 +1376,18 @@ class User extends CommonObject
$adh->user_login=$this->login;
$result=$adh->update($user,0,1);
if ($result < 0)
if ($result < 0)
{
$this->error=$luser->error;
dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
$this->error=$adh->error;
$this->errors=$adh->errors;
dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR);
$error++;
}
}
else
{
$this->error=$adh->error;
$this->errors=$adh->errors;
$error++;
}
}