Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

want to remove members from group but no errors nor any results


Reply


3 Posts   1269 Views

Avatar
vancouverWill

Community Member, 121 Posts

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

Avatar
Hamish

Community Member, 712 Posts

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.

Avatar
vancouverWill

Community Member, 121 Posts

7 August 2009 at 6:33am

haha. yeah you totally spotted what I missed for a couple of hours, thanks very much.

Will