From fa7e9ab5870d1843910e7604cc9703257c6072fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Carretero?= <frederic.carretero@veremes.com> Date: Wed, 21 Nov 2018 10:11:22 +0100 Subject: [PATCH] isDirInWsDataDir() -> teste si le dossier existe dans "ws_data" --- vas/rest/class/vmlib/phpUtil.inc | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/vas/rest/class/vmlib/phpUtil.inc b/vas/rest/class/vmlib/phpUtil.inc index a2aeaefa..b099bf54 100755 --- a/vas/rest/class/vmlib/phpUtil.inc +++ b/vas/rest/class/vmlib/phpUtil.inc @@ -1651,4 +1651,62 @@ function putFileContentInWsDataDir($sModule, $sObject, $mId = '', $sField = '', } } } + + /** + *This method check is the directory exist 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 $sDirectoryName Name of the directory to check. + *@return File content or false. + */ +function isDirInWsDataDir($sModule, $sObject, $mId, $sDirectoryName = '') { + global $properties; + $sDestDir = $properties['ws_data_dir'] . "/" . $sModule . "/" . $sObject . "/" . $mId; + if (!empty($sDirectoryName)) + $sDestDir .= '/' . $sDirectoryName; + 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); + // Vérification de l'existance du répertoire. + try { + $oAwsResult = $s3->listObjects(array( + 'Bucket' => $sBucket, + 'Prefix' => $sServerPath + )); + $aKeys = $oAwsResult->get('Contents'); + if (!empty($aKeys)) + return true; + else + return false; + } + catch(Aws\S3\Exception\S3Exception $e) { + writeToErrorLog($e->getMessage()); + } + } + else { + // Vérification de l'existance du répertoire. + if (file_exists($sDestDir) && is_dir($sDestDir)) + return true; + else + return false; + } +} ?> -- GitLab