From f3e689f841c4b1a0a62779e32866d18d41f347a8 Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Sat, 26 Nov 2022 00:02:17 +0100 Subject: [PATCH 1/6] FIX : Documents API inconsistency --- htdocs/api/class/api_documents.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 3b6e89c6643..ba9035a1fbe 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -462,6 +462,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.'); @@ -469,11 +472,13 @@ 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; + for($i = 0 ; $i < count($filearray) ; $i++) { + if($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) $filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]); + } } } } From a0553c6e5253e589fbf538c5cd678548b8534620 Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Sat, 26 Nov 2022 00:35:08 +0100 Subject: [PATCH 2/6] FIX : Stickler --- htdocs/api/class/api_documents.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index ba9035a1fbe..88c5ecd604c 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -463,7 +463,7 @@ class Documents extends DolibarrApi } $objectType = $modulepart; - if(! empty($object->id) && ! empty($object->table_element)) $objectType = $object->table_element; + 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)) { @@ -476,8 +476,8 @@ class Documents extends DolibarrApi if ($result < 0) { throw new RestException(503, 'Error when retrieve ecm list : ' . $this->db->lasterror()); } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) { - for($i = 0 ; $i < count($filearray) ; $i++) { - if($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) $filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]); + for ($i = 0 ; $i < count($filearray); $i++) { + if ($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) $filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]); } } } From e767c9b4a98427ead0204d2933d6391f934b8cf0 Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Sat, 26 Nov 2022 00:42:50 +0100 Subject: [PATCH 3/6] FIX : Stickler --- htdocs/api/class/api_documents.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 88c5ecd604c..197ca42469d 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -476,7 +476,8 @@ class Documents extends DolibarrApi if ($result < 0) { throw new RestException(503, 'Error when retrieve ecm list : ' . $this->db->lasterror()); } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) { - for ($i = 0 ; $i < count($filearray); $i++) { + $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]); } } From 616e2b79efb0381377190ccdd1fe9dfee48cd876 Mon Sep 17 00:00:00 2001 From: Eric Seigne Date: Sat, 26 Nov 2022 00:50:45 +0100 Subject: [PATCH 4/6] fix #22766: better API response HTTP code --- htdocs/adherents/class/api_members.class.php | 10 +++++++--- .../adherents/class/api_memberstypes.class.php | 9 ++++++--- .../adherents/class/api_subscriptions.class.php | 9 ++++++--- htdocs/product/class/api_products.class.php | 14 +++++++++++++- htdocs/societe/class/api_thirdparties.class.php | 17 ++++++++++++++++- htdocs/user/class/api_users.class.php | 13 ++++++++++++- 6 files changed, 60 insertions(+), 12 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index d57a01510d4..f5efbd8582e 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -382,14 +382,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 b02a81dc5c9..a4ce0ddf1f4 100644 --- a/htdocs/adherents/class/api_memberstypes.class.php +++ b/htdocs/adherents/class/api_memberstypes.class.php @@ -228,14 +228,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 831be2882f1..1cada6c7f3e 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -214,14 +214,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/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 6283b692a28..b3dd2c019df 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -435,7 +435,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 0257b692b62..4646175878c 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -525,7 +525,22 @@ 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 e0cbd849092..83cd88f8ade 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -628,7 +628,18 @@ 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 From 3fd81293a389cb8e0ad2fa3a98ac624da8b43424 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 25 Nov 2022 23:57:35 +0000 Subject: [PATCH 5/6] Fixing style errors. --- htdocs/adherents/class/api_members.class.php | 4 ++-- htdocs/adherents/class/api_memberstypes.class.php | 4 ++-- htdocs/adherents/class/api_subscriptions.class.php | 4 ++-- htdocs/product/class/api_products.class.php | 4 ++-- htdocs/societe/class/api_thirdparties.class.php | 6 ++---- htdocs/user/class/api_users.class.php | 1 - 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index f5efbd8582e..9038ada74d3 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -384,9 +384,9 @@ class Members extends DolibarrApi $res = $member->delete($member->id, DolibarrApiAccess::$user); - if($res < 0) { + if ($res < 0) { throw new RestException(500, "Can't delete, error occurs"); - }elseif($res == 0) { + } elseif ($res == 0) { throw new RestException(409, "Can't delete, that product is probably used"); } diff --git a/htdocs/adherents/class/api_memberstypes.class.php b/htdocs/adherents/class/api_memberstypes.class.php index a4ce0ddf1f4..eb561ff6c60 100644 --- a/htdocs/adherents/class/api_memberstypes.class.php +++ b/htdocs/adherents/class/api_memberstypes.class.php @@ -229,9 +229,9 @@ class MembersTypes extends DolibarrApi } $res = $membertype->delete(); - if($res < 0) { + if ($res < 0) { throw new RestException(500, "Can't delete, error occurs"); - }elseif($res == 0) { + } elseif ($res == 0) { throw new RestException(409, "Can't delete, that product is probably used"); } diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php index 1cada6c7f3e..b3871cb08d6 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -215,9 +215,9 @@ class Subscriptions extends DolibarrApi } $res = $subscription->delete(DolibarrApiAccess::$user); - if($res < 0) { + if ($res < 0) { throw new RestException(500, "Can't delete, error occurs"); - }elseif($res == 0) { + } elseif ($res == 0) { throw new RestException(409, "Can't delete, that product is probably used"); } diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index b3dd2c019df..445387fb2b5 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -436,9 +436,9 @@ class Products extends DolibarrApi $user = DolibarrApiAccess::$user; $res = $this->product->delete(DolibarrApiAccess::$user); - if($res < 0) { + if ($res < 0) { throw new RestException(500, "Can't delete, error occurs"); - }elseif($res == 0) { + } elseif ($res == 0) { throw new RestException(409, "Can't delete, that product is probably used"); } diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 4646175878c..27da78e9456 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -527,9 +527,9 @@ class Thirdparties extends DolibarrApi $this->company->oldcopy = clone $this->company; $res = $this->company->delete($id); - if($res < 0) { + if ($res < 0) { throw new RestException(500, "Can't delete, error occurs"); - }elseif($res == 0) { + } elseif ($res == 0) { throw new RestException(409, "Can't delete, that product is probably used"); } @@ -539,8 +539,6 @@ class Thirdparties extends DolibarrApi 'message' => 'Object deleted' ) ); - - } /** diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index 83cd88f8ade..0acfe30d279 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -639,7 +639,6 @@ class Users extends DolibarrApi 'message' => 'Ticket deleted' ) ); - } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore From a4ac90a316b897661bfd58178658a8d3367af0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Courtier?= Date: Thu, 1 Dec 2022 15:15:31 +0100 Subject: [PATCH 6/6] FIX: PGSQL Int type does not have a free lenght --- htdocs/core/db/pgsql.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 543e24a1b12..3f8be6b6ad3 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1182,7 +1182,7 @@ class DoliDBPgsql extends DoliDB // phpcs:enable $sql = "ALTER TABLE ".$table; $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; - if (in_array($field_desc['type'], array('double', 'tinyint', 'int', 'varchar')) && $field_desc['value']) { + if (in_array($field_desc['type'], array('double', 'varchar')) && $field_desc['value']) { $sql .= "(".$field_desc['value'].")"; }