The og_user_roles_gid_from_tid function should return 0 when called as otherwise a node_load error occurs when viewing a forum page.

Simply adding "return 0;" to the code fixes this problem.

function og_user_roles_gid_from_tid($tid = 0) {
  // Modification as per: http://drupal.org/node/172923
  if (module_exists('og_forum')) {
    $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
    $gid = db_result(db_query($sql, $tid));
    return $gid;
  }
  return 0;
}

I'd produce a patch file, but this really doesn't need it.

Comments

somebodysysop’s picture

Assigned: Unassigned » somebodysysop
StatusFileSize
new2.31 KB

Thanks for the note.

There is another small change necessitated by this change. Here is a patch. See if it resolves the issue for you without creating another one.

Apply this patch against clean download of OGR 5.x-2.6 release.

Also, note that this patch also contains this modification: http://drupal.org/node/192747

Crimson’s picture

This seems like it's the same problem and the patch doesn't fix the problem because I do have og_forum installed. It's a little odd.

Here's my backtrace for the error. It all stems from the same problem, node_load having no arguments.

If you need anything else, just ask.

Edit: Backtrace file removed, not needed anymore.

Crimson’s picture

Some more follow up to my problem. And a solution.

I have some forums that aren't group forums and they are isolated by themselves so they aren't in the og_term table that the function og_user_roles_gid_from_tid looks for.

So all I have done is make the return a little smarter to handle situations like this. I don't know if return 0 is the smartest thing. Shouldn't we skip the node_load and the subsequent variable $custom_theme if it's 0 anyways?

Anyways, here's what I did to og_user_roles_gid_from_tid

function og_user_roles_gid_from_tid($tid = 0) {
  // Modification as per: http://drupal.org/node/172923
  if (module_exists('og_forum')) {
    $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
    $gid = db_result(db_query($sql, $tid));
  }
  return empty($gid) ? 0 : $gid;
}

This will also take care of the problem of not having og_forum installed too.

Edit:
Alright, I've taken it upon myself to tell it not to node_load if $gid is 0. So here's the code for that.

  elseif (arg(0) == 'forum' && is_numeric(arg(1))) {
    $tid = intval(arg(1));
    $gid = og_user_roles_gid_from_tid($tid);
    if (!empty($gid)) {
      $group_node = node_load($gid);
      $custom_theme = $group_node->og_theme;
    }
  }
somebodysysop’s picture

StatusFileSize
new3.52 KB

Thank you for this code! It resolved this issue for me: http://drupal.org/node/199983

Patch is attached. Please apply to clean download of OGR Release 2.6.

Again, thanks!

somebodysysop’s picture

Version: 5.x-2.6 » 5.x-2.7
Status: Needs review » Fixed

Patch code now included in latest OGR release.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.