Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #11402: Project hierarchy cache problem on manage_proj_edit_page.php
manage_proj_edit_page.php didn't cache project hierarchies with disabled
projects included. Thus errors relating to in_array() were seen when
attempting to edit a parent project when one of the sub-projects was
marked as being disabled.
  • Loading branch information
davidhicks committed Jan 17, 2010
1 parent 90d3d4d commit bf80e9e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
60 changes: 35 additions & 25 deletions core/project_hierarchy_api.php
Expand Up @@ -37,9 +37,9 @@

/**
* Add project to project hierarchy
* @param int $p_child_id
* @param int $p_parent_id
* @param bool $p_inherit_parent
* @param int $p_child_id Child project ID
* @param int $p_parent_id Parent project ID
* @param bool $p_inherit_parent Whether or not the child project inherits from the parent project
* @return null
*/
function project_hierarchy_add( $p_child_id, $p_parent_id, $p_inherit_parent = true ) {
Expand All @@ -63,9 +63,9 @@ function project_hierarchy_add( $p_child_id, $p_parent_id, $p_inherit_parent = t

/**
* Update project hierarchy
* @param int $p_child_id
* @param int $p_parent_id
* @param bool $p_inherit_parent
* @param int $p_child_id Child project ID
* @param int $p_parent_id Parent project ID
* @param bool $p_inherit_parent Whether or not the child project inherits from the parent project
* @return null
*/
function project_hierarchy_update( $p_child_id, $p_parent_id, $p_inherit_parent = true ) {
Expand All @@ -84,8 +84,8 @@ function project_hierarchy_update( $p_child_id, $p_parent_id, $p_inherit_parent

/**
* Remove project from project hierarchy
* @param int $p_child_id
* @param int $p_parent_id
* @param int $p_child_id Child project ID
* @param int $p_parent_id Parent project ID
* @return null
*/
function project_hierarchy_remove( $p_child_id, $p_parent_id ) {
Expand All @@ -103,7 +103,7 @@ function project_hierarchy_remove( $p_child_id, $p_parent_id ) {

/**
* Remove any project hierarchy entries relating to project_id
* @param int $p_project_id
* @param int $p_project_id Project ID
* @return null
*/
function project_hierarchy_remove_all( $p_project_id ) {
Expand All @@ -120,14 +120,15 @@ function project_hierarchy_remove_all( $p_project_id ) {

/**
* Returns true if project is at top of hierarchy
* @param bool $p_project_id
* @param bool $p_project_id Project ID
* @param bool $p_show_disabled Whether or not to consider projects which are disabled
* @return bool
*/
function project_hierarchy_is_toplevel( $p_project_id ) {
function project_hierarchy_is_toplevel( $p_project_id, $p_show_disabled = false ) {
global $g_cache_project_hierarchy;

if( null === $g_cache_project_hierarchy ) {
project_hierarchy_cache();
if( ( null === $g_cache_project_hierarchy ) || ( $p_show_disabled ) ) {
project_hierarchy_cache( $p_show_disabled );
}

if( isset( $g_cache_project_hierarchy[ALL_PROJECTS] ) ) {
Expand All @@ -138,8 +139,8 @@ function project_hierarchy_is_toplevel( $p_project_id ) {
}

/**
* cache project hierarchy
* @param bool $p_show_disabled
* Cache project hierarchy
* @param bool $p_show_disabled Whether or not to cache projects which are disabled
* @return bool
*/
function project_hierarchy_cache( $p_show_disabled = false ) {
Expand Down Expand Up @@ -198,26 +199,35 @@ function project_hierarchy_cache( $p_show_disabled = false ) {

/**
* Returns true if the child project inherits categories from the parent.
* @param int $p_child_id
* @param int $p_parent_id
* @todo what happens if cache isn't populated?
* @param int $p_child_id Child project ID
* @param int $p_parent_id Parent project ID
* @param bool $p_show_disabled Whether or not to consider projects which are disabled
* @return bool
*/
function project_hierarchy_inherit_parent( $p_child_id, $p_parent_id ) {
function project_hierarchy_inherit_parent( $p_child_id, $p_parent_id, $p_show_disabled = false ) {
global $g_cache_project_inheritance;

if( ( null === $g_cache_project_inheritance ) || ( $p_show_disabled ) ) {
project_hierarchy_cache( $p_show_disabled );
}

return in_array( $p_parent_id, $g_cache_project_inheritance[$p_child_id] );
}

/**
* Generate an array of project's the given project inherits from,
* including the original project in the result.
* @param int $p_project_id
* @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_inheritance( $p_project_id ) {
function project_hierarchy_inheritance( $p_project_id, $p_show_disabled = false ) {
global $g_cache_project_inheritance;

if( ( null === $g_cache_project_inheritance ) || ( $p_show_disabled ) ) {
project_hierarchy_cache( $p_show_disabled );
}

$t_project_ids = array(
(int) $p_project_id,
);
Expand Down Expand Up @@ -248,14 +258,14 @@ function project_hierarchy_inheritance( $p_project_id ) {

/**
* Get subprojects for a project
* @param int $p_project_id
* @param bool $p_show_disabled
* @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_subprojects( $p_project_id, $p_show_disabled = false ) {
global $g_cache_project_hierarchy;

if(( null === $g_cache_project_hierarchy ) || ( $p_show_disabled ) ) {
if( ( null === $g_cache_project_hierarchy ) || ( $p_show_disabled ) ) {
project_hierarchy_cache( $p_show_disabled );
}

Expand All @@ -268,7 +278,7 @@ function project_hierarchy_get_subprojects( $p_project_id, $p_show_disabled = fa

/**
* Get complete subproject hierarchy for a project
* @param int $p_project_id
* @param int $p_project_id Project ID
* @return array
*/
function project_hierarchy_get_all_subprojects( $p_project_id ) {
Expand Down
4 changes: 2 additions & 2 deletions manage_proj_edit_page.php
Expand Up @@ -234,7 +234,7 @@
<?php echo form_security_field( 'manage_proj_update_children' ) ?>
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<?php
project_hierarchy_cache();
project_hierarchy_cache( true );
$t_subproject_ids = current_user_get_accessible_subprojects( $f_project_id, /* show_disabled */ true );

if ( Array() != $t_subproject_ids ) {
Expand Down Expand Up @@ -266,7 +266,7 @@
<?php
foreach ( $t_subproject_ids as $t_subproject_id ) {
$t_subproject = project_get_row( $t_subproject_id );
$t_inherit_parent = project_hierarchy_inherit_parent( $t_subproject_id, $f_project_id );
$t_inherit_parent = project_hierarchy_inherit_parent( $t_subproject_id, $f_project_id, true );
?>
<tr <?php echo helper_alternate_class() ?>>
<td>
Expand Down

0 comments on commit bf80e9e

Please sign in to comment.