Question

To insert additional logic when a user logs off one might look at function user_logout() in user.pages.inc. This code being in a core module, you should not edit it, but works very well... for example by adding the following code to the top of the 'user_logout()' function...

$last_run = variable_get('cron_last', 0);  
if(time() - $last_run > 86400) {  
    include_once './includes/bootstrap.inc';  
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);  
    drupal_cron_run();  
    drupal_flush_all_caches();  
    watchdog('user', 'cron set to run and cache to be cleared on user logout', array('%name' => $user->name));  
}

... I get the cache cleared and cron run if cron has not run in the last 24 hrs. Okay, not ideal for cron but that's another issue.

Where is the best place to add this little snippet? I could simply implement my own logout menu item... but I'm not keen on that solution.

Thanks in advance.

Was it helpful?

Solution

Instead of modifying core, you can implement hook_user() in a custom module. Then you can check the $op parameter to see if it equals "logout". This code will run whenever a user logs out, regardless of what menu item or link they click to log out.


Note that this is different between Drupal 6 and 7. This question was tagged Drupal 6, but if you're using Drupal 7, or plan to later, be aware that this hook was replaced with hook_user_logout().

OTHER TIPS

Might want to check out the Poor Mans Cron module.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top