vxda Posted June 24, 2014 Share Posted June 24, 2014 Hi i made a module for deleteing users that didnt confirmed their accounts so im using Lazy Cron for doing it. but its not dooing anything.I made module file :removeInactiveUsers.modulein it i have this : <?php class removeInactiveUsers extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Remove inactive users', 'version' => 101, 'summary' => 'Every X minutes removes inactive accounts', 'singular' => true, 'autoload' => true ); } public function init() { $this->addHook('LazyCron::everyMinute', $this, 'removeInactiveUsers'); } public function removeInactiveUsers(HookEvent $e) { //If field "user_activation" is not 0. (zero); $inactiveUsers = $this->$users->find("!user_activation$=0"); if(count($inactiveUsers)){ foreach ($inactiveUsers as $u) { $users->delete($u); } } } } so i installed module and nothing happends.Any tips of what im doing wrong ?Ps. i have Lazy Cron module installed Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 24, 2014 Share Posted June 24, 2014 The second "$" is to much. $this->$users->find("!user_activation$=0"); Link to comment Share on other sites More sharing options...
adrian Posted June 24, 2014 Share Posted June 24, 2014 The first error I see is: $this->$users->find It needs to be: $this->users->find EDIT: Sorry, I loaded this thread, then got distracted and was beaten to it Link to comment Share on other sites More sharing options...
vxda Posted June 24, 2014 Author Share Posted June 24, 2014 Ty guys fixed that double $, but still no good ;/ Link to comment Share on other sites More sharing options...
adrian Posted June 24, 2014 Share Posted June 24, 2014 Try replacing: $users->delete($u); with: $this->users->delete($u); Also, turn on debug mode so you get some error reporting - these should be showing up. 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 24, 2014 Share Posted June 24, 2014 I would use "find("!user_activation=0");" instead of $=, if it's a integer or checkbox field. 2 Link to comment Share on other sites More sharing options...
vxda Posted June 24, 2014 Author Share Posted June 24, 2014 Try replacing: $users->delete($u); with: $this->users->delete($u); Also, turn on debug mode so you get some error reporting - these should be showing up. That did the job ty. Here is my code: <?php class removeInactiveUsers extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Remove inactive users', 'version' => 101, 'summary' => 'Every X minutes removes inactive accounts', 'singular' => true, 'autoload' => true ); } public function init() { $this->addHook('LazyCron::everyMinute', $this, 'removeInactiveUsersFn'); } public function removeInactiveUsersFn(HookEvent $e) { $inactiveUsers = $this->users->find("!user_activation$=0"); if(count($inactiveUsers)){ foreach ($inactiveUsers as $u) { $this->users->delete($u); } } } } Ty for help guys 1 Link to comment Share on other sites More sharing options...
MuchDev Posted September 19, 2015 Share Posted September 19, 2015 Hey, I was just googling for the lazycron documentation and this post popped up #2 so I figure I will throw my implementation of the exact same thing in this post in case anyone looking needs another idea. The only thing that differs in my code is that I compared the creation time to current to allow users an amount of time to validate their account. I also have it log so you can keep an eye on what your server was up to while you weren't looking. public function init() { $this->addHook('LazyCron::every10Minutes', $this, 'userPrune'); } public function userPrune(HookEvent $e) { $usersToValidate = wire('pages')->find('template=user,include=hidden,active=0'); if(count($usersToValidate)){ $log = wire('log'); $now = time(); $invalid = $now - (1*60*60); foreach($usersToValidate as $u){ //if user was created longer than 2hrs ago then delete them if($u->created < $invalid){ $entry = date('Y-m-d',$now)." ".date('H:i:s',$now)." | ".$u->title." | ".$u->email."\r\n"; $u->delete(); $log->save('user-delete-log', $entry); } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now