Fix: Missing error management

This commit is contained in:
Laurent Destailleur 2015-02-26 14:25:30 +01:00
parent fe7889e266
commit 4bde7e9f51
20 changed files with 90 additions and 62 deletions

View File

@ -302,6 +302,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
// Check if we need to also synchronize user information // Check if we need to also synchronize user information
$nosyncuser=0; $nosyncuser=0;
@ -471,6 +472,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
// Check parameters // Check parameters
if (empty($morphy) || $morphy == "-1") { if (empty($morphy) || $morphy == "-1") {

View File

@ -89,6 +89,7 @@ if ($action == 'add' && $user->rights->adherent->configurer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$adht); $ret = $extrafields->setOptionalsFromPost($extralabels,$adht);
if ($ret < 0) $error++;
if ($adht->libelle) if ($adht->libelle)
{ {
@ -126,6 +127,7 @@ if ($action == 'update' && $user->rights->adherent->configurer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$adht); $ret = $extrafields->setOptionalsFromPost($extralabels,$adht);
if ($ret < 0) $error++;
$adht->update($user); $adht->update($user);

View File

@ -127,6 +127,7 @@ if ($action == 'add' && $user->rights->categorie->creer)
if ($parent != "-1") $object->fk_parent = $parent; if ($parent != "-1") $object->fk_parent = $parent;
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $object->label) if (! $object->label)
{ {

View File

@ -90,7 +90,8 @@ if ($action == 'update' && $user->rights->categorie->creer)
if (empty($categorie->error)) if (empty($categorie->error))
{ {
$ret = $extrafields->setOptionalsFromPost($extralabels,$categorie); $ret = $extrafields->setOptionalsFromPost($extralabels,$categorie);
if ($ret < 0) $error++;
if ($categorie->update($user) > 0) if ($categorie->update($user) > 0)
{ {
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type); header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type);

View File

@ -274,6 +274,7 @@ if ($action == 'add')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $error) if (! $error)
{ {
@ -429,6 +430,7 @@ if ($action == 'update')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $error) if (! $error)
{ {

View File

@ -1080,10 +1080,10 @@ if (empty($reshook))
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error)
{
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('propaldao')); $hookmanager->initHooks(array('propaldao'));

View File

@ -271,8 +271,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) if (! $error)
{ {
@ -365,10 +364,10 @@ if (empty($reshook))
} else { } else {
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error)
{
$object_id = $object->create($user); $object_id = $object->create($user);
// If some invoice's lines already known // If some invoice's lines already known
@ -1124,8 +1123,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error) {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)

View File

@ -585,7 +585,7 @@ if (empty($reshook))
$discount->fk_facture_source = $object->id; $discount->fk_facture_source = $object->id;
$error = 0; $error = 0;
foreach ($amount_ht as $tva_tx => $xxx) { foreach ($amount_ht as $tva_tx => $xxx) {
$discount->amount_ht = abs($amount_ht [$tva_tx]); $discount->amount_ht = abs($amount_ht [$tva_tx]);
$discount->amount_tva = abs($amount_tva [$tva_tx]); $discount->amount_tva = abs($amount_tva [$tva_tx]);
@ -636,7 +636,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error ++; if ($ret < 0) $error++;
// Replacement invoice // Replacement invoice
if ($_POST['type'] == Facture::TYPE_REPLACEMENT) if ($_POST['type'] == Facture::TYPE_REPLACEMENT)
@ -1676,8 +1676,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error) {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)

View File

@ -200,6 +200,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! GETPOST("lastname")) if (! GETPOST("lastname"))
{ {
@ -303,6 +304,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$result = $object->update($contactid, $user); $result = $object->update($contactid, $user);

View File

@ -355,6 +355,7 @@ if ($action == 'add' && $user->rights->contrat->creer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error++;
$result = $object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0)
@ -702,19 +703,20 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error)
{
$result = $object->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
else if ($reshook < 0) $error++;
$result = $object->insertExtraFields(); if ($error)
if ($result < 0) { {
$error ++;
}
} else if ($reshook < 0)
$error ++;
if ($error) {
$action = 'edit_extras'; $action = 'edit_extras';
setEventMessage($object->error,'errors'); setEventMessage($object->error,'errors');
} }

View File

@ -1063,7 +1063,7 @@ class ExtraFields
* @param array $extralabels $array of extrafields * @param array $extralabels $array of extrafields
* @param object $object Object * @param object $object Object
* @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset.
* @return int 1 if array_options set / 0 if no value * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example)
*/ */
function setOptionalsFromPost($extralabels,&$object,$onlykey='') function setOptionalsFromPost($extralabels,&$object,$onlykey='')
{ {

View File

@ -783,7 +783,7 @@ if ($action == 'update_extras')
$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if ($ret < 0) $error++; if ($ret < 0) $error++;
if (!$error) if (! $error)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
@ -842,19 +842,26 @@ if ($action == 'add' && $user->rights->fournisseur->commande->creer)
$object->date_livraison = $datelivraison; $object->date_livraison = $datelivraison;
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); if (! $error)
{
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
}
$id = $object->create($user); if (! $error)
if ($id < 0) {
{ $id = $object->create($user);
$error++; if ($id < 0)
} {
$error++;
setEventMessage($langs->trans($object->error), 'errors');
}
}
if ($error) if ($error)
{ {
$langs->load("errors"); $langs->load("errors");
$db->rollback(); $db->rollback();
setEventMessage($langs->trans($object->error), 'errors');
$action='create'; $action='create';
$_GET['socid']=$_POST['socid']; $_GET['socid']=$_POST['socid'];
} }

View File

@ -308,7 +308,7 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error ++; if ($ret < 0) $error++;
$tmpproject = GETPOST('projectid', 'int'); $tmpproject = GETPOST('projectid', 'int');
@ -1071,8 +1071,7 @@ elseif ($action == 'update_extras')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if ($ret < 0) $error++;
if($ret < 0) $error++;
if (!$error) if (!$error)
{ {

View File

@ -262,8 +262,12 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$id = $object->create($user); if (! $error)
{
$id = $object->create($user);
}
if ($id > 0) if ($id > 0)
{ {
@ -339,8 +343,9 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if ($object->check()) if (! $error && $object->check())
{ {
if ($object->update($object->id, $user) > 0) if ($object->update($object->id, $user) > 0)
{ {

View File

@ -147,6 +147,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$result = $object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0)
@ -222,10 +223,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) if ($ret < 0) $error++;
{
$error++;
}
} }
if (! $error) if (! $error)

View File

@ -91,12 +91,15 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$result=$object->update($user); if (! $error)
if ($result < 0)
{ {
setEventMessages($object->error,$object->errors,'errors'); $result=$object->update($user);
if ($result < 0)
{
setEventMessages($object->error,$object->errors,'errors');
}
} }
} }
else else

View File

@ -250,6 +250,7 @@ if ($action == 'add')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($adh->table_element); $extralabels=$extrafields->fetch_name_optionals_label($adh->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$adh); $ret = $extrafields->setOptionalsFromPost($extralabels,$adh);
if ($ret < 0) $error++;
$result=$adh->create($user); $result=$adh->create($user);
if ($result > 0) if ($result > 0)

View File

@ -195,7 +195,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (GETPOST('deletephoto')) $object->logo = ''; if (GETPOST('deletephoto')) $object->logo = '';
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);

View File

@ -211,6 +211,7 @@ if ($action == 'add' && $canadduser)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
// If multicompany is off, admin users must all be on entity 0. // If multicompany is off, admin users must all be on entity 0.
$entity=GETPOST('entity','int'); $entity=GETPOST('entity','int');
@ -358,6 +359,7 @@ if ($action == 'update' && ! $_POST["cancel"])
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! empty($conf->multicompany->enabled)) if (! empty($conf->multicompany->enabled))
{ {
@ -382,20 +384,22 @@ if ($action == 'update' && ! $_POST["cancel"])
if (GETPOST('deletephoto')) $object->photo=''; if (GETPOST('deletephoto')) $object->photo='';
if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
$ret=$object->update($user); if (! $error)
if ($ret < 0)
{ {
$error++; $ret=$object->update($user);
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') if ($ret < 0)
{ {
$langs->load("errors"); $error++;
setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors'); if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
} {
else $langs->load("errors");
{ setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors');
setEventMessage($object->error, 'errors'); }
} else
{
setEventMessage($object->error, 'errors');
}
}
} }
if (! $error && isset($_POST['contactid'])) if (! $error && isset($_POST['contactid']))

View File

@ -101,6 +101,7 @@ if ($action == 'add')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0;
else $object->entity = $_POST["entity"]; else $object->entity = $_POST["entity"];
@ -183,6 +184,7 @@ if ($action == 'update')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0;
else $object->entity = $_POST["entity"]; else $object->entity = $_POST["entity"];