diff --git a/module/lang/lang-en.json b/module/lang/lang-en.json index 835ceda8ca1b508a6525708b37099989db2ee979..5825ce57cd75c2ef770eb340e193153470735195 100644 --- a/module/lang/lang-en.json +++ b/module/lang/lang-en.json @@ -153,6 +153,7 @@ "ERROR_REINTEGRATE_METADATA_PUBLICATION_WORKSPACE" : "Error while project", "CONFIRM_DELETE_LOCKED_WOKSPACE_PUBLICATION_WORKSPACE": "One or more projects are locked and can not be deleted. Continue ?", "FORM_BTN_REGENERATE_METADATA_TOOLTIP_PUBLICATION_WORKSPACE" : "Remplacement des champs Description, Utilisation, Prérequis et Conditions d'utilisation saisis dans GTF par les valeurs correspondantes contenues dans le projet FME source. Attention, les valeurs actuelles seront supprimées.", + "ERROR_WORKSPACE_FILE_NOT_FOUND" : "Reading error on the.fmw file of the FME project", "" : "", "TOOLTIP_TITLE_IMPORT_TOKEN_CONNECTION" : "Generate a token", "FORM_USER_IMPORT_TOKEN_CONNECTION" : "User", diff --git a/module/lang/lang-fr.json b/module/lang/lang-fr.json index 8dde45f8ccb1d7e3f31f1f650f7b4d1047419c5c..95e05117d124089b7d9517ca021abfdeda56fcff 100644 --- a/module/lang/lang-fr.json +++ b/module/lang/lang-fr.json @@ -153,6 +153,7 @@ "ERROR_REINTEGRATE_METADATA_PUBLICATION_WORKSPACE" : "Erreur pendant l'écriture du projet", "CONFIRM_DELETE_LOCKED_WOKSPACE_PUBLICATION_WORKSPACE": "Un ou plusieurs projets sont verrouillés et ne pourront être supprimés. Continuer ?", "FORM_BTN_REGENERATE_METADATA_TOOLTIP_PUBLICATION_WORKSPACE" : "Remplacement des champs Description, Utilisation, Prérequis et Conditions d'utilisation saisis dans GTF par les valeurs correspondantes contenues dans le projet FME source. Attention, les valeurs actuelles seront supprimées.", + "ERROR_WORKSPACE_FILE_NOT_FOUND" : "Erreur de lecture sur le fichier .fmw du projet FME.", "" : "", "TOOLTIP_TITLE_IMPORT_TOKEN_CONNECTION" : "Générer un jeton", "FORM_USER_IMPORT_TOKEN_CONNECTION" : "Utilisateur", diff --git a/web_service/class/gtf_lib/GtfFmwParser.class.inc b/web_service/class/gtf_lib/GtfFmwParser.class.inc index f29e86e27af0226484ce8e602ea092ce0169acd4..ca236956eefccdc01e3047c3788133eb48cdb4ee 100755 --- a/web_service/class/gtf_lib/GtfFmwParser.class.inc +++ b/web_service/class/gtf_lib/GtfFmwParser.class.inc @@ -27,6 +27,7 @@ class GtfFmwParser { var $sSaveDate; var $sSaveBuild; var $sRequirement; + var $aProperties; // var $sOriginalName; @@ -35,8 +36,16 @@ class GtfFmwParser { * le fichier fmw est parcouru ligne par ligne et chaque occurrence * correspondant à un GUI est stocké dans le tableau approrié */ - function __construct($sFmwFileName) { - $this->sFmwFileName = $sFmwFileName; + function __construct($sFmwFileName, $sFmwFileContent, $aProperties) { + // Création du fichier temporaire. + $this->aProperties = $aProperties; + $this->sFmwFileName = $this->aProperties['extract_dir'] . '/' . getUniqRandomId() . '/' . $sFmwFileName; + $sFmwFileDirPath = pathinfo($this->sFmwFileName, PATHINFO_DIRNAME); + if (file_exists($sFmwFileDirPath)) + cleardir($sFmwFileDirPath); + mkdir($sFmwFileDirPath, 0777, true); + file_put_contents($this->sFmwFileName, $sFmwFileContent); + // $oFichier = fopen(utf8_decode($this->sFmwFileName), "r"); $sRc = chr(10); // Compatible avec FME 2014 et inférieur $sRecherche = "^GUI(.*)" . $sRc; @@ -322,17 +331,16 @@ class GtfFmwParser { /** * Product a JSON form - * @param array $aProperties * @param string $sName * @return array */ - function productJson($aProperties, $sName) { + function productJson($sName) { $aJson = array("name" => "Subform", "title" => $sName, "input_size" => "xxs", "nb_cols" => 12, "rows" => array()); $aFields = array("fields" => array()); foreach ($this->aGuiObject as $oGtfGui) { // bizarre mais des lignes peuvent être vides (génération KML)... à voir if ($oGtfGui->sDefault_Macro != "") { - $aFormField = $oGtfGui->getGuiV2($aProperties); + $aFormField = $oGtfGui->getGuiV2($this->aProperties); // Décode les tags de FME et GTF dans les valeurs par défaut du formulaire json. if (!empty($aFormField[0]['default_value'])) $aFormField[0]['default_value'] = $oGtfGui->decodeFmeGtfTags($aFormField[0]['default_value']); @@ -625,7 +633,14 @@ class GtfFmwParser { fclose($ecriture); } - + /* + * Destructeur de la classe GtfFmwParser + */ + function __destruct() { + // Supprime le fichier .fmw temporaire du projet. + $sFmwFileDirPath = pathinfo($this->sFmwFileName, PATHINFO_DIRNAME); + if (file_exists($sFmwFileDirPath)) + cleardir($sFmwFileDirPath); + } } - ?> diff --git a/web_service/ws/Workspaces.class.inc b/web_service/ws/Workspaces.class.inc index aedeb6a0a23d85736f18b8da15fc2d0bb31508a6..f7919371bef63fc8513882758fce30e65f300664 100755 --- a/web_service/ws/Workspaces.class.inc +++ b/web_service/ws/Workspaces.class.inc @@ -402,25 +402,14 @@ class Workspaces extends GTF { // Copie du .fmw original en .bak. copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'][$i], $_FILES['fmw_file']['name'][$i] . '.bak'); // Création des fichiers vides de ressources js et css. - createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js'); - createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css'); - // 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'][$i]); - if ($sFmwFileContent !== false) { - $sFmwFilePath = $this->aProperties['extract_dir'] . '/' . getUniqRandomId() . '/' . $_FILES['fmw_file']['name'][$i]; - mkdir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME)); - file_put_contents($sFmwFilePath, $sFmwFileContent); - } - } - else - $sFmwFilePath = $sDirName . "/fme/" . $_FILES['fmw_file']['name'][$i]; + putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js', ''); + putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css', ''); + // Lit le contenu du fichier .fmw du projet. + $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $_FILES['fmw_file']['name'][$i]); // Sauve le .fmw sans les visualizers. - $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'][$i], file_get_contents($sFmwFilePath)); + $oFmwParser = new GtfFmwParser($_FILES['fmw_file']['name'][$i], $sFmwFileContent, $this->aProperties); + $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"]); if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', json_encode($aJson)) !== false) { @@ -428,9 +417,6 @@ class Workspaces extends GTF { copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', '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)); // $this->aValues["errorkeys"] = ""; } @@ -533,8 +519,8 @@ class Workspaces extends GTF { else { copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], $_FILES['fmw_file']['name'] . '.bak'); // Création des fichiers vides de ressources js et css. - createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js'); - createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css'); + putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js', ''); + putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css', ''); // Upload du fichier de ressource. if ($this->aValues["comp_file"] != "") { $this->aValues['fme'] = $this->aValues['comp_file']; @@ -547,33 +533,19 @@ class Workspaces extends GTF { } */ } - // 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']; + // Lit le contenu du fichier .fmw du projet. + $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $_FILES['fmw_file']['name']); // Sauve le .fmw sans les visualizers. - $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)); + $oFmwParser = new GtfFmwParser($_FILES['fmw_file']['name'], $sFmwFileContent, $this->aProperties); + $oFmwParser->save($oFmwParser->sFmwFileName); + putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], 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'); } $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 { @@ -726,9 +698,13 @@ class Workspaces extends GTF { function PUT() { if (!empty($this->aValues["action"]) && $this->aValues["action"] == "Metadata") { $aReturn = $this->reintegrateMetadata(); - $aXmlRacineAttribute['status'] = $aReturn['status']; - $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); + if ($aReturn['status'] == 1) + $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); + else { + $oError = new VitisError(13, $aReturn['message']); + $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); + } } else { $sDirName = $this->aProperties['workspace_dir'] . "/" . (string) $this->aValues["my_vitis_id"]; @@ -1248,22 +1224,28 @@ class Workspaces extends GTF { */ function regenerateMetadata() { require $this->sRessourcesFile; - $aReturn = array('status' => 1, 'message' => ''); $aFields = $this->getFields($this->aProperties['schema_gtf'], "workspace", "workspace_id"); - $sFmwFile = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme/' . $aFields['fmw_file']; - $oObject = new GtfFmwParser($sFmwFile); - // Valeurs des colonnes "last_save_date" et "last_save_build" originales. - $aParams = array(); - $aParams['sSchemaGtf'] = array('value' => $this->aProperties['schema_gtf'], 'type' => 'schema_name'); - $aParams['workspace_id'] = array('value' => $this->aValues['my_vitis_id'], 'type' => 'number'); - $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getWorkspaceLastSaveData'], $aParams); - if (!$this->oConnection->oBd->enErreur()) { - $aRow = $this->oConnection->oBd->ligneSuivante($oPDOresult); - $oObject->sSaveDate = gmdate('Y-m-d G:i:s'); - $oObject->sSaveBuild = $aRow['last_save_build']; + // Lit le contenu du fichier .fmw du projet. + $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $aFields['fmw_file']); + // Remplace les métas données. + if ($sFmwFileContent !== false) { + $oFmwParser = new GtfFmwParser($aFields['fmw_file'], $sFmwFileContent, $this->aProperties); + // Valeurs des colonnes "last_save_date" et "last_save_build" originales. + $aParams = array(); + $aParams['sSchemaGtf'] = array('value' => $this->aProperties['schema_gtf'], 'type' => 'schema_name'); + $aParams['workspace_id'] = array('value' => $this->aValues['my_vitis_id'], 'type' => 'number'); + $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getWorkspaceLastSaveData'], $aParams); + if (!$this->oConnection->oBd->enErreur()) { + $aRow = $this->oConnection->oBd->ligneSuivante($oPDOresult); + $oFmwParser->sSaveDate = gmdate('Y-m-d G:i:s'); + $oFmwParser->sSaveBuild = $aRow['last_save_build']; + $aReturn = array('status' => 1, 'message' => ''); + } + // Mise à jour du projet en base. + $oFmwParser->updateMetadata($this->oConnection->oBd, $this->aValues["my_vitis_id"]); } - // Mise à jour du projet en base. - $oObject->updateMetadata($this->oConnection->oBd, $this->aValues["my_vitis_id"]); + else + $aReturn = array('status' => 0, 'message' => 'ERROR_WORKSPACE_FILE_NOT_FOUND'); return $aReturn; } @@ -1271,12 +1253,20 @@ class Workspaces extends GTF { * Reintegrate workspace metadata. */ function reintegrateMetadata() { - $aReturn = array('status' => 1, 'message' => ''); $aFields = $this->getFields($this->aProperties['schema_gtf'], "workspace", "workspace_id"); - $sFmwFile = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme/' . $aFields['fmw_file']; - $oObject = new GtfFmwParser($sFmwFile); - $oObject->getBdMetadata($this->oConnection->oBd, $this->aValues["my_vitis_id"]); - $oObject->save($sFmwFile); + // Lit le contenu du fichier .fmw du projet. + $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $aFields['fmw_file']); + // Remplace les métas données. + if ($sFmwFileContent !== false) { + $oFmwParser = new GtfFmwParser($aFields['fmw_file'], $sFmwFileContent, $this->aProperties); + $oFmwParser->getBdMetadata($this->oConnection->oBd, $this->aValues["my_vitis_id"]); + $oFmwParser->save($oFmwParser->sFmwFileName); + putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $aFields['fmw_file'], file_get_contents($oFmwParser->sFmwFileName)); + $aReturn = array('status' => 1, 'message' => ''); + } + else { + $aReturn = array('status' => 0, 'message' => 'ERROR_WORKSPACE_FILE_NOT_FOUND'); + } return $aReturn; }