Merge pull request #12608 from frederic34/patch-19
$id parameter was removed long time ago
This commit is contained in:
commit
37cee5840a
@ -1122,31 +1122,19 @@ class Product extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Delete a product from database (if not used)
|
* Delete a product from database (if not used)
|
||||||
*
|
*
|
||||||
* @param User $user Product id (usage of this is deprecated, delete should be called without parameters on a fetched object)
|
* @param User $user User (object) deleting product
|
||||||
* @param int $notrigger Do not execute trigger
|
* @param int $notrigger Do not execute trigger
|
||||||
* @return int < 0 if KO, 0 = Not possible, > 0 if OK
|
* @return int < 0 if KO, 0 = Not possible, > 0 if OK
|
||||||
*/
|
*/
|
||||||
public function delete(User $user, $notrigger = 0)
|
public function delete(User $user, $notrigger = 0)
|
||||||
{
|
{
|
||||||
// Deprecation warning
|
|
||||||
if ($id > 0) {
|
|
||||||
dol_syslog(__METHOD__." with parameter is deprecated", LOG_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
// Clean parameters
|
|
||||||
if (empty($id)) {
|
|
||||||
$id = $this->id;
|
|
||||||
} else {
|
|
||||||
$this->fetch($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (empty($id)) {
|
if (empty($this->id)) {
|
||||||
$this->error = "Object must be fetched before calling delete";
|
$this->error = "Object must be fetched before calling delete";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1155,14 +1143,15 @@ class Product extends CommonObject
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$objectisused = $this->isObjectUsed($id);
|
$objectisused = $this->isObjectUsed($this->id);
|
||||||
if (empty($objectisused)) {
|
if (empty($objectisused)) {
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if (!$error && empty($notrigger)) {
|
if (!$error && empty($notrigger)) {
|
||||||
// Call trigger
|
// Call trigger
|
||||||
$result = $this->call_trigger('PRODUCT_DELETE', $user);
|
$result = $this->call_trigger('PRODUCT_DELETE', $user);
|
||||||
if ($result < 0) { $error++;
|
if ($result < 0) {
|
||||||
|
$error++;
|
||||||
}
|
}
|
||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
@ -1172,7 +1161,7 @@ class Product extends CommonObject
|
|||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch';
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch';
|
||||||
$sql .= " WHERE fk_product_stock IN (";
|
$sql .= " WHERE fk_product_stock IN (";
|
||||||
$sql .= "SELECT rowid FROM ".MAIN_DB_PREFIX.'product_stock';
|
$sql .= "SELECT rowid FROM ".MAIN_DB_PREFIX.'product_stock';
|
||||||
$sql .= " WHERE fk_product = ".$id.")";
|
$sql .= " WHERE fk_product = ".(int) $this->id.")";
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -1188,7 +1177,7 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
|
||||||
$sql .= " WHERE fk_product = ".$id;
|
$sql .= " WHERE fk_product = ".(int) $this->id;
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -1206,7 +1195,7 @@ class Product extends CommonObject
|
|||||||
//If it is a parent product, then we remove the association with child products
|
//If it is a parent product, then we remove the association with child products
|
||||||
$prodcomb = new ProductCombination($this->db);
|
$prodcomb = new ProductCombination($this->db);
|
||||||
|
|
||||||
if ($prodcomb->deleteByFkProductParent($user, $id) < 0) {
|
if ($prodcomb->deleteByFkProductParent($user, $this->id) < 0) {
|
||||||
$error++;
|
$error++;
|
||||||
$this->errors[] = 'Error deleting combinations';
|
$this->errors[] = 'Error deleting combinations';
|
||||||
}
|
}
|
||||||
@ -1221,7 +1210,7 @@ class Product extends CommonObject
|
|||||||
// Delete from product_association
|
// Delete from product_association
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
|
||||||
$sql .= " WHERE fk_product_pere = ".$id." OR fk_product_fils = ".$id;
|
$sql .= " WHERE fk_product_pere = ".(int) $this->id." OR fk_product_fils = ".(int) $this->id;
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -1233,7 +1222,7 @@ class Product extends CommonObject
|
|||||||
// Delete product
|
// Delete product
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product";
|
$sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product";
|
||||||
$sqlz .= " WHERE rowid = ".$id;
|
$sqlz .= " WHERE rowid = ".(int) $this->id;
|
||||||
|
|
||||||
$resultz = $this->db->query($sqlz);
|
$resultz = $this->db->query($sqlz);
|
||||||
if (!$resultz) {
|
if (!$resultz) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user