Skip to content
Snippets Groups Projects
Commit d55d241f authored by Anthony Borghi's avatar Anthony Borghi
Browse files

Modification du générateur d'URL de Vitis pour utiliser le File_Downloader

parent d245ebda
No related branches found
No related tags found
No related merge requests found
<?php <?php
require_once(__DIR__ . "/../../class/vitis_lib/DbClass.class.inc"); require_once(__DIR__ . "/../../class/vitis_lib/DbClass.class.inc");
require_once ("aws_sdk/aws-autoloader.php");
/** /**
* \file vitis.class.inc * \file vitis.class.inc
...@@ -209,7 +210,7 @@ class Vitis extends DbClass { ...@@ -209,7 +210,7 @@ class Vitis extends DbClass {
* @param $sVitisObjectName Name of the vitis object, if provide and the object contains files stored in ws_data/vitis/$sVitisObjectName the values will be url formed * @param $sVitisObjectName Name of the vitis object, if provide and the object contains files stored in ws_data/vitis/$sVitisObjectName the values will be url formed
* @return the array of objects * @return the array of objects
*/ */
function genericGet($sSchema, $sTable, $sIdField, $bOnlyReturnStatus = false, $sVitisObjectName = "") { function genericGet($sSchema, $sTable, $sIdField, $bOnlyReturnStatus = false, $sVitisObjectName = "", $sVitisModuleName = "vitis", $sVitisPathComplement = "documents") {
if (!empty($this->aProperties['ws_data_alias'])) if (!empty($this->aProperties['ws_data_alias']))
$ws_data_alias = $this->aProperties['ws_data_alias']; $ws_data_alias = $this->aProperties['ws_data_alias'];
else else
...@@ -249,13 +250,69 @@ class Vitis extends DbClass { ...@@ -249,13 +250,69 @@ class Vitis extends DbClass {
// Vérifie si il y a des fichiers à renvoyer // Vérifie si il y a des fichiers à renvoyer
if ($sVitisObjectName != "") { if ($sVitisObjectName != "") {
$sDataDir = $this->aProperties['ws_data_dir'] . '/vitis/' . $sVitisObjectName . '/documents/' . $oObject->aFields[$sIdField]; $sDataUrl = $this->aProperties['web_server_name'] . "/rest/vitis/file_downloader?key=[KEY]&eTag=[ETAG]&d=" . $date->getTimestamp();
$sDataUrl = $this->aProperties['web_server_name'] . "/" . $ws_data_alias . "/vitis/" . $sVitisObjectName . "/documents/" . $oObject->aFields[$sIdField];
if($this->aProperties['fileS3Uploader']){
// use HEAD on s3 Object
// traitement du bucket et de ses sous-dossiers
$sBucket = $this->aProperties['fileS3UploaderBucket'];
$sPrefix = "";
if (strpos($sBucket, "/") > -1){
$aBucket = explode("/", $sBucket );
$sBucket = $aBucket[0];
$sPrefix = implode("/", array_slice($aBucket, 1));
}
// Création du client S3
$s3 = new Aws\S3\S3Client(array(
'version'=>'latest',
'region'=> $this->aProperties['fileS3UploaderRegion'],
'profile'=> $this->aProperties['fileS3UploaderProfil'],
'debug' => false
));
$sListPrefix = $sPrefix . "/ws_data/".$sVitisModuleName.'/' . $sVitisObjectName . '/';
if (!empty($sVitisPathComplement)){
$sListPrefix .= $sVitisPathComplement . '/';
}
$sListPrefix .= $oObject->aFields[$sIdField];
try{
$aList = $s3->listObjectsV2(array(
'Bucket' => $sBucket,
'Prefix' => $sListPrefix
));
if ($aList["KeyCount"] > 0){
foreach ($aList["Contents"] as $aObject){
$aPath = explode("/", $aObject["Key"]);
$sObjectField = $aPath[count($aPath) - 2];
$sFileUrl = str_replace("[KEY]", $aObject["Key"], $sDataUrl);
$oObject->aFields[$sObjectField] = str_replace("[ETAG]", str_replace('"', '', $aObject["ETag"]), $sFileUrl);
}
}
}catch(Aws\S3\Exception\S3Exception $e){
writeToErrorLog($e->getMessage());
}
} else {
// check dans ws_data
$sDataDir = $this->aProperties['ws_data_dir'] . '/'.$sVitisModuleName.'/' . $sVitisObjectName . '/' . $sVitisPathComplement . '/' . $oObject->aFields[$sIdField];
if (is_dir($sDataDir)) { if (is_dir($sDataDir)) {
// Remplace le nom du fichier par son url // Remplace le nom du fichier par son url
foreach ($oObject->aFields as $key => $value) { foreach ($oObject->aFields as $key => $value) {
if (is_dir($sDataDir . "/" . $key)) { if (is_dir($sDataDir . "/" . $key)) {
$oObject->aFields[$key] = $sDataUrl . "/" . $key . "/" . $value . "?d=" . $date->getTimestamp(); $sKey = "ws_data/".$sVitisModuleName.'/' . $sVitisObjectName . '/' . $sVitisPathComplement . '/' . $oObject->aFields[$sIdField]. "/" . $key . "/" . $value;
$sEtag = sha1(file_get_contents($sDataDir . "/" . $key . "/" . $value ), false);
$sFileUrl = str_replace("[KEY]", $sKey, $sDataUrl);
$oObject->aFields[$key] = str_replace("[ETAG]", $sEtag, $sFileUrl);
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment