diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 8308c71fac0..51ef1153a57 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -383,14 +383,18 @@ class Members extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if (!$member->delete($member->id, DolibarrApiAccess::$user)) { - throw new RestException(401, 'error when deleting member'); + + $res = $member->delete($member->id, DolibarrApiAccess::$user); + if ($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + } elseif ($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); } return array( 'success' => array( 'code' => 200, - 'message' => 'member deleted' + 'message' => 'Member deleted' ) ); } diff --git a/htdocs/adherents/class/api_memberstypes.class.php b/htdocs/adherents/class/api_memberstypes.class.php index d95de755166..95c514bfedf 100644 --- a/htdocs/adherents/class/api_memberstypes.class.php +++ b/htdocs/adherents/class/api_memberstypes.class.php @@ -229,14 +229,17 @@ class MembersTypes extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if (!$membertype->delete()) { - throw new RestException(401, 'error when deleting member type'); + $res = $membertype->delete(); + if ($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + } elseif ($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); } return array( 'success' => array( 'code' => 200, - 'message' => 'member type deleted' + 'message' => 'Member type deleted' ) ); } diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php index 0512ea46b20..67484a723fd 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -215,14 +215,17 @@ class Subscriptions extends DolibarrApi throw new RestException(404, 'Subscription not found'); } - if (!$subscription->delete(DolibarrApiAccess::$user)) { - throw new RestException(401, 'error when deleting subscription'); + $res = $subscription->delete(DolibarrApiAccess::$user); + if ($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + } elseif ($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); } return array( 'success' => array( 'code' => 200, - 'message' => 'subscription deleted' + 'message' => 'Subscription deleted' ) ); } diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 2c7653c3bb3..5cf5d7288c3 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -506,6 +506,9 @@ class Documents extends DolibarrApi throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); } + $objectType = $modulepart; + if (! empty($object->id) && ! empty($object->table_element)) $objectType = $object->table_element; + $filearray = dol_dir_list($upload_dir, $type, $recursive, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); if (empty($filearray)) { throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(!empty($object->ref) ? ' or Ref '.$object->ref : '').' does not return any document.'); @@ -513,11 +516,14 @@ class Documents extends DolibarrApi if (($object->id) > 0 && !empty($modulepart)) { require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile = new EcmFiles($this->db); - $result = $ecmfile->fetchAll('', '', 0, 0, array('t.src_object_type' => $modulepart, 't.src_object_id' => $object->id)); + $result = $ecmfile->fetchAll('', '', 0, 0, array('t.src_object_type' => $objectType, 't.src_object_id' => $object->id)); if ($result < 0) { throw new RestException(503, 'Error when retrieve ecm list : '.$this->db->lasterror()); } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) { - $filearray['ecmfiles_infos'] = $ecmfile->lines; + $count = count($filearray); + for ($i = 0 ; $i < $count ; $i++) { + if ($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) $filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]); + } } } } diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 532140481ab..3a586dfc3e5 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -1024,7 +1024,7 @@ class FactureRec extends CommonInvoice if ($this->db->query($sql)) { $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec"); $this->id = $facid; - $this->update_price(); + $this->update_price(1); return $lineId; } else { $this->error = $this->db->lasterror(); @@ -1198,7 +1198,7 @@ class FactureRec extends CommonInvoice dol_syslog(get_class($this)."::updateline", LOG_DEBUG); if ($this->db->query($sql)) { $this->id = $facid; - $this->update_price(); + $this->update_price(1); return 1; } else { $this->error = $this->db->lasterror(); diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index ad1a3b9934a..73fc15e6911 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -638,7 +638,7 @@ class Delivery extends CommonObject $sql .= " WHERE rowid = ".((int) $lineid); if ($this->db->query($sql)) { - $this->update_price(); + $this->update_price(1); return 1; } else { diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index a1afcef74a2..ecb1cf3d65b 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -367,7 +367,7 @@ class ExpenseReport extends CommonObject } if (!$error) { - $result = $this->update_price(); + $result = $this->update_price(1); if ($result > 0) { if (!$notrigger) { // Call trigger @@ -1858,7 +1858,7 @@ class ExpenseReport extends CommonObject $result = $this->line->insert(0, true); if ($result > 0) { - $result = $this->update_price(); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + $result = $this->update_price(1); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. if ($result > 0) { $this->db->commit(); return $this->line->id; @@ -2217,7 +2217,7 @@ class ExpenseReport extends CommonObject return -1; } - $this->update_price(); + $this->update_price(1); $this->db->commit(); @@ -2896,7 +2896,7 @@ class ExpenseReportLine extends CommonObjectLine if (!$fromaddline) { $tmpparent = new ExpenseReport($this->db); $tmpparent->fetch($this->fk_expensereport); - $result = $tmpparent->update_price(); + $result = $tmpparent->update_price(1); if ($result < 0) { $error++; $this->error = $tmpparent->error; @@ -3023,7 +3023,7 @@ class ExpenseReportLine extends CommonObjectLine $tmpparent = new ExpenseReport($this->db); $result = $tmpparent->fetch($this->fk_expensereport); if ($result > 0) { - $result = $tmpparent->update_price(); + $result = $tmpparent->update_price(1); if ($result < 0) { $error++; $this->error = $tmpparent->error; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3e58ceddfce..aed73da97ba 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2138,7 +2138,7 @@ class CommandeFournisseur extends CommonOrder } if ($line->delete($notrigger) > 0) { - $this->update_price(); + $this->update_price(1); return 1; } else { $this->error = $line->error; @@ -2641,7 +2641,7 @@ class CommandeFournisseur extends CommonOrder $sql .= ", ".price2num($comclient->lines[$i]->qty, 'MS').", ".price2num($comclient->lines[$i]->tva_tx, 5).", ".price2num($comclient->lines[$i]->localtax1_tx, 5).", ".price2num($comclient->lines[$i]->localtax2_tx, 5).", ".price2num($comclient->lines[$i]->remise_percent, 3); $sql .= ", '".price2num($comclient->lines[$i]->subprice, 'MT')."','0', '".$this->db->escape($ref)."');"; if ($this->db->query($sql)) { - $this->update_price(); + $this->update_price(1); } } @@ -2894,7 +2894,7 @@ class CommandeFournisseur extends CommonOrder // Mise a jour info denormalisees au niveau facture if ($result >= 0) { - $this->update_price('', 'auto'); + $this->update_price('1', 'auto'); $this->db->commit(); return $result; } else { diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 3f7013fec34..2f607ad75cf 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -809,7 +809,7 @@ class FactureFournisseur extends CommonInvoice // Update total price - $result = $this->update_price(); + $result = $this->update_price(1); if ($result > 0) { // Actions on extra fields if (!$error) { @@ -2425,7 +2425,7 @@ class FactureFournisseur extends CommonInvoice $this->errors[] = $line->error; } else { // Update total price into invoice record - $res = $this->update_price('', 'auto', 0, $this->thirdparty); + $res = $this->update_price('1', 'auto', 0, $this->thirdparty); } return $res; @@ -2472,7 +2472,7 @@ class FactureFournisseur extends CommonInvoice $this->db->rollback(); return -3; } else { - $res = $this->update_price(); + $res = $this->update_price(1); if ($res > 0) { $this->db->commit(); diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index e234f4dba8e..76ee11f727e 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -454,7 +454,19 @@ class Products extends DolibarrApi global $user; $user = DolibarrApiAccess::$user; - return $this->product->delete(DolibarrApiAccess::$user); + $res = $this->product->delete(DolibarrApiAccess::$user); + if ($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + } elseif ($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Object deleted' + ) + ); } /** diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index f68122bdfff..db7eec3096e 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -538,7 +538,20 @@ class Thirdparties extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } $this->company->oldcopy = clone $this->company; - return $this->company->delete($id); + + $res = $this->company->delete($id); + if ($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + } elseif ($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Object deleted' + ) + ); } /** diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index e18c78e6ced..747d4ab3286 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -640,7 +640,17 @@ class Users extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } $this->useraccount->oldcopy = clone $this->useraccount; - return $this->useraccount->delete(DolibarrApiAccess::$user); + + if (!$this->useraccount->delete(DolibarrApiAccess::$user)) { + throw new RestException(500); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Ticket deleted' + ) + ); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore