Commit 60dc52de authored by Celine Noirot's avatar Celine Noirot
Browse files

add email to members if no manager, refactor code

parent 6f82456f
......@@ -845,7 +845,7 @@ class tx_nG6_eid {
$all_projects = trim(t3lib_div::_GP('project'));
print json_encode(tx_nG6_pi6::send_purge_demand_mail($user_id,$all_projects));
}
} elseif ($type == 'refresh_purge_demand') {
} elseif ($type == 'refresh_purge_demand') {
$purge_delay = trim(t3lib_div::_GP('purge_delay'));
print json_encode(tx_nG6_db::get_purge_demand_list($purge_delay));
} elseif ($type == 'refresh_purge_list') {
......
......@@ -196,93 +196,77 @@ class tx_nG6_db {
function select_list_retention_data_info($where) {
$by_project=array();
$empty_res_structure = array(
'project_id' => "",
'project_name' => "",
'state' => array("purged" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"extended" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"stored" => array ( 'nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()
)
),
'total_purgeable_size' => 0,
'nb_runs' =>0,
'nb_analyses' =>0);
//select obsolete runs
$res = tx_nG6_db::select_all_in_view( "tx_nG6_view_project_run" , $where);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$current_project_id = $res_row['project_id'];
if (!isset ($by_project[$res_row['project_id']])) {
$by_project[$res_row['project_id']]= array(
'project_id' => $res_row['project_id'],
'project_name' => $res_row['project_name'],
'state' => array( "purged" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"extended" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"stored" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array())
),
'total_purgeable_size' => $res_row['storage_size'],
'nb_runs' =>0,
'nb_analyses' =>0);
$by_project[$current_project_id]= $empty_res_structure;
$by_project[$current_project_id]['project_name']= $res_row['project_name'];
}
if ($res_row['run_id'] != "") {
$by_project[$res_row['project_id']]['state'][$res_row['state']]['nb_run']+=1;
$key = 'storage_size';
if($res_row['state'] == "purged"){
$key = "purged_size";
}
$by_project[$res_row['project_id']]['state'][$res_row['state']]['size_run']+=$res_row[$key];
$by_project[$res_row['project_id']]['state'][$res_row['state']]['run_ids'][]=$res_row['run_id'];
$by_project[$res_row['project_id']]['total_purgeable_size'] += $res_row['storage_size'];
if ($res_row['run_id'] != "") {
$by_project[$res_row['project_id']]['state'][$res_row['state']]['nb_run']+=1;
$key = 'storage_size';
if($res_row['state'] == "purged"){
$key = "purged_size";
}
$by_project[$current_project_id]['state'][$res_row['state']]['size_run']+=$res_row[$key];
$by_project[$current_project_id]['state'][$res_row['state']]['run_ids'][]=$res_row['run_id'];
$by_project[$current_project_id]['total_purgeable_size'] += $res_row['storage_size'];
}
}
//select obsolete analyses of a run
$res = tx_nG6_db::select_all_in_view("tx_nG6_view_project_run_analyze",$where,'10');
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$current_project_id = $res_row['project_id'];
if (!isset ($by_project[$res_row['project_id']])) {
$by_project[$res_row['project_id']]= array(
'project_id' => $res_row['project_id'],
'project_name' => $res_row['project_name'],
'state' => array( "purged" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"extended" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"stored" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array())
),
'total_purgeable_size' => $res_row['storage_size'],
'nb_runs' =>0,
'nb_analyses' =>0);
$by_project[$current_project_id]= $empty_res_structure;
$by_project[$current_project_id]['project_name']= $res_row['project_name'];
}
if ($res_row['analyze_id'] != ""){
$by_project[$res_row['project_id']]['state'][$res_row['state']]['nb_analyze'] += 1;
$key = 'storage_size';
if($res_row['state'] == "purged"){
$key = "purged_size";
}
$by_project[$res_row['project_id']]['state'][$res_row['state']]['size_analyze'] += $res_row[$key];
$by_project[$res_row['project_id']]['state'][$res_row['state']]['analysis_ids'][]=$res_row['analyze_id'];
$by_project[$res_row['project_id']]['total_purgeable_size'] += $res_row['storage_size'];
if ($res_row['analyze_id'] != ""){
$by_project[$current_project_id]['state'][$res_row['state']]['nb_analyze'] += 1;
$key = 'storage_size';
if($res_row['state'] == "purged"){
$key = "purged_size";
}
$by_project[$current_project_id]['state'][$res_row['state']]['size_analyze'] += $res_row[$key];
$by_project[$current_project_id]['state'][$res_row['state']]['analysis_ids'][]=$res_row['analyze_id'];
$by_project[$current_project_id]['total_purgeable_size'] += $res_row['storage_size'];
}
}
//select obsolete analyses of a project
$res = tx_nG6_db::select_all_in_view("tx_nG6_view_project_analyze", $where);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$current_project_id = $res_row['project_id'];
if (!isset ($by_project[$res_row['project_id']])) {
$by_project[$res_row['project_id']]= array(
'project_id' => $res_row['project_id'],
'project_name' => $res_row['project_name'],
'state' => array( "purged" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"extended" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array()),
"stored" => array ('nb_run' => 0, 'size_run' => 0, 'run_ids'=> array(),
"nb_analyze"=> 0, "size_analyze"=> 0, 'analysis_ids'=> array())
) ,
'total_purgeable_size' => $res_row['storage_size'],
'nb_runs' =>0,
'nb_analyses' =>0);
$by_project[$current_project_id]= $empty_res_structure;
$by_project[$current_project_id]['project_name']= $res_row['project_name'];
}
if ($res_row['analyze_id'] != ""){
$by_project[$res_row['project_id']]['state'][$res_row['state']]['nb_analyze'] += 1;
$by_project[$current_project_id]['state'][$res_row['state']]['nb_analyze'] += 1;
$key = 'storage_size';
if($res_row['state'] == "purged"){
$key = "purged_size";
}
$by_project[$res_row['project_id']]['state'][$res_row['state']]['size_analyze'] += $res_row[$key];
$by_project[$res_row['project_id']]['state'][$res_row['state']]['analysis_ids'][]=$res_row['analyze_id'];
$by_project[$res_row['project_id']]['total_purgeable_size'] += $res_row['storage_size'];
$by_project[$current_project_id]['state'][$res_row['state']]['size_analyze'] += $res_row[$key];
$by_project[$current_project_id]['state'][$res_row['state']]['analysis_ids'][]=$res_row['analyze_id'];
$by_project[$current_project_id]['total_purgeable_size'] += $res_row['storage_size'];
}
}
......@@ -337,11 +321,11 @@ class tx_nG6_db {
$date= time();
$purge_data = array(
'cruser_id' => $cruser_id,
'project_id' => $project_id,
'analyze_ids' => implode(',',$all_analyses_ids),
'run_ids' => implode(',',$all_runs_ids),
'project_id' => $project_id,
'analyze_ids' => implode(',',$all_analyses_ids),
'run_ids' => implode(',',$all_runs_ids),
'mail_sent_date' => $date,
'purge_size' => $total_purgeable_size,
'purge_size' => $total_purgeable_size,
'demand_state' => "sent",
'tstamp' => $date,
'crdate' => $date
......@@ -356,10 +340,10 @@ class tx_nG6_db {
$res= tx_nG6_db::select_user_by_username($user_name);
$purge_data_user = array(
'tstamp' => $date,
'crdate' => $date,
'cruser_id' => $cruser_id,
'crdate' => $date,
'cruser_id' => $cruser_id,
'purge_demand_id' => $purge_demand_id,
'fe_users_id' => $res['uid']
'fe_users_id' => $res['uid']
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_nG6_purge_demand_fe_users', $purge_data_user);
}
......@@ -412,7 +396,6 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup',
'ORDERBY' => '',
'LIMIT' => ''
);
$results=array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row= $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
......@@ -430,7 +413,7 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup',
);
}
}
return ($results);
return ($results);
}
......
......@@ -136,33 +136,38 @@ Files impacted of:
$p=tx_nG6_db::select_a_project_retention_data_info($project_id);
#build email list of managers
$managers_email=Array();
$managers_name=Array();
$admin_email = Array();
$admin_name = Array();
$users_names=array();
$users_emails = array();
foreach ( $p[$project_id]["users"] as $u ){
if ( $u["right_level_label"] == "manager" ){
$managers_email[]=$u["email"];
$managers_name[]=$u["user_name"];
}elseif( $u["right_level_label"] == "administrator"){
$admin_email[] = $u["email"];
$admin_name[] = $u["user_name"];
}
if (!isset ($users_names[$u["right_level_label"]]) ){
$users_names[$u["right_level_label"]]=Array();
$users_emails[$u["right_level_label"]]=Array();
}
$users_names[$u["right_level_label"]][] = $u["user_name"];
$users_emails[$u["right_level_label"]][] = $u["email"];
}
#Warn if mail is sent to several manager
$email_warn="" ;
$purge_email_to="";
if ( count($managers_email) >= 1 ) {
$email_warn="Be aware that this project is associated to several managers (all recieved this email), please send only one answer per purge alert number.\n";
$purge_email_to=join(',', $managers_email);
}elseif ( count($managers_email ==0)) {
$email_warn="As this project do not have managers, administrators recieved this alert.\n";
$purge_email_to=join(',', $admin_email);
$managers_name=$admin_name;
}
$purge_name_to=Array();
if ( count( $users_emails['manager']) >= 1 ) {
if ( count( $users_emails['manager']) > 1 ) {
$email_warn="Be aware that this project is associated to several managers (all recieved this email), please send only one answer per purge alert number.\n";
}
$purge_email_to=join(',', $users_emails['manager']);
$purge_name_to=$users_names['manager'];
} elseif ( count($users_emails['manager']) == 0) {
$purge_email_to=join(', ', array_merge($users_emails['administrator'],$users_emails['member']));
$purge_name_to=array_merge($users_names['administrator'],$users_names['member']);
$email_warn="As this project do not have managers, administrators and members recieved this alert.\n";
$email_warn.= " - Administrator(s): ".join(', ',$users_emails['administrator']). "\n";
$email_warn.= " - Members(s): ".join(', ',$users_emails['member']). "\n";
}
//Retrieve purgeable information for email
$run_info=Array();
//ici bug car on prend l'ensemble des runs/analyses du projets
$all_purgeable_runs=array_merge($p[$project_id]["state"]["stored"]["run_ids"],$p[$project_id]["state"]["extended"]["run_ids"]);
$all_purgeable_analysis=array_merge($p[$project_id]["state"]["stored"]["analysis_ids"],$p[$project_id]["state"]["extended"]["analysis_ids"]);
$nb_run_purgeable = $p[$project_id]["state"]["stored"]["nb_run"]+ $p[$project_id]["state"]["extended"]["nb_run"];
......@@ -175,7 +180,7 @@ Files impacted of:
}
#Add purge demand to get id
$purge_demand_id = tx_nG6_db::add_purge_demand($user_id,$project_id,$p[$project_id]["total_purgeable_size"],$all_purgeable_runs,$all_purgeable_analysis,$managers_name);
$purge_demand_id = tx_nG6_db::add_purge_demand($user_id,$project_id,$p[$project_id]["total_purgeable_size"],$all_purgeable_runs,$all_purgeable_analysis,$purge_name_to);
#Build corresponding string array
$search=array("###nb_run###","###nb_analyse###","###PROJECT_NAME###","###PROJET_ID###","###DEMAND_ID###",
......
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