diff --git a/vas/rest/class/vmlib/lang_vmlib/en-lang.inc b/vas/rest/class/vmlib/lang_vmlib/en-lang.inc index 44a182f35c904eb3dc8192f48a955801f712d184..1c43c89f2689e72a5e23cfa80cc3b3d3a1c26e06 100755 --- a/vas/rest/class/vmlib/lang_vmlib/en-lang.inc +++ b/vas/rest/class/vmlib/lang_vmlib/en-lang.inc @@ -102,6 +102,7 @@ define('ERROR_MONTH_CODE', 'The month code "'); 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('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 36e37795d6b49feaaed20971b26f88216ddf4eb2..06b608380e57c77d8e6afe2d60faab385087766b 100755 --- a/vas/rest/class/vmlib/lang_vmlib/fr-lang.inc +++ b/vas/rest/class/vmlib/lang_vmlib/fr-lang.inc @@ -102,6 +102,7 @@ define('ERROR_MONTH_CODE', 'Le code du mois "'); 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('YES', 'Oui'); define('NO', 'Non'); diff --git a/vas/rest/class/vmlib/phpUtil.inc b/vas/rest/class/vmlib/phpUtil.inc index 5b57b12567515992abb5838229dd45b8b8ace67a..2435bfbb6bcfa8dbdf0c2e430d9f847db8a86801 100755 --- a/vas/rest/class/vmlib/phpUtil.inc +++ b/vas/rest/class/vmlib/phpUtil.inc @@ -1438,4 +1438,64 @@ function copyFileInWsDataDir($sModule, $sObject, $mId, $sField = '', $sFileName, } return $sErrorMsg; } + + /** + *This method create an empty 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 copy. + *@return $sErrorMsg The error message. + */ +function createEmptyFileInWsDataDir($sModule, $sObject, $mId, $sField = '', $sFileName) { + global $properties; + $sErrorMsg = ''; + $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); + // Création du fichier vide. + try { + $aResult = $s3->putObject(array( + 'Bucket' => $sBucket, + 'Key' => $sServerPath . '/' . $sFileName, + 'Body' => '' + )); + } + catch(Aws\S3\Exception\S3Exception $e) { + writeToErrorLog($e->getMessage()); + } + } + else { + $sFilePath = $sDestDir . '/' . $sFileName; + // Création du répertoire de destination si inexistant. + if (!file_exists($sDestDir)) + if (!mkdir($sDestDir, 0777, true)) { + writeToErrorLog(ERROR_CREATING_DIRECTORY . $sDestDir); + return ERROR_CREATING_DIRECTORY . $sDestDir; + } + fclose(fopen($sFilePath, "w+")); + } + return $sErrorMsg; +} ?>