Skip to content

Commit

Permalink
FIX: PUT /thirdparties/{id} and PUT /contacts/{id} should throw excep…
Browse files Browse the repository at this point in the history
…tion if update returns < 0 (#29596)

+ FIX some PHPDoc (types and throws)
+ FIX issue #29594: trigger should be called on contact update by API
  • Loading branch information
atm-florianm authored May 3, 2024
1 parent 8474360 commit cf6cbaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 10 additions & 7 deletions htdocs/societe/class/api_contacts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct()
* @param int $id ID of contact
* @param int $includecount Count and return also number of elements the contact is used as a link for
* @param int $includeroles Includes roles of the contact
* @return array|mixed data without useless information
* @return object data without useless information
*
* @throws RestException
*/
Expand Down Expand Up @@ -304,9 +304,12 @@ public function post($request_data = null)
/**
* Update contact
*
* @param int $id Id of contact to update
* @param array $request_data Datas
* @return int
* @param int $id Id of contact to update
* @param array $request_data Datas
* @return object Representation of the Contact
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500
*/
public function put($id, $request_data = null)
{
Expand Down Expand Up @@ -334,11 +337,11 @@ public function put($id, $request_data = null)
$this->contact->setNoEmail($this->contact->no_email);
}

if ($this->contact->update($id, DolibarrApiAccess::$user, 1, 'update')) {
if ($this->contact->update($id, DolibarrApiAccess::$user, 0, 'update') > 0) {
return $this->get($id);
} else {
throw new RestException(500, $this->contact->error);
}

return false;
}

/**
Expand Down
17 changes: 10 additions & 7 deletions htdocs/societe/class/api_thirdparties.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct()
* Return an array with thirdparty informations
*
* @param int $id Id of third party to load
* @return array|mixed Cleaned Societe object
* @return object Cleaned Societe object
*
* @throws RestException
*/
Expand Down Expand Up @@ -277,7 +277,10 @@ public function post($request_data = null)
*
* @param int $id Id of thirdparty to update
* @param array $request_data Datas
* @return array|mixed|boolean
* @return object
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500
*/
public function put($id, $request_data = null)
{
Expand Down Expand Up @@ -305,11 +308,11 @@ public function put($id, $request_data = null)
$this->company->setNoEmail($this->company->no_email);
}

if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update', 1)) {
if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update', 1) > 0) {
return $this->get($id);
} else {
throw new RestException(500, $this->company->error);
}

return false;
}

/**
Expand Down Expand Up @@ -1790,7 +1793,7 @@ public function deleteSocieteAccounts($id)
* Clean sensible object datas
*
* @param Object $object Object to clean
* @return array|mixed Object with cleaned properties
* @return object Object with cleaned properties
*/
protected function _cleanObjectDatas($object)
{
Expand Down Expand Up @@ -1873,7 +1876,7 @@ private function _validate($data)
* @param string $idprof6 Prof id 6 of third party (Warning, this can return several records)
* @param string $email Email of third party (Warning, this can return several records)
* @param string $ref_alias Name_alias of third party (Warning, this can return several records)
* @return array|mixed cleaned Societe object
* @return object cleaned Societe object
*
* @throws RestException
*/
Expand Down

0 comments on commit cf6cbaf

Please sign in to comment.