From d7871f5ddd88f02c47cc942c1ce09c738c60ca5a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Carretero?=
 <frederic.carretero@veremes.com>
Date: Mon, 19 Nov 2018 16:23:43 +0100
Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20des=20formulaires=20json=20d'un?=
 =?UTF-8?q?=20projet=20FME=20sur=20S3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 web_service/ws/Workspaces.class.inc | 34 +++++++++++++++++++----------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/web_service/ws/Workspaces.class.inc b/web_service/ws/Workspaces.class.inc
index 1c01ecbb..5bd38768 100755
--- a/web_service/ws/Workspaces.class.inc
+++ b/web_service/ws/Workspaces.class.inc
@@ -527,23 +527,33 @@ class Workspaces extends GTF {
                                     }
                                     */
                                 }
-                                $oFmwParser = new GtfFmwParser($sDirName . "/fme/" . $_FILES['fmw_file']['name']);
+                                // Télécharge le fichier .fmw qui est sur S3.
+                                if ($this->aProperties['fileS3Uploader'] === true) {
+                                    $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $_FILES['fmw_file']['name']);
+                                    if ($sFmwFileContent !== false) {
+                                        $sFmwFilePath = $this->aProperties['extract_dir'] . '/' . getUniqRandomId() . '/' . $_FILES['fmw_file']['name'];
+                                        mkdir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
+                                        file_put_contents($sFmwFilePath, $sFmwFileContent);
+                                    }
+                                }
+                                else
+                                    $sFmwFilePath = $sDirName . "/fme/" . $_FILES['fmw_file']['name'];
                                 // Sauve le .fmw sans les visualizers.
-                                $oFmwParser->save($sDirName . "/fme/" . utf8_decode($_FILES['fmw_file']['name']));
+                                $oFmwParser = new GtfFmwParser($sFmwFilePath);
+                                $oFmwParser->save($sFmwFilePath);
+                                // Sauve le fichier sur S3.
+                                if ($this->aProperties['fileS3Uploader'] === true)
+                                    putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], file_get_contents($sFmwFilePath));
                                 // Création des formulaires json.
                                 $aJson = $oFmwParser->productJson($this->aProperties, $oWorkspace->aFields["name"]);
-                                $fJson = fopen($sDirName . "/form/Subform.json", "w+");
-                                if (fwrite($fJson, json_encode($aJson)) == FALSE) {
-                                    if ($fJson == FALSE) {
-                                        writeToErrorLog("Subform.json can't be opened : " . $sDirName . "/form/ressources/Subform.json" . "(Workspaces.class.inc : verify the property workspace_dir)");
-                                    } else {
-                                        writeToErrorLog("Subform.json can't be writed : " . $sDirName . "/form/ressources/Subform.json" . "(Workspaces.class.inc : verify the folder's rights)");
-                                    }
+                                if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', json_encode($aJson)) !== false) {
+                                    copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'WSubform.json');
+                                    copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'DSubform.json');
                                 }
-                                fclose($fJson);
-                                copy($sDirName . "/form/Subform.json", $sDirName . "/form/WSubform.json");
-                                copy($sDirName . "/form/Subform.json", $sDirName . "/form/DSubform.json");
                                 $oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]);
+                                // Supprime le fichier .fmw temporaire.
+                                if ($this->aProperties['fileS3Uploader'] === true)
+                                    clearDir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
                                 /*                         * ************************************************************** */
                             } else {
                                 writeToErrorLog("the uploaded file is not a fmw file or no file uploaded (Workspaces.class.inc : user_id->" . $_SESSION["user_id"] . ")");
-- 
GitLab