Hi there,
Code seems to be broken, perhaps. I'll create a ticket, or find out if there's already one.
EDIT: Ticket created - http://open.silverstripe.com/ticket/1562
You might do this instead:
// check if member exists, first
if($member = Member::currentUser()) {
// look for current group
if($group = DataObject::get_one('Group', "Code = 'my-users'")) {
// check this member isn't in the group
if(!$member->isInGroup($group->ID)) {
// add the member to the group
$member->Groups()->add($group);
}
} else {
// otherwise, create a new group
$group = new Group();
$group->Code = 'my-users';
$group->write();
// add the member to the group
$member->Groups()->add($group);
}
}
This checks if the member exists, adds the member to a current group it finds in the database. If that group doesn't exist, create a new one with that code value, and add it into the system.
Cheers,
Sean