Erik Richter Posted October 12, 2015 Share Posted October 12, 2015 Hey folks, does anybody have an idea how I can change field values after a set time via API? I know how to change values of fields, but have no idea how could create a automatic change. Example: I have a user created via Formbuilder or any other API method. This user has the Role Gold and after 30 days it should change to silver. Since Roles are just fields like any other field there must be a cool solution for this. Appreciate any ideas Link to comment Share on other sites More sharing options...
kongondo Posted October 12, 2015 Share Posted October 12, 2015 Sorry, nothing specific but there are several possibilities including autoload module, a cron job and maybe the new cool and shiny Iftrunner...Gotta go, but sure you'll get better answers Link to comment Share on other sites More sharing options...
SteveB Posted October 12, 2015 Share Posted October 12, 2015 When you change the user to Gold put the current date or expiration date in another field. Setup a really simple module to hook on login. Then it can test the date field and role to see if it's an expired Gold user and change their role. Maybe even redirect them. $this->addHookAfter('Session::loginSuccess', $this, 'hookAfterLogin'); and public function hookAfterLogin ($event) { $user = $event->arguments[0]; foreach($user->roles as $role){ do things... } } Edit: More here http://wiki.processwire.com/index.php/Module_Creation#How_to_attach_hooks_with_a_module 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted October 13, 2015 Share Posted October 13, 2015 SteveB's solution should work. You can run the check not only on login, but periodically with Lazy Cron core module or with a cron job as kongondo suggested. 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