I'm getting the following errors (screenshot attached) repeatedly.

warning: Invalid argument supplied for foreach() in /home/loho0004/sites/wikijoba/modules/subscriptions/subscriptions.module on line 500.

The errors come when using the advanced forum module. I've been trying to debug this but without much luck. Line 500 is:

  foreach ($defaults[$uid] as $key => $value) {

I'm not sure where to look next. Could it be a permissions issue?

CommentFileSizeAuthor
subscriptions misery.jpg192.75 KBchrism2671

Comments

chrism2671’s picture

Just thought I should paste that entire foreach loop:

    foreach ($defaults[$uid] as $key => $value) {
      if ($value < 0) {  // not set, use site dft
        $defaults[$uid][$key] = $defaults[-DRUPAL_AUTHENTICATED_RID][$key];
        $defaults[$uid]['uses_defaults'] = TRUE;
      }
    }
chrism2671’s picture

Status: Postponed (maintainer needs more info) » Active

In order to help diagnose the problem, I have acquired and pasted the contents of $defaults

Array ( [-2] => Array ( 
[uid] => -2 
[digest] => 0 
[send_interval] => 1
[send_updates] => 1 
[send_comments] => 1 
[send_interval_visible] => 0 
[send_updates_visible] => 0 
[send_comments_visible] => 0 
[autosub_on_post] => 1 [
autosub_on_update] => 1 
[autosub_on_comment] => 1 
[send_self] => 0 ) ) 

Hope this helps. Any assitance much appreciated.

salvis’s picture

Status: Active » Postponed (maintainer needs more info)

What action do you do to get this error? Under what account? What's the value of $uid?

chrism2671’s picture

I am logged in as a normal user. The errors arise from merely visiting a page, although it does not occur on all pages. The function attempts to determine if the user has made a subscription choice, or else otherwise apply the default settings.

For reference I have pasted the entire code block for the this function. The relevant section is indicated, towards the bottom. Any help would be much appreciated!

Thanks,
Chris.

/**
 * Helper function to retrieve
 *   send_self/autosub_on_post/autosub_on_update/autosub_on_comment/    | 1, 0,
 *   digest/send_interval/send_updates/send_comments/                   | -1 = use default
 *   send_interval_visible/send_updates_visible/send_comments_visible/  | 1, 0, -1 = only preference, -2 = always use site default
 *   uses_defaults values;
 * $account can be NULL/0 (for site default), a user object, or a uid.
 */
function _subscriptions_get_setting($name, $account) {
  global $user;
  if (!isset($account) || empty($account->uid) || is_numeric($account) && $account <= 0 ) {
    $uid = -DRUPAL_AUTHENTICATED_RID;
    unset($account);
  }
  elseif (is_numeric($account)) {
    if ($account == $user->uid) {
      $account = $user;
      $uid = $user->uid;
    }
    else {
      $uid = $account;
      unset($account);
    }
  }
  if (is_object($account)) {
    $uid = $account->uid;
  }

  static $defaults = array();
  if (!isset($defaults[$uid][$name])) {
    $result = db_query("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 (%d, %d) ORDER BY uid", -DRUPAL_AUTHENTICATED_RID, $uid);
	
    while ($s = db_fetch_array($result)) {
      $defaults[$s['uid']] = $s;
    }
//THE ERRORS RELATE TO THE FOLLOWING FOREACH LOOP!
    foreach ($defaults[$uid] as $key => $value) {
      if ($value < 0) {  // not set, use site dft
        $defaults[$uid][$key] = $defaults[-DRUPAL_AUTHENTICATED_RID][$key];
        $defaults[$uid]['uses_defaults'] = TRUE;
      }
    }
    foreach (array('interval', 'updates', 'comments') as $parm ) {
      // Site overrides user values.
      if ($defaults[-DRUPAL_AUTHENTICATED_RID]['send_'. $parm .'_visible'] == -2) {
        $defaults[$uid]['send_'. $parm] = $defaults[-DRUPAL_AUTHENTICATED_RID]['send_'. $parm];
      }
    }
  }
  return $defaults[$uid][$name];
}
salvis’s picture

I know the function, no need to post it here.

That code is working fine for everyone else. Something on your site causes it to be called in an invalid context, and we need to find out what that something is.

Please find out what the value of $uid is at that point, and also the values of $name and $account on function entry.

chrism2671’s picture

$name and $uid didn't have values, however $account did:

tdClass Object ( [uid] => 1000002 [name] => chrism2671 [pass] => df1c0bac4d4d33b360c187b63b1150b3 [mail] => hello@world.com [mode] => 0 [sort] => 0 [threshold] => 0 [theme] => [signature] => [created] => 1186994202 [access] => 1212302311 [login] => 1212232769 [status] => 1 [timezone] => 0 [language] => [picture] => [init] => [data] => a:6:{s:7:"contact";i:0;s:14:"picture_delete";s:0:"";s:14:"picture_upload";s:0:"";s:16:"privatemsg_allow";i:1;s:28:"privatemsg_setmessage_notify";i:1;s:20:"privatemsg_mailalert";s:1:"0";} [sid] => 82fdbf544f0d20e1108cf485258d7e0c [hostname] => 86.3.90.180 [timestamp] => 1212302311 [cache] => 0 [session] => [contact] => 0 [picture_delete] => [picture_upload] => [privatemsg_allow] => 1 [privatemsg_setmessage_notify] => 1 [privatemsg_mailalert] => 0 [roles] => Array ( [2] => authenticated user [1000002] => Registered Users [1000006] => Administrators ) )

(I stuck in a fake email for the sake of pasting).

salvis’s picture

$uid cannot be empty. We have

  if (is_object($account)) {
    $uid = $account->uid;
  }

so $uid would have to be 1000002. It's odd that you have such high UID numbers — they start at 1...

$name cannot be empty. Most calls to _subscriptions_get_setting() in Subscriptions pass a string constant as their first parameter. There are one or two where $name is the concatenation of two strings, but they all have a constant part, so they won't be empty.

Please look through your entire source code — there must be a module that calls _subscriptions_get_setting() with invalid parameters.

You can also experiment with debug_backtrace(), which should show you where the function is called from.

chrism2671’s picture

Status: Active » Closed (fixed)

I've managed to solve the problem. The issue was that the subscriptions_user table wasn't fully populated with all users. This (including the high uid numbers) was caused by the a data import from vbulletin (using the vb to drupal import module). By repopulating this table, all the errors disappeared!

Thanks for all your help!

Chris.

salvis’s picture

Good, thanks for letting me know.

That means that the vb to drupal import module isn't making the appropriate hook_user('insert') call when importing users. This is a bug and can cause all sorts of problems with other modules that track the users. You should report this to their issues queue.