I received 3 of the following error from the subscriptions module in the logs when running via cron(one for each content type subscribed to):
Invalid argument supplied for foreach() in C:\wamp\www\fujitsinfo\sites\all\modules\subscriptions\subscriptions.module on line 456.
I installed subscriptions over the top of the previous installation (subscriptions-5.x-1.x-dev) and ran the update script. I deactivated the previous module before installing. I have a single admin user on the system. That user had previously existing subscriptions.
Environment:
- Drupal 5.7
- Wamp Server 2.0
- Apache 2.2.6
- PHP 5.2.5
- Windows XP
- Modules Installed:
- backup-5.x-3.0
- cck-5.x-1.6-1
- feedapi-5.x-1.0
- feedapi_mapper-5.x-1.0-beta4
- fivestar-5.x-1.11-beta3
- mail_edit-5.x-1.1
- notify-5.x-1.x-dev (inactive)
- smtp-5.x-1.x-dev
- subscriptions-5.x-2.0-beta11
- views-5.x-1.6
- votingapi-5.x-1.5
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | subscriptions_content.FeedAPI.patch | 987 bytes | salvis |
Comments
Comment #1
yellek commentedAfter reinstalling Drupal I am still getting this error when trying to process subscriptions to nodes newly created from a FeedAPI feed. The nodes that are created are standard page nodes. If I edit one of the nodes that the feed creates then notifications work correctly. Pages created through the interface also work correctly.
Comment #2
salvisThanks for pursuing this. Apparently, the FeedAPI nodes aren't quite standard, if it works with manually created page nodes, but I fail to see the connection between odd nodes and the error you describe. Or the FeedAPI nodes trigger different subscriptions than your manually created ones.
What you describe looks more like having recipient_uid's in the {subscriptions} table that aren't in the {subscriptions_user} table.
Could it be that you have left-over recipient_uid's from 1.x that don't correspond to currently existing users in the {users} table (from which the {subscriptions_user} table was built)?
Comment #3
yellek commentedAfter first getting this error I reinstalled Drupal from scratch and still managed to get the error.
The users table contains UID 0 and UID 1.
The subscriptions user table contains 2 UIDs: UID -2 with a send interval of 86400 and UID 1 with a send interval of 1. I assume that UID -2 is the global default settings.
The subscriptions table contains a number of subscriptions with recipient UID 1 and author UID -1 (?) (CSV included below for reference).
The nodes table contains a number of page nodes created by feedapi with UID 1 with their create dates set to the create dates of the original RSS items and the modify dates set to when they were added to Drupal.
Please let me know if you want dumps of any of the other tables, this is a development system and there is very little data there at present.
subscriptions:
"sid","module","field","value","recipient_uid","send_interval","author_uid","send_updates","send_comments"
"1","node","type","link","1","1","-1","1","1"
"2","node","type","page","1","1","-1","1","1"
"3","node","type","story","1","1","-1","1","1"
"4","node","nid","1","1","1","-1","1","1"
"5","node","nid","2","1","1","-1","1","1"
"6","node","nid","7","1","1","-1","1","1"
"7","node","nid","12","1","1","-1","1","1"
"8","node","nid","13","1","1","-1","1","1"
"9","node","nid","14","1","1","-1","1","1"
"10","node","nid","15","1","1","-1","1","1"
"11","node","nid","16","1","1","-1","1","1"
"12","node","nid","17","1","1","-1","1","1"
"13","node","nid","18","1","1","-1","1","1"
Comment #4
salvisYes, UID -2 in {subscriptions_user} is the global default record — sorry, I should have told you.
-1 in {subscriptions}.author_uid means no specific author, i.e. subscriptions for all authors. That looks fine, but what is type "link"? I've never seen that. Is that what's created by FeedAPI? Can you edit these, too, to try resending?
Comment #5
yellek commentedThat is a custom content type I created with CCK, it shouldn't be an issue because the nodes that feedapi is creating at the moment are standard pages rather than links.
I can't help thinking that the error has something to do with pages created during a cron run rather than via a user directly.
Comment #6
salvisI'm totally in the dark here.
Try comparing a page node from FeedAPI and one that you created manually, or maybe before and after you edit it (you wrote that after editing there were no complaints).
Comment #7
yellek commentedI have put some debug log statements in the code and the uid it is looking for is uid 0. I am assuming that cron runs as the anonymous user which is what the problem is. Given that the anonymous user can't have an email address by definition I would suggest that the proper fix would be to test for uid 0 and send no subscriptions in that case.
Does that make sense?
Comment #8
yellek commentedI tried adding a row for uid 0 in the subscriptions_user table which stopped the errors but still didn't send any notifications when the nodes were created. The page nodes all have uid 1 in the nodes table.
Comment #9
salvisThere must not be a uid=0 row in subscriptions_user. Please remove that row.
subscriptions_mail_cron() has no problem running under the anonymous user; we are way beyond this type of error. This is an issue that is unique to your system, which doesn't mean we don't need to fix it, but unfortunately I can provide very little help.
Please try to find out where that 0 comes from. Start by checking what $account parameter you get in _subscriptions_get_setting(). It can be a user object, a uid (if > 0) or a rid (if < 0).
Comment #10
yellek commentedIt is an object with uid=0
Comment #11
yellek commentedOK I've done some more digging.
From the beginning of the hook in subscriptions_content_nodeapi the $user global variable has $user->uid =0. The call stack goes through subscriptions_content_nodeapi to subscriptions_autosubscribe to _subscriptions_get_setting.
The name parameter for _subscriptions_get_setting is autosub_on_post. _subscriptions_get_setting runs the following database query to determine the auto subscribe settings:
SELECT uid, digest, send_interval, send_updates, send_comments, send_interval_visible, send_updates_visible, send_comments_visible, autosub_on_post, autosub_on_update, autosub_on_comment, send_self FROM subscriptions_user WHERE uid in (-2, 0) ORDER BY uid
This query returns a single row for uid -2 (there being no row with uid 0 in subscriptions_user).
The function then proceeds to populate the $defaults array and sets $defaults[-2] from the result set. It then tries to do a foreach ($defaults[$uid] as $key => $value) where $uid is 0 as previously stated. This of course is null and we get a php error.
This begs the question: Is the $user variable supposed to have uid = 0 during cron runs? If not then there is something weird in my environment. If it is then there needs to be some way to handle this situation in subscriptions.
Have you tested subscriptions with nodes created by modules during cron execution before?
Comment #12
yellek commentedAnd the reason why no notifications are being sent for nodes created through FeedAPI is that the form is not used when creating nodes via the API and so the value of subscriptions_notify is never set in these cases.
My suggestion would be to default the value of this to true if it is not present unless there is a way of adding a sensible configuration option for this.
Comment #13
salvisAh, now I'm beginning to understand. We're in cron.php, but not in subscriptions_cron(). We're in FeedAPI_cron() (whatever it's called)! And we're trying to check whether the cron user wants to autosubscribe to the node that FeedAPI is creating.
That's exactly the point: no. Now we know where to look.
You're right, subscriptions_notify not being set is the problem.
Please check whether FeedAPI calls hook_nodapi($node, 'prepare') and try to set $node->subscriptions_notify=TRUE at that time. I think that would be the proper place. Defaulting to TRUE would also be an option, but a less delicate one.
I need to look more closely into _subscriptions_get_setting(), but creating that uid=0 row actually might be the solution.
Thank you for digging into this!
Comment #14
salvisPlease try the attached patch — it should fix both issues.
Comment #15
ezra-g commentedI observed this error in watchdog but it disappeared before I was able to review this patch. I tried adding per-content type subscriptions for uid 1 and an authenticated user and ran cron but still can't recreate the error.
Are there any specific steps I could take to create the error and help test this patch?
Comment #16
salvisThe error is likely to occur if "something" creates nodes on your site without going through the regular Create-content-and-[Submit]-the-form cycle.
Yes, I'd be very interested to hear whether it works for you! Creating nodes in odd ways is a challenge for modules like Subscriptions.
Comment #17
ezra-g commentedI'll try programatically creating a node and seeing what happens.
Comment #18
ezra-g commentedWithout applying the patch, I still don't get this error programatically creating a node and running cron.php. I've tried this with subscriptions disabled and enabled as well as with $node->uid 0 and also with 1. I create the node by executing the following code in the devel excecute php block:
Comment #19
ezra-g commentedI also don't get the errors when I simultaneously have multiple programatically-created nodes of both uid 0 and uid 1.
Comment #20
salvisI suspect you'll get the error when you don't call node_prepare(). Maybe you even have to drop node_submit()...
I don't know what exactly FeedAPI was doing, but somehow it didn't call the required hooks, probably as uid 0.
Comment #21
ezra-g commentedI still can't get the errors to come back. I've tried to recreate the errors by creating nodes without node_prepare() and without node_submit(). It's worth noting that I never had FeedAPI enabled on this installation. I also tried creating a node by simply performing, similar to the code in feedapi.module feedapi_create_node() :
Comment #22
salvisWell, thanks for trying. The posted fix will be in BETA12 (and I'll set the status to fixed when it's out).
Comment #23
salvisComment #24
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.