I have a process that needs to run repeatedly at an interval (let's say every minute), and also needs to be scaled as far as how many processes are running concurrently, depending on how much "work" there is to do.
The process needs to have access to various Elgg entities and metadata with "admin" privileges.
Initially I setup an admin user and at the beginning of the function I added code to log in as the user, therefore giving the cron job all the Elgg access it needed during the session.
if ($user = authenticate($elgg_username,$elgg_password)) {
login($user, true);
admin_init(); // Required so that access is properly initialized
}
However, Elgg will only allow one login per user at a time, so if the 1st cron job was still running when the 2nd one started, the 1st one would automatically be logged out.
So I took a look at \engine\lib\access.php to see how I could "fool" Elgg into thinking I had admin privileges without having to log in as a specific user.
Turns out it's super easy :)
global $is_admin;
$is_admin = true;
Done and done. Just thought I'd share this with y'all in case you had the same requirement.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Kevin Jardine@kevin

Kevin Jardine - 0 likes
- Kane@kane

Kane - 0 likes
- Cash@costelloc

Cash - 0 likes
You must log in to post replies.People should note that Kane's comments apply to Elgg 1.6.1 or earlier.
The access over-ride process has changed in Elgg 1.7.
Oops, thanks for the clarification Kevin. I'm on Elgg 1.5 :)
I'll also add that Elgg 1.7 allows a user to be logged in multiple times at once (but with a limit of one session backed by the "remember me" cookie).