Trying to update OG from 2.7 to 2.9 in Open Atrium. Running into some infinite loops with og_context(). Seems that it now calls user_load, which if the Real Name module is installed, causes a token load, which if using og_vocab can cause og_context() to be called again, resulting in infinite loop. I know it's a pretty obscure set of modules and tough to reproduce.

But in debugging a fix for this, I saw that the og_context_is_init() function was added somewhat recently. This seems to be an attempt to detect if og_context() has already been called. However, I never see this function actually used anywhere. Seems like this could be used to prevent an infinite loop and maybe that was the original intent. But the commit to add og_context_is_init() doesn't correspond to any issue number to indicate the thinking behind it.

Would be good to know if this function is working as intended and how it is supposed to be used and if OG itself should be trying to prevent infinite calls to og_context. The problem arises from using og_context plugins that might trigger something like a node_load that can cause og_context to be called again.

Probably going to put some sort of infinite loop detection in Atrium to bypass this issue.

Comments

mpotter created an issue. See original summary.

JayDarnell’s picture

I also tried to update from 7.x-2.7 to 7.x-2.9 only to find that the custom panels I had created to manually set og_context on a few key pages of my site stopped working. Here is the code I was using in a custom panel pane

<?php

// Convert the path into an array of parts
$pathparts = explode('/', current_path());

// Create the path alias for the group that owns the page we're currently viewing by recombining the first two path parts.
$alias= $pathparts[0] . '/' . $pathparts[1];

// Find the default node/nid path for this alias
$normalpath = drupal_get_normal_path($alias);

// Now that we have the normal path of the group extract the nid from it
$np = explode('/', $normalpath);
if (!empty($np[1])) {
  // Set the context
  og_context('node', node_load($np[1]));
} 

?>

In a nutshell I have a few pages that have paths set up to make them appear as if they are part of a group when the content in these pages is not actually group content. I grab the path (generated by pathauto) figure out the group the path belongs to and then set the context - this way I can display the group header and group menu on these custom pages.

pianomansam’s picture

Status: Active » Closed (duplicate)

Closing as a duplicate of #2717489: Infinite loop with og_context() which even though is newer, has provided a patch.

@CopperBot, you have experienced a separate issue. See #2720337: Unable to get active groups with og_context()

pianomansam’s picture

Component: og.module » og-context