Product SiteDocumentation Site

7.6.2. Example Custom Function Override

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 ) {
			throw new ClientException( "Validation error",
				ERROR_VALIDATE_FAILURE,
				[ 'The resolution cannot be "open" to resolve the issue' ]
			);
		}
		$t_version_count = count( version_get_all_rows( $p_bug_data->project_id ) );
		if( ( $t_version_count > 0 ) && ( $p_bug_data->fixed_in_version == '' ) ) {
			throw new ClientException( "Validation error",
				ERROR_VALIDATE_FAILURE,
				[ 'Fixed in version must be set to resolve the issue' ]
			);
		}
	}
}

?>
The errors will also need to be defined, by modifying the following files