1)); // D7: use user_load(1);
// Take your action here where you pretend to be the user with UID = 1 (typically the admin user on a site)
// If your code fails, it's not a problem because the session will not be saved
$user = $original_user;
session_save_session(TRUE); // // D7: use drupal_save_session(TRUE);
// From here on the $user is back to normal so it's OK for the session to be saved
?>
original post : http://www.zimplicit.se/knowledge/running-cron-administrator-or-another…It is quite common to run a script in drupal and need specific permissions to select or retrieve the data you need. Several times the user that runs the script does not have these rights and we need to do a little hacking in drupal to do our script to run properly without problems.For example when you let the server run cron on Drupal it runs as Anonymous ( not authenticated ) user where uid=0.So if you have some tasks that requires admin access no one of them will execute.One workaround it to temporary fake another user , like it was the admin ( uid=1) who run the cronjob .This is a safer way to temporary change the user because if the function crashes it has not saved the temporary user. If the function succeed it returns to Anonymous user when finished.
superuser admin