Commit d2c6f4f1 authored by Gerald Salin's avatar Gerald Salin
Browse files

ajout d'une vérification de taille avant de lancer le téléchargement de...

ajout d'une vérification de taille avant de lancer le téléchargement de données + timeout sur les requêtes ajax
parent 79003eb2
......@@ -45,9 +45,83 @@ class tx_nG6_eid {
$ids = trim(t3lib_div::_GP('ids'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$tmp_folder = trim(t3lib_div::_GP('tmp_folder'));
print $this->get_download_file($ids, $data_folder, $tmp_folder);
}
print $this->get_download_file($ids, $data_folder, $tmp_folder);
}else if ($type == 'getFileSize') {
$ids = trim(t3lib_div::_GP('ids'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
print $this->get_file_size($ids, $data_folder);
}
}
function get_file_size($ids, $data_folder) {
$src_directories = Array();
$vals = split(";", $ids);
$fileSize = 0;
foreach($vals as $val) {
if ($val != "undefined" && $val != "") {
$id = split("_", $val);
if ($id[0] == "data") {
$run = $this->get_run($id[1]);
if (!in_array($data_folder.$run["directory"], $src_directories)) {
$src_directories[] = $data_folder.$run["directory"];
$fileSize += $this->getSize($data_folder.$run["directory"]);
}
} else if ($id[0] == "run") {
$run = $this->get_run($id[1]);
if (!in_array($data_folder.$run["directory"], $src_directories)) {
$src_directories[] = $data_folder.$run["directory"];
$fileSize += $this->getSize($data_folder.$run["directory"]);
}
foreach($this->get_run_analysis($id[1]) as $analyse_id => $analyse_values) {
if (!in_array($data_folder.$analyse_values["directory"], $src_directories)) {
$src_directories[] = $data_folder.$analyse_values["directory"];
$fileSize += $this->getSize($data_folder.$analyse_values["directory"]);
}
}
} else if ($id[0] == "analyse") {
$analyse = $this->get_analyse($id[1]);
if (!in_array($data_folder.$analyse["directory"], $src_directories)) {
$src_directories[] = $data_folder.$analyse["directory"];
$fileSize += $this->getSize($data_folder.$analyse["directory"]);
}
}
}
}
return $fileSize;
}
/**
* get total size of files contained in $dir_src
*
* @param string $dir_src: name of a file or directory for wich we want the size
* @return integer total size of the files
*/
function getSize($dir_src)
{
$filesSize = 0;
##Do an exhaustive list of files from the directories list
$iterator = new DirectoryIterator($dir_src);
foreach ($iterator as $fileinfo)
{
$filename = $fileinfo->getFilename() ;
$isNotRecursiveLink = ($filename!="." and $filename!="..") ;
$isNotCrap = ($isNotRecursiveLink and $filename!="index.html" and $filename!="run.cfg" );
if ($fileinfo->isDir() and $isNotCrap)
{ // get recursively subdirectories files
$dirpathname = $this->dirSlash($fileinfo->getPathname());
// then actualize the list of file to zip
$filesSize += $this->getSize( $dirpathname) ;
}
elseif ($fileinfo->isFile() and $isNotCrap)
{
$filesSize = $fileinfo->getSize();
//echo "Nom du fichier : " . $filename . "<br />";
//echo "taille du fichiers : $fileSize <br />";
//echo "taille des fichiers : $filesSize <br />";
}
}
return $filesSize;
}
function get_download_file($ids, $data_folder, $tmp_folder) {
$src_directories = Array();
......@@ -445,4 +519,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/cla
$SOBE = t3lib_div::makeInstance('tx_nG6_eid');
$SOBE->main();
?>
\ No newline at end of file
?>
......@@ -177,18 +177,48 @@ class tx_nG6_pi5 extends tslib_pibase {
$("#download_btn").click(function() {
if (!$(this).hasClass("tx-nG6-pi5-download-disable")) {
var url_val = "index.php?eID=tx_nG6&type=download&data_folder='.$this->conf["data"].'&tmp_folder='.$this->conf["temp"].'&ids=";
var url_test_filesize = "index.php?eID=tx_nG6&type=getFileSize&data_folder='.$this->conf["data"].'&ids=";
var url_val = "index.php?eID=tx_nG6&type=download&data_folder='.$this->conf["data"].'&tmp_folder='.$this->conf["temp"].'&ids=";
$(".jstree-checked > ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked").each(function(){
url_val += $(this).attr("id")+";";
url_test_filesize += $(this).attr("id")+";";
url_val += $(this).attr("id")+";";
});
$("#download_dialog").dialog("option", "title", "'.$this->getFieldHeader('download_dialog_title').'");
$("#download_dialog").html(\'<img src="fileadmin/templates/nG6template/images/light_wait.gif"/> '.$this->getFieldHeader('download_dialog_msg').'\').dialog("open");
$.ajax({
url: url_val,
success: function(val) {
$("#download_dialog").dialog("close");
location.href = "'.$tmp_url.'/"+val;
}
url: url_test_filesize,
timeout: 2500,
error: function(xhr, status, error) {
if(status == "timeout"){
// Display a generic error for now.
alert("'.$this->getFieldHeader('download_alert_timeout_getFileSize_msg').' '.$this->getFieldHeader('download_use_command_line_msg').'");
}
},
success: function(val,status, xhr) {
var limitFileSize = 200000000;//limite à 200 Mo
if (val < limitFileSize){
//alert("OK, taille inferieure a " + limitFileSize/1000 + "Ko ("+ val/1000 +" Ko)");
$("#download_dialog").dialog("option", "title", "'.$this->getFieldHeader('download_dialog_title').'");
$("#download_dialog").html(\'<img src="fileadmin/templates/nG6template/images/light_wait.gif"/> '.$this->getFieldHeader('download_dialog_msg').'\').dialog("open");
$.ajax({
url: url_val,
timeout: 90000,
error: function(xhr, status, error) {
$("#download_dialog").dialog("close");
if(status == "timeout"){
// Display a generic error for now.
alert("'.$this->getFieldHeader('download_alert_timeout_msg').' '.$this->getFieldHeader('download_use_command_line_msg').'");
}
},
success: function(val,status, xhr) {
$("#download_dialog").dialog("close");
location.href = "'.$tmp_url.'/"+val;
}
});
}else{
alert("'.$this->getFieldHeader('download_alert_max_filesize_exceeded_msg').'(" + val/1000000 + " sur "+ limitFileSize/1000000+"Mo autorises). '.$this->getFieldHeader('download_use_command_line_msg').'");
}
}
});
}
});
......@@ -211,7 +241,7 @@ class tx_nG6_pi5 extends tslib_pibase {
$content .= '<div '.$this->pi_classParam('download-builder').'> ';
$content .= '<div '.$this->pi_classParam('download-builder-group').'> <h2>'.$this->getFieldHeader('download_list_title').'<h2> <div id="download_list"> <ul><li><span>'.$this->getFieldHeader('download_list_no_select').'</span></li></ul></div></div>';
$content .= '<div '.$this->pi_classParam('download-builder-group').'> <h2>'.$this->getFieldHeader('download_format_title').'</h2>';
$content .= '<input type="radio" name="format" value="tar.gz" selected="selected"> .tar.gz</div>';
$content .= '<input type="radio" name="format" value="tar.gz" checked> .tar.gz</div>';
$content .= '<div '.$this->pi_classParam('download-builder-group').' style="border-bottom: 0;margin-top: 0;margin-bottom:0;padding-bottom:0;"> <input class="tx-nG6-pi5-download tx-nG6-pi5-download-disable" id="download_btn" type="button" value="'.$this->getFieldHeader('download_btn_label').'" /> </div> </div>';
return $content;
}
......@@ -413,4 +443,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi5
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi5/class.tx_nG6_pi5.php']);
}
?>
\ No newline at end of file
?>
......@@ -20,6 +20,10 @@
<label index="listFieldHeader_download_format_title">Download format :</label>
<label index="listFieldHeader_download_list_no_select">No run neither any analyse selected.</label>
<label index="listFieldHeader_all">Raw data + all analyses</label>
<label index="listFieldHeader_download_alert_timeout_getFileSize_msg">Getting the size of the files to be downloaded takes too long time.</label>
<label index="listFieldHeader_download_alert_timeout_msg">The download takes too long time.</label>
<label index="listFieldHeader_download_alert_max_filesize_exceeded_msg">The total size of the files you want to download is too high </label>
<label index="listFieldHeader_download_use_command_line_msg">Please use the command line to get your data.</label>
</languageKey>
<languageKey index="fr" type="array">
<label index="listFieldHeader_download_btn_label">T&amp;eacute;l&amp;eacute;charger</label>
......@@ -36,6 +40,10 @@
<label index="listFieldHeader_download_format_title">Format :</label>
<label index="listFieldHeader_download_list_no_select">Aucun run ni analyse s&amp;eacute;l&amp;eacute;ctionn&amp;eacute;.</label>
<label index="listFieldHeader_all">Donn&amp;eacute;es brutes + toutes les analyses</label>
<label index="listFieldHeader_download_alert_timeout_getFileSize_msg">La récupération de la taille totale des fichiers à charger prend trop de temps.</label>
<label index="listFieldHeader_download_alert_timeout_msg">Le chargement des données prend trop de temps.</label>
<label index="listFieldHeader_download_alert_max_filesize_exceeded_msg">La taille totale des fichiers que vous souhaitez télécharger est trop élevée </label>
<label index="listFieldHeader_download_use_command_line_msg">Veuillez utiliser l'outil en ligne de commande pour récupérer vos données SVP.</label>
</languageKey>
</data>
</T3locallang>
\ No newline at end of file
</T3locallang>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment