From a9d3d1a5fdf0414a4911fe857ad0a4f8ded4e942 Mon Sep 17 00:00:00 2001
From: Laurent Giovannoni <laurent.giovannoni@maarch.org>
Date: Thu, 9 Mar 2017 18:09:54 +0100
Subject: [PATCH] add route to store a resource in rest

---
 .gitignore                                    |   1 +
 .../tmp/test/test_source.txt                  |   1 +
 core/Controllers/ResController.php            | 371 ++++++++++--------
 core/Test/DocserverControllerTest.php         |   2 +-
 core/Test/DocserverToolsControllerTest.php    |   2 +-
 core/Test/DocserverTypeControllerTest.php     |   2 +-
 core/Test/ResControllerTest.php               |  87 +++-
 core/Test/StatusControllerTest.php            |   2 +-
 php_errors.log                                | 103 +++++
 rest/index.php                                |   3 +
 10 files changed, 408 insertions(+), 166 deletions(-)
 create mode 100644 apps/maarch_entreprise/tmp/test/test_source.txt
 create mode 100644 php_errors.log

diff --git a/.gitignore b/.gitignore
index 5b50eef7f1e..4356eae274b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ apps/maarch_entreprise/xml/log4php.xml
 .phplint.yml
 fonctionnel.log
 technique.log
+xdelete.sh
diff --git a/apps/maarch_entreprise/tmp/test/test_source.txt b/apps/maarch_entreprise/tmp/test/test_source.txt
new file mode 100644
index 00000000000..76425fca885
--- /dev/null
+++ b/apps/maarch_entreprise/tmp/test/test_source.txt
@@ -0,0 +1 @@
+a unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit testa unit test
\ No newline at end of file
diff --git a/core/Controllers/ResController.php b/core/Controllers/ResController.php
index c8583d8b358..55c35742345 100644
--- a/core/Controllers/ResController.php
+++ b/core/Controllers/ResController.php
@@ -24,6 +24,30 @@ use Core\Controllers\DocserverController;
 
 class ResController
 {
+    public function create(RequestInterface $request, ResponseInterface $response, $aArgs)
+    {
+        if (!empty($aArgs)) {
+            $aArgs = $aArgs;
+        } else {
+            $aArgs = $request->getQueryParams();
+            //print_r($aArgs['data']);
+            $aArgs['data'] = json_decode($aArgs['data']);
+            $aArgs['data'] = $this->object2array($aArgs['data']);
+            //print_r($aArgs['data']);exit;
+        }
+
+        $return = $this->storeResource($aArgs);
+
+        if ($return['errors']) {
+            return $response
+                ->withStatus(500)
+                ->withJson(
+                    ['errors' => _NOT_CREATE . ' ' . $return['errors']]
+                );
+        }
+        
+        return $response->withJson($return);
+    }
 
     /**
      * Store resource on database.
@@ -366,180 +390,205 @@ class ResController
         return $data;
     }
 
-    //TODO
-    public function storeExtResource($resId, $data, $table)
+    /**
+     * Store ext resource on database.
+     * @param  $resId  integer
+     * @param  $data array
+     * @param  $table  string
+     * @return res_id
+     */
+    public function storeExtResource($aArgs, $resId, $data, $table)
     {
-        try {
-            if ($resId <> "") {
-                $func = new functions();
-                $data = $func->object2array($data);
-                $queryExtFields = '(';
-                $queryExtValues = '(';
-                $queryExtValuesFinal = '(';
-                $parameters = array();
-                $db = new Database();
-                $findProcessLimitDate = false;
-                $findProcessNotes = false;
-                $delayProcessNotes = 0;
-
-                for ($i = 0; $i < count($data); $i++) {
-                    if ($data[$i]['column'] == 'process_limit_date') {
-                        $findProcessLimitDate = true;
-                    }
-                    // if ($data[$i]['column'] == 'process_notes') {
-                    //     $findProcessNotes = true;
-                    //     $delayProcessNotes = $data[$i]['value'];
-                    // }
-                    if ($data[$i]['column'] == 'process_notes') {
-                        $findProcessNotes = true;
-                        $donnees = explode(',', $data[$i]['value']);
-                        $delayProcessNotes = $donnees['0'];
-                        $calendarType = $donnees['1'];
-                    }
-                }
+        if (empty($aArgs['resId'])) {
+            return ['errors' => 'resId ' . _EMPTY];
+        }
 
-                if ($table == 'mlb_coll_ext') {
-                    if ($delayProcessNotes > 0) {
-                        $processLimitDate = $this->retrieveProcessLimitDate(
-                            $resId,
-                            $delayProcessNotes,
-                            $calendarType
-                        );
-                    } else {
-                        $processLimitDate = $this->retrieveProcessLimitDate($resId);
-                    }
-                    //echo $processLimitDate;
-                }
-                
-                if (!$findProcessLimitDate && $processLimitDate <> '') {
-                    array_push(
-                        $data,
-                        array(
-                        'column' => 'process_limit_date',
-                        'value' => $processLimitDate,
-                        'type' => 'date',
-                        )
-                    );
-                }
+        if (empty($aArgs['data'])) {
+            return ['errors' => 'data ' . _EMPTY];
+        }
 
-                //var_dump($data);
-                for ($i = 0; $i < count($data); $i++) {
-                    if (strtoupper($data[$i]['type']) == 'INTEGER' || strtoupper($data[$i]['type']) == 'FLOAT') {
-                        if ($data[$i]['value'] == '') {
-                            $data[$i]['value'] = '0';
-                        }
-                        $data[$i]['value'] = str_replace(',', '.', $data[$i]['value']);
-                    }
-                    if (strtoupper($data[$i]['column']) == strtoupper('category_id')) {
-                        $categoryId = $data[$i]['value'];
-                    }
-                    if (strtoupper($data[$i]['column']) == strtoupper('alt_identifier') && $data[$i]['value'] == "") {
-                        require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
-                            . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_chrono.php';
-                        $chronoX = new chrono();
-                        for ($iColl=0; $iColl<=count($_SESSION['collections']); $iColl++) {
-                            if ($_SESSION['collections'][$iColl]['extensions'][0] == $table) {
-                                $resViewTable = $_SESSION['collections'][$iColl]['view'];
-                                break;
-                            }
-                        }
-                        $stmt = $db->query("SELECT destination, type_id FROM " . $resViewTable
-                            . " WHERE res_id = ?", array($resId));
-                        $resView = $stmt->fetchObject();
-                        $myVars = array(
-                            'entity_id' => $resView->destination,
-                            'type_id' => $resView->type_id,
-                            'category_id' => $categoryId,
-                            'folder_id' => "",
-                        );
-                        $myChrono = $chronoX->generate_chrono($categoryId, $myVars, 'false');
-                        $data[$i]['value'] = $myChrono;
-                    }
-                    if (strtoupper($data[$i]['column']) == strtoupper('exp_contact_id') &&
-                        $data[$i]['value'] <> "" && !is_numeric($data[$i]['value'])) {
-                        $theString = str_replace(">", "", $data[$i]['value']);
-                        $mail = explode("<", $theString);
-                        $stmt = $db->query("SELECT contact_id FROM view_contacts WHERE email = ? "
-                            . " and enabled = 'Y' order by creation_date asc", array($mail[count($mail) -1]));
-                        $contact = $stmt->fetchObject();
-
-                        if ($contact->contact_id <> "") {
-                            $data[$i]['value'] = $contact->contact_id;
-                        } else {
-                            $data[$i]['value'] = 0;
-                        }
-                    }
-                    if (strtoupper($data[$i]['column']) == strtoupper('address_id') &&
-                        $data[$i]['value'] <> "" && !is_numeric($data[$i]['value'])) {
-                        $theString = str_replace(">", "", $data[$i]['value']);
-                        $mail = explode("<", $theString);
-                        $stmt = $db->query("SELECT ca_id FROM view_contacts WHERE email = ? "
-                            . " and enabled = 'Y' order by creation_date asc", array($mail[count($mail) -1]));
-                        $contact = $stmt->fetchObject();
-                        if ($contact->ca_id <> "") {
-                            $data[$i]['value'] = $contact->ca_id;
-                        } else {
-                            $data[$i]['value'] = 0;
-                        }
-                    }
-                    //COLUMN
-                    $data[$i]['column'] = strtolower($data[$i]['column']);
-                    $queryExtFields .= $data[$i]['column'] . ',';
-                    //VALUE
-                    if ($data[$i]['type'] == 'string' || $data[$i]['type'] == 'date') {
-                        $queryExtValues .= "'" . $data[$i]['value'] . "',";
-                    } else {
-                        $queryExtValues .= $data[$i]['value'] . ",";
+        if (empty($aArgs['table'])) {
+            return ['errors' => 'table ' . _EMPTY];
+        }
+
+
+        $func = new functions();
+        
+        $queryExtFields = '(';
+        $queryExtValues = '(';
+        $queryExtValuesFinal = '(';
+        $parameters = array();
+        $db = new Database();
+        $findProcessLimitDate = false;
+        $findProcessNotes = false;
+        $delayProcessNotes = 0;
+
+        for ($i = 0; $i < count($data); $i++) {
+            if ($data[$i]['column'] == 'process_limit_date') {
+                $findProcessLimitDate = true;
+            }
+            if ($data[$i]['column'] == 'process_notes') {
+                $findProcessNotes = true;
+                $donnees = explode(',', $data[$i]['value']);
+                $delayProcessNotes = $donnees['0'];
+                $calendarType = $donnees['1'];
+            }
+        }
+
+        if ($table == 'mlb_coll_ext') {
+            if ($delayProcessNotes > 0) {
+                $processLimitDate = $this->retrieveProcessLimitDate(
+                    $resId,
+                    $delayProcessNotes,
+                    $calendarType
+                );
+            } else {
+                $processLimitDate = $this->retrieveProcessLimitDate($resId);
+            }
+        }
+        
+        if (!$findProcessLimitDate && $processLimitDate <> '') {
+            array_push(
+                $data,
+                array(
+                'column' => 'process_limit_date',
+                'value' => $processLimitDate,
+                'type' => 'date',
+                )
+            );
+        }
+
+        for ($i = 0; $i < count($data); $i++) {
+            if (strtoupper($data[$i]['type']) == 'INTEGER' || 
+                strtoupper($data[$i]['type']) == 'FLOAT') {
+                if ($data[$i]['value'] == '') {
+                    $data[$i]['value'] = '0';
+                }
+                $data[$i]['value'] = str_replace(',', '.', $data[$i]['value']);
+            }
+            if (strtoupper($data[$i]['column']) == strtoupper('category_id')) {
+                $categoryId = $data[$i]['value'];
+            }
+            if (strtoupper($data[$i]['column']) == strtoupper('alt_identifier') && 
+                $data[$i]['value'] == "") {
+                require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
+                    . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_chrono.php';
+                $chronoX = new chrono();
+                for ($iColl=0; $iColl<=count($_SESSION['collections']); $iColl++) {
+                    if ($_SESSION['collections'][$iColl]['extensions'][0] == $table) {
+                        $resViewTable = $_SESSION['collections'][$iColl]['view'];
+                        break;
                     }
-                    $parameters[] = $data[$i]['value'];
-                    $queryExtValuesFinal .= "?,";
                 }
-                $queryExtFields = preg_replace('/,$/', ',res_id)', $queryExtFields);
-                $queryExtValues = preg_replace(
-                    '/,$/',
-                    ',' . $resId . ')',
-                    $queryExtValues
-                );
-                $queryExtValuesFinal = preg_replace(
-                    '/,$/',
-                    ',' . $resId . ')',
-                    $queryExtValuesFinal
+                $stmt = $db->query("SELECT destination, type_id FROM " . $resViewTable
+                    . " WHERE res_id = ?", array($resId));
+                $resView = $stmt->fetchObject();
+                $myVars = array(
+                    'entity_id' => $resView->destination,
+                    'type_id' => $resView->type_id,
+                    'category_id' => $categoryId,
+                    'folder_id' => "",
                 );
-                /*$queryExt = " insert into " . $table . " " . $queryExtFields
-                       . ' values ' . $queryExtValues ;*/
-                $queryExt = " insert into " . $table . " " . $queryExtFields
-                       . ' values ' . $queryExtValuesFinal ;
-                //echo $queryExt;exit;
-                $returnCode = 0;
-                if ($db->query($queryExt, $parameters)) {
-                    $returnResArray = array(
-                        'returnCode' => (int) 0,
-                        'resId' => $resId,
-                        'error' => '',
-                    );
+                $myChrono = $chronoX->generate_chrono($categoryId, $myVars, 'false');
+                $data[$i]['value'] = $myChrono;
+            }
+            if (strtoupper($data[$i]['column']) == strtoupper('exp_contact_id') &&
+                $data[$i]['value'] <> "" && !is_numeric($data[$i]['value'])) {
+                $theString = str_replace(">", "", $data[$i]['value']);
+                $mail = explode("<", $theString);
+                $stmt = $db->query("SELECT contact_id FROM view_contacts WHERE email = ? "
+                    . " and enabled = 'Y' order by creation_date asc", array($mail[count($mail) -1]));
+                $contact = $stmt->fetchObject();
+
+                if ($contact->contact_id <> "") {
+                    $data[$i]['value'] = $contact->contact_id;
+                } else {
+                    $data[$i]['value'] = 0;
+                }
+            }
+            if (strtoupper($data[$i]['column']) == strtoupper('address_id') &&
+                $data[$i]['value'] <> "" && !is_numeric($data[$i]['value'])) {
+                $theString = str_replace(">", "", $data[$i]['value']);
+                $mail = explode("<", $theString);
+                $stmt = $db->query("SELECT ca_id FROM view_contacts WHERE email = ? "
+                    . " and enabled = 'Y' order by creation_date asc", array($mail[count($mail) -1]));
+                $contact = $stmt->fetchObject();
+                if ($contact->ca_id <> "") {
+                    $data[$i]['value'] = $contact->ca_id;
                 } else {
-                    $returnResArray = array(
-                        'returnCode' => (int) -2,
-                        'resId' => '',
-                        'error' => 'Pb with SQL insertion',
-                    );
+                    $data[$i]['value'] = 0;
                 }
-                return $returnResArray;
+            }
+            //COLUMN
+            $data[$i]['column'] = strtolower($data[$i]['column']);
+            $queryExtFields .= $data[$i]['column'] . ',';
+            //VALUE
+            if ($data[$i]['type'] == 'string' || $data[$i]['type'] == 'date') {
+                $queryExtValues .= "'" . $data[$i]['value'] . "',";
             } else {
-                $returnResArray = array(
-                    'returnCode' => (int) -3,
-                    'resId' => '',
-                    'error' => 'resId is not set',
-                );
-                return $returnResArray;
+                $queryExtValues .= $data[$i]['value'] . ",";
             }
-        } catch (Exception $e) {
+            $parameters[] = $data[$i]['value'];
+            $queryExtValuesFinal .= "?,";
+        }
+        $queryExtFields = preg_replace('/,$/', ',res_id)', $queryExtFields);
+        $queryExtValues = preg_replace(
+            '/,$/',
+            ',' . $resId . ')',
+            $queryExtValues
+        );
+        $queryExtValuesFinal = preg_replace(
+            '/,$/',
+            ',' . $resId . ')',
+            $queryExtValuesFinal
+        );
+
+        $queryExt = " insert into " . $table . " " . $queryExtFields
+                . ' values ' . $queryExtValuesFinal ;
+
+        $returnCode = 0;
+        if ($db->query($queryExt, $parameters)) {
             $returnResArray = array(
-                'returnCode' => (int) -1,
+                'returnCode' => (int) 0,
+                'resId' => $resId,
+                'error' => '',
+            );
+        } else {
+            $returnResArray = array(
+                'returnCode' => (int) -2,
                 'resId' => '',
-                'error' => 'unknown error' . $e->getMessage(),
+                'error' => 'Pb with SQL insertion',
             );
-            return $returnResArray;
         }
+        return $returnResArray;
+        
+    }
+
+    /**
+    * Convert an object to an array
+    * @param  $object object to convert
+    */
+    private function object2array($object)
+    {
+        $return = null;
+        if (is_array($object)) {
+            foreach ($object as $key => $value) {
+                $return[$key] = $this->object2array($value);
+            }
+        } else {
+            if (is_object($object)) {
+                $var = get_object_vars($object);
+                if ($var) {
+                    foreach ($var as $key => $value) {
+                        $return[$key] = ($key && !$value) ? null : $this->object2array($value);
+                    }
+                } else {
+                    return $object;
+                }
+            } else {
+                return $object;
+            }
+        }
+        return $return;
     }
 }
diff --git a/core/Test/DocserverControllerTest.php b/core/Test/DocserverControllerTest.php
index 8fb412bd2d4..485654c4008 100644
--- a/core/Test/DocserverControllerTest.php
+++ b/core/Test/DocserverControllerTest.php
@@ -11,7 +11,7 @@ namespace MaarchTest;
 
 require_once __DIR__.'/define.php';
 
-class DocserverControllerTest extends PHPUnit_Framework_TestCase
+class DocserverControllerTest extends \PHPUnit_Framework_TestCase
 {
     // public function testGetList()
     // {
diff --git a/core/Test/DocserverToolsControllerTest.php b/core/Test/DocserverToolsControllerTest.php
index 3a1a48fbaa8..41bd681198d 100644
--- a/core/Test/DocserverToolsControllerTest.php
+++ b/core/Test/DocserverToolsControllerTest.php
@@ -11,7 +11,7 @@ namespace MaarchTest;
 
 require_once __DIR__.'/define.php';
 
-class DocserverToolsControllerTest extends PHPUnit_Framework_TestCase
+class DocserverToolsControllerTest extends \PHPUnit_Framework_TestCase
 {
     public function testSetRights()
     {
diff --git a/core/Test/DocserverTypeControllerTest.php b/core/Test/DocserverTypeControllerTest.php
index fc1e6cebcc8..8a891ce8f2b 100644
--- a/core/Test/DocserverTypeControllerTest.php
+++ b/core/Test/DocserverTypeControllerTest.php
@@ -11,7 +11,7 @@ namespace MaarchTest;
 
 require_once __DIR__.'/define.php';
 
-class DocserverTypeControllerTest extends PHPUnit_Framework_TestCase
+class DocserverTypeControllerTest extends \PHPUnit_Framework_TestCase
 {
     public function testGetList()
     {
diff --git a/core/Test/ResControllerTest.php b/core/Test/ResControllerTest.php
index 9cc586e9e92..afccc1a219d 100644
--- a/core/Test/ResControllerTest.php
+++ b/core/Test/ResControllerTest.php
@@ -11,7 +11,7 @@ namespace MaarchTest;
 
 require_once __DIR__.'/define.php';
 
-class ResControllerTest extends PHPUnit_Framework_TestCase
+class ResControllerTest extends \PHPUnit_Framework_TestCase
 {
 
     public function testPrepareStorage()
@@ -192,4 +192,89 @@ class ResControllerTest extends PHPUnit_Framework_TestCase
         
         $this->assertGreaterThanOrEqual(0, $response);
     }
+
+    public function testCreate()
+    {
+        $action = new \Core\Controllers\ResController();
+
+        $environment = \Slim\Http\Environment::mock(
+            [
+                'REQUEST_METHOD' => 'POST',
+            ]
+        );
+
+        $path = $_SESSION['config']['tmppath'] . '/test/';
+
+        if (!is_dir($path)) {
+            mkdir($path);
+        }
+
+        $fileSource = 'test_source.txt';
+
+        $fp = fopen($path . $fileSource, 'a');
+        fwrite($fp, 'a unit test');
+        fclose($fp);
+
+        $fileContent = file_get_contents($path . $fileSource, FILE_BINARY);
+        $encodedFile = base64_encode($fileContent);
+        //echo $encodedFile . PHP_EOL;exit;
+        
+        $data = [];
+
+        array_push(
+            $data,
+            array(
+                'column' => 'subject',
+                'value' => 'UNIT TEST from slim',
+                'type' => 'string',
+            )
+        );
+
+        array_push(
+            $data,
+            array(
+                'column' => 'type_id',
+                'value' => 110,
+                'type' => 'integer',
+            )
+        );
+
+        array_push(
+            $data,
+            array(
+                'column' => 'custom_t1',
+                'value' => 'TEST',
+                'type' => 'string',
+            )
+        );
+
+        array_push(
+            $data,
+            array(
+                'column' => 'custom_t10',
+                'value' => 'lgi@maarch.org',
+                'type' => 'string',
+            )
+        );
+        //print_r(json_encode($data));
+        //sample in json : [{"column":"subject","value":"UNIT T
+        //EST from slim","type":"string"},{"column":"type_id","value":110,"type":"integer"},
+        //{"column":"custom_t1","value":"TES
+        //T","type":"string"},{"column":"custom_t10","value":"lgi@maarch.org","type":"string"}]
+
+        $aArgs = [
+            'encodedFile'   => $encodedFile,
+            'data'          => $data,
+            'collId'        => 'letterbox_coll',
+            'table'         => 'res_letterbox',
+            'fileFormat'    => 'txt',
+            'status'        => 'new',
+        ];
+
+        $request = \Slim\Http\Request::createFromEnvironment($environment);
+        $response = new \Slim\Http\Response();
+        $response = $action->create($request, $response, $aArgs);
+        //print_r($response);exit;
+        $this->assertGreaterThan(1, json_decode($response->getBody())[0]);
+    }
 }
diff --git a/core/Test/StatusControllerTest.php b/core/Test/StatusControllerTest.php
index 1d28fd04d9c..63c743ef985 100644
--- a/core/Test/StatusControllerTest.php
+++ b/core/Test/StatusControllerTest.php
@@ -11,7 +11,7 @@ namespace MaarchTest;
 
 require_once __DIR__.'/define.php';
 
-class StatusControllerTest extends PHPUnit_Framework_TestCase
+class StatusControllerTest extends \PHPUnit_Framework_TestCase
 {
     public function testGetList()
     {
diff --git a/php_errors.log b/php_errors.log
new file mode 100644
index 00000000000..fa45543fdac
--- /dev/null
+++ b/php_errors.log
@@ -0,0 +1,103 @@
+[09-Mar-2017 16:31:07 Europe/Paris] PHP Fatal error:  Class 'MaarchTest\PHPUnit_Framework_TestCase' not found in /var/www/html/MaarchCourrier/core/Test/ResControllerTest.php on line 14
+[09-Mar-2017 16:31:07 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   1. {main}() /usr/bin/phpunit:0
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:29
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:106
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:128
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:65
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   6. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:124
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   7. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Runner/StandardTestSuiteLoader.php:39
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   8. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:38
+[09-Mar-2017 16:31:07 Europe/Paris] PHP   9. include_once() /usr/share/php/PHPUnit/Util/Fileloader.php:56
+[09-Mar-2017 16:32:36 Europe/Paris] PHP Fatal error:  Class 'MaarchTest\PHPUnit_Framework_TestCase' not found in /var/www/html/MaarchCourrier/core/Test/StatusControllerTest.php on line 14
+[09-Mar-2017 16:32:36 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   1. {main}() /usr/bin/phpunit:0
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:29
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:106
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:128
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:65
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   6. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:124
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   7. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Runner/StandardTestSuiteLoader.php:39
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   8. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:38
+[09-Mar-2017 16:32:36 Europe/Paris] PHP   9. include_once() /usr/share/php/PHPUnit/Util/Fileloader.php:56
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  include(apps//css/styles.css): failed to open stream: No such file or directory in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 109
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  include(): Failed opening 'apps//css/styles.css' for inclusion (include_path='/var/www/html/MaarchCourrier/:.:/usr/share/php') in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 109
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  array_keys() expects parameter 1 to be array, null given in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 110
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   2. array_keys() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:110
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 110
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  include_once(apps//css/doctype_levels.css): failed to open stream: No such file or directory in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 127
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  include_once(): Failed opening 'apps//css/doctype_levels.css' for inclusion (include_path='/var/www/html/MaarchCourrier/:.:/usr/share/php') in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 127
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  include_once(apps//css/chosen.min.css): failed to open stream: No such file or directory in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 128
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Warning:  include_once(): Failed opening 'apps//css/chosen.min.css' for inclusion (include_path='/var/www/html/MaarchCourrier/:.:/usr/share/php') in /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php on line 128
+[09-Mar-2017 16:54:48 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 16:54:48 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/apps/maarch_entreprise/merged_css.php:0
+[09-Mar-2017 17:05:07 Europe/Paris] PHP Warning:  Illegal string offset 'column' in /var/www/html/MaarchCourrier/core/Controllers/ResController.php on line 93
+[09-Mar-2017 17:05:07 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/rest/index.php:0
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   2. Slim\App->run() /var/www/html/MaarchCourrier/rest/index.php:128
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   3. Slim\App->process() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:293
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   4. Slim\App->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:332
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   5. Slim\App->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   6. Slim\Route->run() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:438
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   7. Slim\Route->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:316
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   8. Slim\Route->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   9. Slim\Handlers\Strategies\RequestResponse->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:344
+[09-Mar-2017 17:05:07 Europe/Paris] PHP  10. call_user_func:{/var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41}() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:05:07 Europe/Paris] PHP  11. Core\Controllers\ResController->create() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:05:07 Europe/Paris] PHP  12. Core\Controllers\ResController->storeResource() /var/www/html/MaarchCourrier/core/Controllers/ResController.php:35
+[09-Mar-2017 17:05:07 Europe/Paris] PHP Fatal error:  Cannot use string offset as an array in /var/www/html/MaarchCourrier/core/Controllers/ResController.php on line 93
+[09-Mar-2017 17:05:07 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/rest/index.php:0
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   2. Slim\App->run() /var/www/html/MaarchCourrier/rest/index.php:128
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   3. Slim\App->process() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:293
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   4. Slim\App->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:332
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   5. Slim\App->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   6. Slim\Route->run() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:438
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   7. Slim\Route->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:316
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   8. Slim\Route->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:05:07 Europe/Paris] PHP   9. Slim\Handlers\Strategies\RequestResponse->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:344
+[09-Mar-2017 17:05:07 Europe/Paris] PHP  10. call_user_func:{/var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41}() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:05:07 Europe/Paris] PHP  11. Core\Controllers\ResController->create() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:05:07 Europe/Paris] PHP  12. Core\Controllers\ResController->storeResource() /var/www/html/MaarchCourrier/core/Controllers/ResController.php:35
+[09-Mar-2017 17:06:16 Europe/Paris] PHP Fatal error:  Cannot use object of type stdClass as array in /var/www/html/MaarchCourrier/core/Controllers/ResController.php on line 94
+[09-Mar-2017 17:06:16 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/rest/index.php:0
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   2. Slim\App->run() /var/www/html/MaarchCourrier/rest/index.php:128
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   3. Slim\App->process() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:293
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   4. Slim\App->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:332
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   5. Slim\App->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   6. Slim\Route->run() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:438
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   7. Slim\Route->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:316
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   8. Slim\Route->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:06:16 Europe/Paris] PHP   9. Slim\Handlers\Strategies\RequestResponse->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:344
+[09-Mar-2017 17:06:16 Europe/Paris] PHP  10. call_user_func:{/var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41}() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:06:16 Europe/Paris] PHP  11. Core\Controllers\ResController->create() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:06:16 Europe/Paris] PHP  12. Core\Controllers\ResController->storeResource() /var/www/html/MaarchCourrier/core/Controllers/ResController.php:36
+[09-Mar-2017 17:13:15 Europe/Paris] PHP Fatal error:  Cannot use object of type stdClass as array in /var/www/html/MaarchCourrier/core/Controllers/ResController.php on line 96
+[09-Mar-2017 17:13:15 Europe/Paris] PHP Stack trace:
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   1. {main}() /var/www/html/MaarchCourrier/rest/index.php:0
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   2. Slim\App->run() /var/www/html/MaarchCourrier/rest/index.php:128
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   3. Slim\App->process() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:293
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   4. Slim\App->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:332
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   5. Slim\App->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   6. Slim\Route->run() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/App.php:438
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   7. Slim\Route->callMiddlewareStack() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:316
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   8. Slim\Route->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:116
+[09-Mar-2017 17:13:15 Europe/Paris] PHP   9. Slim\Handlers\Strategies\RequestResponse->__invoke() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Route.php:344
+[09-Mar-2017 17:13:15 Europe/Paris] PHP  10. call_user_func:{/var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41}() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:13:15 Europe/Paris] PHP  11. Core\Controllers\ResController->create() /var/www/html/MaarchCourrier/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php:41
+[09-Mar-2017 17:13:15 Europe/Paris] PHP  12. Core\Controllers\ResController->storeResource() /var/www/html/MaarchCourrier/core/Controllers/ResController.php:38
diff --git a/rest/index.php b/rest/index.php
index c0dcc05af39..10acbdaa012 100644
--- a/rest/index.php
+++ b/rest/index.php
@@ -120,6 +120,9 @@ $app->post('/attachments', \Attachments\Controllers\AttachmentsController::class
 $app->get('/{basketId}/signatureBook/{resId}', \Visa\Controllers\VisaController::class . ':getSignatureBook');
 $app->put('/{collId}/{resId}/unsign', \Visa\Controllers\VisaController::class . ':unsignFile');
 
+//resource
+$app->post('/res', \Core\Controllers\ResController::class . ':create');
+
 
 
 $app->run();
-- 
GitLab