Custom Functions

Custom functions are used to extend the functionality of MantisBT by integrating user writtenfunctions into the issue processing at strategic places. This allows the system administrator to changethe functionality without re-writing parts of the internals of the code.

User versions of these functions are placed in a file called custom_functions_inc.php in the root directory of MantisBT. This is the same place that the "config_inc.php" file modifying MantisBT defaults is placed. In normal processing, MantisBT will look for override functions and execute them instead of the provided default functions.

Custom functions have names like custom_function_override_descriptive_name where descriptive namedescribed the particular function. The specific functions are described below. The simplest way tocreate a custom function is to copy the default function, named custom_function_default_descriptive_namefrom the core/custom_function_api.php file to your override file (custom_functions_inc.php), andrename it. The specific functionality you need can then be coded into the override function.

Defined Functions

custom_function_default_changelog_include_issue( $p_issue_id ) returns true or false if the issue if to be included in the Changelogcustom_function_default_changelog_print_issue( $p_issue_id ) returns a formatted string to be included for the issue in the Changelogcustom_function_default_checkin( $p_issue_id, $p_comment, $p_file, $p_new_version ) registers a checkin in source control in MantisBT custom_function_default_issue_update_validate( $p_issue_id, $p_new_bug, $p_bug_note_text ) validate bug field settings before an update occurs. It returns true or fails with an error.custom_function_default_issue_update_notify( $p_issue_id ) notify after a bug has been updatedcustom_function_default_issue_create_validate( $p_new_bug ) validate bug field settings before an issue is created. It returns true or fails with an error.custom_function_default_issue_create_notify( $p_issue_id ) notify after a bug has been openedcustom_function_default_issue_delete_validate( $p_issue_id ) validate bug field settings before an issue can be deleted. It returns true or fails with an error.custom_function_default_issue_delete_notify( $p_issue_id ) notify after a bug has been deleted

Example Custom Function

The following function is used to validate an issue before it is resolved.

<?php 
# -------------------- 
# Hook to validate Validate field settings before resolving 
# verify that the resolution is not set to OPEN 
# verify that the fixed in version is set (if versions of the product exist)

function custom_function_override_issue_update_validate( $p_issue_id, $p_bug_data, $p_bugnote_text ) {
if ( $p_bug_data->status == RESOLVED ) { 
if ( $p_bug_data->resolution == OPEN ) {
error_parameters( 'the resolution cannot be open to resolve the issue' ); 
trigger_error( ERROR_BUG_VALIDATE_FAILURE, ERROR ); 
}
$t_version_count = count( version_get_all_rows( $p_bug_data-&gt;project_id ) );
if ( ( $t_version_count > 0 ) && ( $p_bug_data->fixed_in_version == '' ) ) {
error_parameters( 'fixed in version must be set to resolve the issue' ); 
trigger_error( ERROR_BUG_VALIDATE_FAILURE, ERROR ); 
} 
} 
}
?>
                    
The errors will also need to be defined by adding the following to custom_constant_inc.php
                        define ( 'ERROR_VALIDATE_FAILURE', 2000 );
                        To custom_strings_inc.php
                        $MANTIS_ERROR['ERROR_VALIDATE_FAILURE'] = 'This change cannot be made because %s';