Skip to content

Commit

Permalink
Additional scripts
Browse files Browse the repository at this point in the history
Additional scripts
  • Loading branch information
CasN committed Jun 21, 2024
1 parent 55fd0c4 commit 74e1372
Show file tree
Hide file tree
Showing 3 changed files with 306 additions and 51 deletions.
61 changes: 23 additions & 38 deletions scripts/bug_reminder_mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
require_once( $t_core_path.'bugnote_api.php' );
require_once( $t_core_path.'category_api.php' );
require_once( $t_core_path.'helper_api.php' );

$allok= true ;

$t_rem_project = config_get( 'plugin_Reminder_reminder_project_id' );
$t_rem_days = config_get( 'plugin_Reminder_reminder_days_treshold' );
$t_rem_status = config_get( 'plugin_Reminder_reminder_bug_status' );
Expand All @@ -32,14 +29,12 @@
$t_rem_subject = config_get( 'plugin_Reminder_reminder_group_subject' );
$t_rem_body1 = config_get( 'plugin_Reminder_reminder_group_body1' );
$t_rem_body2 = config_get( 'plugin_Reminder_reminder_group_body2' );

$t_rem_hours = config_get('plugin_Reminder_reminder_hours');
if (ON != $t_rem_hours){
$multiply=24;
} else{
$multiply=1;
}

//
// access level for manager= 70
// this needs to be made flexible
Expand All @@ -57,18 +52,18 @@
}
}
$t_rem_include = config_get( 'plugin_Reminder_reminder_include' );
$t_rem_projects = "(";
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id');
$t_rem_projects .= ")";
if ( ON==$t_rem_include ){
if ( !empty( config_get( 'plugin_Reminder_reminder_project_id' ) ) ) {
$query .= " and bugs.project_id IN ". $t_rem_projects;
}
} else {
if (!empty( config_get( 'plugin_Reminder_reminder_project_id' ) )) {
$query .= " and bugs.project_id NOT IN ".$t_rem_projects;
$t_rem_projects = "(";
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id');
$t_rem_projects .= ")";
if ( ON==$t_rem_include ){
if ( !empty( config_get( 'plugin_Reminder_reminder_project_id' ) ) ) {
$query .= " and bugs.project_id IN ". $t_rem_projects;
}
} else {
if (!empty( config_get( 'plugin_Reminder_reminder_project_id' ) )) {
$query .= " and bugs.project_id NOT IN ".$t_rem_projects;
}
}
}

if ( ON == $t_rem_group1 ) {
$query .=" order by handler_id" ;
Expand Down Expand Up @@ -138,9 +133,7 @@
$body .= $list. " \n\n";
$body .= $t_rem_body2;
$result = email_group_reminder( $handler2, $body);

}
//
}
}
}
Expand All @@ -155,21 +148,17 @@
$query .=" and due_date>1" ;
}
}
// if ( $t_rem_project>0 ) {
// $query .=" and bugs.project_id=$t_rem_project" ;
// }

$t_rem_include = config_get('plugin_Reminder_reminder_include');
$t_rem_projects = "(";
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id');
$t_rem_projects .= ")";
if (ON==$t_rem_include){
if ($t_rem_projects <>"0") {
$query .= " and bugs.project_id IN ". $t_rem_projects;
$t_rem_include = config_get('plugin_Reminder_reminder_include');
$t_rem_projects = "(";
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id');
$t_rem_projects .= ")";
if (ON==$t_rem_include){
if ($t_rem_projects <>"0") {
$query .= " and bugs.project_id IN ". $t_rem_projects;
}
} else {
$query .= " and bugs.project_id NOT IN ".$t_rem_projects;
}
}else{
$query .= " and bugs.project_id NOT IN ".$t_rem_projects;
}
$query .=" and bugs.project_id=man.project_id and man.access_level=70" ;
$query .=" order by man.project_id,man.user_id" ;
$results = db_query( $query );
Expand Down Expand Up @@ -207,14 +196,10 @@
$body .= $list. " \n\n";
$body .= $t_rem_body2;
$result = email_group_reminder( $man2, $body);

}
//
}
}
if (php_sapi_name() !== 'cli'){
echo config_get( 'plugin_Reminder_reminder_finished' );
}


# Send Grouped reminder
function email_group_reminder( $p_user_id, $issues ) {
Expand Down Expand Up @@ -262,4 +247,4 @@ function formatBugEntry($data){
$t_message .= $t_email_separator1 . " \n\n\n";

return $t_message;
}
}
271 changes: 271 additions & 0 deletions scripts/bug_reminder_mail2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
<?php
# This page tests sending an E-mail if a due date is getting near
# Real email is sent but notes are not created for the various issues
require_once( '../../../core.php' );
$t_login = config_get( 'plugin_Reminder_reminder_login' );
$ok=auth_attempt_script_login( $t_login );
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path.'bug_api.php' );
require_once( $t_core_path.'email_api.php' );
require_once( $t_core_path.'bugnote_api.php' );
require_once( $t_core_path.'category_api.php' );
require_once( $t_core_path.'helper_api.php' );
$t_rem_project = config_get( 'plugin_Reminder_reminder_project_id' );
$t_rem_days = config_get( 'plugin_Reminder_reminder_days_treshold' );
$t_rem_status = config_get( 'plugin_Reminder_reminder_bug_status' );
$t_rem_body = config_get( 'plugin_Reminder_reminder_mail_subject' );
$t_rem_store = config_get( 'plugin_Reminder_reminder_store_as_note' );
$t_rem_ignore = config_get( 'plugin_Reminder_reminder_ignore_unset' );
$t_rem_ign_past = config_get( 'plugin_Reminder_reminder_ignore_past' );
$t_rem_handler = config_get( 'plugin_Reminder_reminder_handler' );
$t_rem_group1 = config_get( 'plugin_Reminder_reminder_group_issues' );
$t_rem_group2 = config_get( 'plugin_Reminder_reminder_group_project' );
$t_rem_manager = config_get( 'plugin_Reminder_reminder_manager_overview' );
$t_rem_subject = config_get( 'plugin_Reminder_reminder_group_subject' );
$t_rem_body1 = config_get( 'plugin_Reminder_reminder_group_body1' );
$t_rem_body2 = config_get( 'plugin_Reminder_reminder_group_body2' );

$t_rem_hours = config_get('plugin_Reminder_reminder_hours');
if (ON != $t_rem_hours){
$multiply=24;
} else{
$multiply=1;
}
//
// access level for manager= 70
// this needs to be made flexible
// we will only produce overview for those projects that have a separate manager
//
$baseline = time()+ ($t_rem_days*$multiply*60*60);
$basenow = time();

echo "Path setting retrieved : ".config_get('path');
echo "<br>";

if ( ON == $t_rem_handler ) {
$query = "select id,handler_id,project_id from {bug} bugs where status in (".implode(",", $t_rem_status).") and due_date<=$baseline and handler_id>0 ";
$query = "select bugs.id, bugs.handler_id, bugs.project_id, bugs.priority, bugs.category_id, bugs.status, bugs.severity, bugs.summary from {bug} bugs JOIN {bug_text} text ON (bugs.bug_text_id = text.id) where status in (".implode(",", $t_rem_status).") and due_date<=$baseline and handler_id<>0 ";

if ( ON == $t_rem_ign_past ) {
$query .=" and due_date>=$basenow" ;
} else{
if ( ON == $t_rem_ignore ) {
$query .=" and due_date>1" ;
}
}
$t_rem_include = config_get('plugin_Reminder_reminder_include');
$t_rem_projects = "(";
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id');
$t_rem_projects .= ")";
if ( ON==$t_rem_include ){
if ( !empty( config_get( 'plugin_Reminder_reminder_project_id' ) ) ) {
$query .= " and bugs.project_id IN ". $t_rem_projects;
}
} else {
if (!empty( config_get( 'plugin_Reminder_reminder_project_id' ) )) {
$query .= " and bugs.project_id NOT IN ".$t_rem_projects;
}
}

if ( ON == $t_rem_group1 ) {
$query .=" order by handler_id" ;
}else{
if ( ON == $t_rem_group2 ) {
$query .=" order by bugs.project_id,handler_id" ;
}
}
$results = db_query( $query );
$resnum=db_num_rows($results);
if ( OFF == $t_rem_group1 ) {
if ($results) {
while ($row1 = db_fetch_array($results)) {
$id = $row1['id'];
$handler = $row1['handler_id'];
$list = string_get_bug_view_url_with_fqdn( $id, $handler2 );
$body = $t_rem_body1;
$body .= "<br>";
$body .= $list;
$body .= "<br>";
$body .= $t_rem_body2;
$result = email_group_reminder( $handler, $body );
# Add reminder as bugnote if store reminders option is ON.
if ( ON == $t_rem_store ) {
$t_attr = '|'.$handler2.'|';
bugnote_add( $id, $t_rem_body, 0, config_get( 'default_reminder_view_status' ) == VS_PRIVATE, REMINDER, $t_attr, NULL, FALSE );
}
}
}
} else {
if ($results){
$start = true ;
$list= "";
// first group and store reminder per issue
while ($row1 = db_fetch_array($results)) {
$id = $row1['id'];
$handler = $row1['handler_id'];
$project = $row1['project_id'];
if ($start){
$handler2 = $handler ;
$start = false ;
}
if ($handler==$handler2){
$list .= formatBugEntry($row1);
// $list .="<br>";
// $list .= string_get_bug_view_url_with_fqdn( $id, $handler2 );
# Add reminder as bugnote if store reminders option is ON.
if ( ON == $t_rem_store ) {
$t_attr = '|'.$handler2.'|';
bugnote_add( $id, $t_rem_body, 0, config_get( 'default_reminder_view_status' ) == VS_PRIVATE, REMINDER, $t_attr, NULL, FALSE );
}
} else {
// now send the grouped email
$body = $t_rem_body1;
$body .= "<br>";
$body .= $list;
$body .= "<br>";
$body .= $t_rem_body2;
$result = email_group_reminder( $handler2, $body);
$handler2 = $handler ;
$list .= formatBugEntry($row1);
// $list ="<br>";
// $list= string_get_bug_view_url_with_fqdn( $id, $handler2 );
# Add reminder as bugnote if store reminders option is ON.
if ( ON == $t_rem_store ) {
$t_attr = '|'.$handler2.'|';
bugnote_add( $id, $t_rem_body, 0, config_get( 'default_reminder_view_status' ) == VS_PRIVATE, REMINDER, $t_attr, NULL, FALSE );
}
}
}
// handle last one
if ($resnum>0){
// now send the grouped email
$body = $t_rem_body1;
$body .= "<br>";
$body .= $list;
$body .= "<br>";
$body .= $t_rem_body2;
$result = email_group_reminder( $handler2, $body);

}
}
}
}

