Closed (duplicate)
Project:
Organic Groups
Version:
5.x-1.x-dev
Component:
og.module
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Feb 2007 at 12:06 UTC
Updated:
28 Feb 2007 at 18:28 UTC
og_ancestry entryies are cleared after edit of a public post that is in no group.
og_save_ancestry deletes the entry but if node->og_groups is no array or empty it does not insert it again
INSERT INTO `og_ancestry` (nid, group_nid, is_public) VALUES (nid,0,1);
you can look up nodes that have no more entry via
SELECT n.nid FROM `node` n LEFT JOIN `og_ancestry` na ON n.nid = na.nid WHERE ISNULL(na.nid)
then insert entries manually for this via above insert
Note: group nodes have no entry...
Will try to post a patch this evening.....
function og_save_ancestry($node) {
if (!og_is_omitted_type($node->type)) {
$sql = "DELETE FROM {og_ancestry} WHERE nid = %d";
db_query($sql, $node->nid);
if (is_array($node->og_groups) && count($node->og_groups)) {
foreach ($node->og_groups as $gid) {
$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
db_query($sql, $node->nid, $gid, $node->og_public);
}
}
else {
$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
db_query($sql, $node->nid, 0, $node->og_public);
}
}
}
Comments
Comment #1
moshe weitzman commentedi don't understand. if a node has no groups, then it it doesn't need any records in ancestry.
Comment #2
bwynants commentedbut if it has no entry, is it then public? what if all boxes where off?
The problem was that when I click 'edit' for a certain node the public checkbox is not selected anymore and I could not select it either. after submit it was always off again..... the post disappeared for the users...
maybe it's something else (like bad public initialization)? however this fixed it for me....
I'll have a look at the code again this evening....
Comment #3
moshe weitzman commentedi recently committed a fix for a missing Public checkbox ... also see http://drupal.org/node/107289
Comment #4
bwynants commented// $Id: og.module,v 1.298.2.34 2007/02/17 04:39:48 weitzman Exp $
So if there is no entry in og_ancestry, where gets og_public set?
Comment #5
moshe weitzman commentedtrue ... i guess we should assume that a node without any groups is public. see that other issue i linked to.
Comment #6
bwynants commentedso, how do you want to proceed.
I agree, no groups is public.
I see 3 solutions
1) My initial solution -> larger table
2) First do a count of the entries for a node. If empty -> set public true else take public from the row (consistency problem...multiple rows for one node do not need to have the same value...hence the 'db_query_range' off-course)
3) remove public and let group 0 be the public group (entry with group value 0 available -> set as public) public is kind of redundand...
I think (3) is the best most compact solution but most complex (update of db needed and several code changes)
and (2) gives an extra query and (1) is the easiest solution that at least for now fixes it.
Comment #7
moshe weitzman commentedsorry, i'm not seeing a problem anymore. 'public' has no meaning if a node isn't in any groups. the node will always be public. for consistency, i should fix that part of node_load() but i don't know of anything that is breaking.
Comment #8
bwynants commentedok, i'll try to explain.
I upgraded from 4.7 to 5.0 (after that all nodes had an entry in og_ancestry the public ones with group 0, public 1)
I did an edit of a node (as user 0) that was public and in no group (it's entry disappeared from og_ancestry, and that should have been ok...)
However, the node disappeared from the front page for the users....
edit again, public was off -> enabled it again -> no avail, not viewable only as admin....
Did my initial fix (see description) and the node became visible for all users....
Looked again in the code:
As you can see from comment 4 $node->og_public will only be correct if there is an entry in og_ancestry table.
what would happen if og_node_access_records is called when no groups are selected and $node->og_public is not set due to comment 4?
og_node_access_records does not check if groups is empty only if $node->og_public is set.....
maybe this is the problem then?
Comment #9
bwynants commentedmoshe, do you see/understand the problem? how do we proceed. I really think this is a critical bug. Should I prepare a patch with how I think it should be solved?
Comment #10
bwynants commentedIt turned out that appart from fixing og_ancestry for the missing entries I also had to correct the node_access table. It was, for some nodes, also missing an entry resulting in not being public.....
This was on a live site.
Comment #11
moshe weitzman commentedthis will be fixed by http://drupal.org/node/107289. please discuss there. i will not be adding entries in ancestry for nodes that have no group affiliations.