Skip to content

Commit

Permalink
Fixes #5668: versions of parent project should be used in subprojects.
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Jul 8, 2009
1 parent b5f79b9 commit 336a964
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 72 deletions.
6 changes: 3 additions & 3 deletions bug_view_advanced_page.php
Expand Up @@ -75,9 +75,9 @@
if ( $t_show_product_version ) {
$t_version_rows = version_get_all_rows( $t_bug->project_id );

$t_product_version_string = prepare_version_string( $f_bug_id, $t_bug->project_id, $t_bug->version, $t_version_rows );
$t_target_version_string = prepare_version_string( $f_bug_id, $t_bug->project_id, $t_bug->target_version, $t_version_rows );
$t_fixed_in_version_string = prepare_version_string( $f_bug_id, $t_bug->project_id, $t_bug->fixed_in_version, $t_version_rows );
$t_product_version_string = prepare_version_string( $t_bug->project_id, version_get_id( $t_bug->version, $t_bug->project_id ), $t_version_rows );
$t_target_version_string = prepare_version_string( $t_bug->project_id, version_get_id( $t_bug->target_version, $t_bug->project_id) , $t_version_rows );
$t_fixed_in_version_string = prepare_version_string( $t_bug->project_id, version_get_id( $t_bug->fixed_in_version, $t_bug->project_id ), $t_version_rows );
} else {
$t_product_version_string = '';
$t_target_version_string = '';
Expand Down
3 changes: 2 additions & 1 deletion bug_view_page.php
Expand Up @@ -59,7 +59,8 @@
$t_access_level_needed = config_get( 'view_history_threshold' );
$t_can_view_history = access_has_bug_level( $t_access_level_needed, $f_bug_id );
$t_show_product_version = version_should_show_product_version( $t_bug->project_id );
$t_product_version_string = $t_show_product_version ? prepare_version_string( $f_bug_id, $t_bug->project_id, $t_bug->version ) : '';

$t_product_version_string = $t_show_product_version ? prepare_version_string( $t_bug->project_id, version_get_id( $t_bug->version, $t_bug->project_id ) ) : '';

compress_enable();

Expand Down
28 changes: 20 additions & 8 deletions config_defaults_inc.php
Expand Up @@ -823,14 +823,6 @@
*/
$g_show_project_menu_bar = OFF;


/**
* show extra dropdown for subprojects
* Shows only top projects in the project dropdown and adds an extra dropdown for subprojects.
* @global int $g_show_extended_project_browser
*/
$g_show_extended_project_browser = OFF;

/**
* show assigned to names
* This is in the view all pages
Expand Down Expand Up @@ -3656,3 +3648,23 @@
*/
$g_due_date_view_threshold = NOBODY;

/*****************
* Sub-projects
*****************
/**
* show extra dropdown for subprojects
* Shows only top projects in the project dropdown and adds an extra dropdown for subprojects.
* @global int $g_show_extended_project_browser
*/
$g_show_extended_project_browser = OFF;

/**
* Sub-projects should inherit categories from parent projects.
*/
$g_subprojects_inherit_categories = ON;

/**
* Sub-projects should inherit versions from parent projects.
*/
$g_subprojects_inherit_versions = ON;
16 changes: 13 additions & 3 deletions core/category_api.php
Expand Up @@ -379,12 +379,12 @@ function category_cache_array_rows_by_project( $p_project_id_array ) {
* Return all categories for the specified project id.
* Obeys project hierarchies and such.
* @param int $p_project_id Project id
* @param bool $p_inherit indicates whether to inherit categories from parent projects
* @param bool $p_inherit indicates whether to inherit categories from parent projects, or null to use configuration default.
* @param bool $p_sort_by_project
* @return array array of categories
* @access public
*/
function category_get_all_rows( $p_project_id, $p_inherit = true, $p_sort_by_project = false ) {
function category_get_all_rows( $p_project_id, $p_inherit = null, $p_sort_by_project = false ) {
global $g_category_cache, $g_cache_category_project;

if( isset( $g_cache_category_project[ (int)$p_project_id ] ) ) {
Expand All @@ -411,7 +411,17 @@ function category_get_all_rows( $p_project_id, $p_inherit = true, $p_sort_by_pro
$t_category_table = db_get_table( 'mantis_category_table' );
$t_project_table = db_get_table( 'mantis_project_table' );

if( $p_inherit ) {
if ( $c_project_id == ALL_PROJECTS ) {
$t_inherit = false;
} else {
if ( $p_inherit === null ) {
$t_inherit = config_get( 'subprojects_inherit_categories' );
} else {
$t_inherit = $p_inherit;
}
}

if ( $t_inherit ) {
$t_project_ids = project_hierarchy_inheritance( $p_project_id );
$t_project_where = ' project_id IN ( ' . implode( ', ', $t_project_ids ) . ' ) ';
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/filter_api.php
Expand Up @@ -3621,7 +3621,7 @@ function print_filter_show_version() {
<select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_PRODUCT_VERSION;?>[]">
<option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
<option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
<?php print_version_option_list( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION], null, VERSION_RELEASED, false, true )?>
<?php print_version_option_list( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION], /* projectId */ null, /* released */ VERSION_ALL, /* leadingBlank */ false, /* withSubs */ true )?>
</select>
<?php
}
Expand All @@ -3635,7 +3635,7 @@ function print_filter_show_fixed_in_version() {
<select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_FIXED_IN_VERSION;?>[]">
<option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
<option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
<?php print_version_option_list( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION], null, VERSION_ALL, false, true )?>
<?php print_version_option_list( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION], /* projectId */ null, /* released */ VERSION_ALL, /* leadingBlank */ false, /* withSubs */ true )?>
</select>
<?php
}
Expand All @@ -3649,7 +3649,7 @@ function print_filter_show_target_version() {
<select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_TARGET_VERSION;?>[]">
<option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_TARGET_VERSION], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
<option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_TARGET_VERSION], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
<?php print_version_option_list( $t_filter[FILTER_PROPERTY_TARGET_VERSION], null, VERSION_ALL, false, true )?>
<?php print_version_option_list( $t_filter[FILTER_PROPERTY_TARGET_VERSION], /* projectId */ null, /* released */ VERSION_ALL, /* leadingBlank */ false, /* withSubs */ true )?>
</select>
<?php
}
Expand Down
30 changes: 11 additions & 19 deletions core/prepare_api.php
Expand Up @@ -72,30 +72,22 @@ function prepare_user_name( $p_user_id ) {
* A function that prepares the version string for outputting to the user on view / print issue pages.
* This function would add the version date, if appropriate.
*
* @param string $p_bug_id The bug id.
* @param string $p_project_id The project id.
* @param string $p_version_string The version name (e.g. 1.2.0rc1)
* @param string $p_version_rows The version rows to be re-used or null to retrieve it within the function.
* @param integer $p_project_id The project id.
* @param integer $p_version_id The version id. If false then this method will return an empty string.
* @return The formatted version string.
*/
function prepare_version_string( $p_bug_id, $p_project_id, $p_version_string, $p_version_rows = null ) {
$t_version_text = $p_version_string;
function prepare_version_string( $p_project_id, $p_version_id ) {
if ( $p_version_id === false ) {
return '';
}

if ( !is_blank( $t_version_text ) && access_has_bug_level( config_get( 'show_version_dates_threshold' ), $p_bug_id ) ) {
$t_short_date_format = config_get( 'short_date_format' );
$t_version_text = version_full_name( $p_version_id, /* showProject */ null, $p_project_id );

if ( $p_version_rows === null ) {
$t_version_rows = version_get_all_rows( $p_project_id );
} else {
$t_version_rows = $p_version_rows;
}
if ( access_has_project_level( config_get( 'show_version_dates_threshold' ), $p_project_id ) ) {
$t_short_date_format = config_get( 'short_date_format' );

foreach ( $t_version_rows as $t_version_row ) {
if ( $t_version_row['version'] == $p_version_string ) {
$t_version_text .= ' (' . date( $t_short_date_format, $t_version_row['date_order'] ) . ')';
break;
}
}
$t_version = version_get( $p_version_id );
$t_version_text .= ' (' . date( $t_short_date_format, $t_version->date_order ) . ')';
}

return $t_version_text;
Expand Down
20 changes: 13 additions & 7 deletions core/print_api.php
Expand Up @@ -450,8 +450,15 @@ function print_assign_to_option_list( $p_user_id = '', $p_project_id = null, $p_
print_user_option_list( $p_user_id, $p_project_id, $p_threshold );
}

# --------------------
# List projects that the current user has access to
/**
* List projects that the current user has access to.
*
* @param integer $p_project_id The current project id or null to use cookie.
* @param bool $p_include_all_projects true: include "All Projects", otherwise false.
* @param mixed $p_filter_project_id The id of a project to exclude or null.
* @param string $p_trace The current project trace, identifies the sub-project via a path from top to bottom.
* @return void
*/
function print_project_option_list( $p_project_id = null, $p_include_all_projects = true, $p_filter_project_id = null, $p_trace = false ) {
$t_project_ids = current_user_get_accessible_projects();
project_cache_array_rows( $t_project_ids );
Expand Down Expand Up @@ -664,7 +671,7 @@ function print_category_option_list( $p_category_id = 0, $p_project_id = null )
}
}

$cat_arr = category_get_all_rows( $t_project_id, true, true );
$cat_arr = category_get_all_rows( $t_project_id, /* inherit */ null, /* sortByProject */ true );

foreach( $cat_arr as $t_category_row ) {
$t_category_id = $t_category_row['id'];
Expand Down Expand Up @@ -797,10 +804,9 @@ function print_version_option_list( $p_version = '', $p_project_id = null, $p_re
$t_listed[] = $t_version;
echo '<option value="' . $t_version . '"';
check_selected( $p_version, $t_version );
$t_version_string = $t_version;
if( $t_show_version_dates ) {
$t_version_string .= ' (' . date( $t_short_date_format, $version['date_order'] ) . ')';
}

$t_version_string = string_attribute( prepare_version_string( $c_project_id, $version['id'] ) );

echo '>', string_shorten( $t_version_string , $t_max_length ), '</option>';
}
}
Expand Down
92 changes: 81 additions & 11 deletions core/version_api.php
Expand Up @@ -371,9 +371,9 @@ function version_cache_array_rows( $p_project_id_array ) {
* @param int $p_project_id
* @param int $p_released
* @param bool $p_obsolete
* @return array
* @return array Array of version rows (in array format)
*/
function version_get_all_rows( $p_project_id, $p_released = null, $p_obsolete = false ) {
function version_get_all_rows( $p_project_id, $p_released = null, $p_obsolete = false, $p_inherit = null ) {
global $g_cache_versions, $g_cache_versions_project;

if( isset( $g_cache_versions_project[ (int)$p_project_id ] ) ) {
Expand All @@ -392,12 +392,13 @@ function version_get_all_rows( $p_project_id, $p_released = null, $p_obsolete =

$t_param_count = 0;

$t_project_where = version_get_project_where_clause( $p_project_id, $p_inherit );

$query = "SELECT *
FROM $t_project_version_table
WHERE project_id=" . db_param( $t_param_count++ );
$query_params = array(
$c_project_id,
);
WHERE $t_project_where";

$query_params = array();

if( $p_released !== null ) {
$c_released = db_prepare_int( $p_released );
Expand Down Expand Up @@ -475,10 +476,12 @@ function version_get_all_rows_with_subs( $p_project_id, $p_released = null, $p_o
* returns false if not found, otherwise returns the id.
* @param string $p_version
* @param int $p_project_id
* @param mixed $p_inherit true to look for version in parent projects, false not to, null to use default configuration.
* @return int
*/
function version_get_id( $p_version, $p_project_id = null ) {
function version_get_id( $p_version, $p_project_id = null, $p_inherit = null ) {
global $g_cache_versions;

if( $p_project_id === null ) {
$c_project_id = helper_get_current_project();
} else {
Expand All @@ -491,13 +494,15 @@ function version_get_id( $p_version, $p_project_id = null ) {
}
}

$t_project_where = version_get_project_where_clause( $c_project_id, $p_inherit );

$t_project_version_table = db_get_table( 'mantis_project_version_table' );

$query = "SELECT id FROM $t_project_version_table
WHERE project_id=" . db_param() . " AND
WHERE " . $t_project_where . " AND
version=" . db_param();

$result = db_query_bound( $query, Array( $c_project_id, $p_version ) );
$result = db_query_bound( $query, Array( $p_version ) );

if( 0 == db_num_rows( $result ) ) {
return false;
Expand Down Expand Up @@ -525,6 +530,38 @@ function version_get_field( $p_version_id, $p_field_name ) {
}
}

/**
* Gets the full name of a version. This may include the project name as a prefix (e.g. '[MantisBT] 1.2.0')
*
* @param int $p_version_id The version id.
* @param bool $p_show_project Whether to include the project or not, null means include the project if different from current.
* @param int $p_current_project_id The current project id or null to use the cookie.
* @return string The full name of the version.
*/
function version_full_name( $p_version_id, $p_show_project = null, $p_current_project_id = null ) {
if ( 0 == $p_version_id ) {
# No Version
return '';
} else {
$t_row = version_cache_row( $p_version_id );
$t_project_id = $t_row['project_id'];

$t_current_project_id = is_null( $p_current_project_id ) ? helper_get_current_project() : $p_current_project_id;

if ( $p_show_project === null ) {
$t_show_project = $t_project_id != $t_current_project_id;
} else {
$t_show_project = $p_show_project;
}

if ( $t_show_project && $t_project_id != $t_current_project_id ) {
return '[' . project_get_name( $t_project_id ) . '] ' . $t_row['version'];
}

return $t_row['version'];
}
}

/**
* get information about a version given its id
* @param int $p_version_id
Expand Down Expand Up @@ -571,11 +608,44 @@ function version_prepare_db( $p_version_info ) {
/**
* Checks whether the product version should be shown
* (i.e. report, update, view, print).
* @param $p_project_id The project id.
* @return true: show, false: otherwise.
* @param integer $p_project_id The project id.
* @return bool true: show, false: otherwise.
*/
function version_should_show_product_version( $p_project_id ) {
return ( ON == config_get( 'show_product_version', /* default */ null, /* user_id */ null, $p_project_id ) )
|| ( ( AUTO == config_get( 'show_product_version', /* default */ null, /* user_id */ null, $p_project_id ) )
&& ( count( version_get_all_rows( $p_project_id ) ) > 0 ) );
}

/**
* Gets the where clause to use for retrieving versions.
*
* @param integer $p_project_id The project id to use.
* @param bool $p_inherit Include versions from parent projects? true: yes, false: no, null: use default configuration.
* @return string The where clause not including WHERE.
*/
function version_get_project_where_clause( $p_project_id, $p_inherit ) {
project_hierarchy_cache();

if ( $p_project_id == ALL_PROJECTS ) {
$t_inherit = false;
} else {
if ( $p_inherit === null ) {
$t_inherit = ( ON == config_get( 'subprojects_inherit_versions' ) );
} else {
$t_inherit = $p_inherit;
}
}

$c_project_id = db_prepare_int( $p_project_id );

if ( $t_inherit ) {
$t_project_ids = project_hierarchy_inheritance( $p_project_id );

$t_project_where = ' project_id IN ( ' . implode( ', ', $t_project_ids ) . ' ) ';
} else {
$t_project_where = ' project_id=' . $c_project_id . ' ';
}

return $t_project_where;
}

0 comments on commit 336a964

Please sign in to comment.