Skip to content

Commit

Permalink
Fix #11624: Update version refs in child projects
Browse files Browse the repository at this point in the history
When updating version names, we need to properly cascade those changes
to child projects that are using the inherited version names.  This can
potentially cause an issue with child projects that have a version with
the same name as the parent project, but I believe this mechanism better
handles the user's intent, and prevents sites from "breaking" with the
new version inheritance feature.

A better solution would be to fix versions so that they are referenced
by unique IDs everywhere, similar to how categories were upgraded to use
IDs instead of duplicating the name everywhere.  However, that solution
would not be considered within the scope of 1.2 due to schema changes
necessary for such a change.

Also, the project hierarchy was updated slightly to allow the version
API to access a full list of subprojects, including disabled projects.
  • Loading branch information
amyreese committed Mar 6, 2010
1 parent b03397a commit 402d897
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
7 changes: 4 additions & 3 deletions core/project_hierarchy_api.php
Expand Up @@ -264,17 +264,18 @@ function project_hierarchy_get_subprojects( $p_project_id, $p_show_disabled = fa
/**
* Get complete subproject hierarchy for a project
* @param int $p_project_id Project ID
* @param bool $p_show_disabled Whether or not to consider projects which are disabled
* @return array
*/
function project_hierarchy_get_all_subprojects( $p_project_id ) {
$t_todo = project_hierarchy_get_subprojects( $p_project_id );
function project_hierarchy_get_all_subprojects( $p_project_id, $p_show_disabled = false ) {
$t_todo = project_hierarchy_get_subprojects( $p_project_id, $p_show_disabled );
$t_subprojects = Array();

while( $t_todo ) {
$t_elem = array_shift( $t_todo );
if( !in_array( $t_elem, $t_subprojects ) ) {
array_push( $t_subprojects, $t_elem );
$t_todo = array_merge( $t_todo, project_hierarchy_get_subprojects( $t_elem ) );
$t_todo = array_merge( $t_todo, project_hierarchy_get_subprojects( $t_elem, $p_show_disabled ) );
}
}

Expand Down
44 changes: 28 additions & 16 deletions core/version_api.php
Expand Up @@ -229,19 +229,25 @@ function version_update( $p_version_info ) {
db_query_bound( $query, Array( $c_version_name, $c_description, $c_released, $c_date_order, $c_obsolete, $c_version_id ) );

if( $c_version_name != $c_old_version_name ) {
$t_project_list = array( $c_project_id );
if ( config_get( 'subprojects_inherit_versions' ) ) {
$t_project_list = array_merge( $t_project_list, project_hierarchy_get_all_subprojects( $c_project_id, true ) );
}
$t_project_list = implode( ',', $t_project_list );

$query = 'UPDATE ' . $t_bug_table . ' SET version=' . db_param() .
' WHERE ( project_id=' . db_param() . ') AND ( version=' . db_param() . ')';
db_query_bound( $query, Array( $c_version_name, $c_project_id, $c_old_version_name ) );
" WHERE ( project_id IN ( $t_project_list ) ) AND ( version=" . db_param() . ')';
db_query_bound( $query, Array( $c_version_name, $c_old_version_name ) );

$query = "UPDATE $t_bug_table
SET fixed_in_version=" . db_param() . '
WHERE ( project_id=' . db_param() . ') AND ( fixed_in_version=' . db_param() . ')';
db_query_bound( $query, Array( $c_version_name, $c_project_id, $c_old_version_name ) );
SET fixed_in_version=" . db_param() . "
WHERE ( project_id IN ( $t_project_list ) ) AND ( fixed_in_version=" . db_param() . ')';
db_query_bound( $query, Array( $c_version_name, $c_old_version_name ) );

$query = "UPDATE $t_bug_table
SET target_version=" . db_param() . '
WHERE ( project_id=' . db_param() . ') AND ( target_version=' . db_param() . ')';
db_query_bound( $query, Array( $c_version_name, $c_project_id, $c_old_version_name ) );
SET target_version=" . db_param() . "
WHERE ( project_id IN ( $t_project_list ) ) AND ( target_version=" . db_param() . ')';
db_query_bound( $query, Array( $c_version_name, $c_old_version_name ) );

/**
* @todo We should consider using ids instead of names for foreign keys. The main advantage of using the names are:
Expand Down Expand Up @@ -278,20 +284,26 @@ function version_remove( $p_version_id, $p_new_version = '' ) {
WHERE id=" . db_param();
db_query_bound( $query, Array( $c_version_id ) );

$t_project_list = array( $c_project_id );
if ( config_get( 'subprojects_inherit_versions' ) ) {
$t_project_list = array_merge( $t_project_list, project_hierarchy_get_all_subprojects( $c_project_id, true ) );
}
$t_project_list = implode( ',', $t_project_list );

$query = "UPDATE $t_bug_table
SET version=" . db_param() . "
WHERE project_id=" . db_param() . " AND version=" . db_param();
db_query_bound( $query, Array( $p_new_version, $c_project_id, $t_old_version ) );
WHERE project_id IN ( $t_project_list ) AND version=" . db_param();
db_query_bound( $query, Array( $p_new_version, $t_old_version ) );

$query = "UPDATE $t_bug_table
SET fixed_in_version=" . db_param() . '
WHERE ( project_id=' . db_param() . ' ) AND ( fixed_in_version=' . db_param() . ')';
db_query_bound( $query, Array( $p_new_version, $c_project_id, $t_old_version ) );
SET fixed_in_version=" . db_param() . "
WHERE ( project_id IN ( $t_project_list ) ) AND ( fixed_in_version=" . db_param() . ')';
db_query_bound( $query, Array( $p_new_version, $t_old_version ) );

$query = "UPDATE $t_bug_table
SET target_version=" . db_param() . '
WHERE ( project_id=' . db_param() . ' ) AND ( target_version=' . db_param() . ')';
db_query_bound( $query, array( $p_new_version, $c_project_id, $t_old_version ) );
SET target_version=" . db_param() . "
WHERE ( project_id IN ( $t_project_list ) ) AND ( target_version=" . db_param() . ')';
db_query_bound( $query, array( $p_new_version, $t_old_version ) );

# db_query errors on failure so:
return true;
Expand Down

0 comments on commit 402d897

Please sign in to comment.