My Question:

Which tables does the Category module check against to generate the list of categories and containers within the Parent Category dropdown list (when creating a new category)

Problem Description:

This problem may have started when I activated OG Subgroups. When I go to set up a new or edit an existing category, the list of parent categories displays each container and it's categories twice. Within each level of sub-category there is an additional layer of duplication. See below for example..

Example:

Container 1
    Sub-Category 1
    Sub-Category 1
        Sub-Category 1
        Sub-Category 1
        Sub-Category 1
    Sub-Category 2
    Sub-Category 2
        Sub-Category 2
        Sub-Category 2
        Sub-Category 2
Container 1
    Sub-Category 1
    Sub-Category 1
        Sub-Category 1
        Sub-Category 1
        Sub-Category 1
    Sub-Category 2
    Sub-Category 2
        Sub-Category 2
        Sub-Category 2
        Sub-Category 2
Container 2

etc..

Nowhere else am I able to see this same duplication. In addition, each duplicated category retains the correct category ID. So it's not affecting the selection of categories programatically. The primary issue is that with a list of 150+ categories the user has to look through 300 lines instead.

When I disable OG permissions, this duplication disappears. I've checked the database multiple times and I've dumped my data to MS Access/Excel to manually check for dupes in og_ancestry and node_access. Disabling Sub-groups has no impact though I still suspect it may be the culprit.

I've spent A LOT of time on this and so I am now seeking help. Thank you!

Comments

ianchan’s picture

Priority: Normal » Critical

Basically, when the parent dropdown, on the category edit page, is generated it is inserting a duplicate list item for every category to which the user has access via more than one organic group.

Thus if a user as access to one category via two separate organic groups, the category is listed twice.

If a user has access to separate containers via two separate organic groups the entire content o the container is listed twice.

ianchan’s picture

I think I've found the problem. OG creates multiple entries for each node within node_access. However, while the nids are the same within each entry, the group id is different. when the category module checks permissions within the node_access table, it is listing each entry where the user is part of the group indicated by the gid. As such, for users in multiple organic groups, categories appear duplicated within the parent category list.

The category module code needs to be modified to check for unique node ids when generating the parent category list. How does one do that?

ianchan’s picture

why and how do _category_category_select_options and _category_node_select_options operate in different ways. the latter works correctly while the former does not. _category_category_select_options is displaying duplicated categories based on node_access while _category_node_select_options does not.

help please..

ianchan’s picture

@ line 1877 in category.module - this fixes the problem. Hopefully someone will let me know if this is not a good thing to do.

- foreach ($tree as $category) {
- // Boolean blasphemy has been cleaned up and moved to separate function
- if (_category_category_select_check_category($category, $container, $cnid, $exclude)) {
- $choice = new stdClass(); //mod-ic generates parents list
- $choice->option = array($category->cid => str_repeat('---', $category->depth) . ($category->cnid ? $category->title : $category->admin_title) . ($category->cnid ? '' : ' *'));
- $options[] = $choice;
- }
- }
+ foreach ($tree as $category) { //mod-ic generates desc cats lists
+ if (!in_array($category->cid, $exclude) && node_access('view', node_load($category->cid))) {
+ $options[$category->cid] = str_repeat(' - - ', $category->depth) . $category->title;
+ }
+ }