Fix missing transaction in update_perso function

This commit is contained in:
Laurent Destailleur 2016-08-02 16:55:32 +02:00
parent cc21909909
commit 75b909ce93
2 changed files with 35 additions and 7 deletions

View File

@ -474,13 +474,16 @@ class Contact extends CommonObject
* *
* @param int $id Id of contact * @param int $id Id of contact
* @param User $user User asking to change alert or birthday * @param User $user User asking to change alert or birthday
* @param int $notrigger 0=no, 1=yes
* @return int <0 if KO, >=0 if OK * @return int <0 if KO, >=0 if OK
*/ */
function update_perso($id, $user=null) function update_perso($id, $user=null, $notrigger=0)
{ {
$error=0; $error=0;
$result=false; $result=false;
$this->db->begin();
// Mis a jour contact // Mis a jour contact
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
$sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null"); $sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
@ -531,6 +534,26 @@ class Contact extends CommonObject
} }
} }
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('CONTACT_MODIFY',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
$this->db->rollback();
return -$error;
}
return $result; return $result;
} }

View File

@ -135,11 +135,9 @@ $object->fetch($id, $user);
$head = contact_prepare_head($object); $head = contact_prepare_head($object);
dol_fiche_head($head, 'perso', $title, 0, 'contact');
if ($action == 'edit') if ($action == 'edit')
{ {
/* /*
* Fiche en mode edition * Fiche en mode edition
*/ */
@ -148,6 +146,8 @@ if ($action == 'edit')
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
dol_fiche_head($head, 'perso', $title, 0, 'contact');
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref // Ref
@ -213,7 +213,9 @@ if ($action == 'edit')
} }
print '</tr>'; print '</tr>';
print "</table><br>"; print "</table>";
dol_fiche_end();
print '<div class="center">'; print '<div class="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
@ -227,6 +229,8 @@ else
{ {
// View mode // View mode
dol_fiche_head($head, 'perso', $title, 0, 'contact');
$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', ''); dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
@ -285,16 +289,17 @@ else
} }
else else
{ {
print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>"; print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3"></td>';
} }
print "</tr>"; print "</tr>";
print "</table>"; print "</table>";
print '</div>'; print '</div>';
dol_fiche_end();
} }
dol_fiche_end();
if ($action != 'edit') if ($action != 'edit')
{ {