Using a recent CVS version of OG on a drupal 4.7-cvs installation:

$Id: og_mandatory_group.module,v 1.2 2006/03/04 17:37:36 weitzman Exp $

When I enable og_mandatory_group, and then try to register a new user, I get a fatal error:

Fatal error: Call to undefined function: og_create_subscription() in /home/prince14/public_html/modules/og/contrib/og_mandatory_group/og_mandatory_group.module on line 24

From a manual comparison with between these two versions of og.module:

$Id: og.module,v 1.138 2006/03/01 17:26:32 webchick Exp $
$Id: og.module,v 1.148 2006/03/28 21:20:21 weitzman Exp $

it looks as though the function name in og.module was changed from og_create_subscription() to og_save_subscription().

Changing this function call to see if that fixes it, I get the following errors instead:

* warning: Invalid argument supplied for foreach() in /home/prince14/public_html/modules/og/contrib/og_mandatory_group/og_mandatory_group.module on line 33.
* warning: array_keys(): The first argument should be an array in /home/prince14/public_html/modules/user.module on line 339.
* warning: implode(): Bad arguments. in /home/prince14/public_html/modules/user.module on line 339.
* user warning: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN () in /home/prince14/public_html/includes/database.mysql.inc on line 120.
* warning: array_keys(): The first argument should be an array in /home/prince14/public_html/modules/user.module on line 339.
* warning: implode(): Bad arguments. in /home/prince14/public_html/modules/user.module on line 339.
* user warning: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN () in /home/prince14/public_html/includes/database.mysql.inc on line 120.

These errors seem to be of the same nature as what I reported before at http://drupal.org/node/52346

Again, the outcome is that the user is added to the mandatory group, but I don't want to have new users scared off by this kind of error message.

Comments

moshe weitzman’s picture

i fixed the wrong function name. no time to investigate other issue". perhaps contact the author of this module. he might have his checkbox values mixed up.

pwolanin’s picture

Status: Active » Needs work
StatusFileSize
new1.34 KB

I have, I think, corrected the next bug "warning: Invalid argument supplied for foreach()" on line 33 of the module in the attached patch. Thanks to Zack who's 4.7 port of this module at www.zacker.org had this line corrected and confirmed my thought as to how to fix it.

I also prevented the remainder of the errors by commenting out a call to the user.module function "user_access()" on line 62. Not a real fix, but
(for me at least) there is no loss in functionality because the function call resulted in an error anyhow. The purpose of the function call is to determine whether to add a helpful line to the notification e-mail.

pwolanin’s picture

eurka- I think I found the problem. The last batch of errors are from this function:

http://api.drupal.org/api/HEAD/function/user_access

The implode statment references: $account->roles

However, in og.module, the SQL query returns only some fields from {user} and {og_user}
In contrast, the user_access() function expects the full $user object generated by
user_load() which includes #user->roles. So, the function call to user_access,/code> is passing an invalid parameter.

pwolanin’s picture

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

Ok, after my insight above and too much browsing of user.module, I think the attached patch brings the full intended functionality to this module. Tested using 4.7RC3, PHP 4.3.10, mySQL 4.0.25. Please review/test/commit and maybe move this module back into the 4.7 branch of OG.

-Peter

ajwwong’s picture

Status: Needs review » Reviewed & tested by the community

Patch works:

Upon new registration, users were getting the scary message --


Warning: Invalid argument supplied for foreach() in /home/ithou/public_html/modules/og/contrib/og_mandatory_group/og_mandatory_group.module on line 32

Warning: array_keys(): The first argument should be an array in /home/ithou/public_html/modules/user.module on line 378

Warning: implode(): Bad arguments. in /home/ithou/public_html/modules/user.module on line 378

Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: user_access SELECT DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN () in /home/ithou/public_html/includes/database.mysql.inc on line 120

Warning: Cannot modify header information - headers already sent by (output started at /home/ithou/public_html/modules/og/contrib/og_mandatory_group/og_mandatory_group.module:32) in /home/ithou/public_html/includes/common.inc on line 266

Thanks to the patch, this scary message has gone away.

I don't know the inner workings of the patch, or the mechanics of *how* it works, but it does trick.

I don't know appropriate policy on this, or if this patch actually needs further review, but I'm marking as RTC.

pwolanin’s picture

The full (most recent) patch should not only make the scary error messages go away, but also any group admins who have the 'administer users' permission should now have received an e-mail that includes a link to administer the account of the newly-joined user.

-Peter

pwolanin’s picture

Assigned: Unassigned » pwolanin

I'm pretty confident that this patch is, indeed, ready to be committed. Please let me know...

killes@www.drop.org’s picture

$registered = array(0);
- foreach ($edit['og_register'] as $key => $value) {
+ if ($edit['og_register']) {
$registered[] = ($value ? $key : 0);
}

I am not sure that will work for more than one group

pwolanin’s picture

@killes - thanks for reviewing this.

I'm looking at the code with a fresh eye and I'm now thinking, perhaps, the foreach is needed, but the usage was wrong in some other way. This current patch has been working for me since I don't have any groups available during registration.

A better patch to follow.

dww’s picture

Status: Reviewed & tested by the community » Needs work
pwolanin’s picture

Below is a fragment of the code from og.module for the 'insert' case in hook_user. From the SQL query, it looks as though this was changed as part of the "let any node be a group" reform.

I will use this same logic in place of the foreach().

function og_user($op, &$edit, &$account, $category = NULL) {
  global $user;

  switch ($op) {

...
    case 'insert':
      $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND n.status = 1 AND o.register = 1'), variable_get('og_node_types', array('og')));
      while ($group = db_fetch_object($result)) {
        if ($edit['og_register'][$group->nid]) {
          $return = og_subscribe_user($group->nid, $account);
          if (!empty($return['message'])) {
            drupal_set_message($return['message']);
          }
        }
      }

      break;
 ...
pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new3.09 KB

revised patch attached- does work for me to send e-mail describing groups joined during registration form.

pwolanin’s picture

StatusFileSize
new4.83 KB

patched module, plus orig and README attached in a .zip for those who want to easily test the patch in #12.

jdsaward’s picture

Component: OG Mandatory Group » og.module

Just confirming that I downloaded and installed and used the mandatory group module with no errors and no pain.

I had a recipe problem which I received help with and wrote this:

'I have installed the latest version of og_mandatory_group that I could find. I set it to make the "Members" group the mandatory group and indeed as soon as I added a new test-user that user belonged to the mandatory group but no other group. Works like magic.'

I was requested to follow up here; to complete the documentation. So I am.

pwolanin’s picture

Title: Fatal error when enabling og_mandatory_group » update og_mandatory_group for Drupal 4.7
Project: Organic Groups » Organic Groups Mandatory Group
Version: master »
Component: og.module » Code
Status: Needs review » Fixed

Commited changes- working 4.7 version now available for download:

http://drupal.org/project/og_mandatory_group

Anonymous’s picture

Status: Fixed » Closed (fixed)