Commit f1d1ce12 authored by Celine Noirot's avatar Celine Noirot
Browse files

correct purge if an analyse list or run list is empty #24; test of connection only in utils;

parent a0472678
......@@ -856,23 +856,13 @@ class tx_nG6_eid {
print json_encode(tx_nG6_db::filter_list_retention_data_info($filter_size,$max_retention_date,$create_users, $without_laboratories_id,$with_laboratories_id));
} elseif ($type == 'delete_purge_data') {
//Delete data link to the list of purge demand
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$user_login = trim(t3lib_div::_GP('user_login'));
$user_pwd = trim(t3lib_div::_GP('user_pwd'));
// check login and password
$res = 0;
if (isset($user_login) && isset($user_pwd) && $user_login != 'undefined' && $user_pwd != 'undefined') {
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) { $res = 3; }
if (!ssh2_auth_password($connection, $user_login, $user_pwd)) { $res=2;}
} else {
$res = 3;
}
if ($res == 0) {
$res = tx_nG6_db::delete_purge_demand($purge_ids,$user_login, $user_pwd, $data_folder);
}
print $res;
$res = tx_nG6_db::delete_purge_demand($purge_ids,$user_login, $user_pwd, $data_folder);
print $res;
} elseif ($type == 'extend_retention_date_from_demand') {
//Extend the retention date for the
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
......
......@@ -449,9 +449,7 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup',
$all_demands=tx_nG6_db::get_purge_demand_from_id( join(', ', $demand_ids));
$all_runs=array();
$all_analyses=array();
error_log("extend extend_retention_date_from_demand ". join(',',$demand_ids) . " TYPE ". $type_extend);
foreach($all_demands as $res){
error_log("DEMAND ". json_encode($res) );
if ($res["demand_state"] != "deleted")
{
$all_runs=array();
......@@ -510,7 +508,6 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup',
}
}
function extend_runs_analyses($all_runs, $all_analyses, $date){
error_log("extend RUNS ". join(',',$all_runs)." - ANALYSES : " . join(',',$all_analyses));
tx_nG6_db::update_field('tx_nG6_run', $all_runs,
array("retention_date","data_state", "mail_sent_date","purge_demand_id"),
array($date,"extended","","NULL"),
......@@ -528,17 +525,22 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup',
$res = 0 ;
foreach($all_demands as $demand){
if ($demand["state"] != "deleted"){
foreach(explode(',',$demand["analyze_ids"]) as $a_id){
$res = tx_nG6_db::purge_analysis($a_id, $user_login, $user_pwd, $data_folder);
if ($res != 0) {
break;
if ($demand["analyze_ids"] != ""){
foreach(explode(',',$demand["analyze_ids"]) as $a_id){
$res = tx_nG6_db::purge_analysis($a_id, $user_login, $user_pwd, $data_folder);
if ($res != 0) {
break;
}
}
}
if ($res == 0) {
foreach(explode(',',$demand["run_ids"]) as $r_id){
$res = tx_nG6_db::purge_run($r_id, $user_login, $user_pwd, $data_folder);
if ($res != 0) {
break;
if ($demand["run_ids"] != ""){
foreach(explode(',',$demand["run_ids"]) as $r_id){
$res = tx_nG6_db::purge_run($r_id, $user_login, $user_pwd, $data_folder);
if ($res != 0) {
break;
}
}
}
}
......@@ -2087,9 +2089,8 @@ function get_project_runs($project_id, $orderby='', $limit='') {
'storage_size' => 0
);
$res = tx_nG6_utils::purge_directory($user_login, $user_pwd, $data_folder.$my_run['directory']);
$res = tx_nG6_utils::purge_directory($user_login, $user_pwd, $data_folder.$my_run['directory']);
if ($res == 0 ){ //delete file ok
if ( $my_run['data_state'] != "purged"){
$res_query = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_nG6_run', 'uid='.$r_id, $datas );
......@@ -2422,7 +2423,6 @@ function get_project_runs($project_id, $orderby='', $limit='') {
foreach ($analyzes_comments as $id => $values){
tx_nG6_db::delete_analyze_comment($a_id, $values['id']);
}
return $res;
}
......@@ -2436,6 +2436,7 @@ function get_project_runs($project_id, $orderby='', $limit='') {
* @param string $data_folder the data folder
* @return 0=>everything ok, 1=>user right problem, 2=>wrong authentification, 3=>connection error
*/
function purge_analysis($a_id, $user_login, $user_pwd, $data_folder) {
$res = 0;
......
......@@ -122,12 +122,10 @@ class tx_nG6_utils {
*/
function purge_directory($user_login, $user_pwd, $directory) {
// First try to connect the specified user using ssh
if ($directory != 'undefined' && $directory != '') {
if ($directory != 'undefined' && $directory != '') {
// And process the directories structure, remove all files except .html ans .png
$connection = ssh2_connect('127.0.0.1', 22);
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) {
return 3;
}else{
......@@ -142,13 +140,10 @@ class tx_nG6_utils {
stream_set_blocking($stream, true);
// Whichever of the two below commands is listed first will receive its appropriate output. The second command receives nothing
error_log("Output: " . stream_get_contents($stream));
if(stream_get_contents($errorStream)) {
error_log("mauvais identifiant");
return 1;
}else{
error_log("bon identifiant ");
return 0;
}
......@@ -160,6 +155,7 @@ class tx_nG6_utils {
}
return 0;
}
/**
* Return the string representation of a byte
......
Markdown is supported
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