There is a critical bug in og_notifications_add_form_submit() - the form used to create group subscriptions.

The module calls for a variable that is never set anywhere. A foreach is used to iterate the variable, but since it doesn't exist, nothing happens, and you're still given a success message that the subscription was saved.

function og_notifications_add_form_submit($form, &$form_state) {
  $form_values = $form_state['values'];

  $subscription = new stdClass;
  $subscription->type = 'grouptype';
  $subscription->uid = $form_values['account']->uid;
  $subscription->send_interval = $form_values['subscription']['send_interval'][0];
  $subscription->send_method = isset($form_values['send_method']) ? $form_values['send_method'] :     
  $form_values['subscription']['send_method'][0];
  // String cast due to notifications requiring it as the value field is
  // a varchar.
  $subscription->fields = array('group' => (string) $form_values['subscription']['group'][0], 'type' =>        
  $form_values['subscription']['node_type'][0]);
  if ($form_values['subscription']['node_type'][0] == 'all') {

   /** THE PROBLEM IS RIGHT BELOW HERE **/

    $types = array_filter(variable_get('og_notifications_content_types', array()));
    foreach ($types as $type) {
      $subscription->fields['type'] = $type;
      notifications_save_subscription($subscription);
      unset($subscription->sid);
    }
  }
  else {
    notifications_save_subscription($subscription);
  }

  drupal_set_message(t('Subscription saved.'));
}

Comments

ensemble’s picture

I'm having this problem too. I just came here to find out if anyone else had the same problem, although I hadn't looked into the code yet to try to figure out what was happening. Subscribing.

ensemble’s picture

From what I can tell by puttering around on my site, the "og_notifications_content_types" is, in fact set. In my case, it's set to:
Array
(
[blog] => 0
[og_user_roles_subgroup] => 0
[articulation] => 0
[blogpost] => 0
[story] => 0
)

when I was testing. However, since they're all set to 0, the array_filter gets rid of them all. I'm too new at this to know what that means - I don't know where that particular list came from (it doesn't correspond to the content types that are in use in my groups) or why they're set to 0.

mstef’s picture

Grep the entire og module. The only time they're set is by the .install file in an update hook.

Open atrium purposely ships with the variable strongarmed because thats the only way it works.

ensemble’s picture

Just checking back. Has anyone looked into this? Does anyone know if there are any plans to fix it? It's a pretty important bug that's keeping me from upgrading OG to the newest version.

mstef’s picture

There's a very large amount of bugs in the current OG version. I will be digging in to this one within a few weeks.

crifi’s picture

+1 subscribe

amitaibu’s picture

> I will be digging in to this one within a few weeks.

Great, any help will be appreciated, as I'm dealing most of the time with getting OG7 ready.

jgoodwill01’s picture

+1 Subscribe

tbenice’s picture

looking for resolution. I'm going to try and find a solution.

tbenice’s picture

line 90 of og_notifications.module

      $form['group']['og_notifications_content_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Allowed content types'),
        '#default_value' => variable_get('og_notifications_content_types', array()),
        '#options' => $select,
        '#description' => t('Select specific content types which should be <em>allowed</em> for subscriptions to <em>group + content type</em>.'),
        '#multiple' => TRUE
      );
      break;

found by find/replace. This is version 6.21 of OG.

/admin/messaging/notifications/subscriptions/content allows you to pick from content types that are group posts.

The subscriptions show up in the account page. However none of my notifications are sending now. Going to try and troubleshoot.

mstef’s picture

Found the problem(s) -- patching now

tbenice’s picture

thats fantastick, thanks so much!

mstef’s picture

Attached is a patch that seems to clear up all the necessary issues..

Subscriptions will save now properly.

Just make sure that at least some nodes have the Content type in group subscription enabled, as well as the UI options. I removed the admin settings for per-node choices for group subscriptions, but it's really just a duplication of the per-node options that notifications offers itself.

Please test and get back to me.

Feedback and suggestions welcome.

mstef’s picture

It's worth noting, that this patch is not necessarily required to get og_notifications working. You just have to set a number of variables before anything actually works, and there is no indication that these settings are missing. The patch is most helpful in that it eliminates the duplicate admin setting, as described in the previous post.

This is also helpful when you're dealing with a site that contains a number of features, each which contains a content type (like Drupal Commons, for instance). With the way this module works, prior to my patch, there is only one variable used to determine which group node types should be available for subscriptions - and it shouldn't be like that, because then you can only export that variable to one feature.

mstef’s picture

There still are some problems..

1) Notifications allows you to duplicate group/content-type subscriptions

2) If you're subscribed to content type X (globally), you're allowed to subscribe to content type X inside group A

tbenice’s picture

Not seeing any content types to choose in user/uid/notifications/add/grouptype and selecting 'all content types' (only option) does not save any subscriptions.

and yes, the redundancy is odd. in theory it will be a problem because it will send 2 notifications (one for thread and one for group)?

mstef’s picture

@tbenice: read #14. you need to turn on the og notifications.

tbenice’s picture

@mikesteff-

The og notifications fieldset in /admin/messaging/notifications/subscriptions/content is no longer there with the patch, so I cant select them. Sorry!

mstef’s picture

@tbenice: You skipped over everything I wrote, right?

(loc: /admin/messaging/notifications/content)
Global options:
Content type in group. Subscribe to specific content within a group.
Thread. Subscribe to all changes and comments for a thread.
Content type. Subscribe to all content of a given type.
Author. Subscribe to all content submitted by a user.
Content type and Author. Subscribe to all content of a given type submitted by a user.

If you're using per-nodetype options, you need to edit each node type and turn that on for it.

Please re-read what I wrote about removing the duplicate node-type options on this admin page.

tbenice’s picture

