View Issue Details

IDProjectCategoryView StatusLast Update
0010304mantisbtfeaturepublic2015-12-06 02:46
Reportercas Assigned Toatrol  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionduplicate 
Product Version1.2.0a3 
Summary0010304: Automatic adjustment of status
Description

Our procedure is that once an issue is finished, we give it status RESOLVED. Then the customer has max 5 workingdays the time to react in a different way.
Without that reaction, we move the issue to CLOSED.
Attached is a script that can do this automatically, you can define number of days to take into account, the user it should be booked upon, the status to evaluate and the status to be given.

Inside the script is some more info on how to call this utility

Additional Information

For using in Mantis versions below 1.2, simply change the db_get_table function (2x) to config_get function

Tagspatch
Attached Files
automatic_status_update.php (3,315 bytes)   
<?php
# This page updates issues with a new status if a certain status is there for more than a number of days
# parameters that can be set:
# days		=> number of days to take into account to raise warning
# fromstat	=> Status that needs to be checked
# tostat	=> Status to be set
# muser		=> Userid from mantis (Integer)
# sendmail  => Should mantis noficiation take place
# if not passed as parameter, default values 7,80,90,1,N are being used
# 
# Call script like: http://www.YourMantisHome.com/automatic_status_update.php?days=7&fromstat=80&tostat=90&muser=1$sendmail='Y'
# or like : http://www.YourMantisHome.com/automatic_status_update.php to use defaults
# or like : http://www.YourMantisHome.com/automatic_status_update.php?sendmail='Y' to send mail and use other defaults
#
# Automatical scheduling                                                         
# automatic_status_update.php can be used via cron like this:
# */1440 *   *   *   * lynx --dump http://mantis.homepage.com/automatic_status_update.php?
#
# or via command line interface
# */1440 *   *   *   * /usr/local/bin/php /path/to/mantis/automatic_status_update.php?
# This line would update  every day. 
#
# You also can use a scheduled task under windows by calling a batch-file like:
# REM *** this batch is running as a scheduled task under the ... Account ***
# g:
# cd \inetpub\wwwroot\mantis
# php.exe automatic_status_update.php
#
# Created by Cas Nuy http://www.nuy.info
# April 2009
#
$reqVar = '_' . $_SERVER['REQUEST_METHOD'];
$form_vars = $$reqVar;
$parm1= $form_vars['days'] ;
$parm2= $form_vars['fromstat'] ;
$parm3= $form_vars['tostat'] ;
$parm4= $form_vars['muser'] ;
$parm5= $form_vars['sendmail'] ;
if (!$parm1){
	$t_days		= 7;
}else{
	$t_days		= $parm1;
}
if (!$parm2){
	$t_fromstat		= 80;
}else{
	$t_fromstat		= $parm2;
}
if (!$parm3){
	$t_tostat		= 90;
}else{
	$t_tostat		= $parm3;
}
if (!$parm4){
	$muser		= 1;
}else{
	$muser		= $parm4;
}
if (!$parm5){
	$sendmail	= 'N';
}else{
	$sendmail	= $parm5;
}
require_once( 'core.php' );
$t_core_path 	= config_get( 'core_path' );
$t_bug_table	= db_get_table( 'mantis_bug_table' );
$t_his_table	= db_get_table( 'mantis_bug_history_table' );

$query1			="select id from $t_bug_table where status=" ;
$query1 		.= $t_fromstat ;
$result1		= db_query($query1);
$num_records1 	= db_num_rows( $result1 );

if ($num_records1 >0){
	for( $i=0; $i < $num_records1; $i++ ) {
		$t_row = db_fetch_array( $result1 );
		$val1=$t_row["id"] ;
		// now retrieve last date of from status 
		$query2 = " select date_modified from $t_his_table where bug_id=";
		$query2 .= $val1;
		$query2 .= " and new_value = ".$t_fromstat;
		$query2 .=" AND field_name = 'status' order by date_modified";	
		$result2= db_query($query2);
		$t_row2 = db_fetch_array( $result2 );
		$val2   = 	$t_row2["date_modified"] ;
		$val3 = round(strtotime($val2)/86400) ;
		$today = mktime(0, 0, 0, date("m")  , date("d"), date("Y"));
		$val4 =round($today/86400);
		if (($val4-$val3)>$t_days){
			// update status 
			bug_set_field( $val1, 'status', $t_tostat ); 
			// should we send an email
			if (strtoupper($sendmail)<>'N'){
				email_close( $p_bug_id );
				email_relationship_child_closed( $p_bug_id ); 
			}
		}
	}
}
?>
automatic_status_update.php (3,315 bytes)   

Relationships

duplicate of 0012521 new Script to automatically change status 

Activities

cas

cas

2009-04-20 10:00

reporter   ~0021603

Last edited: 2009-04-20 10:00

Provided update with the ability to send email and increased use of standard functions.

vboctor

vboctor

2009-10-27 04:03

manager   ~0023393

I've uploaded the php extracted from automatic_status_update_2.zip for convenience.

jurgenhaas

jurgenhaas

2010-06-18 13:38

reporter   ~0025916

I guess there is something missing: you should add two more lines just behind require_once( 'core.php' );

global $g_cache_current_user_id;
$g_cache_current_user_id = $muser;

Otherwise writing the history fails as there is no user defined at this point.