From cad573f2c9f0b0b29d91e91ddfdb35893bd51fb2 Mon Sep 17 00:00:00 2001
From: Laurent Giovannoni <laurent.giovannoni@maarch.org>
Date: Fri, 19 May 2017 12:09:46 +0200
Subject: [PATCH] FEAT #5549 simple_attachment type on WS

---
 core/class/resources_controler.php | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/core/class/resources_controler.php b/core/class/resources_controler.php
index 453a4ac6ace..610172838ab 100755
--- a/core/class/resources_controler.php
+++ b/core/class/resources_controler.php
@@ -115,7 +115,8 @@ class resources_controler
                 $data, 
                 $storeResult['docserver_id'],
                 $status,
-                $fileFormat
+                $fileFormat,
+                $table
             );
             unlink($Fnm);
             //var_dump($data);exit;
@@ -156,7 +157,7 @@ class resources_controler
         }
     }
 
-    private function prepareStorage($data, $docserverId, $status, $fileFormat)
+    private function prepareStorage($data, $docserverId, $status, $fileFormat, $table)
     {
         $statusFound = false;
         $typistFound = false;
@@ -165,6 +166,7 @@ class resources_controler
         $userPrimaryEntity = false;
         $destinationFound = false;
         $initiatorFound = false;
+        $attachmentTypeFound = false;
         $db = new Database();
         for ($i=0;$i<count($data);$i++) {
             if (strtoupper($data[$i]['type']) == 'INTEGER' || strtoupper($data[$i]['type']) == 'FLOAT') {
@@ -217,6 +219,9 @@ class resources_controler
                         
                 }
             }
+            if (strtoupper($data[$i]['column']) == strtoupper('attachment_type')) {
+                $attachmentTypeFound = true;
+            }
         }
         if (!$typistFound && !$toAddressFound) {
             array_push(
@@ -307,7 +312,19 @@ class resources_controler
                     )
                 );
             }
-        }    
+        }
+
+        if (!$attachmentTypeFound && $table == 'res_attachments') {
+            array_push(
+                $data,
+                array(
+                    'column' => 'attachment_type',
+                    'value' => 'simple_attachment',
+                    'type' => 'string',
+                )
+            );
+        } 
+
         array_push(
             $data,
             array(
-- 
GitLab