I got the following warning when I installed this module. I had previously installed the og_mandatory_groups module:

warning: Invalid argument supplied for foreach() in /sites/all/modules/og_multiple_mandatory_groups_by_role/og_multiple_mandatory_groups_by_role.install on line 61.

The offending code is:


if (db_table_exists(og_multi_mand_groups_role_groups)) {
      drupal_set_message(t('using existing Mandatory Groups for new <em>Available Groups</em> table...'));
      foreach ($all as $gid => $value) {
        $sql = "SELECT n.title FROM {node} n WHERE n.nid = %d";
        $result = db_fetch_object(db_query($sql, $gid));
        if (db_query("INSERT INTO {og_multi_mand_groups_role_groups} VALUES (%d, '%s')", $gid, $result->title)) {
          drupal_set_message(t("added <em>%name</em> to the group availability table...", array('%name' => $result->title)));
        }
      }
    }
    db_query("DELETE FROM {variable} WHERE name = '%s'", 'og_mandatory_group');

There should probably be a check on the $all array:

if(! empty($all)) {
     ...
}

Comments

rconstantine’s picture

Actually, what if on the line four lines above your quote I change the array() part of the variable_get to FALSE? Would that do the trick? It would be the first line here:

if ($all = variable_get(og_mandatory_group, FALSE)) {
    $all_users_mand_groups = $all;
    drupal_set_message(t('Found previously used Mandatory Group variables...'));
    drupal_set_message(t('using existing Mandatory Groups for new <em>All Users</em> category...'));
    if (db_table_exists(og_multi_mand_groups_role_groups)) {
      drupal_set_message(t('using existing Mandatory Groups for new <em>Available Groups</em> table...'));
      foreach ($all as $gid => $value) {
        $sql = "SELECT n.title FROM {node} n WHERE n.nid = %d";
        $result = db_fetch_object(db_query($sql, $gid));
        if (db_query("INSERT INTO {og_multi_mand_groups_role_groups} VALUES (%d, '%s')", $gid, $result->title)) {
          drupal_set_message(t("added <em>%name</em> to the group availability table...", array('%name' => $result->title)));
        }
      }
    }
    db_query("DELETE FROM {variable} WHERE name = '%s'", 'og_mandatory_group');
  }
rconstantine’s picture

Status: Active » Fixed

Well, I think that should fix it. Let me know if it is now broken worse.

palazis’s picture

I got the same warning when I installed the module without having the og_mandatory_groups module previously. Now I can't see any available groups at admin/og/og_multiple_mandatory_groups_by_role/groups page and I see the same waning there too.
Any progress on the issue?
Thanks in advance.

palazis’s picture

Status: Fixed » Active
rconstantine’s picture

Did you replace the offending code from the install file as per the above discussion? I haven't uploaded any changes yet since I don't know if the above code works or not yet. I need testers. The file isn't that long and it should be plain based on the original post in this thread which code should be replaced. Let me know if you tried it.

palazis’s picture

Yes I did replace the code - In fact I have used the dev version where the code is already replaced.
The problem (warning) still exists.

rconstantine’s picture

Try this instead:

if ($all = variable_get(og_mandatory_group, FALSE)) {
    $all_users_mand_groups = $all;
    drupal_set_message(t('Found previously used Mandatory Group variables...'));
    drupal_set_message(t('using existing Mandatory Groups for new <em>All Users</em> category...'));
    if (db_table_exists(og_multi_mand_groups_role_groups) && $all !== FALSE) {
      drupal_set_message(t('using existing Mandatory Groups for new <em>Available Groups</em> table...'));
      foreach ($all as $gid => $value) {
        $sql = "SELECT n.title FROM {node} n WHERE n.nid = %d";
        $result = db_fetch_object(db_query($sql, $gid));
        if (db_query("INSERT INTO {og_multi_mand_groups_role_groups} VALUES (%d, '%s')", $gid, $result->title)) {
          drupal_set_message(t("added <em>%name</em> to the group availability table...", array('%name' => $result->title)));
        }
      }
    }
    db_query("DELETE FROM {variable} WHERE name = '%s'", 'og_mandatory_group');
  }

I only changed one line there.

rconstantine’s picture

Wait a minute. Although I saw that you said this earlier, I forgot to ask: you say you didn't have the other module installed when you installed this one, but you got the same error; was it the same line of code that was indicated as the problem? Or was there another line mentioned? Because the function call to "db_table_exists(og_multi_mand_groups_role_groups)" should really work. If the change above doesn't work, then try this last one:

if ($all = variable_get(og_mandatory_group, FALSE)) {
    $all_users_mand_groups = $all;
    drupal_set_message(t('Found previously used Mandatory Group variables...'));
    drupal_set_message(t('using existing Mandatory Groups for new <em>All Users</em> category...'));
    if (db_table_exists('og_multi_mand_groups_role_groups') && $all !== FALSE) {
      drupal_set_message(t('using existing Mandatory Groups for new <em>Available Groups</em> table...'));
      foreach ($all as $gid => $value) {
        $sql = "SELECT n.title FROM {node} n WHERE n.nid = %d";
        $result = db_fetch_object(db_query($sql, $gid));
        if (db_query("INSERT INTO {og_multi_mand_groups_role_groups} VALUES (%d, '%s')", $gid, $result->title)) {
          drupal_set_message(t("added <em>%name</em> to the group availability table...", array('%name' => $result->title)));
        }
      }
    }
    db_query("DELETE FROM {variable} WHERE name = '%s'", 'og_mandatory_group');
  }

Note, the only change here is the addition of single quotes around the table name.

palazis’s picture

You got that right - it's not a problem of the same nature most probably...
Let me try to be more precise:
After installing the module I see the following error:
"There was an error installing the OG Multiple Mandatory Groups by Role database table." No line number is indicated there.
After visiting admin/og/og_multiple_mandatory_groups_by_role I see two (2) identical records:
Role (which is empty!) and Operations (assign groups).
When I choose Available groups I see the following warning:
"warning: Invalid argument supplied for foreach() in ...public_html/includes/form.inc on line 948."
I don't understand: I have plenty of roles and groups in my site.
Trying the different versions of code mentioned here did not help.

rconstantine’s picture

Status: Active » Fixed

That sounds like a completely different issue. Please copy your last post into a new issue.

palazis’s picture

ok.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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