After updating from 6x-1.6 to 6.x-1.x-dev, I started receiving the following errors any time I change a user role (which changes the badges):

warning: array_key_exists(): The first argument should be either a string or an integer in user_badges.module on line 273.
warning: Illegal offset type in user_badges.module on line 276.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

srees’s picture

user_badges_get_roles has an error setting the default value for returnbadges. It is setting it to a string, and then performing a boolean evaluation on it. This was causing it to unexpectedly return objects instead of badge ids to calling functions, and breaking them. This is the primary issue with this ticket.

There are also flaws in the logic implementing 'type' with badges.

The function user_badges_user_save, while it doesn't appear to be used anywhere in this module (why??), may be called externally (which I was doing writing user_badges support into user_import). It does not save 'type' when it stores a badge. However, when modifying a user and changing their roles, it explicitly only deletes badges of type 'role'. I can't take a user created with user_badges_user_save and modify their badges anymore because of this. I can't set them since it thinks they are already set (checking badges doesn't check the type), and it won't let me unset them because they don't have a type.

Since the user hook is dependent on roles to change badges, it seems appropriate it only affects that type of badge - in which case it seems best to me to modify the user_badges_user_save function to have an additional optional argument on the end to enable setting the type.

Further code errors I've addressed:
Line 262 looks like it was a debugging statement that someone failed to remove, hardcoding a role number.
Line 379 increments a variable that was never set.
Line 560 expects the $user global, which wasn't declared. This could have caused permissions issues.

Hope this patch helps.

srees’s picture

Status: Active » Needs review
shabana.navas’s picture

Issue summary: View changes
Status: Needs review » Fixed

@srees, thanks a lot for catching all these errors. I have made the changes to the dev version and releasing a production version based on this.

Status: Fixed » Closed (fixed)

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