diff --git a/src/module_gtf/web_service/ws/Workspace.class.inc b/src/module_gtf/web_service/ws/Workspace.class.inc index 229163284fef843c8cfc6d14a1abf9152c0ef1fc..183128f8f1ec9263b8f4d5d8b7215618c9f51c33 100755 --- a/src/module_gtf/web_service/ws/Workspace.class.inc +++ b/src/module_gtf/web_service/ws/Workspace.class.inc @@ -2,6 +2,7 @@ require_once 'Gtf.class.inc'; require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vitis_lib/Connection.class.inc'; +require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/files/Files_manager.class.inc'; /** * \file Workspace.class.inc @@ -12,7 +13,7 @@ require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vitis_lib/Connection * \brief This file contains the Workspace php class * * This class defines operation for one Workspace - * + * */ class Workspace extends GTF { @@ -32,7 +33,7 @@ class Workspace extends GTF { } /** - * @SWG\Get(path="/workspaces/{workspace_id}", + * @SWG\Get(path="/workspaces/{workspace_id}", * tags={"Workspaces"}, * summary="Get Workspace", * description="Request to get Workspace by id", @@ -169,6 +170,7 @@ class Workspace extends GTF { * get informations about workspace */ function GET() { + $oFilesManager = new Files_manager($this->aProperties); if (!empty($this->aValues["form"])) { require $this->sRessourcesFile; $this->aFields = $this->getFields($this->aProperties['schema_gtf'], "v_workspace", "workspace_id"); @@ -186,20 +188,19 @@ class Workspace extends GTF { $this->oError = new VitisError(1, "Error parameter is not a known mode"); } // Contenu du fichier de formulaire. - $sFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'form', $sFile); + $sDirPath = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"]; + $sFileContent = $oFilesManager->oFileInterface->file_get_contents($sDirPath . '/form/' . $sFile); if ($sFileContent !== false) { $aJson = json_decode($sFileContent, true); $this->aFields["json_form"] = array($aJson); $sJs = ""; $sCss = ""; // Url du fichier js du formulaire. - $sFileUrl = getFileUrlInWsDataDir('gtf', 'workspace', $this->aValues['my_vitis_id'], 'form/ressources', 'Subform.js'); - if ($sFileUrl !== false) - $sJs = $sFileUrl; + $sFileUrl = $oFilesManager->oFileInterface->getProxyPassUrl($sDirPath . '/form/ressources/Subform.js'); + $sJs = $sFileUrl; // Url du fichier css du formulaire. - $sFileUrl = getFileUrlInWsDataDir('gtf', 'workspace', $this->aValues['my_vitis_id'], 'form/ressources', 'Subform.css'); - if ($sFileUrl !== false) - $sCss = $sFileUrl; + $sFileUrl = $oFilesManager->oFileInterface->getProxyPassUrl($sDirPath . '/form/ressources/Subform.css'); + $sCss = $sFileUrl; // array_push($this->aFields["json_form"], $sJs); array_push($this->aFields["json_form"], $sCss); @@ -212,13 +213,15 @@ class Workspace extends GTF { $this->getGroups(); // Url vers le fichier fmw du projet. if (!empty($this->aFields['fmw_file'])) { - $sFmwFileUrl = getFileUrlInWsDataDir('gtf', 'workspace', $this->aValues['my_vitis_id'], 'fme', $this->aFields['fmw_file']); - if ($sFmwFileUrl !== false) + $sFilePath = $this->aProperties['workspace_dir'] . '/' . $this->aValues['my_vitis_id'] . '/fme/' . $this->aFields['fmw_file']; + $sFmwFileUrl = $oFilesManager->oFileInterface->getProxyPassUrl($sFilePath); + if (!empty($sFmwFileUrl)) $this->aFields['fmw_file_url'] = $sFmwFileUrl; } } // Formatage de la colonne "form_type". - if (!fileExistsInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json')) + $sFilePath = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/form/Subform.json'; + if (!$oFilesManager->oFileInterface->file_exists($sFilePath)) $this->aFields['form_type'] = ''; else { if ($this->aFields['form_type'] != "custom") @@ -258,10 +261,12 @@ class Workspace extends GTF { $this->oError = new VitisError(1, $this->oConnection->oBd->getBDMessage()); } else { // Suppression du répertoire du projet FME. - deleteDirectoryInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], '', ''); + $oFilesManager = new Files_manager($this->aProperties); + $sDirPath = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"]; + $oFilesManager->oFileInterface->clearDir($sDirPath); } } } -?> \ No newline at end of file +?> diff --git a/src/module_gtf/web_service/ws/Workspaces.class.inc b/src/module_gtf/web_service/ws/Workspaces.class.inc index 0e9a34d296abd5978bb566e2f83e17972c619b6c..63d7fd789faade6ab7c49cdb1d9db9d5c8d8573d 100755 --- a/src/module_gtf/web_service/ws/Workspaces.class.inc +++ b/src/module_gtf/web_service/ws/Workspaces.class.inc @@ -9,7 +9,7 @@ * \brief This file contains the Workspaces php class * * This class defines Rest Api to Gtf workspaces - * + * */ require_once 'Gtf.class.inc'; require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vitis_lib/Connection.class.inc'; @@ -17,6 +17,7 @@ require_once 'Workspace.class.inc'; require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/BdDataAccess.inc'; require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/phpUtil.inc'; require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/gtf_lib/GtfFmwParser.class.inc'; +require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/files/Files_manager.class.inc'; class Workspaces extends GTF { /** @@ -168,8 +169,10 @@ class Workspaces extends GTF { $aReturn = $this->genericGet($this->aProperties['schema_gtf'], "v_workspace", "workspace_id"); // Formatage de la colonne "form_type". if ($aReturn['sStatus'] == 1) { + $oFilesManager = new Files_manager($this->aProperties); foreach ($this->aObjects as &$oWorkspace) { - if (!fileExistsInWsDataDir('gtf', 'workspace', $oWorkspace->aFields['workspace_id'], 'form', 'Subform.json')) + $sFilePath = $this->aProperties['workspace_dir'] . '/' . $oWorkspace->aFields['workspace_id'] . '/form/Subform.json'; + if (!$oFilesManager->oFileInterface->file_exists($sFilePath)) $oWorkspace->aFields['form_type'] = ''; else { if ($oWorkspace->aFields['form_type'] != "custom") @@ -308,8 +311,9 @@ class Workspaces extends GTF { * @return id of the workspace created */ function POST() { + $oFilesManager = new Files_manager($this->aProperties); require $this->sRessourcesFile; - // Importation de projets. + // Création du fichier html du widget. if (!empty($this->aPath[3]) && $this->aPath[3] === "GenerateWidgetFile") { unset($this->aPath[3]); $oWorkspace = new Workspace($this->aPath, $this->aValues, $this->aProperties, $this->oConnection); @@ -320,10 +324,15 @@ class Workspaces extends GTF { $sWidgetHtml = '<!DOCTYPE html>' . PHP_EOL . '<html>' . PHP_EOL . '<head>' . PHP_EOL . '<title>Widget</title>' . PHP_EOL . '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . PHP_EOL . '<meta http-equiv="X-UA-Compatible" content="IE=edge">' . PHP_EOL . '</head>' . PHP_EOL . '<body>'; $sWidgetHtml .= $this->aValues['widgetFileContent']; $sWidgetHtml .= '' . PHP_EOL . '</body>' . PHP_EOL . '</html>'; + // Création du répertoire des widgets si inexistant. + $sDirPath = $this->aProperties['ws_data_dir'] . '/gtf/widget'; + if (!$oFilesManager->oFileInterface->is_dir($sDirPath)) + $oFilesManager->oFileInterface->mkdir($sDirPath, 0777, true); // Création du fichier du widget. - if (putFileContentInWsDataDir('gtf', 'widget', '', '', $sWorkspace_key . ".html", $sWidgetHtml) !== false) { + $sFilePath = $sDirPath . '/' . $sWorkspace_key . ".html"; + if ($oFilesManager->oFileInterface->file_put_contents($sFilePath, $sWidgetHtml) !== false) { // Url du fichier du widget. - $sFileUrl = getFileUrlInWsDataDir('gtf', 'widget', '', '', $sWorkspace_key . ".html"); + $sFileUrl = $oFilesManager->oFileInterface->getProxyPassUrl($sFilePath); if ($sFileUrl !== false) $this->aFields['widget_file_url'] = $sFileUrl; $aXmlRacineAttribute['status'] = 1; @@ -336,6 +345,7 @@ class Workspaces extends GTF { } return $sMessage; } + // Importation de projets. if (!empty($this->aValues['mode']) && $this->aValues['mode'] == "import") { for ($i = 0; $i < count($_FILES['fmw_file']['name']); $i++) { $aParams = array(); @@ -384,7 +394,8 @@ class Workspaces extends GTF { $sFilePathName = $this->aProperties['workspace_dir'] . "/" . $oWorkspace->aFields["workspace_id"] . "/fme/" . $_FILES['fmw_file']['name'][$i]; $sDirName = $this->aProperties['workspace_dir'] . "/" . $oWorkspace->aFields["workspace_id"]; // Si le répertoire existe déja : suppression. - deleteDirectoryInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], '', ''); + if ($oFilesManager->oFileInterface->is_dir($sDirName)) + $oFilesManager->oFileInterface->clearDir($sDirName); // Upload du fichier fmw. $this->aValues['fme'] = $this->aValues['fmw_file']; $_FILES['fme'] = array( @@ -402,21 +413,22 @@ class Workspaces extends GTF { $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); } else { // 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'); + $oFilesManager->oFileInterface->copy($sDirName . '/fme/' . $_FILES['fmw_file']['name'][$i], $sDirName . '/fme/' . $_FILES['fmw_file']['name'][$i] . '.bak'); // Création des fichiers vides de ressources js et 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', ''); + $oFilesManager->oFileInterface->mkdir($sDirName . '/form/ressources', 0777, true); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/ressources/Subform.js', ''); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/ressources/Subform.css', ''); // Lit le contenu du fichier .fmw du projet. - $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'][$i]); + $sFmwFileContent = $oFilesManager->oFileInterface->file_get_contents($sDirName . '/fme/' . $_FILES['fmw_file']['name'][$i]); // Sauve le .fmw sans les visualizers. $oFmwParser = new GtfFmwParser($_FILES['fmw_file']['name'][$i], $this->aProperties, $sFmwFileContent); $oFmwParser->save($oFmwParser->sFmwFileName); - putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'][$i], file_get_contents($oFmwParser->sFmwFileName)); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/fme/' . $_FILES['fmw_file']['name'][$i], file_get_contents($oFmwParser->sFmwFileName)); // Création des formulaires json. $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'); + if ($oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/Subform.json', json_encode($aJson)) !== false) { + $oFilesManager->oFileInterface->copy($sDirName . '/form/Subform.json', $sDirName . '/form/WSubform.json'); + $oFilesManager->oFileInterface->copy($sDirName . '/form/Subform.json', $sDirName . '/form/DSubform.json'); } $oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]); // @@ -458,7 +470,7 @@ class Workspaces extends GTF { $oError = new VitisError(1, "FORM_WORKSPACE_NAME_EXISTS_PUBLICATION_WORKSPACE"); $aXmlRacineAttribute['status'] = 0; $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); - } + } else { $this->aValues['creation_date'] = gmdate('Y-m-d H:i:s'); // Création de la clé du projet. @@ -506,12 +518,12 @@ class Workspaces extends GTF { } $sDirName = $this->aProperties['workspace_dir'] . "/" . $oWorkspace->aFields["workspace_id"]; // Si le répertoire existe déja : suppression. - deleteDirectoryInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], '', ''); + if ($oFilesManager->oFileInterface->is_dir($sDirName)) + $oFilesManager->oFileInterface->clearDir($sDirName); // Upload du fichier fmw. $this->aValues['fme'] = $this->aValues['fmw_file']; $_FILES['fme'] = $_FILES['fmw_file']; $sErrorMessage = uploadInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], "fme", $this->aValues, -1, "fmw"); - // Copie du .fmw original en .bak. if (!empty($sErrorMessage)) { writeToErrorLog($sErrorMessage); $oError = new VitisError(8, $sErrorMessage); @@ -519,10 +531,12 @@ class Workspaces extends GTF { $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); } else { - copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], $_FILES['fmw_file']['name'] . '.bak'); + // Copie du .fmw original en .bak. + $oFilesManager->oFileInterface->copy($sDirName . '/fme/' . $_FILES['fmw_file']['name'], $sDirName . '/fme/' . $_FILES['fmw_file']['name'] . '.bak'); // Création des fichiers vides de ressources js et 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', ''); + $oFilesManager->oFileInterface->mkdir($sDirName . '/form/ressources', 0777, true); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/ressources/Subform.js', ''); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/ressources/Subform.css', ''); // Upload du fichier de ressource. if ($this->aValues["comp_file"] != "") { // Si le fichier est une archive .zip -> décompression et copie des fichiers. @@ -533,16 +547,16 @@ class Workspaces extends GTF { $sErrorMessage = uploadInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], "fme", $this->aValues); } // Lit le contenu du fichier .fmw du projet. - $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name']); + $sFmwFileContent = $oFilesManager->oFileInterface->file_get_contents($sDirName . '/fme/' . $_FILES['fmw_file']['name']); // Sauve le .fmw sans les visualizers. $oFmwParser = new GtfFmwParser($_FILES['fmw_file']['name'], $this->aProperties, $sFmwFileContent); $oFmwParser->save($oFmwParser->sFmwFileName); - putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], file_get_contents($oFmwParser->sFmwFileName)); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/fme/' . $_FILES['fmw_file']['name'], file_get_contents($oFmwParser->sFmwFileName)); // Création des formulaires json. $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'); + if ($oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/Subform.json', json_encode($aJson)) !== false) { + $oFilesManager->oFileInterface->copy($sDirName . '/form/Subform.json', $sDirName . '/form/WSubform.json'); + $oFilesManager->oFileInterface->copy($sDirName . '/form/Subform.json', $sDirName . '/form/DSubform.json'); } $oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]); /* * ************************************************************** */ @@ -695,6 +709,7 @@ class Workspaces extends GTF { * @return id of the workspace if ok error object if ko */ function PUT() { + $oFilesManager = new Files_manager($this->aProperties); if (!empty($this->aValues["action"]) && $this->aValues["action"] == "Metadata") { $aReturn = $this->reintegrateMetadata(); $aXmlRacineAttribute['status'] = $aReturn['status']; @@ -706,14 +721,9 @@ class Workspaces extends GTF { } } else { $sDirName = $this->aProperties['workspace_dir'] . "/" . (string) $this->aValues["my_vitis_id"]; - - - $sDirName = $this->aProperties['workspace_dir'] . "/" . (string) $this->aValues["my_vitis_id"]; - $error_message = ""; - // Si le dossier {id} n'existe pas (Important pour gérer les erreurs) - if (isDirInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"]) !== true) { + if (!$oFilesManager->oFileInterface->is_dir($sDirName)) { $error_message .= $sDirName . " does not exist"; writeToErrorLog("WARNING: " . $error_message); @@ -724,7 +734,7 @@ class Workspaces extends GTF { return $sMessage; } // Si le dossier {id}/fme n'existe pas (Important pour gérer les erreurs) - if (isDirInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme') !== true) { + if (!$oFilesManager->oFileInterface->is_dir($sDirName . '/fme')) { $error_message .= $sDirName . "/fme does not exist"; writeToErrorLog("WARNING: " . $error_message); @@ -736,10 +746,11 @@ class Workspaces extends GTF { } // Si le dossier {id}/form n'existe pas il est crée - if (isDirInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form') !== true) { + if (!$oFilesManager->oFileInterface->is_dir($sDirName . '/form')) { writeToErrorLog("WARNING: " . $sDirName . "/form dit not exist"); - if ($this->aProperties['fileS3Uploader'] === false) - @mkdir($sDirName . "/form"); + $oFilesManager->oFileInterface->mkdir($sDirName . '/form', 0777, true); + //if ($this->aProperties['fileS3Uploader'] === false) + //@mkdir($sDirName . "/form"); } if (!empty($this->aValues["cmd"])) { @@ -750,13 +761,13 @@ class Workspaces extends GTF { // 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 (!fileExistsInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json')) { + if (!$oFilesManager->oFileInterface->file_exists($sDirName . '/form/DSubform.json')) { $this->aValues["cmd"] = "Default_Reset"; $this->PUT(); } // 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'); + $oFilesManager->oFileInterface->unlink($sDirName . '/form/Subform.json'); + $oFilesManager->oFileInterface->copy($sDirName . '/form/DSubform.json', $sDirName . '/form/Subform.json'); $this->aValues["form_type"] = 'default'; break; // Regénère le formulaire par défaut en fonction du fmw @@ -766,7 +777,6 @@ class Workspaces extends GTF { if (empty($oWorkspace->aFields["fmw_file"])) { $error_message .= "Any FME file founded in" . $sDirName . "/fme/ "; writeToErrorLog("WARNING: " . $error_message); - $aXmlRacineAttribute['status'] = 0; $this->aFields = array(); $this->aFields['errorMessage'] = $error_message; @@ -774,44 +784,44 @@ class Workspaces extends GTF { return $sMessage; } // Lit le contenu du fichier .fmw du projet. - $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $oWorkspace->aFields["fmw_file"]); + $sFmwFileContent = $oFilesManager->oFileInterface->file_get_contents($sDirName . '/fme/' . $oWorkspace->aFields["fmw_file"]); // Création des formulaires json. $oFmwParser = new GtfFmwParser($oWorkspace->aFields["fmw_file"], $this->aProperties, $sFmwFileContent); $aJson = $oFmwParser->productJson($oWorkspace->aFields["name"]); - if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json', json_encode($aJson)) === false) + if ($oFilesManager->oFileInterface->file_put_contents($sDirName . '/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" : - deleteFileFromWsDataDirTree('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json'); - copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'WSubform.json', 'Subform.json'); + $oFilesManager->oFileInterface->unlink($sDirName . '/form/Subform.json'); + $oFilesManager->oFileInterface->copy($sDirName . '/form/WSubform.json', $sDirName . '/form/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 (!fileExistsInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json')) { + if (!$oFilesManager->oFileInterface->file_exists($sDirName . '/form/DSubform.json')) { $this->aValues["cmd"] = "Default_Reset"; $this->PUT(); } // 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'); + $oFilesManager->oFileInterface->unlink($sDirName . '/form/WSubform.json'); + $oFilesManager->oFileInterface->copy($sDirName . '/form/DSubform.json', $sDirName . '/form/WSubform.json'); break; // Sauvegarde le formulaire personnalisé. case "Perso_Save": // Sauve le formulaire personnalisé. - if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'WSubform.json', $this->aValues["Json"]) === false) + if ($oFilesManager->oFileInterface->file_put_contents($sDirName . '/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"] != "") { - if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js', $this->aValues["Js"]) === false) + if ($oFilesManager->oFileInterface->file_put_contents($sDirName . '/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"] != "") { - if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css', $this->aValues["Css"]) === false) + if ($oFilesManager->oFileInterface->file_put_contents($sDirName . '/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; @@ -824,7 +834,8 @@ class Workspaces extends GTF { // Upload du fichier de ressource. if (!empty($this->aValues["comp_file_file"])) { $this->aValues["comp_file"] = $this->aValues["comp_file_name"]; - putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $this->aValues["comp_file_name"], $this->aValues["comp_file_file"]); + $sFilePath = $sDirName . '/fme/' . $this->aValues["comp_file_name"]; + $oFilesManager->oFileInterface->file_put_contents($sFilePath, $this->aValues["comp_file_file"]); // Si le fichier est une archive .zip -> décompression et copie du répertoire. if (pathinfo($this->aValues["comp_file"], PATHINFO_EXTENSION) == "zip") { $sZipFilePath = $this->aProperties['extract_dir'] . '/' . $this->aValues["comp_file_name"]; @@ -858,8 +869,8 @@ class Workspaces extends GTF { $aExt = explode(".", $this->aValues["fmw_file_name"]); if ($aExt[count($aExt) - 1] == "fmw") { // Sauve le nouveau fichier fmw. - putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $this->aValues["fmw_file_name"], $this->aValues["fmw_file_file"]); - // Copie du .fmw original en .bak. + $sFilePath = $sDirName . '/fme/' . $this->aValues["fmw_file_name"]; + $oFilesManager->oFileInterface->file_put_contents($sFilePath, $this->aValues["fmw_file_file"]); if (!empty($sErrorMessage)) { writeToErrorLog($sErrorMessage); $oError = new VitisError(8, $sErrorMessage); @@ -867,21 +878,22 @@ class Workspaces extends GTF { $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); } else { - copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $this->aValues['fmw_file_name'], $this->aValues['fmw_file_name'] . '.bak'); + // Copie du .fmw original en .bak. + $oFilesManager->oFileInterface->copy($sDirName . '/fme/' . $this->aValues['fmw_file_name'], $sDirName . '/fme/' . $this->aValues['fmw_file_name'] . '.bak'); // Création des fichiers vides de ressources js et 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', ''); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/ressources/Subform.js', ''); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/ressources/Subform.css', ''); // Lit le contenu du fichier .fmw du projet. - $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $this->aValues['fmw_file_name']); + $sFmwFileContent = $oFilesManager->oFileInterface->file_get_contents($sDirName . '/fme/' . $this->aValues['fmw_file_name']); // Sauve le .fmw sans les visualizers. $oFmwParser = new GtfFmwParser($this->aValues['fmw_file_name'], $this->aProperties, $sFmwFileContent); $oFmwParser->save($oFmwParser->sFmwFileName); - putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $this->aValues['fmw_file_name'], file_get_contents($oFmwParser->sFmwFileName)); + $oFilesManager->oFileInterface->file_put_contents($sDirName . '/fme/' . $this->aValues['fmw_file_name'], file_get_contents($oFmwParser->sFmwFileName)); // Création des formulaires json. $aJson = $oFmwParser->productJson($oWorkspace->aFields["name"]); - if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json', json_encode($aJson)) !== false && $oWorkspace->aFields["form_type"] == 'default') { - copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json', 'WSubform.json'); - copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'DSubform.json', 'Subform.json'); + if ($oFilesManager->oFileInterface->file_put_contents($sDirName . '/form/DSubform.json', json_encode($aJson)) !== false) { + $oFilesManager->oFileInterface->copy($sDirName . '/form/DSubform.json', $sDirName . '/form/WSubform.json'); + $oFilesManager->oFileInterface->copy($sDirName . '/form/DSubform.json', $sDirName . '/form/Subform.json'); } // Récupère les anciens paramètres. $oFmwParser->getBdMetadata($this->oConnection->oBd, $this->aValues["my_vitis_id"]); @@ -1053,7 +1065,9 @@ class Workspaces extends GTF { $oWorkspace->GET(); $sWorkspace_key = $oWorkspace->aFields["key"]; // Suppression du fichier de widget. - if (deleteFileFromWsDataDirTree('gtf', 'widget', '', '', $sWorkspace_key . '.html') === false) { + $oFilesManager = new Files_manager($this->aProperties); + $sFilePath = $this->aProperties['ws_data_dir'] . '/gtf/widget/' . $sWorkspace_key . '.html'; + if ($oFilesManager->oFileInterface->file_exists($sFilePath) && !$oFilesManager->oFileInterface->unlink($sFilePath)) { $aReturn = array('status' => 0, 'message' => 'DELETE_FILE_ERROR_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY', 'error_code' => null); writeToErrorLog('Failed to remove the wisget file ' . $sWorkspace_key . '.html'); } @@ -1087,7 +1101,7 @@ class Workspaces extends GTF { } else $this->aFields['tree'] = $aWorkspaceDirectoryTree; - } + } else { $sWorkspaceDir = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme'; $sTreeName = 'fme'; @@ -1159,7 +1173,7 @@ class Workspaces extends GTF { // Sauve le nom et la date du fichier. $aFilteredDir['files'][] = array( 'path' => utf8_encode($sPath), - 'last_modif' => floor((time() - $aFileInfos['mtime']) / (24 * 3600)) // dernière modif. (Nb jours). + 'last_modif' => floor((time() - $aFileInfos['mtime']) / (24 * 3600)) // dernière modif. (Nb jours). ); } } @@ -1171,7 +1185,9 @@ class Workspaces extends GTF { */ function getWorkspaceFile() { // Chargement du contenu du fichier. - $sFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $this->aValues['file_name']); + $oFilesManager = new Files_manager($this->aProperties); + $sFilePath = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme/' . $this->aValues['file_name']; + $sFileContent = $oFilesManager->oFileInterface->file_get_contents($sFilePath); if ($sFileContent !== false) { // Copie du fichier dans un répertoire temporaire. $sFilePath = $this->aProperties['extract_dir'] . '/' . getUniqRandomId() . '/' . $this->aValues['file_name']; @@ -1196,21 +1212,22 @@ class Workspaces extends GTF { * Check if Widget file exist */ function checkWidgetFile() { + $oFilesManager = new Files_manager($this->aProperties); $aReturn = array('status' => 1); unset($this->aPath[3]); $oWorkspace = new Workspace($this->aPath, $this->aValues, $this->aProperties, $this->oConnection); $oWorkspace->GET(); $this->aFields['workspace_key'] = $oWorkspace->aFields["key"]; $sWidgetFile = $this->aFields['workspace_key'] . '.html'; - if (!fileExistsInWsDataDir('gtf', 'widget', '', '', $sWidgetFile)) { + $sFilePath = $this->aProperties['ws_data_dir'] . '/gtf/widget/' . $sWidgetFile; + if (!$oFilesManager->oFileInterface->file_exists($sFilePath)) { $aReturn = array('status' => 0, 'error_code' => 13, 'message' => 'The file ' . $sWidgetFile . ' does not exist.'); WriteToErrorLog("The file '$sWidgetFile' does not exist."); } else { // Url du fichier du widget. - $sFileUrl = getFileUrlInWsDataDir('gtf', 'widget', '', '', $sWidgetFile); - if ($sFileUrl !== false) - $this->aFields['widget_file_url'] = $sFileUrl; + $sFileUrl = $oFilesManager->oFileInterface->getProxyPassUrl($sFilePath); + $this->aFields['widget_file_url'] = $sFileUrl; } return $aReturn; } @@ -1219,8 +1236,10 @@ class Workspaces extends GTF { * Delete workspace file. */ function deleteWorkspaceFile() { + $oFilesManager = new Files_manager($this->aProperties); $aReturn = array('status' => 1, 'message' => ''); - if (deleteFileFromWsDataDirTree('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $this->aValues['file_name']) === false) + $sFilePath = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme/' . $this->aValues['file_name']; + if (!$oFilesManager->oFileInterface->unlink($sFilePath)) $aReturn = array('status' => 0, 'message' => 'DELETE_FILE_ERROR_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY', 'error_code' => null); return $aReturn; } @@ -1232,7 +1251,9 @@ class Workspaces extends GTF { require $this->sRessourcesFile; $aFields = $this->getFields($this->aProperties['schema_gtf'], "workspace", "workspace_id"); // Lit le contenu du fichier .fmw du projet. - $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $aFields['fmw_file']); + $oFilesManager = new Files_manager($this->aProperties); + $sFilePath = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme/' . $aFields['fmw_file']; + $sFmwFileContent = $oFilesManager->oFileInterface->file_get_contents($sFilePath); // Remplace les métas données. if ($sFmwFileContent !== false) { $oFmwParser = new GtfFmwParser($aFields['fmw_file'], $this->aProperties, $sFmwFileContent); @@ -1261,13 +1282,15 @@ class Workspaces extends GTF { function reintegrateMetadata() { $aFields = $this->getFields($this->aProperties['schema_gtf'], "workspace", "workspace_id"); // Lit le contenu du fichier .fmw du projet. - $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], 'fme', $aFields['fmw_file']); + $oFilesManager = new Files_manager($this->aProperties); + $sFilePath = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme/' . $aFields['fmw_file']; + $sFmwFileContent = $oFilesManager->oFileInterface->file_get_contents($sFilePath); // Remplace les métas données. if ($sFmwFileContent !== false) { $oFmwParser = new GtfFmwParser($aFields['fmw_file'], $this->aProperties, $sFmwFileContent); $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)); + $oFilesManager->oFileInterface->file_put_contents($sFilePath, file_get_contents($oFmwParser->sFmwFileName)); $aReturn = array('status' => 1, 'message' => ''); } else { @@ -1392,4 +1415,4 @@ class Workspaces extends GTF { } } -?> \ No newline at end of file +?>