View Issue Details

IDProjectCategoryView StatusLast Update
0017475mantisbtcustomizationpublic2014-10-01 10:12
ReporterIT Assigned To 
PriorityhighSeverityfeatureReproducibilityalways
Status acknowledgedResolutionopen 
Product Version1.2.17 
Summary0017475: Subprojects inherit parent project configuration / Configuration option set to multiple projects
Description

To give our example: We have 12 projects, only one of those projects has 10 sub-projects.
In this parent project I only want the following fields in bug_report_page_fields, bug_update_page_fields and bug_view_page_fields:

array (
0 => 'category_id',
1 => 'reproducibility',
2 => 'priority',
3 => 'severity',
4 => 'summary',
5 => 'description',
6 => 'additional_info',
7 => 'attachments',
8 => 'due_date',
)

Plus two custom ones. Now...if I set them in config_inc.php of course this affects all projects (Unwanted behaviour!!), if i set them in "Manage Configuration >> Configuration Report" for the parent...it only affects the parent! I cannot select multiple projects from this single drop-down list, so the only remaining answer is to tediously copy+paste these configuration options, three times, for all subprojects. Thats 60 lots of copy and paste for what should be a simple job!


Please at least give the option for either:
A) Option for subprojects to Inherit parent projects customisation - checkbox in manage projects page per project for customisation inheritance Y/N?


B) Ability to select multiple projects when adding a new customisation.

Thanks!

Additional Information

Possibly related / duplicate of 0005884, however I was unable to tell exactly what this bug was referring to, the discription seems very anorexic.

TagsNo tags attached.

Relationships

has duplicate 0005884 closeddregad Subprojects get settings from main project 

Activities

dregad

dregad

2014-07-03 05:36

developer   ~0040872

Thanks for the bug report. I agree that this would indeed be a useful feature to have.

mmmichael

mmmichael

2014-10-01 10:12

reporter   ~0041328

This is the solution:

function BL_Config_getParentProjectIds($projectId, $arReturn=array()){
$parent_projectId = project_hierarchy_get_parent($projectId, $arReturn);

if($parent_projectId > 0){
    $arReturn[] = $parent_projectId; 
    $arReturn = BL_Config_getParentProjectIds($parent_projectId, $arReturn); 
}

return $arReturn; 

}

function config_get( $p_option, $p_default = null, $p_user = null, $p_project = null ) {
global $g_cache_config, $g_cache_config_access, $g_cache_db_table_exists, $g_cache_filled;
global $g_cache_config_user, $g_cache_config_project, $g_project_override;

# @@ debug @@ echo "lu o=$p_option ";
# bypass table lookup for certain options
$t_bypass_lookup = !config_can_set_in_database( $p_option );

# @@ debug @@ if ($t_bypass_lookup) { echo "bp=$p_option match=$t_match_pattern <br />"; }

if( !$t_bypass_lookup ) {
    if( $g_project_override !== null && $p_project === null ) {
        $p_project = $g_project_override;
    }
    # @@ debug @@ if ( ! db_is_connected() ) { echo "no db "; }
    # @@ debug @@ echo "lu table=" . ( db_table_exists( $t_config_table ) ? "yes " : "no " );
    if( !$g_cache_db_table_exists ) {
        $t_config_table = db_get_table( 'mantis_config_table' );
        $g_cache_db_table_exists = ( TRUE === db_is_connected() ) && db_table_exists( $t_config_table );
    }

    if( $g_cache_db_table_exists ) {

        # @@ debug @@ echo " lu db $p_option ";
        # @@ debug @@ error_print_stack_trace();
        # prepare the user's list
        $t_users = array();
        if( null === $p_user ) {
            if( !isset( $g_cache_config_user ) ) {
                $t_users[] = auth_is_user_authenticated() ? auth_get_current_user_id() : ALL_USERS;
                if( !in_array( ALL_USERS, $t_users ) ) {
                    $t_users[] = ALL_USERS;
                }
                $g_cache_config_user = $t_users;
            } else {
                $t_users = $g_cache_config_user;
            }
        } else {
            $t_users[] = $p_user;
            if( !in_array( ALL_USERS, $t_users ) ) {
                $t_users[] = ALL_USERS;
            }
        }

        # prepare the projects list
        $t_projects = array();
        if(( null === $p_project ) ) {
            if( !isset( $g_cache_config_project ) ) {
                $t_projects[] = auth_is_user_authenticated() ? helper_get_current_project() : ALL_PROJECTS;
                $t_projects = array_merge($t_projects, BL_Config_getParentProjectIds($t_projects[0])); 
                if( !in_array( ALL_PROJECTS, $t_projects ) ) {
                    $t_projects[] = ALL_PROJECTS;
                }
                $g_cache_config_project = $t_projects;
            } else {
                $t_projects = $g_cache_config_project;
            }
        } else {
            $t_projects[] = $p_project;
            $t_projects = array_merge($t_projects, BL_Config_getParentProjectIds($p_project)); 
            if( !in_array( ALL_PROJECTS, $t_projects ) ) {
                $t_projects[] = ALL_PROJECTS;
            }
        }

        # @@ debug @@ echo 'pr= '; var_dump($t_projects);
        # @@ debug @@ echo 'u= '; var_dump($t_users);

        if( !$g_cache_filled ) {
            $t_config_table = db_get_table( 'mantis_config_table' );
            $query = "SELECT config_id, user_id, project_id, type, value, access_reqd FROM $t_config_table";
            $result = db_query_bound( $query );
            while( false <> ( $row = db_fetch_array( $result ) ) ) {
                $t_config = $row['config_id'];
                $t_user = $row['user_id'];
                $t_project = $row['project_id'];
                $g_cache_config[$t_config][$t_user][$t_project] = $row['type'] . ';' . $row['value'];
                $g_cache_config_access[$t_config][$t_user][$t_project] = $row['access_reqd'];
            }
            $g_cache_filled = true;
        }

        if( isset( $g_cache_config[$p_option] ) ) {
            $t_found = false;
            reset( $t_users );
            while(( list(, $t_user ) = each( $t_users ) ) && !$t_found ) {
                reset( $t_projects );
                while(( list(, $t_project ) = each( $t_projects ) ) && !$t_found ) {
                    if( isset( $g_cache_config[$p_option][$t_user][$t_project] ) ) {
                        $t_value = $g_cache_config[$p_option][$t_user][$t_project];
                        $t_found = true;

                        # @@ debug @@ echo "clu found u=$t_user, p=$t_project, v=$t_value ";
                    }
                }
            }

            if( $t_found ) {
                list( $t_type, $t_raw_value ) = explode( ';', $t_value, 2 );

                switch( $t_type ) {
                    case CONFIG_TYPE_FLOAT:
                        $t_value = (float) $t_raw_value;
                        break;
                    case CONFIG_TYPE_INT:
                        $t_value = (int) $t_raw_value;
                        break;
                    case CONFIG_TYPE_COMPLEX:
                        $t_value = unserialize( $t_raw_value );
                        break;
                    case CONFIG_TYPE_STRING:
                    default:
                        $t_value = config_eval( $t_raw_value );
                }
                return $t_value;
            }
        }
    }
}
return config_get_global( $p_option, $p_default );

}