diff --git a/web_service/ws/Workspaces.class.inc b/web_service/ws/Workspaces.class.inc index e0b3ac58621b1e540356b232e8db0bddeff98c98..f38f596690621a8c6a58aaa5238dad661daf5a0c 100755 --- a/web_service/ws/Workspaces.class.inc +++ b/web_service/ws/Workspaces.class.inc @@ -409,7 +409,7 @@ class Workspaces extends GTF { $oFmwParser->save($oFmwParser->sFmwFileName); putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'][$i], file_get_contents($oFmwParser->sFmwFileName)); // Création des formulaires json. - $aJson = $oFmwParser->productJson($this->aProperties, $oWorkspace->aFields["name"]); + $aJson = $oFmwParser->productJson($oWorkspace->aFields["name"]); 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'); @@ -743,26 +743,25 @@ class Workspaces extends GTF { if (!empty($this->aValues["cmd"])) { switch ($this->aValues["cmd"]) { - // DSubform: formulaire par défaut // Subform: formulaire publié // WSubform: formulaire personnalié // Remplace le formulaire publié par celui par défaut case "Default_Published": // Si le fichier par défaut n'existe pas, il est généré - if (!file_exists($sDirname . "/form/DSubform.json")) { + if (!fileExistsInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json')) { $this->aValues["cmd"] = "Default_Reset"; $this->PUT(); } - @unlink($sDirname . "/form/Subform.json"); - copy($sDirName . "/form/DSubform.json", $sDirName . "/form/Subform.json"); + // Remplace 'Subform.json' par le formulaire par défaut 'DSubform.json'. + deleteFileFromWsDataDirTree('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json'); + copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json', 'Subform.json'); $this->aValues["form_type"] = 'default'; break; // Regénère le formulaire par défaut en fonction du fmw case "Default_Reset": $oWorkspace = new Workspace($this->aPath, $this->aValues, $this->aProperties, $this->oConnection); $oWorkspace->GET(); - if (empty($oWorkspace->aFields["fmw_file"])) { $error_message .= "Any FME file founded in" . $sDirName . "/fme/ "; writeToErrorLog("WARNING: " . $error_message); @@ -773,70 +772,46 @@ class Workspaces extends GTF { $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); return $sMessage; } - - $oFmwParser = new GtfFmwParser($sDirName . "/fme/" . $oWorkspace->aFields["fmw_file"]); - $aJson = $oFmwParser->productJson($this->aProperties, $oWorkspace->aFields["name"]); - $fJson = fopen($sDirName . "/form/DSubform.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)"); - } - } - fclose($fJson); + // Lit le contenu du fichier .fmw du projet. + $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $oWorkspace->aFields["fmw_file"]); + // Création des formulaires json. + $oFmwParser = new GtfFmwParser($oWorkspace->aFields["fmw_file"], $sFmwFileContent, $this->aProperties); + $aJson = $oFmwParser->productJson($oWorkspace->aFields["name"]); + if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json', json_encode($aJson)) === false) + writeToErrorLog("Subform.json can't be writed : " . $sDirName . "/form/ressources/Subform.json" . "(Workspaces.class.inc : verify the folder's rights)"); //$oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]); break; // Remplace le formulaire publié par celui personnalisé case "Perso_Published" : - @unlink($sDirname . "/form/Subform.json"); - copy($sDirName . "/form/WSubform.json", $sDirName . "/form/Subform.json"); + deleteFileFromWsDataDirTree('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json'); + copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'WSubform.json', 'Subform.json'); $this->aValues["form_type"] = 'custom'; break; // Remplace le fornulaire personnalisé par le formulaire par défaut case "Perso_Reset": // Si le fichier par défaut n'existe pas, il est généré - if (!file_exists($sDirname . "/form/DSubform.json")) { + if (!fileExistsInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json')) { $this->aValues["cmd"] = "Default_Reset"; $this->PUT(); } - @unlink($sDirname . "/form/WSubform.json"); - copy($sDirName . "/form/DSubform.json", $sDirName . "/form/WSubform.json"); + // Remplace 'Subform.json' par 'WSubform.json'. + deleteFileFromWsDataDirTree('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'WSubform.json'); + copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json', 'WSubform.json'); break; - // Sauvegarde le formulaire personnalisé + // Sauvegarde le formulaire personnalisé. case "Perso_Save": - $pFile = fopen($sDirName . "/form/WSubform.json", "w"); - if (fwrite($pFile, $this->aValues["Json"]) == 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)"); - } - } - fclose($pFile); - + // Sauve le formulaire personnalisé. + if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'WSubform.json', $this->aValues["Json"]) === false) + writeToErrorLog("Subform.json can't be writed : " . $sDirName . "/form/ressources/Subform.json" . "(Workspaces.class.inc : verify the folder's rights)"); + // Sauve le javascript. if ($this->aValues["Js"] != "") { - $pFileJS = fopen($sDirName . "/form/ressources/Subform.js", "w+"); - if (fwrite($pFileJS, $this->aValues["Js"]) == FALSE) { - if ($pFileJS == FALSE) { - writeToErrorLog("Subform.js can't be opened : " . $sDirName . "/form/ressources/Subform.js" . "(Workspaces.class.inc : verify the property workspace_dir)"); - } else { - writeToErrorLog("Subform.js can't be writed : " . $sDirName . "/form/ressources/Subform.js" . "(Workspaces.class.inc : verify the folder's rights)"); - } - } - fclose($pFileJS); + if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js', $this->aValues["Js"]) === false) + writeToErrorLog("Subform.json can't be writed : " . $sDirName . "/form/ressources/Subform.json" . "(Workspaces.class.inc : verify the folder's rights)"); } - + // Sauve le css. if ($this->aValues["Css"] != "") { - $pFileCSS = fopen($sDirName . "/form/ressources/Subform.css", "w+"); - if (fwrite($pFileCSS, $this->aValues["Css"]) == FALSE) { - if ($pFileCSS == FALSE) { - writeToErrorLog("Subform.css can't be opened : " . $sDirName . "/form/ressources/Subform.css" . "(Workspaces.class.inc : verify the property workspace_dir)"); - } else { - writeToErrorLog("Subform.css can't be writed : " . $sDirName . "/form/ressources/Subform.css" . "(Workspaces.class.inc : verify the folder's rights)"); - } - } - fclose($pFileCSS); + if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css', $this->aValues["Css"]) === false) + writeToErrorLog("Subform.css can't be writed : " . $sDirName . "/form/ressources/Subform.css" . "(Workspaces.class.inc : verify the folder's rights)"); } break; default : writeToErrorLog("ERROR : Bad request from Client : " . $this->aValues["cmd"] . " form user ->" . $_SESSION["user_id"]);