Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Adding 'everyone' to a new group

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 667 Views
  • Futureweb
    Avatar
    Community Member
    232 Posts

    Adding 'everyone' to a new group Link to this post

    Hi,
    I've created a new group type called 'newsletter', and I want to add everyone (about 2000 people) to this list (then i'll manually remove the few that don't want to receive newsletters).

    Is there an easy way of doing this? I cant seem to see how without going through each person individually...

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: Adding 'everyone' to a new group Link to this post

    You could write a small function within SS that copies the users over and then visit the function's address in the browser to trigger it.

  • Futureweb
    Avatar
    Community Member
    232 Posts

    Re: Adding 'everyone' to a new group Link to this post

    ok, if there is no function within the CMS, i'll probably do it by exporting a CSV file of all the members, opening in excel, removing all the data but the ID, and then importing again into Group_Member table..

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Adding 'everyone' to a new group Link to this post

    Hey - no need for the export you can just do a little function like this:

    function MoveGroups(){
       $oldGroupID = "1";
       $newGroupID = "2";
       
       $oldGroup = DataObject::get_one('Group', "ID = $oldGroupID");
       $newGroup = DataObject::get_one('Group', "ID = $newGroupID");
       
       foreach ($oldGroup->Members() as $member) {
          $member->Groups()->add($newGroup);
       }
       
       Director::redirect($this->link());
    }

    Then if you set the IDs to be the correct groups and run the function it'll move them over. I haven't actually tested that code so you may need to play with it a lil to get it to work.

    667 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.