if ( ON == $t_rem_manager ) {
// select relevant issues in combination with an assigned manager to the project
$query = "select id,handler_id,user_id from {bug} bugs,{project_user_list} man where status in (".implode(",", $t_rem_status).") and due_date<=$baseline ";
if ( ON == $t_rem_ign_past ) {
$query .=" and due_date>=$basenow" ;
} else{
if ( ON == $t_rem_ignore ) {
$query .=" and due_date>1" ;
}
}

$t_rem_include = config_get('plugin_Reminder_reminder_include');
$t_rem_projects = "(";
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id');
$t_rem_projects .= ")";
if (ON==$t_rem_include){
if ($t_rem_projects <>"0") {
$query .= " and bugs.project_id IN ". $t_rem_projects;
}
}else{
$query .= " and bugs.project_id NOT IN ".$t_rem_projects;
}
$query .=" and bugs.project_id=man.project_id and man.access_level=70" ;
$query .=" order by man.project_id,man.user_id" ;
$results = db_query( $query );
$resnum=db_num_rows($results);
if ($results){
$start = true ;
$list= "";
// first group and store reminder per issue
while ($row1 = db_fetch_array($results)) {
$id = $row1['id'];
$handler = $row1['handler_id'];
$manager = $row1['user_id'];
if ($start){
$man2 = $manager ;
$start = false ;
}
if ($manager==$man2){
$list .=" \n\n";
$list .= string_get_bug_view_url_with_fqdn( $id, $man2 );
} else {
// now send the grouped email
$body = $t_rem_body1. " \n\n";
$body .= $list. " \n\n";
$body .= $t_rem_body2;
$result = email_group_reminder( $man2, $body);
$man2 = $manager ;
$list= string_get_bug_view_url_with_fqdn( $id, $man2 );
$list .= " \n\n";
}
}
// handle last one
if ($resnum>0){
// now send the grouped email
$body = $t_rem_body1. " \n\n";
$body .= $list. " \n\n";
$body .= $t_rem_body2;
$result = email_group_reminder( $man2, $body);

}
}
}


# Send Grouped reminder
function email_group_reminder( $p_user_id, $issues ) {
$t_username = user_get_field( $p_user_id, 'username' );
$t_email = user_get_email( $p_user_id );
$t_subject = config_get( 'plugin_Reminder_reminder_group_subject' );
$t_message = $issues ;
if( !is_blank( $t_email ) ) {
echo $t_email;
echo '**';
echo $t_subject;
echo '<br>';
echo $t_message;
echo '<br>';
email_store( $t_email, $t_subject, $t_message );
if( OFF == config_get( 'email_send_using_cronjob' ) ) {
email_send_all();
}
}
}

function formatBugEntry($data){
lang_push( user_pref_get_language( $data['handler_id'] ) );

$p_visible_bug_data = $data;
$p_visible_bug_data['email_project'] = project_get_name( $data['project_id']);
$p_visible_bug_data['email_category'] = category_get_name($data['category_id']);

$t_email_separator1 = config_get( 'email_separator1' );
$t_email_separator2 = config_get( 'email_separator2' );

$p_visible_bug_data['email_bug'] = $data['id'];
$p_visible_bug_data['email_status'] = get_enum_element( 'status', $p_visible_bug_data['status'], $data['handler_id'], $data['project_id'] );
$p_visible_bug_data['email_severity'] = get_enum_element( 'severity', $p_visible_bug_data['severity'] );
$p_visible_bug_data['email_priority'] = get_enum_element( 'priority', $p_visible_bug_data['priority'] );
$p_visible_bug_data['email_reproducibility'] = get_enum_element( 'reproducibility', $p_visible_bug_data['reproducibility'] );
$p_visible_bug_data['email_summary'] = $data['summary'];

$t_message = $t_email_separator1 . " \n";
$t_message .= string_get_bug_view_url_with_fqdn( $data['id'], $data['handler_id'] ) . " \n";
$t_message .= $t_email_separator1 . " \n";

$t_message .= email_format_attribute( $p_visible_bug_data, 'email_project' );
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_bug' );
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_category' );
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_priority' );
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_status' );
$t_message .= $t_email_separator1 . " \n";

$t_message .= email_format_attribute( $p_visible_bug_data, 'email_summary' );
$t_message .= $t_email_separator1 . " \n\n\n";

return $t_message;
}
Loading

0 comments on commit 74e1372

Please sign in to comment.