As a result of some improvements in the Notifications package, the query arguments returned by hook_notifications() need some small change. One line patch attached.

Comments

ryan_courtnage’s picture

Hi Jose,

I believe that there is something wrong with this patch (or perhaps the new query builder). I'm running your latest notifications and messaging (DRUPAL-6--1 as of January 12), and have applied the patch attached to this bug. There are 3 observations:

1) The error "[function.array-merge]: Argument #1 is not an array in " that I've seen others complain of is fixed

2) OG notifications does *not* add anything to notifications_queue (even though there are subscriptions).

3) All other events also fail to add their notifications to notifications_queue. For example, if a user is subscribed to a comment thread in a forum, no notifications will be added to the queue so long as og_notifications is enabled.

Here is a resulting query generated for a comment on a forum post. You will see that the og_notification additions to the query result in no results ever being returned (I'm guessing because of "AND (oga.nid = %d)":


INSERT INTO {notifications_queue}(uid, sid, module, eid, send_interval, send_method, cron, created, conditions) SELECT DISTINCT s.uid, s.sid, s.module, %d, s.send_interval, s.send_method, s.cron, %d, s.conditions FROM {notifications} s INNER JOIN {notifications_fields} f ON s.sid = f.sid LEFT JOIN {og_ancestry} oga ON f.field = 'group' AND f.value = CAST(oga.group_nid AS CHAR(255)) WHERE (s.status = 1) AND (s.event_type = '%s') AND (s.send_interval >= 0) AND (s.uid <> %d) AND (oga.nid = %d) AND ((f.field = '%s' AND f.value = '%s') OR (f.field = '%s' AND f.value = '%s') OR (f.field = '%s' AND f.value = '%s')) GROUP BY s.uid, s.sid, s.module, s.send_interval, s.send_method, s.cron, s.conditions HAVING s.conditions = count(f.sid)

Thanks!

ryan_courtnage’s picture

Here's an attempt to better illustrate the problem.

Test: Commenting on a forum post that user is subscribed to (forum not related to og).
og_notifications.module enabled.

INSERT INTO {notifications_queue}(uid, sid, module, eid, send_interval, send_method, cron, created, conditions) 
SELECT DISTINCT s.uid, s.sid, s.module, %d, s.send_interval, s.send_method, s.cron, %d, s.conditions FROM {notifications} s 
INNER JOIN {notifications_fields} f ON s.sid = f.sid 
LEFT JOIN {og_ancestry} oga ON f.field = 'group' 
AND f.value = CAST(oga.group_nid AS CHAR(255)) 
WHERE (
  s.status = 1
) 
AND (
  s.event_type = '%s'
) 
AND (
  s.send_interval >= 0
) 
AND (
  s.uid <> %d
) 
AND (
  oga.nid = %d
) 
AND (
  (
    f.field = '%s' 
    AND f.value = '%s'
  ) 
  OR (
    f.field = '%s' 
    AND f.value = '%s'
  ) 
  OR (
    f.field = '%s' 
    AND f.value = '%s'
  )
) 
GROUP BY s.uid, s.sid, s.module, s.send_interval, s.send_method, s.cron, s.conditions 
HAVING s.conditions = count(f.sid)

$args is

Array ( [0] => 41 [1] => 1231945458 [2] => node [3] => 2 [4] => 3 [5] => nid [6] => 3 [7] => type [8] => forum [9] => author [10] => 2 ) 

The above query results in 0 rows being affected (nothing is added to the notifications queue).

Here is the same forum post test, but with the og_notifications module disabled:

INSERT INTO {notifications_queue}(uid, sid, module, eid, send_interval, send_method, cron, created, conditions) 
SELECT DISTINCT s.uid, s.sid, s.module, %d, s.send_interval, s.send_method, s.cron, %d, s.conditions FROM {notifications} s 
INNER JOIN {notifications_fields} f ON s.sid = f.sid 
WHERE (
  s.status = 1
) 
AND (
  s.event_type = '%s'
) 
AND (
  s.send_interval >= 0
) 
AND (
  s.uid <> %d
) 
AND (
  (
    f.field = '%s' 
    AND f.value = '%s'
  ) 
  OR (
    f.field = '%s' 
    AND f.value = '%s'
  ) 
  OR (
    f.field = '%s' 
    AND f.value = '%s'
  )
) 
GROUP BY s.uid, s.sid, s.module, s.send_interval, s.send_method, s.cron, s.conditions 
HAVING s.conditions = count(f.sid)

$args is

Array ( [0] => 40 [1] => 1231945398 [2] => node [3] => 2 [4] => nid [5] => 3 [6] => type [7] => forum [8] => author [9] => 2 )

This properly results in a notification being added to the queue.

igorik’s picture

I can confirm this comment at all.
with enabled og notification (with 1 line patch)
watchdog error message stopped, but all notifications are broken, nothing is send

Igorik

amitaibu’s picture

Status: Active » Needs work

setting the correct status.

karens’s picture

Just looking at the code (not testing anything) I see a couple possible problems:

1) It looks like Notifications expects 'join' and 'where' to be arrays, but og_notifications is passing strings (around line 261 of og_notifications.module)

2) It looks like Notifications then merges the passed information into arrays, where the string values from OG might create some odd results (around line 418 of notifications.module)

3) Then the (possibly borked) 'join' array is used to add arguments to the query (around line 487 of notifications.module). I think that is actually a Notifications bug, since it seems to think there might be 'join args' but they are never defined anywhere.

I can't test the theory, but someone could see what happens if in addition to the above patch you also fix og_notifications so it is sending an array instead of a string for the 'join'. If that doesn't work, try removing 'join' from the foreach list used to create the args.

Anyway I think something somewhere in there is a problem.

karens’s picture

Edit, the $join array is not used for adding join args, but I still think it's a mistake to have 'join' in there when there are no 'join args' defined anywhere.

jose reyero’s picture

Status: Needs work » Needs review
StatusFileSize
new1.03 KB

I think there's problem with that query. Though the og table is a LEFT JOIN, there's this WHERE condition that will make it work as an INNER JOIN: oga.nid = %d

We need to either add that condition on the join, which is what this patch does or other option, if someone wants to try may be WHERE (oga.nid = %d OR oga.nid IS NULL)

ryan_courtnage’s picture

Using og_notifications_query_args_02.patch, the following error results after leaving a comment on a subscribed thread:


warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/rcourtna/workspace/tysc/sites/all/modules/notifications/notifications.module on line 440

I'm not entirely sure how to make the alternate change you recommended. Would it look like this?:

        if (isset($node->og_groups)) {
          $query[] = array(
            'join' => "LEFT JOIN {og_ancestry} oga ON f.field = 'group' AND f.value = CAST(oga.group_nid AS CHAR(255))",
            'where' => 'oga.nid = %d OR oga.nid IS NULL',
            'where args' => array($node->nid)
          );
        }
jose reyero’s picture

StatusFileSize
new1.01 KB

@rcourtna,
Thanks for testing the patch. The issue was not in the patch but in notifications module, that array was not properly initialized, it should work now.

Update to latest notifications-dev (just committed, may take a while to get repackaged so better use cvs) and run update.php

This new patch is the same with some addition. It uses a new feature in notifications that should be a performance boost for og queries, see #364734: Performance boost: Store field values as integer

mariagwyn’s picture

Applied the patch, got the following errors:

* warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/.../sites/all/modules/notifications/notifications.module on line 447.

* user warning: Unknown column 'f.intval' in 'on clause' query: SELECT s.*, f.* FROM notifications s INNER JOIN notifications_fields f ON s.sid = f.sid LEFT JOIN og_ancestry oga ON oga.nid = 1 AND f.field = 'group' AND f.intval = oga.group_nid WHERE (s.uid = 0) AND (s.event_type = 'nid') AND ((f.field = '124' AND f.value = 'type') OR (f.field = 'page' AND f.value = 'author') OR (f.field = '1' AND f.value = '')) in /home/.../sites/all/modules/notifications/notifications.module on line 568.
jose reyero’s picture

@mariagwyn,
You need to update to the latest (dev) version of Notifications and run update.php

igorik’s picture

Hi

I can confirm that with latest dev versions of notifications and messaging - these modules now works both with og_notifications enabled.
But - og_notification doesn't work. I tried og_notification without any patch and with your latest patch from #9 too.
It doesn't works with both cases.

Doesn't works mean no notification about new content in the group was sent (I try user and admin)

Thanks
Igorik

ryan_courtnage’s picture

Status: Needs review » Needs work

I can confirm what igorik is seeing. Running the latest notifications-dev, with og_notifications_query_args_03.patch applied. Notifications and messaging work, but no OG notifications for new group content.

mariagwyn’s picture

Status: Needs work » Needs review

@jose:

