In function og_statistics_nodeapi() there is this code:

   case 'update':
      // Update statistics.
      if (og_is_group_post_type($node->type)) {
        if (isset($node->og_groups)) {
          $updated_gid = array_intersect($node->og_groups, $node->og_initial_groups);
          $added_gid = array_diff($node->og_groups, $node->og_initial_groups);
          $removed_gid = array_diff($node->og_initial_groups, $node->og_groups);
          foreach ($updated_gid as $gid) {
            og_statistics_update_last_node($node, $gid);
          }
          foreach ($added_gid as $gid) {
            og_statistics_add_node($gid);
            og_statistics_update_last_node($node, $gid);
          }
          foreach ($removed_gid as $gid) {
            og_statistics_remove_node($node->nid, $gid);
          }
        }
      }

It seems that $node->og_initial_groups is nowhere defined before, so it is not array and it shows warnings messages.

CommentFileSizeAuthor
#1 og_statistics-610930.patch591 bytesDeFr

Comments

DeFr’s picture

Status: Active » Needs review
StatusFileSize
new591 bytes

Obvious patch attached.

og_initial_groups is in fact set by OG when generating the node edit form. Thus, this code is correct when the node is saved after an edit. It's not if you're doing something along the line of node_save(node_load($nid)) though, which happens a lot when you're doing bulk edit of your nodes (mass publishing for example).

Assuming those mass operations doesn't affect the groups the node is assigned to, I guess this patch is correct. If they change, we're no worse than without this patch and there's no warning, but database wise the situation won't match the code expectations.

A safer approach would be to detect the missing og_initial_groups in presave, and populate it with the still intact info form the database, but that might hurt mass operation performance.

dawehner’s picture

Status: Needs review » Fixed

Thanks thats really abvios. Thanks for the patch.

A simpletest would be cool :)

Status: Fixed » Closed (fixed)

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