diff --git a/bin/ng6_database.sql b/bin/ng6_database.sql index 4747b33c608f7687a9181a8b923a1a5e3ee34af1..b4533a2c390858283a72db264cf3a182a6ab2bb2 100644 --- a/bin/ng6_database.sql +++ b/bin/ng6_database.sql @@ -1233,6 +1233,34 @@ CREATE ALGORITHM=UNDEFINED DEFINER=`ng6`@`localhost` SQL SECURITY DEFINER VIEW ` CREATE ALGORITHM=UNDEFINED DEFINER=`ng6`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_user` AS select `tx_nG6_project`.`uid` AS `project_id`,`tx_nG6_project`.`space_id` AS `space_id`,`fe_users`.`uid` AS `user_id`, `fe_users`.`username` AS `user_name`,`fe_users`.`email` AS `email`,`fe_users`.`usergroup` AS `user_group`,`fe_rights_levels`.`right_level_label` AS `right_level_label`,`fe_groups`.`title` AS `user_group_title` from ((((`tx_nG6_project` join `fe_rights` on((`fe_rights`.`project_id` = `tx_nG6_project`.`uid`))) join `fe_users` on((`fe_rights`.`fe_user_id` = `fe_users`.`uid`))) join `fe_groups` on((`fe_users`.`usergroup` = `fe_groups`.`uid`))) join `fe_rights_levels` on((`fe_rights_levels`.`right_level_id` = `fe_rights`.`right_id`))); +-- +-- Trigger check_demand_insert to prevent the insertion of a second purge demand for a single project +-- + +DELIMITER ;; + +CREATE TRIGGER check_demand_insert BEFORE INSERT ON `tx_nG6_purge_demand` +FOR EACH ROW +BEGIN + +DECLARE var_demand_state, var_project_id, var_count int; + +SELECT demand_state, project_id, count(*) as count +INTO var_demand_state, var_project_id, var_count +FROM tx_nG6_purge_demand +WHERE demand_state = 'sent' AND project_id = new.project_id +GROUP BY demand_state, project_id; + +IF var_count > 0 THEN +set @message_text = concat('A purge demand already exists for project ', new.project_id); +signal sqlstate '45000' +set message_text = @message_text; +END IF; + +END; +;; + + /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; diff --git a/ui/nG6/lib/class.tx_nG6_db.php b/ui/nG6/lib/class.tx_nG6_db.php index b654e7246608885fc3ef6d98d882f06c58345e19..9129db95bd8fdd77b878ad37ecfdeb553d8faeda 100644 --- a/ui/nG6/lib/class.tx_nG6_db.php +++ b/ui/nG6/lib/class.tx_nG6_db.php @@ -368,18 +368,21 @@ class tx_nG6_db { $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_nG6_purge_demand', $purge_data); $purge_demand_id = $GLOBALS['TYPO3_DB']->sql_insert_id(); - tx_nG6_db::update_field('tx_nG6_run', $all_runs_ids, array('mail_sent_date','purge_demand_id'),array($date,$purge_demand_id)); - tx_nG6_db::update_field('tx_nG6_analyze',$all_analyses_ids,array('mail_sent_date','purge_demand_id'),array($date,$purge_demand_id)); + //If the trigger "check_demand_insert" is triggered, the previous request will return 0, so we have to prevents the updates to tx_nG6_run and tx_nG6_analyzes in that case + if( $purge_demand_id > 0){ + tx_nG6_db::update_field('tx_nG6_run', $all_runs_ids, array('mail_sent_date','purge_demand_id'),array($date,$purge_demand_id)); + tx_nG6_db::update_field('tx_nG6_analyze',$all_analyses_ids,array('mail_sent_date','purge_demand_id'),array($date,$purge_demand_id)); - foreach($user_ids as $a_id){ + foreach($user_ids as $a_id){ $purge_data_user = array( 'tstamp' => $date, - 'crdate' => $date, + 'crdate' => $date, 'cruser_id' => $cruser_id, 'purge_demand_id' => $purge_demand_id, 'fe_users_id' => $a_id ); $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_nG6_purge_demand_fe_users', $purge_data_user); + } } return $purge_demand_id; } @@ -1192,7 +1195,7 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup', * @param string $project_id the project id * @return hash table with all runs information */ -static function get_project_runs($project_id, $orderby='', $limit='') { +static function get_project_runs($project_id, $get_hidden=TRUE, $orderby='', $limit='') { // First select all runs from the database $queryParts = Array( @@ -1223,6 +1226,10 @@ static function get_project_runs($project_id, $orderby='', $limit='') { 'ORDERBY' => $orderby, 'LIMIT' => $limit ); + + if(!$get_hidden){ + $queryParts['WHERE'] .= ' AND tx_nG6_run.hidden = 0'; + } // Then create the result hash table @@ -1343,7 +1350,7 @@ static function get_project_runs($project_id, $orderby='', $limit='') { * @param string $project_id the project id * @return hash table with all analysis information */ - static function get_project_analysis($project_id, $orderby='', $limit='') { + static function get_project_analysis($project_id, $get_hidden=TRUE, $orderby='', $limit='') { // First select all analysis from the database $queryParts = array( @@ -1372,6 +1379,11 @@ static function get_project_runs($project_id, $orderby='', $limit='') { 'ORDERBY' => $orderby, 'LIMIT' => $limit ); + + if(!$get_hidden){ + $queryParts['WHERE'] .= ' AND tx_nG6_analyze.hidden = 0'; + } + // Then create the result hash table $results = array(); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); @@ -1608,19 +1620,20 @@ static function get_project_runs($project_id, $orderby='', $limit='') { * * @param string $p_id the project id to return the size * @param string $data_folder the data folder - * @param boolean $get_analyzes get analyzes size ? + * @param boolean $get_analyzes get analyzes size ? + * @param boolean $get_hidden get the hidden runs and analyzes ? */ - static function get_project_size($p_id, $get_analyzes=false) { + static function get_project_size($p_id, $get_analyzes=false, $get_hidden=true) { $full_size = 0; // All runs - $project_runs = tx_nG6_db::get_project_runs($p_id); + $project_runs = tx_nG6_db::get_project_runs($p_id, $get_hidden); foreach($project_runs as $run_id => $run_values) { $full_size += tx_nG6_db::get_run_size($run_values['id'], $get_analyzes); } - if ($get_analyzes) { + if ($get_analyzes) { // All analysis - $project_analysis = tx_nG6_db::get_project_analysis($p_id); + $project_analysis = tx_nG6_db::get_project_analysis($p_id, $get_hidden); foreach($project_analysis as $analyse_id => $analyze_values) { $full_size += tx_nG6_db::get_analysis_size($analyze_values['id']); } diff --git a/ui/nG6/lib/class.tx_nG6_utils.php b/ui/nG6/lib/class.tx_nG6_utils.php index d404d5d6500877a6c87971f8d8903cde6dac7480..39432c43e5167fed5414e4649761372676a206d6 100644 --- a/ui/nG6/lib/class.tx_nG6_utils.php +++ b/ui/nG6/lib/class.tx_nG6_utils.php @@ -266,6 +266,32 @@ $template_mail.='<p>Yours sincerely</p> return $mail; } + /** + * Returns the mail content to warn the nG6 admins that a purge demand already exists for the given project + * @param string $project_name + * @return $mail, a string containing the mail content + */ + static function get_multiple_purge_demand_mail($project_name) { + $template_mail=' + <html> + <head> + <title>Data Purge on nG6</title> + </head> + <body> + <p>Dear nG6 admin,</p> + <p>A purge demand already exists for the project ###PROJECT_NAME###.</p> + <p>Please, purge the data corresponding to the previous purge demand before opening a new one.</p></br> + <p>Yours sincerely</p> + <p>nG6 team (for GeT-Genotoul and Bioinfo-Genotoul facilities)</p> + </body> + </html> + '; + + $mail = str_replace('###PROJECT_NAME###', $project_name, $template_mail); + + return $mail; + } + /** * hash password (using default encryption method) * @param string $password diff --git a/ui/nG6/pi6/class.tx_nG6_pi6.php b/ui/nG6/pi6/class.tx_nG6_pi6.php index 03be3567c955e8297c3d3217ce7a6c3bb9f7dec4..5c71630a8486506f62da674cc2c7737f3ef8ac6e 100755 --- a/ui/nG6/pi6/class.tx_nG6_pi6.php +++ b/ui/nG6/pi6/class.tx_nG6_pi6.php @@ -106,163 +106,210 @@ 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(); - - $log_file_path = tx_nG6_utils::get_log_path(); - error_log(date("d/m/Y, h:i:s")." IN tx_nG6_pi6.php, 'add_purge_demand' \n p = ".print_r($p, TRUE), 3, $log_file_path); - - $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."; - } - - $log_file_path = tx_nG6_utils::get_log_path(); - error_log(date("d/m/Y, h:i:s")." IN tx_nG6_pi6.php, 'add_purge_demand' \n all_purgeable_runs = ".print_r($all_purgeable_runs, TRUE), 3, $log_file_path); - - #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); - - - #Build corresponding string array - //TODO RETURN TOTAL SIZE tx_nG6_utils::get_octet_string_representation($p[$project_id]["total_size"] - $total_project_size = tx_nG6_db::get_project_size($project_id, true); + //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[] = '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) { + static function resend_purge_demand_mail ($demands_id) { $res_demands = tx_nG6_db::get_purge_demand_from_id($demands_id); foreach($res_demands as $res_demand){ $res_project = tx_nG6_db::select_project($res_demand["project_id"]); - $total_project_size = tx_nG6_db::get_project_size($res_demand["project_id"], true) ; + //We compute the project size without hidden elements + $total_project_size = tx_nG6_db::get_project_size($res_demand["project_id"], true, false) ; $run_info=Array(); $analyses_info=Array(); $search=array("###TYPE_OBJECT###","###RUN_ID###","###PROJECT_ID###"); $project_id = $res_demand["project_id"]; $all_purgeable_runs = explode(',',$res_demand["run_ids"]); $all_purgeable_analysis = explode(',',$res_demand["analyze_ids"]); + $nb_run_purgeable = 0; + $nb_analyse_purgeable = 0; + $displayed_purge_size = 0; 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>'; + // We exclude hidden runs from the mail + if( $run["hidden"] != 1 && isset($run["name"]) ){ + $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>'; + $nb_run_purgeable++; + $displayed_purge_size = $displayed_purge_size + $run["storage_size"]; + } } 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>'; + // We exclude hidden analyzes from the mail + if( $analysis["hidden"] != 1 && isset($analysis["name"]) ){ + $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>'; + $nb_analyse_purgeable++; + $displayed_purge_size = $displayed_purge_size + $analysis["storage_size"]; + } } //We now use join(', ', $run_info) and join(', ', $analyses_info) in get_purge_mail(). $extension_allowed = 1; $mail = tx_nG6_utils::get_purge_mail($res_project["name"],$res_demand["project_id"], - count(explode(",", $res_demand["run_ids"])), count(explode(",", $res_demand["analyze_ids"])), $res_demand["demand_id"], - tx_nG6_utils::get_octet_string_representation($res_demand["purge_size"]), tx_nG6_utils::get_octet_string_representation($total_project_size), + $nb_run_purgeable, $nb_analyse_purgeable, $res_demand["demand_id"], + tx_nG6_utils::get_octet_string_representation($displayed_purge_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"], "This email was send to ". join(', ',$res_demand["emails"]).". ", join(', ', $run_info), join(', ', $analyses_info), $extension_allowed); + $headers = array(); $subject = '[nG6 purge / reminder] No '.$res_demand["demand_id"].' - Project '.$res_project["name"]; $headers[] = 'From: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_from"]; //$headers[] = 'Errors-To: '.$GLOBALS['TSFE']->tmpl->setup["plugin."]["tx_nG6_pi6."]["email_copy"];