From 3c74f3ff2708ac5a80d17e4cf281e368dd0b4cf0 Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 6 Jun 2013 14:02:33 +0000 Subject: bug 2907 fixed (only on 2.5, rvelices did a deeper rewrite for 2.6): wrong number of sub-albums git-svn-id: http://piwigo.org/svn/branches/2.5@23075 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions_user.inc.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 4f92b7d3d..50467e909 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -404,6 +404,7 @@ SELECT COUNT(DISTINCT(image_id)) as total $user_cache_cats = get_computed_categories($userdata, null); if ( !is_admin($userdata['status']) ) { // for non admins we forbid categories with no image (feature 1053) + $uppercats_of = null; $forbidden_ids = array(); foreach ($user_cache_cats as $cat) { @@ -411,6 +412,33 @@ SELECT COUNT(DISTINCT(image_id)) as total { $forbidden_ids[] = $cat['cat_id']; unset( $user_cache_cats[$cat['cat_id']] ); + + if (empty($uppercats_of)) + { + $query = ' +SELECT + id, + uppercats + FROM '.CATEGORIES_TABLE.' +;'; + $uppercats_of = simple_hash_from_query($query, 'id', 'uppercats'); + } + + // if child album is removed, we must decrease the number of + // sub-albums of all parent albums (to the root) + if (isset($uppercats_of[$cat['cat_id']])) + { + foreach (explode(',', $uppercats_of[$cat['cat_id']]) as $id) + { + // the last $id is the current album removed, it will always + // fail the following condition because it was removed a few + // lines before. + if (isset($user_cache_cats[$id])) + { + $user_cache_cats[$id]['count_categories']--; + } + } + } } } if ( !empty($forbidden_ids) ) -- cgit v1.2.3