I was pretty sure I had already updated, but since I wasn't sure, I uninstalled all modules (removing DB tables), reinstalled the two dev modules, ran update (nothing to update...), and immediately upon visiting my home page, received errors. And when I try to post to a group which is supposed to send, also receive errors. Here is a shortened list:

    * warning: array_merge() [function.array-merge]: Argument #1 is not an array in /.../sites/all/modules/notifications/notifications.module on line 447.
    * user warning: Unknown column 'f.intval' in 'on clause' query: INSERT INTO notifications_queue(uid, sid, module, eid, send_interval, send_method, cron, created, conditions) SELECT DISTINCT s.uid, s.sid, s.module, 1, s.send_interval, s.send_method, s.cron, 1233082872, s.conditions FROM notifications s INNER JOIN notifications_fields f ON s.sid = f.sid LEFT JOIN og_ancestry oga ON oga.nid = 0 AND f.field = 'group' AND f.intval = oga.group_nid WHERE (s.status = 1) AND (s.event_type = '1') AND (s.send_interval >= 0) AND (s.uid <> 0) AND ((f.field = '131' AND f.value = 'type') OR (f.field = 'group_post' AND f.value = 'author') OR (f.field = '1' AND f.value = '')) GROUP BY s.uid, s.sid, s.module, s.send_interval, s.send_method, s.cron, s.conditions HAVING s.conditions = count(f.sid) in /.../sites/all/modules/notifications/notifications.module on line 377.
    * warning: array_merge() [function.array-merge]: Argument #1 is not an array in /.../sites/all/modules/notifications/notifications.module on line 447.
    * user warning: Unknown column 'f.intval' in 'on clause' query: SELECT s.*, f.* FROM notifications s INNER JOIN notifications_fields f ON s.sid = f.sid LEFT JOIN og_ancestry oga ON oga.nid = 1 AND f.field = 'group' AND f.intval = oga.group_nid WHERE (s.uid = 0) AND (s.event_type = 'nid') AND ((f.field = '131' AND f.value = 'type') OR (f.field = 'group_post' AND f.value = 'author') OR (f.field = '1' AND f.value = '')) in /.../sites/all/modules/notifications/notifications.module on line 568.

Not sure if this is the issue, but I am not seeing a column f.intval anywhere in my DB.

Maria

mariagwyn’s picture

I backported to the non-dev versions, reversed the OG patch. I have everything working now, except OG Notifications. More specifically, a notification is sent out as a "Node Creation" rather than an OG Notification. I checked this via the message templates: waht is pulled when I create any kind of Group post is a message using the Node Creation templates. So, it works, but not quite like I assume it should. Again, this is not on the dev versions (which I couldn't get to work at all and gave up trying for lack of time...but I can try again if it helps).

igorik’s picture

Maria, I am not sure of sense of trying and reporting about non dev versions of messaging and notifications with this bug, becasue they are more then 2 months old.
Could you try please the new dev versions with clean drupal 6 installation?

jose reyero’s picture

StatusFileSize
new1.04 KB

Well, some of the previous errors were because the good code was in the CVS, not the same as the -dev package until after a few hours (it may take a day to be repackaged).

Some others were because my previous patch was crap.

I think this is the good one. This og query was needing some very special parameters which I've just built into notifications query builder.

If this works and someone with a big enough install (many groups, many users subscribed) could also report on performance improvements (time of previous query in og/notficiations stable vs time of this new version) that would be great.

I insist this patch works with Notifications CVS (6.x branch). It will be in the .tar.gz package in a few hours, or to be sure, tomorrow

Thanks for the reviews and testing.

igorik’s picture

Hi

With the latest dev version of Notifications no notifications are sent at all. It doesn't matter if og_notification is enabled or disabled.
There are no notifications sent. I had to use version before this again.

ryan_courtnage’s picture

Status: Needs review » Needs work

Hi Jose,

With og_notifications_query_args_04.patch and the latest notifications (DRUPAL-6--1 tag), notifications are properly added to the queue (both OG content notifications and other notifications).

However, when trying to process the queue (using Run Process button), the following error is created for each item in the queue:

warning: array_shift() [function.array-shift]: The argument should be an array in /home/rcourtna/workspace/drupal/sites/all/modules/notifications/notifications.cron.inc on line 416.

Ryan

jose reyero’s picture

@rcourtna,

I haven't seen this one in my tests. Is it possible that you have old rows in that table (without events)? Could you reset the queue and try again?

ryan_courtnage’s picture

Status: Needs work » Reviewed & tested by the community

Hi Jose,

Well perhaps. Today I was able to duplicated the problem a couple of times, but then it magically disappeared! We may never know the cause, but it all seems to be working just fine now. Thanks a bunch.

Ryan

igorik’s picture

Hi
With latest dev notifications and messaging, it works for me too.
notifications are sent, include og notifications.

thanks for your work
Igorik

mariagwyn’s picture

I updated everything, and it seems to be working. Notifications are still being sent from the General events message template rather than the OG template, but they are being successfully sent, no errors!

thanks,
m

Zen’s picture

Version: 6.x-1.1 » 5.x-8.x-dev
Assigned: Unassigned » Zen
Priority: Critical » Normal
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to OG HEAD. Tested with MySQL only on my end.

Patch needs to be back-ported based on the outcome of #364734 .

-K

AFowle’s picture

subscribe

jose reyero’s picture

Status: Patch (to be ported) » Fixed

It doesn't need backporting, nor you can unless we backport also the Notifications D6 feature (reworked query builder), no plans for that for now. I'll open a new issue here if so.

Status: Fixed » Closed (fixed)

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