From ca95bd67f881598872d8f900a29b7a8208bf7099 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Oct 2013 02:23:25 +0200 Subject: [PATCH] Qual: control of delete usage --- htdocs/product/class/product.class.php | 20 +++++++++++++++----- htdocs/product/class/service.class.php | 5 ++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 1ac8d9cbfd5..61f1c199d8c 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2007-2011 Jean Heimburger @@ -457,7 +457,7 @@ class Product extends CommonObject if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; if (empty($this->status)) $this->status = 0; if (empty($this->status_buy)) $this->status_buy = 0; - + if (empty($this->country_id)) $this->country_id = 0; $this->accountancy_code_buy = trim($this->accountancy_code_buy); @@ -588,15 +588,25 @@ class Product extends CommonObject /** * Delete a product from database (if not used) * - * @param int $id Product id + * @param int $id Product id (usage of this is deprecated, delete should be called without parameters on a fetched object) * @return int < 0 if KO, 0 = Not possible, > 0 if OK */ - function delete($id) + function delete($id=0) { global $conf,$user,$langs; $error=0; + // Clean parameters + if (empty($id)) $id=$this->id; + else $this->fetch($id); + + // Check parameters + if (empty($id)) + { + $this->error = "Object must be fetched before calling delete"; + return -1; + } if (($this->type == 0 && empty($user->rights->produit->supprimer)) || ($this->type == 1 && empty($user->rights->service->supprimer))) { $this->error = "ErrorForbidden"; @@ -904,7 +914,7 @@ class Product extends CommonObject function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0) { $result = 0; - + // We do select by searching with qty and prodfournprice $sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity,"; $sql.= " pfp.fk_product, pfp.ref_fourn, pfp.fk_soc, pfp.tva_tx"; diff --git a/htdocs/product/class/service.class.php b/htdocs/product/class/service.class.php index b3f96434a73..b67699a7f2a 100644 --- a/htdocs/product/class/service.class.php +++ b/htdocs/product/class/service.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2013 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,8 +25,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; /** - * \class Service - * \brief Classe permettant la gestion des services predefinis + * Class to manage predefined services */ class Service extends CommonObject {