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.
Comment | File | Size | Author |
---|---|---|---|
#4 | group-2389979-4.patch | 2.44 KB | kristiaanvandeneynde |
#1 | group-undefined_addmember-2389979.patch | 2.56 KB | Merkator |
Comments
Comment #1
Merkator CreditAttribution: Merkator commentedThere is the patch for this issue.
Comment #2
Merkator CreditAttribution: Merkator commentedComment #3
kristiaanvandeneyndeHi 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:
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.
Comment #4
kristiaanvandeneyndeCould you check out this patch?
Comment #5
kristiaanvandeneyndeConsidering fixed.