3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1027 Views |
-
want to remove members from group but no errors nor any results

6 August 2009 at 1:24pm
Hi All
I have written up a piece of code which should run very straightforwards. I first select all members, then cycling through them I create an array of members which are in group 8( the one I want to remove my members from). I should then be able to either as the cycle goes through remove the membership or cycle through the new array and remove the membership then. Fairly simple I think but no luck whatsoever. Also if it helps
<?php
class ClearExpiredUsersTask extends HourlyTask {
function process() {
$allExpiredMembers = array();
$ExpiredUsersGroup = DataObject::get_one('Group', "Code = 'expired-users'");foreach($members as $member) {
if($member->inGroup("8")){
$allExpiredMembers[$member->ID] = htmlentities($member->Email);
//$expiredMember = DataObject::get_by_id("Member", $member->ID);
//$expiredMember->Groups()->remove($ExpiredUsersGroup);
}
}//////////not necessary but shows what is going on ///////////////////////////////////////////
print_r($allExpiredMembers);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
foreach($allExpiredMembers as $member=>$Email)
{
$expiredMember = DataObject::get_one("Member", "Email = '$Email'");
$expiredMember->Groups()->remove(DataObject::get_one('Group', $ExpiredUsersGroup));
}
}
}?>
[\code]Any tips would be really appreciated.
Thanks
Will
-
Re: want to remove members from group but no errors nor any results

6 August 2009 at 4:35pm
Are you writing the changes?
Put $member->write(); after the remove statement - that will apply the changes to your database.
-
Re: want to remove members from group but no errors nor any results

7 August 2009 at 6:33am
haha. yeah you totally spotted what I missed for a couple of hours, thanks very much.
Will
| 1027 Views | ||
|
Page:
1
|
Go to Top |


