For a client project, I have a list of group name.
I use migrate to create group from this list : one row = one group.

In my migrate process, I call the function entity_save() :

entity_save('group', $group);

During the saving process, Drupal call the fonction invoke() :

$this->invoke('insert', $entity);

$this is the group controller : GroupController. So Drupal call the GroupController::invoke().
This function exist and do something on an insert saving. It add the curent user (normally the user creating the group) in this new group.

But there is two problems :

  • The migrate object isn't a Group object but a stdClass. So when the GroupController call the $group->addMember() function, that issue this error message : "undefined method stdClass::addMember()"
  • The current user is Drush, so the user id is 0 for the anonymous user. And I think we souldn't never try to add an anonymous user to a new created group :)

I will push a patch checking this id and don't do this addMember() if the user is anonymous.
This patch should solve the two problems in a same time.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Merkator’s picture

There is the patch for this issue.

Merkator’s picture

Status: Active » Needs review
kristiaanvandeneynde’s picture

Title: undefined method stdClass::addMember() » Do not allow anonymous users to join groups
Assigned: Merkator » kristiaanvandeneynde
Category: Bug report » Task

Hi there, thanks for creating an issue about this!

About your migration

You can't save a group unless it is, in fact, a Group object. Otherwise Entity API wouldn't know what to do with it when it tries to save it to the database correctly. You need to make sure that you aren't dealing with a stdObject, but a Group instead. Try using $group = entity_create('group', $values); instead. Where values may be an empty array or some preset properties you want the group to have.

About anonymous users

Okay, so there's not really a bug here, just something to consider.

Up until now I was still on the fence whether an anonymous user could join a group or not. However, given the following recent changes:

  • You can now set group permissions specifically for "Anonymous"
  • This will lead to confusion if an anonymous user can still be a "Member"
  • You can always give "Anonymous" the exact same permissions as "Member" to fill this hole

I am inclined to disallow anonymous users to join a group. This would have to be done on more levels than just GroupController::invoke(), though. Starting with the more obvious Group::addMember() instead.

Changing this into a Task instead to deal with the anonymous user issue. If you still have trouble with your migration, please open a separate support request for it.

kristiaanvandeneynde’s picture

FileSize
2.44 KB

Could you check out this patch?

kristiaanvandeneynde’s picture

Status: Needs review » Fixed

Considering fixed.

Status: Fixed » Closed (fixed)

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