diff --git a/vas/rest/class/vmlib/lang_vmlib/en-lang.inc b/vas/rest/class/vmlib/lang_vmlib/en-lang.inc index 1c43c89f2689e72a5e23cfa80cc3b3d3a1c26e06..006365fec1f7e23e8f0f64c221df4cdd04c8d8f7 100755 --- a/vas/rest/class/vmlib/lang_vmlib/en-lang.inc +++ b/vas/rest/class/vmlib/lang_vmlib/en-lang.inc @@ -103,6 +103,11 @@ define('ERROR_NUMBER_PHPUTIL', 'It can\'t be a number.'); define('ERROR_WEEK_CODE', 'The day code of the week "'); define('ERROR_CODE_3_VALUES', 'The code does not contain three values separated by a space.'); define('ERROR_CREATING_DIRECTORY', 'Error when creating the directory '); +define('ERROR_DELETING_DIRECTORY', 'Error when deleting the directory '); +define('ERROR_DELETING_FILE', 'Error when deleting the file '); +define('ERROR_READING_FILE_CONTENT', 'Error when reading the file '); +define('ERROR_WRITING_FILE_CONTENT', 'Erreor when writing data to the file '); +define('ERROR_FILE_NOT_FOUND', 'Erreur, file not found : '); define('YES', 'Yes'); define('NO', 'No'); diff --git a/vas/rest/class/vmlib/lang_vmlib/fr-lang.inc b/vas/rest/class/vmlib/lang_vmlib/fr-lang.inc index 06b608380e57c77d8e6afe2d60faab385087766b..b6081f918f8e766ff77716cddfb0d687bae4f464 100755 --- a/vas/rest/class/vmlib/lang_vmlib/fr-lang.inc +++ b/vas/rest/class/vmlib/lang_vmlib/fr-lang.inc @@ -103,6 +103,11 @@ define('ERROR_NUMBER_PHPUTIL', 'Il ne peut pas être un nombre.'); define('ERROR_WEEK_CODE', 'Le code du jour de la semaine "'); define('ERROR_CODE_3_VALUES', 'Le code ne contient pas trois valeurs séparées par un espace.'); define('ERROR_CREATING_DIRECTORY', 'Erreur lors de la création du répertoire '); +define('ERROR_DELETING_DIRECTORY', 'Erreur lors de la suppression du répertoire '); +define('ERROR_DELETING_FILE', 'Erreur lors de la suppression du fichier '); +define('ERROR_READING_FILE_CONTENT', 'Erreur lors de la lecture du fichier '); +define('ERROR_WRITING_FILE_CONTENT', 'Erreur lors de l\'écriture des données dans le fichier '); +define('ERROR_FILE_NOT_FOUND', 'Erreur, le fichier n\'existe pas : '); define('YES', 'Oui'); define('NO', 'Non'); diff --git a/vas/rest/class/vmlib/phpUtil.inc b/vas/rest/class/vmlib/phpUtil.inc index 67f9e08bfba1b1dd094123134f7ae4673c3c663a..092902c426a1fad4269b62ca74a4df65bcf90f7b 100755 --- a/vas/rest/class/vmlib/phpUtil.inc +++ b/vas/rest/class/vmlib/phpUtil.inc @@ -1566,4 +1566,68 @@ function deleteDirectoryInWsDataDir($sModule, $sObject, $mId, $sField = '', $sDi } return $sErrorMsg; } + + /** + *This method return the content of a file in ws_data. + *@file vmlib/phpUtil.inc + *@param $sModule Name of the module. + *@param $sObject Name of the object. + *@param $mId Id of the current object. + *@param $sField field name (generally DB column name). + *@param $sFileName Name of the file to read. + *@return File content or false. + */ +function getFileContentInWsDataDir($sModule, $sObject, $mId, $sField = '', $sFileName) { + global $properties; + $sDestDir = $properties['ws_data_dir'] . "/" . $sModule . "/" . $sObject . "/" . $mId; + if(!empty($sField)) + $sDestDir .= "/" . $sField; + if ($properties['fileS3Uploader'] === true) { + require_once ("aws_sdk/aws-autoloader.php"); + $s3 = new Aws\S3\S3Client(array( + 'version'=>'latest', + 'region'=> $properties['fileS3UploaderRegion'], + 'profile'=> $properties['fileS3UploaderProfil'], + 'debug' => false + )); + $sBucket = $properties['fileS3UploaderBucket']; + $sPrefix = ""; + if (strpos($sBucket, "/") > -1){ + $aBucket = explode("/", $sBucket ); + $sBucket = $aBucket[0]; + $sPrefix = implode("/", array_slice($aBucket, 1)); + } + $sServerPath = str_replace($properties["vas_home"], $sPrefix, $sDestDir); + // Suppression du slash de début de ligne (sinon création d'un répertoire vide sur S3). + if (strpos($sServerPath, '/') === 0) + $sServerPath = substr($sServerPath, 1); + if (!empty($sFileName)) + $sServerPath .= '/' . $sFileName; + // Lecture du fichier. + try { + $oAwsResult = $s3->getObject(array( + 'Bucket' => $sBucket, + 'Key' => $sServerPath + )); + return $oAwsResult->get('Body'); + } + catch(Aws\S3\Exception\S3Exception $e) { + writeToErrorLog($e->getMessage()); + } + } + else { + // Chargment du contenu du fichier. + $sFilePath = $sDestDir . '/' . $sFileName; + if (file_exists($sFilePath)) { + $sFileContent = file_get_contents($sFilePath); + if ($sFileContent === false) + writeToErrorLog(ERROR_READING_FILE_CONTENT . $sFilePath); + return $sFileContent; + } + else { + writeToErrorLog(ERROR_FILE_NOT_FOUND . $sFilePath); + return false; + } + } +} ?>