Fix: Uniformize error management
This commit is contained in:
parent
c9d9c25be7
commit
c21aaea1e6
@ -23,7 +23,7 @@
|
|||||||
* \file htdocs/compta/bank/bankid_fr.php
|
* \file htdocs/compta/bank/bankid_fr.php
|
||||||
* \ingroup banque
|
* \ingroup banque
|
||||||
* \brief Fiche creation compte bancaire
|
* \brief Fiche creation compte bancaire
|
||||||
* \version $Id$
|
* \version $Id: bankid_fr.php,v 1.27 2011/07/29 20:47:35 eldy Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
@ -75,7 +75,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$message='<div class="error">'.$account->error().'</div>';
|
$message='<div class="error">'.$account->error.'</div>';
|
||||||
$_GET["action"]='edit'; // Force chargement page edition
|
$_GET["action"]='edit'; // Force chargement page edition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,5 +386,5 @@ if ($_GET["id"] && $_GET["action"] == 'edit' && $user->rights->banque->configure
|
|||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
llxFooter('$Date$ - $Revision$');
|
llxFooter('$Date: 2011/07/29 20:47:35 $ - $Revision: 1.27 $');
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
* \file htdocs/compta/bank/fiche.php
|
* \file htdocs/compta/bank/fiche.php
|
||||||
* \ingroup banque
|
* \ingroup banque
|
||||||
* \brief Page to create/view a bank account
|
* \brief Page to create/view a bank account
|
||||||
* \version $Id$
|
* \version $Id: fiche.php,v 1.77 2011/07/29 20:47:35 eldy Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
@ -99,7 +99,7 @@ if ($_POST["action"] == 'add')
|
|||||||
$_GET["id"]=$id; // Force chargement page en mode visu
|
$_GET["id"]=$id; // Force chargement page en mode visu
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$message='<div class="error">'.$account->error().'</div>';
|
$message='<div class="error">'.$account->error.'</div>';
|
||||||
$action='create'; // Force chargement page en mode creation
|
$action='create'; // Force chargement page en mode creation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$message='<div class="error">'.$account->error().'</div>';
|
$message='<div class="error">'.$account->error.'</div>';
|
||||||
$action='edit'; // Force chargement page edition
|
$action='edit'; // Force chargement page edition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,5 +608,5 @@ else
|
|||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
llxFooter('$Date$ - $Revision$');
|
llxFooter('$Date: 2011/07/29 20:47:35 $ - $Revision: 1.77 $');
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
* \file htdocs/product/class/product.class.php
|
* \file htdocs/product/class/product.class.php
|
||||||
* \ingroup produit
|
* \ingroup produit
|
||||||
* \brief Fichier de la classe des produits predefinis
|
* \brief Fichier de la classe des produits predefinis
|
||||||
* \version $Id: product.class.php,v 1.46 2011/07/29 06:59:36 tiaris Exp $
|
* \version $Id: product.class.php,v 1.47 2011/07/29 20:47:35 eldy Exp $
|
||||||
*/
|
*/
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
|
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
|
||||||
|
|
||||||
@ -192,13 +192,14 @@ class Product extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Insert product into database
|
* Insert product into database
|
||||||
* @param user User making insert
|
* @param user User making insert
|
||||||
* @return int id of product/service if OK or number of error < 0
|
* @param notrigger Disable triggers
|
||||||
|
* @return int Id of product/service if OK or number of error < 0
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user,$notrigger=0)
|
||||||
{
|
{
|
||||||
global $conf ;
|
global $conf, $langs;
|
||||||
|
|
||||||
$this->errno = 0;
|
$error=0;
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
$this->ref = dol_string_nospecial(trim($this->ref));
|
$this->ref = dol_string_nospecial(trim($this->ref));
|
||||||
@ -250,23 +251,27 @@ class Product extends CommonObject
|
|||||||
$this->error='ErrorWrongParameters';
|
$this->error='ErrorWrongParameters';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (empty($this->ref))
|
||||||
|
{
|
||||||
|
$this->error='ErrorWrongParameters';
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
dol_syslog("Product::Create ref=".$this->ref." price=".$this->price." price_ttc=".$this->price_ttc." tva_tx=".$this->tva_tx." price_base_type=".$this->price_base_type." Category : ".$this->catid, LOG_DEBUG);
|
dol_syslog("Product::Create ref=".$this->ref." price=".$this->price." price_ttc=".$this->price_ttc." tva_tx=".$this->tva_tx." price_base_type=".$this->price_base_type." Category : ".$this->catid, LOG_DEBUG);
|
||||||
|
|
||||||
if ($this->ref)
|
|
||||||
{
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "SELECT count(*)";
|
$sql = "SELECT count(*) as nb";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product";
|
||||||
$sql.= " WHERE ref = '" .$this->ref."'";
|
$sql.= " WHERE ref = '" .$this->ref."'";
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
$result = $this->db->query($sql) ;
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_array($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
if ($row[0] == 0)
|
if ($obj->nb == 0)
|
||||||
{
|
{
|
||||||
// Produit non deja existant
|
// Produit non deja existant
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product (";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product (";
|
||||||
@ -281,6 +286,8 @@ class Product extends CommonObject
|
|||||||
$sql.= ", price";
|
$sql.= ", price";
|
||||||
$sql.= ", price_ttc";
|
$sql.= ", price_ttc";
|
||||||
$sql.= ", price_base_type";
|
$sql.= ", price_base_type";
|
||||||
|
$sql.= ", tobuy";
|
||||||
|
$sql.= ", tosell";
|
||||||
$sql.= ", canvas";
|
$sql.= ", canvas";
|
||||||
$sql.= ", finished";
|
$sql.= ", finished";
|
||||||
$sql.= ", hidden";
|
$sql.= ", hidden";
|
||||||
@ -296,6 +303,8 @@ class Product extends CommonObject
|
|||||||
$sql.= ", ".price2num($price_ht);
|
$sql.= ", ".price2num($price_ht);
|
||||||
$sql.= ", ".price2num($price_ttc);
|
$sql.= ", ".price2num($price_ttc);
|
||||||
$sql.= ", '".$this->price_base_type."'";
|
$sql.= ", '".$this->price_base_type."'";
|
||||||
|
$sql.= ", ".$this->status;
|
||||||
|
$sql.= ", ".$this->status_buy;
|
||||||
$sql.= ", '".$this->canvas."'";
|
$sql.= ", '".$this->canvas."'";
|
||||||
$sql.= ", ".$this->finished;
|
$sql.= ", ".$this->finished;
|
||||||
$sql.= ", ".$this->hidden;
|
$sql.= ", ".$this->hidden;
|
||||||
@ -329,42 +338,41 @@ class Product extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->_setErrNo("Create",260,$this->error);
|
$error++;
|
||||||
|
$this->error='ErrorFailedToUpdateRecord';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$error++;
|
||||||
$this->_setErrNo("Create",264,$this->error);
|
$this->error=$this->db->lasterror();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->_setErrNo("Create",259);
|
$error++;
|
||||||
|
$this->error='ErrorFailedToGetInsertedId';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$error++;
|
||||||
$this->_setErrNo("Create",258,$this->error);
|
$this->error=$this->db->lasterror();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Le produit existe deja
|
// Product already exists with this ref
|
||||||
$this->error='ErrorProductAlreadyExists';
|
$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->_setErrNo("Create",263);
|
$error++;
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (! $error && ! $notrigger)
|
||||||
* END COMMIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ($this->errno === 0)
|
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
@ -372,49 +380,19 @@ class Product extends CommonObject
|
|||||||
$result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf);
|
$result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf);
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||||
// Fin appel triggers
|
// Fin appel triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->_setErrNo("Create",262);
|
|
||||||
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Positionne le numero d'erreur
|
|
||||||
* @param func Nom de la fonction
|
|
||||||
* @param num Numero de l'erreur
|
|
||||||
* @param error string
|
|
||||||
*/
|
|
||||||
function _setErrNo($func, $num, $error='')
|
|
||||||
{
|
|
||||||
$this->errno = $num;
|
|
||||||
dol_syslog(get_class($this)."::".$func." - ERRNO(".$this->errno.")".($error?' - '.$error:''), LOG_ERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retourne le texte de l'erreur
|
|
||||||
*/
|
|
||||||
function error()
|
|
||||||
{
|
|
||||||
$errs[257] = "ErrorProductAlreadyExists";
|
|
||||||
$errs[262] = "ErrorProductBadRefOrLabel";
|
|
||||||
|
|
||||||
return $errs[$this->errno];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a record into database
|
* Update a record into database
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
* \file htdocs/product/fiche.php
|
* \file htdocs/product/fiche.php
|
||||||
* \ingroup product
|
* \ingroup product
|
||||||
* \brief Page to show product
|
* \brief Page to show product
|
||||||
* \version $Id$
|
* \version $Id: fiche.php,v 1.373 2011/07/29 20:47:35 eldy Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("../main.inc.php");
|
require("../main.inc.php");
|
||||||
@ -294,6 +294,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->produit->
|
|||||||
{
|
{
|
||||||
$product->ref = GETPOST('clone_ref');
|
$product->ref = GETPOST('clone_ref');
|
||||||
$product->status = 0;
|
$product->status = 0;
|
||||||
|
$product->status_buy = 0;
|
||||||
$product->finished = 1;
|
$product->finished = 1;
|
||||||
$product->id = null;
|
$product->id = null;
|
||||||
|
|
||||||
@ -1645,6 +1646,6 @@ if ($product->id && $action == '' && $product->status)
|
|||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
llxFooter('$Date$ - $Revision$');
|
llxFooter('$Date: 2011/07/29 20:47:35 $ - $Revision: 1.373 $');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
* \files htdocs/societe/class/companybankaccount.class.php
|
* \files htdocs/societe/class/companybankaccount.class.php
|
||||||
* \ingroup societe
|
* \ingroup societe
|
||||||
* \brief File of class to manage bank accounts description of third parties
|
* \brief File of class to manage bank accounts description of third parties
|
||||||
* \version $Id$
|
* \version $Id: companybankaccount.class.php,v 1.10 2011/07/29 20:47:35 eldy Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/compta/bank/class/account.class.php");
|
require_once(DOL_DOCUMENT_ROOT ."/compta/bank/class/account.class.php");
|
||||||
@ -182,15 +182,6 @@ class CompanyBankAccount extends Account
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function error()
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
* \file htdocs/societe/rib.php
|
* \file htdocs/societe/rib.php
|
||||||
* \ingroup societe
|
* \ingroup societe
|
||||||
* \brief BAN tab for companies
|
* \brief BAN tab for companies
|
||||||
* \version $Id$
|
* \version $Id: rib.php,v 1.36 2011/07/29 20:47:34 eldy Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("../main.inc.php");
|
require("../main.inc.php");
|
||||||
@ -73,7 +73,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
|||||||
$result = $account->update($user);
|
$result = $account->update($user);
|
||||||
if (! $result)
|
if (! $result)
|
||||||
{
|
{
|
||||||
$message=$account->error();
|
$message=$account->error;
|
||||||
$_GET["action"]='edit'; // Force chargement page edition
|
$_GET["action"]='edit'; // Force chargement page edition
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -272,5 +272,5 @@ if ($_GET["socid"] && $_GET["action"] == 'edit' && $user->rights->societe->creer
|
|||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
|
|
||||||
llxFooter('$Date$ - $Revision$');
|
llxFooter('$Date: 2011/07/29 20:47:34 $ - $Revision: 1.36 $');
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user