RAPPEL : Opération de maintenance > ForgeMIA indisponible le 20 Janvier entre 7h et 12h

Commit 19dd974e authored by Romain Therville's avatar Romain Therville 🐭
Browse files

Update to tx_nG6_pi6.php

The send_purge_demand_mail() is now going to send an alert mail to the
nG6 admins if a purge demand already exists for a given project, instead
of creating a new one.

Issue #192
parent 0d951e86
......@@ -106,148 +106,161 @@ class tx_nG6_pi6 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
return $smarty->fetch('administration_view.tpl');
}
static function send_purge_demand_mail($project_ids, $extension_allowed = 1) {
$project_name="";
foreach(explode(",", $project_ids) as $project_id){
static function send_purge_demand_mail($project_ids, $extension_allowed = 1) {
$project_name="";
foreach(explode(",", $project_ids) as $project_id){
#retrieve project data
$p=tx_nG6_db::select_a_project_retention_data_info($project_id, FALSE, TRUE);
#retrieve project data
$p=tx_nG6_db::select_a_project_retention_data_info($project_id, FALSE, TRUE);
#retrieve discarded emails
$string_emails_to_discard = $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_to_discard"] ;
$array_emails_to_discard = explode(',',$string_emails_to_discard);
#retrieve discarded emails
$string_emails_to_discard = $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_to_discard"] ;
$array_emails_to_discard = explode(',',$string_emails_to_discard);
#build email list of managers
$users_id=array();
$users_emails = array();
foreach ( $p[$project_id]["users"] as $u ){
if (!isset ($users_id[$u["right_level_label"]]) ){
$users_id[$u["right_level_label"]]=Array();
$users_emails[$u["right_level_label"]]=Array();
}
$users_id[$u["right_level_label"]][] = $u["user_id"];
$users_emails[$u["right_level_label"]][] = $u["email"];
}
#build email list of managers
$users_id=array();
$users_emails = array();
foreach ( $p[$project_id]["users"] as $u ){
if (!isset ($users_id[$u["right_level_label"]]) ){
$users_id[$u["right_level_label"]]=Array();
$users_emails[$u["right_level_label"]]=Array();
}
$users_id[$u["right_level_label"]][] = $u["user_id"];
$users_emails[$u["right_level_label"]][] = $u["email"];
}
//Warn if mail is sent to several manager
$email_warn="" ;
$purge_email_to="";
if ( count( $users_emails['manager']) > 1 ) {
$email_warn.="Be aware that every user associated with this project received this email, please send only one answer per purge alert number.\n";
}
$purge_user_id_to = array();
$users_emails_to = array();
if(isset($users_emails['administrator'])){
$users_emails_to = array_merge($users_emails_to, $users_emails['administrator']);
$purge_user_id_to = array_merge($purge_user_id_to, $users_id['administrator']);
}
if(isset($users_emails['manager'])){
$users_emails_to = array_merge($users_emails_to,$users_emails['manager']);
$purge_user_id_to = array_merge($purge_user_id_to, $users_id['manager']);
}
if(isset($users_emails['member'])){
$users_emails_to = array_merge($users_emails_to, $users_emails['member']);
$purge_user_id_to = array_merge($purge_user_id_to, $users_id['member']);
}
$purge_email_to = join(', ',$users_emails_to );
$email_warn.= "Every user associated with this project received this alert.\n";
if( isset($users_emails['administrator']) && count($users_emails['administrator']) > 0 ){
$email_warn.= " - Administrator(s): ".join(', ',$users_emails['administrator']). "\n";
}
if( isset($users_emails['manager']) && count($users_emails['manager']) > 0 ){
$email_warn.= " - Manager(s): ".join(', ',$users_emails['manager']). "\n";
}
if( isset($users_emails['member']) && count($users_emails['member']) > 0 ){
$email_warn.= " - Member(s): ".join(', ',$users_emails['member']). "\n";
}
//Retrieve purgeable information for email
$run_info=Array();
$analyses_info=Array();
$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"];
$nb_analyse_purgeable = $p[$project_id]["state"]["stored"]["nb_analyze"]+ $p[$project_id]["state"]["extended"]["nb_analyze"];
//Retrieve run name
$search=array("###TYPE_OBJECT###","###RUN_ID###","###PROJECT_ID###");
foreach($all_purgeable_runs as $run_id ){
$run = tx_nG6_db::select_run($run_id);
$run_name = $run["name"];
$replace=array("run_id",$run_id,$project_id);
$run_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$run["name"].' ('.$run_id.')</a>';
}
foreach($all_purgeable_analysis as $analysis_id ){
$analysis = tx_nG6_db::select_analyse($analysis_id);
$analysis_name = $analysis["name"];
$replace=array("analyze_id",$analysis_id,$project_id);
$analyses_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$analysis_name.' ('.$analysis_id.')</a>';
}
if (!$GLOBALS['TSFE']->fe_user->user['uid']){
http_response_code(401);
return "Nobody seems to be authenticated.";
}
#Add purge demand to get id
$purge_demand_id = tx_nG6_db::add_purge_demand($GLOBALS['TSFE']->fe_user->user['uid'],$project_id,$p[$project_id]["total_purgeable_size"],$all_purgeable_runs,$all_purgeable_analysis,$purge_user_id_to);
// We remove the hidden runs and analyzes from $p so they will not appear in the purge alert mail
$p=tx_nG6_db::select_a_project_retention_data_info($project_id, FALSE, FALSE);
//We then need to compute the displayed values once more, to make the hidden elements part of the purge without displaying them in the mail
$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"];
$nb_analyse_purgeable = $p[$project_id]["state"]["stored"]["nb_analyze"]+ $p[$project_id]["state"]["extended"]["nb_analyze"];
//We need to reset those values to only display unhidden elements
$run_info=Array();
$analyses_info=Array();
foreach($all_purgeable_runs as $run_id ){
$run = tx_nG6_db::select_run($run_id);
$run_name = $run["name"];
$replace=array("run_id",$run_id,$project_id);
$run_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$run["name"].' ('.$run_id.')</a>';
}
foreach($all_purgeable_analysis as $analysis_id ){
$analysis = tx_nG6_db::select_analyse($analysis_id);
$analysis_name = $analysis["name"];
$replace=array("analyze_id",$analysis_id,$project_id);
$analyses_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$analysis_name.' ('.$analysis_id.')</a>';
}
#Build corresponding string array
//We get the project size without any hidden run or analyze
$total_project_size = tx_nG6_db::get_project_size($project_id, true, false);
//Warn if mail is sent to several manager
$email_warn="" ;
$purge_email_to="";
if ( count( $users_emails['manager']) > 1 ) {
$email_warn.="Be aware that every user associated with this project received this email, please send only one answer per purge alert number.\n";
}
$purge_user_id_to = array();
$users_emails_to = array();
if(isset($users_emails['administrator'])){
$users_emails_to = array_merge($users_emails_to, $users_emails['administrator']);
$purge_user_id_to = array_merge($purge_user_id_to, $users_id['administrator']);
}
if(isset($users_emails['manager'])){
$users_emails_to = array_merge($users_emails_to,$users_emails['manager']);
$purge_user_id_to = array_merge($purge_user_id_to, $users_id['manager']);
}
if(isset($users_emails['member'])){
$users_emails_to = array_merge($users_emails_to, $users_emails['member']);
$purge_user_id_to = array_merge($purge_user_id_to, $users_id['member']);
}
$purge_email_to = join(', ',$users_emails_to );
$email_warn.= "Every user associated with this project received this alert.\n";
if( isset($users_emails['administrator']) && count($users_emails['administrator']) > 0 ){
$email_warn.= " - Administrator(s): ".join(', ',$users_emails['administrator']). "\n";
}
if( isset($users_emails['manager']) && count($users_emails['manager']) > 0 ){
$email_warn.= " - Manager(s): ".join(', ',$users_emails['manager']). "\n";
}
if( isset($users_emails['member']) && count($users_emails['member']) > 0 ){
$email_warn.= " - Member(s): ".join(', ',$users_emails['member']). "\n";
}
//Retrieve purgeable information for email
$run_info=Array();
$analyses_info=Array();
$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"];
$nb_analyse_purgeable = $p[$project_id]["state"]["stored"]["nb_analyze"]+ $p[$project_id]["state"]["extended"]["nb_analyze"];
//Retrieve run name
$search=array("###TYPE_OBJECT###","###RUN_ID###","###PROJECT_ID###");
foreach($all_purgeable_runs as $run_id ){
$run = tx_nG6_db::select_run($run_id);
$run_name = $run["name"];
$replace=array("run_id",$run_id,$project_id);
$run_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$run["name"].' ('.$run_id.')</a>';
}
foreach($all_purgeable_analysis as $analysis_id ){
$analysis = tx_nG6_db::select_analyse($analysis_id);
$analysis_name = $analysis["name"];
$replace=array("analyze_id",$analysis_id,$project_id);
$analyses_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$analysis_name.' ('.$analysis_id.')</a>';
}
if (!$GLOBALS['TSFE']->fe_user->user['uid']){
http_response_code(401);
return "Nobody seems to be authenticated.";
}
#Add purge demand to get id
$purge_demand_id = tx_nG6_db::add_purge_demand($GLOBALS['TSFE']->fe_user->user['uid'],$project_id,$p[$project_id]["total_purgeable_size"],$all_purgeable_runs,$all_purgeable_analysis,$purge_user_id_to);
//If the trigger check_demand_insert is triggered, add_purge_demand() returns 0 and the process has to send a mail to warn the admins instead.
if($purge_demand_id > 0){
// We remove the hidden runs and analyzes from $p so they will not appear in the purge alert mail
$p=tx_nG6_db::select_a_project_retention_data_info($project_id, FALSE, FALSE);
//We then need to compute the displayed values once more, to make the hidden elements part of the purge without displaying them in the mail
$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"];
$nb_analyse_purgeable = $p[$project_id]["state"]["stored"]["nb_analyze"]+ $p[$project_id]["state"]["extended"]["nb_analyze"];
//We need to reset those values to only display unhidden elements
$run_info=Array();
$analyses_info=Array();
foreach($all_purgeable_runs as $run_id ){
$run = tx_nG6_db::select_run($run_id);
$run_name = $run["name"];
$replace=array("run_id",$run_id,$project_id);
$run_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$run["name"].' ('.$run_id.')</a>';
}
foreach($all_purgeable_analysis as $analysis_id ){
$analysis = tx_nG6_db::select_analyse($analysis_id);
$analysis_name = $analysis["name"];
$replace=array("analyze_id",$analysis_id,$project_id);
$analyses_info[] = '<a href="'.str_replace($search, $replace, $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["run_link_url"]).'">'.$analysis_name.' ('.$analysis_id.')</a>';
}
#Build corresponding string array
//We get the project size without any hidden run or analyze
$total_project_size = tx_nG6_db::get_project_size($project_id, true, false);
$mail = tx_nG6_utils::get_purge_mail($p[$project_id]["project_name"],$project_id, $nb_run_purgeable,$nb_analyse_purgeable, $purge_demand_id,
tx_nG6_utils::get_octet_string_representation($p[$project_id]["total_purgeable_size"]), tx_nG6_utils::get_octet_string_representation($total_project_size),
$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["delay_purge"],
$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["extension_url_price"], $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["min_extension_duration"],
$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["min_extension_size"], $email_warn, join(', ', $run_info), join(', ', $analyses_info), $extension_allowed);
$mail = tx_nG6_utils::get_purge_mail($p[$project_id]["project_name"],$project_id, $nb_run_purgeable,$nb_analyse_purgeable, $purge_demand_id,
tx_nG6_utils::get_octet_string_representation($p[$project_id]["total_purgeable_size"]), tx_nG6_utils::get_octet_string_representation($total_project_size),
$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["delay_purge"],
$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["extension_url_price"], $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["min_extension_duration"],
$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["min_extension_size"], $email_warn, join(', ', $run_info), join(', ', $analyses_info), $extension_allowed);
$to = $purge_email_to;
$subject = '[nG6 purge] No '.$purge_demand_id.' - Project '.$p[$project_id]["project_name"];
$headers = array();
$headers[] = 'From: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_from"];
//$headers[] = 'From: gerald.salin@inra.fr';
//$headers[] = 'Errors-To: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_copy"];
$headers[] = 'Errors-To: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_from"];
$headers[] = 'X-Mailer: PHP/' . phpversion();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=utf-8';
$headers[] = 'Cc: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_copy"];
mail($to, $subject, $mail, implode("\r\n", $headers));
//TODO check return function mail ok
}
return "Mail sent";
}
$to = $purge_email_to;
$subject = '[nG6 purge] No '.$purge_demand_id.' - Project '.$p[$project_id]["project_name"];
$headers = array();
$headers[] = 'From: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_from"];
$headers[] = 'Errors-To: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_from"];
$headers[] = 'X-Mailer: PHP/' . phpversion();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=utf-8';
$headers[] = 'Cc: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_copy"];
mail($to, $subject, $mail, implode("\r\n", $headers));
//TODO check return function mail ok
}else{
//If the demand could not be inserted because another one already exists for the given project, we send a mail to the nG6 admins
$mail = tx_nG6_utils::get_multiple_purge_demand_mail($p[$project_id]["project_name"]);
//We send the mail to ng6-support@groupes.renater.fr and Didier (See $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_warning"] )
$to = $GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_warning"];
$subject = '[nG6 purge] Project '.$p[$project_id]["project_name"].' already has a purge demand';
$headers[] = 'From: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_from"];
$headers[] = 'Errors-To: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_from"];
$headers[] = 'X-Mailer: PHP/' . phpversion();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=utf-8';
$headers[] = 'Cc: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_copy"];
mail($to, $subject, $mail, implode("\r\n", $headers));
}
return "Mail sent";
}
static function resend_purge_demand_mail ($demands_id) {
$res_demands = tx_nG6_db::get_purge_demand_from_id($demands_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