Hi favioagg,
I just want to say, that I don't know for sure, if my solution is working properly. For me, it does right now. I will post my solution here. Maybe some devs of Mantis will see it and tell me, if I broke my Mantis with that or can give me some tips to make my solution better.
Quick summary of what I wanted to achive. I wanted to define more Workflows than one in the config_inc.php. Mantis should then choose the right workflow based on the category of the bug and the access role of the currently logged in user (Reporter, Manager, Administrator...). The addition of the access role helps to define workflows for reporter and managers (or other roles) of a project. The reporter can close a bug, but can't reopen it. The manager has his own workflow and can reopen the bug anytime.
So here is what I did.
First of all I created a new api file "NEWFILE_api.php" in the core directory, for new funtcions. One function I made was "bug_get_category_ID ($bug_id). This funtion gets the Category ID of the currently opened Bug from the database.
Code: Select all
<?php
/** Get Category_ID of currently opened BUG
* @param int p_bug_id
*/
function bug_get_category_ID( $p_bug_id ) {
$c_bug_id = db_prepare_int( $p_bug_id );
$t_bugnote_table = db_get_table( 'mantis_bug_table' );
$query = "SELECT category_id
FROM $t_bugnote_table
WHERE bug_text_id=" . $p_bug_id . "";
$result = db_query_bound( $query, Array( $c_bug_id ), 1 );
$row = db_result( $result );
if( false === $row ) {
return false;
} else {
return $row;
}
}
?>
Then I added my different workflows in the config_inc.php. For example I named them like
Code: Select all
$g_status_enum_workflow_test_Administrator = array (
10 => '20:in Bearbeitung',
20 => '40:Test,30:zurückgestellt,50:Test Kunde,80:Rechnungsstellung,90:geschlossen',
30 => '20:in Bearbeitung',
40 => '50:Test Kunde,20:in Bearbeitung,30:zurückgestellt,90:geschlossen',
50 => '80:Rechnungsstellung,20:in Bearbeitung,40:Test',
80 => '90:geschlossen',
90 => '20:in Bearbeitung,10:geöffnet',
);
Code: Select all
$g_status_enum_workflow_test = array (
10 => '20:in Bearbeitung',
20 => '90:geschlossen,10:geöffnet',
90 => '20:in Bearbeitung',
);
And a default one
Code: Select all
$g_status_enum_workflow_default = array (
10 => '20:in Bearbeitung',
20 => '40:Test,30:zurückgestellt,50:Test Kunde,80:Rechnungsstellung,90:geschlossen',
30 => '20:in Bearbeitung',
40 => '50:Test Kunde,20:in Bearbeitung,30:zurückgestellt,10:geöffnet',
50 => '80:Rechnungsstellung,20:in Bearbeitung,40:Test',
80 => '90:geschlossen',
90 => '20:in Bearbeitung,10:geöffnet',
);
The first two workflows are defined for the category with the name "test". As you can see, the name of the variable has a pattern. It is "$g_status_enum_workflow_categoryname_Userrole". If you don't need a specific workflow for the Userrole, then just leave it out. In my case, I need both workflows.
The default workflow is only needed, if no other workflow is defined for the current category.
Then I edited the function get_status_option_list() in the file core/print_api.php. I added a new Parameter $bug_id, because now I will call the function "bug_get_category_ID($bug_ID)" within get status_option_list().
Code: Select all
function get_status_option_list( $p_user_auth = 0, $p_current_value = 0, $p_show_current = true, $p_add_close = false, $p_project_id = ALL_PROJECTS, $bug_id ) {
Then I've edited the first lines of the function get_status_option_list. This code checks, if there is a defined workflow with the categoryname of the currently opened bug and userrole of the currently logged in user. If not, check if there is a workflow only for the categoryname. And if not, just take the default workflow.
Code: Select all
function get_status_option_list( $p_user_auth = 0, $p_current_value = 0, $p_show_current = true, $p_add_close = false, $p_project_id = ALL_PROJECTS, $bug_id ) {
$t_config_var_value = config_get( 'status_enum_string', null, null, $p_project_id );
if (config_get( 'status_enum_workflow' . _ . category_get_name( bug_get_category_ID( $bug_id )) . _ . get_enum_element( 'access_levels', current_user_get_access_level() ), null, null, $p_project_id ) != null) {
$t_enum_workflow = config_get( 'status_enum_workflow' . _ . category_get_name( bug_get_category_ID( $bug_id )) . _ . get_enum_element( 'access_levels', current_user_get_access_level() ), null, null, $p_project_id );
} elseif (config_get( 'status_enum_workflow' . _ . category_get_name( bug_get_category_ID( $bug_id )) , null, null, $p_project_id ) != null) {
$t_enum_workflow = config_get( 'status_enum_workflow'. _ . category_get_name( bug_get_category_ID( $bug_id )), null, null, $p_project_id );
} else {
$t_enum_workflow = config_get( 'status_enum_workflow_default', null, null, $p_project_id );
}
if( count( $t_enum_workflow ) < 1 ) {
You also have to put a require_once in print_api.php for your new api file.
Code: Select all
require_once( 'NEWFILE_api.php' );
Because we've added a new parameter to the function get_status_option_list() you have to add the parameter to every file, where the function is called.
Add the parameter to:
bug_update_advanced_page.php
bug_report_page.php (add to function print_status_option_list())
html_api.php
print_api.php
Now you have to disable the Exception Output for the workflow config. Usually you have one workflow defined in the config_inc.php file. If Mantis does not find it, it will display an error message "Application warning 100". Because of the new if statements, that loads different workflows, it could happen, that the error is displayed, despite the fact, that everything is alright. This happens because mantis now searches for different workflows till it finds the right one or jumps to the default one. To disable that error message you have to go to core/config_api.php and comment out the line "trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, WARNING );".
This is what I did. Like I said, I don't know if this is a good solution. I hope I could explain it good enough and I didn't forget anything.
Note, that you have to put all these changes in back in mantis, after you updated to a new version.
Best regards,
Mathias