Skip to content
Snippets Groups Projects
Commit fa7e9ab5 authored by Frédéric Carretero's avatar Frédéric Carretero
Browse files

isDirInWsDataDir() -> teste si le dossier existe dans "ws_data"

parent afad5d18
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment