From 58c25ff665d0eb6f09772b1732433a6b86e57291 Mon Sep 17 00:00:00 2001
From: Xebax <xebax@wanadoo.fr>
Date: Thu, 16 Jun 2016 22:31:34 +0200
Subject: [PATCH] REST API: fix the error 500 when updating a product.

---
 htdocs/api/class/api.class.php              | 11 +++++++++++
 htdocs/product/class/api_products.class.php |  1 -
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php
index b3a2cdaf9d0..00621fdeb59 100644
--- a/htdocs/api/class/api.class.php
+++ b/htdocs/api/class/api.class.php
@@ -88,6 +88,17 @@ class DolibarrApi
         // Remove $db object property for object
 		unset($object->db);
 
+        // Remove the $oldcopy property because it is not supported by the JSON
+        // encoder. The following error is generated when trying to serialize
+        // it: "Error encoding/decoding JSON: Type is not supported"
+        // Note: Event if this property was correctly handled by the JSON
+        // encoder, it should be ignored because keeping it would let the API
+        // have a very strange behavior: calling PUT and then GET on the same
+        // resource would give different results:
+        // PUT /objects/{id} -> returns object with oldcopy = previous version of the object
+        // GET /objects/{id} -> returns object with oldcopy empty
+        unset($object->oldcopy);
+
         // If object has lines, remove $db property
         if(isset($object->lines) && count($object->lines) > 0)  {
             $nboflines = count($object->lines);
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index b5eb3d6bd87..ce0a812558e 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -275,7 +275,6 @@ class Products extends DolibarrApi
      * @param int   $id             Id of product to update
      * @param array $request_data   Datas   
      * @return int 
-     * FIXME The product is correctluy updated but the API returns an error 500.
      */
     function put($id, $request_data = NULL)
     {
-- 
GitLab