From af51f55815da3bb39f738795e6f0313fa550c49e Mon Sep 17 00:00:00 2001 From: flop25 Date: Wed, 19 Jun 2013 20:39:44 +0000 Subject: bug:2855 $conf['inheritance_by_default'] applies on FTP added albums git-svn-id: http://piwigo.org/svn/trunk@23376 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/site_update.php | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) (limited to 'admin/site_update.php') diff --git a/admin/site_update.php b/admin/site_update.php index c705d3690..687061449 100644 --- a/admin/site_update.php +++ b/admin/site_update.php @@ -266,6 +266,7 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank $db_categories[$insert{'id'}] = array( 'id' => $insert['id'], + 'parent' => $parent, 'status' => $insert['status'], 'visible' => $insert['visible'], 'uppercats' => $insert['uppercats'], @@ -298,11 +299,97 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank // add default permissions to categories $category_ids = array(); + $category_up = array(); foreach ($inserts as $category) { $category_ids[] = $category['id']; + $category_up[] = $category['id_uppercat']; + } + $category_up=implode(',',array_unique($category_up)); + if ($conf['inheritance_by_default']) + { + $query = ' + SELECT * + FROM '.GROUP_ACCESS_TABLE.' + WHERE cat_id IN ('.$category_up.') + ;'; + $result = pwg_query($query); + $granted_grps = array(); + while ($row = pwg_db_fetch_assoc($result)) + { + if (is_null($granted_grps[$row['cat_id']])) + { + $granted_grps[$row['cat_id']]=array(); + } + array_push( + $granted_grps, + array( + $row['cat_id'] => array_push($granted_grps[$row['cat_id']],$row['group_id']) + ) + ); + } + $insert_granted_grps=array(); + foreach ($category_ids as $ids) + { + $parent=$db_categories[$ids]['parent']; + foreach ($granted_grps[$parent] as $granted_grp) + { + array_push( + $insert_granted_grps, + array( + 'group_id' => $granted_grp, + 'cat_id' => $ids + ) + ); + + } + } + + mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $insert_granted_grps); + + $query = ' + SELECT * + FROM '.USER_ACCESS_TABLE.' + WHERE cat_id IN ('.$category_up.') + ;'; + $result = pwg_query($query); + $granted_users = array(); + while ($row = pwg_db_fetch_assoc($result)) + { + if (is_null($granted_users[$row['cat_id']])) + { + $granted_users[$row['cat_id']]=array(); + } + array_push( + $granted_users, + array( + $row['cat_id'] => array_push($granted_users[$row['cat_id']],$row['user_id']) + ) + ); + } + $insert_granted_users=array(); + foreach ($category_ids as $ids) + { + $parent=$db_categories[$ids]['parent']; + foreach ($granted_users[$parent] as $granted_user) + { + array_push( + $insert_granted_users, + array( + 'user_id' => $granted_user, + 'cat_id' => $ids + ) + ); + + } + } + mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert_granted_users); + + } + else + { + add_permission_on_category($category_ids, get_admins()); } - add_permission_on_category($category_ids, get_admins()); } $counts['new_categories'] = count($inserts); -- cgit v1.2.3