MantisBT - Piwigo
View Issue Details
0002907Piwigoalbumspublic2013.05.24 22:472013.06.06 16:03
plg 
rvelices 
normaltextalways
closedfixed 
2.5.0 
2.5.22.5.2 
any
Apache 1.3.x
0002907: wrong number of sub-albums
On gallery side, next to the album thumbnail, if the album has sub-albums, Piwigo writes "X photos in Y sub-albums".

Due to 0001053 empty albums are removed from user_cache_categories. But the Y (ie user_cache_categories.count_categories) is not modified when empty albums are removed.
No tags attached.
Issue History
2013.05.24 22:47plgNew Issue
2013.05.24 22:47plgStatusnew => assigned
2013.05.24 22:47plgAssigned To => plg
2013.05.24 22:47plgbrowser => any
2013.05.24 22:47plgWeb server => Apache 1.3.x
2013.05.25 06:03rvelicesNote Added: 0006998
2013.05.25 06:03rvelicesNote Edited: 0006998
2013.05.25 06:03rvelicesNote Edited: 0006998
2013.05.25 06:48rvelicesNote Edited: 0006998
2013.05.25 09:12plgNote Added: 0006999
2013.05.25 10:50rvelicesNote Added: 0007003
2013.05.26 21:59rvelicesNote Added: 0007008
2013.06.06 16:02svnCheckin
2013.06.06 16:02svnNote Added: 0007023
2013.06.06 16:03plgAssigned Toplg => rvelices
2013.06.06 16:03plgStatusassigned => closed
2013.06.06 16:03plgResolutionopen => fixed
2013.06.06 16:03plgFixed in Version => 2.5.2

Notes
(0006998)
rvelices   
2013.05.25 06:03   
(edited on: 2013.05.25 06:48)
please wait a bit if not started ... I was completely rewriting the "branch" computation algorithm (too cocomplicated today) for bug 0002908

If you want I can do it while I'm at it

(0006999)
plg   
2013.05.25 09:12   
I have already fixed the bug, but not commited yet officialy:

===================================================================
--- functions_user.inc.php (revision 1357)
+++ functions_user.inc.php (working copy)
@@ -413,6 +413,7 @@
       $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)
         {
@@ -420,6 +421,33 @@
           {
             $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) )


For now i'ts only on Piwigo.com, but I planned to commit it on Piwigo.org too, if nobody tells me something is wrong.

Maybe we can apply this fix on 2.5 and have a better way to fix it on 2.6? (I suppose you don't plan a full rewrite of categories cache for 2.5)
(0007003)
rvelices   
2013.05.25 10:50   
let me do the trunk. i just rewrote the algo that computes the counters and there will be no need for an aditional query
(0007008)
rvelices   
2013.05.26 21:59   
[Subversion] r22879
(0007023)
svn   
2013.06.06 16:02   
[Subversion] r23075 by plg on branch 2.5

-----[Subversion commit log]----------------------------------------------------
bug 2907 fixed (only on 2.5, rvelices did a deeper rewrite for 2.6): wrong number of sub-albums