Thanks, I did read what you wrote, and doing that makes sense. However, with global settings and with the og notifications selected there are no post type options in user/#/notifications/add/og. I don't know how to explain the problem more clearly.

of course og notifications must be selected, I did that. It still doesn't work, sorry.

mstef’s picture

Check permissions?

tbenice’s picture

using user 1. I'll try again fresh and let you know.

tbenice’s picture

I think that I know what the problem is, let me test and then get back.

tbenice’s picture

Here is what I've found:

1) i stuck a dprint_r under line 50 of og_notifications.pages.inc to print out $node_types and it gives an empty array
2) since $node_types is filled by og_notifications_node_types() I did the same in that function to print out $group_types and $allowed. og_notifications_node_types() returns the array based on logic between these 2 arrays. $group_types was an array with the expected data (types that are posted into groups), but $allowed was an empty array.
3) $allowed is filled by notifications_content_types('names', 'grouptype'). However, that function takes only 1 argument ($subs_type). So I think that the correct call is notifications_content_types('grouptype'). However, that call simply returns all content types not those that are 'grouptype'.

I'm not sure when or where the 'grouptype' option is saved.

I think that this fixes it, updated patch for og_notifications.module (only) attached.

tbenice’s picture

one other problem I've found:

selecting 'all content types' in /user/#/notifications/add/grouptype seems to only save the topmost content type in the list...not all. I think that was there before the patch though, and might be a separate issue.

mstef’s picture

1) The only time it will give an empty array is if you haven't enabled grouptype subscriptions via the admin UI.
2) See 1.
3) It takes two arguments, the latter being the subtype, which is 'grouptype'.

Not really sure how you're having these issues as it works perfectly for me. Maybe try with a fresh install..

Ps: dsm() (from devel.module) is the best for printing arrays/objects.

tbenice’s picture

mikesteff, I don't know what to say here. Did you look at the code?

EDIT: Maybe we're using different versions of notifications? I'm using 4.0 Beta 7. I wonder if og_notifications is written for an earlier version? I don't remember reading anything about that though...

/**
 * Get content types available for subscriptions to content type
 * 
 * @param $subs_type
 *   Optional type of subscription for which to find allowed content types.
 *   If none, return all content types for which any subscription type is enabled.
 */
function notifications_content_types($subs_type = NULL) {
  // Get list of available node types, all of them will be allowed by default
  $types = array();

  foreach (notifications_content_type_name() as $key => $name) {
    if (notifications_content_type_enabled($key, $subs_type)) {
      $types[$key] = $name;
    }
  }

  return $types;  
}

I see only 1 argument.

I seem to have this part fixed to my satisfaction thanks to your work and my fix. Whether you agree that it is a fix or just suspect that I don't know anything is of no consequence to me. I'll go with what I have.

btw, same problem on a fresh install. good idea though!

Thanks!

tbenice’s picture

Indeed I see that this is my issue most likely. The 6.x-dev patches for notifications/messaging 4x have not been in a stable release yet.

I'll try the -dev version of og and see how that works. Thanks for the patience.

-Ted

mstef’s picture

Oh..that makes sense then.. og 6.x-2.1 supports notifications 2.x. og 6.x-dev supports notifications 4.x...

thepanz’s picture

mikesteff: I'm fighting with your same issue (you can find my new code here: https://github.com/thePanz/og/tree/DRUPAL-6--2).
it works with notifications 4.x (you can find my patches in my GitHub too).
Few works need to be done for:
1. per-group subscription settings
2. remove subscription duplication for grouptype and nodetype
3. if I enable "all post in group" i MUST also enable "post-type in group", in such case the user, when he/she subscribes to a "all group content" will see also the grouptype subscriptions..

Comments and suggestions are welcome..

mstef’s picture

I'm using Notifications 2.x.

thepanz’s picture

ok, I missed the OG version your patch was against.
Maybe my code can help others (using Notifications 4.x)

Grayside’s picture

Status: Active » Needs review

OG6 is now on Notifications 2.x for releases and dev. Skimming the issue, looks like we are in Needs Review.

Status: Needs review » Needs work

The last submitted patch, og_notifications-subscriptions-not-saving-835030.patch, failed testing.

greggles’s picture

Status: Needs work » Needs review
hankvanzile’s picture

Version: 6.x-2.1 » 6.x-2.2

I am experiencing this issue with 6.x-2.2 with Commons 6.x.2.4. Old subscriptions remain in place and notifications based on node type, etc. are working, so I know it's related to OG. How can I help test this? Should I apply the patch in comment 25?

greggles’s picture

@RightSizedView - yes, that's the next step. Thanks for helping!

hankvanzile’s picture

Just make sure that at least some nodes have the Content type in group subscription enabled

Well, this is embarrassing, but @mikestefff's comment made me check my og_contenttype settings. They were, in fact, all turned off. I'm wondering if something in upgrading OG to 6.x-2.2 turned them off? Ah well.

I can report that this is working as expected in Organic Groups Notifications 6.x-2.2 using Drupal Commons 6.x-2.5.

Grayside’s picture

OG Notifications was barely touched between 6.x-2.1 and 6.x-2.2. In between it was partially upgraded for Notifications 4.x compatibility then reverted because of that "partial" bit.

There should have been no upgrade path pain on this. That said, there are a lot of bugs with OG Notifications, and some other zany interaction might be buggy enough to drop settings. I do not use OG Notifications, so I look to the community of users that do to identify problems and drive solutions.

Grayside’s picture

Status: Needs review » Needs work

Someone needs to reproduce this problem. Marking needs work in hopes of some more attention.

claudiu.cristea’s picture

Status: Needs work » Closed (outdated)

This version of Drupal is not supported anymore. If this is still an issue in the 8.x-1.x branch, please open a new up-to-date ticket. Closing.