Has anybody ever successfully created a Cron plugin that could access PRIVATE Entities?

I'm having no luck at all.

I've implemented exactly what's described in these two docs.

http://docs.elgg.org/wiki/CronPlugins

http://docs.elgg.org/wiki/PermissionsCheck

But every time I call get_entities() it only returns PUBLIC entities.  But the whole point of Cron jobs is to to automated processing *behind the scenes* so I'd think most folks would need access to the "meat and potatoes" of their Elgg system...ie. PRIVATE entities.

Here's the previous thread I started - http://community.elgg.org/mod/groups/topicposts.php?topic=182208&group_guid=7

If anyone, anywhere, has ever gotten this to work, I'd love to see some code!  If the Elgg developer who actually wrote the permissions_check plugin hook functionality is reading this...please HELP!!

Or should I just report a bug?  I'm not sure how to proceed because I've been stuck on this one thing for a few days now.

  • We may be making progress.. I'm running as bare php code. thru the browser -  If it works here it should work via CRON.  Note that sneaky sleep(2), auth, login 2x ? Something I read somewhere about delayed / cached IO.  btw am using get on on guid (2).

    <head>
    <title>
    UTIL____LOGIN_ADMIN.php
    </title>
    <h2>UTIL____LOGIN_ADMIN.php</h2>
    </haad>
    <body style="margin-left:25px;">
    <?php
    echo "<pre>\nENGINE START";
        require_once("engine/start.php");
        echo "\nAUTHENTICATE -- CHECK";
        if ($user = authenticate("ADMIN","PWD) )
        {
            echo "\nAUTHENTICATE -- OK ";
            echo "\nLOGIN -- CHECK";
            $result = login($user, false);
        }
        sleep(2);
        if ($user = authenticate("ADMIN","PWD) )
            $result = login($user, false);
        sleep(2);
        if ($result)
        {
            echo "\nLOGIN -- OK ";
            echo "\nGET_ACCESS_LIST= ",get_access_list();
            $entity = get_entity(2);
            echo "\n<hr>";
            echo "\n<h2>ENTITY (2)::</h2>";
            print_r($entity);
            echo "\n<hr>";
            $result = logout();
        }
        else
        {
            echo "\nAUTHENTICATE / LOGIN -- ERROR ";
        }
        //forward("pg/dashboard/");
    ?>

     

     

    UTIL____LOGIN_ADMIN.php

    ENGINE START
    AUTHENTICATE -- CHECK
    AUTHENTICATE -- OK
    LOGIN -- CHECK
    LOGIN -- OK
    GET_ACCESS_LIST= (2,1,0)

    ENTITY (2)::ElggUser Object
    (
    [attributes:protected] => Array
    (
    [guid] => 2
    [type] => user
    [subtype] => 0
    [owner_guid] => 0
    [container_guid] => 0
    [site_guid] => 1
    [access_id] => 2
    [time_created] => 1244825512
    [time_updated] => 1247882693
    [enabled] => yes
    [tables_split] => 2
    [tables_loaded] => 2
    [name] => admin
    [username] => admin
    [password] => 852ba6c905d5e6d03f91853465219413
    [salt] => 179aa9a8
    [email] => xxx@xxx.com
    [language] => es
    [code] => 56202cebc66921267dd1468313c9723b
    [banned] => no
    [last_action] => 1247882693
    [prev_last_action] => 1247882636
    [last_login] => 1247882636
    [prev_last_login] => 1247882634
    )

    [url_override:protected] =>
    [icon_override:protected] =>
    [temp_metadata:protected] => Array
    (
    )

    [temp_annotations:protected] => Array
    (
    )

    [valid:private] =>
    )


  • Shit hahaha - I actually tried sleep(10) a while back but that didn't seem to help, I still had to refresh the page to get the correct access.

    Ok I'll play with it some more - thanks so much for your help!

  • did you do just 1 sleep(10) ?

    i did --

    " Note that sneaky sleep(2), auth, login 2x ? Something I read somewhere about delayed / cached IO.."

    i.e.
    auth
    login
    sleep
    auth
    login

    seems to do ok..;;-O

     

  • Nope, I just tried authenticate(), login(), sleep(2) repeat x 5 (yes five times!)

    It never gives me access_id 0 on the first page load.

    Maybe this is a limitation of the cron plugin hook?

    I suppose I could have my cron job point to a raw PHP page rather than loading /pg/cron/*

    Ok I'll try that next.

  • Just try that bare code I did and shove it into CRON... and see..;;;-O

    oopss, and drop that permissions check code out !!!

  • I just tried it, but no luck.  I had to comment out the require_once("engine/start.php"); though.


    ENGINE START
    AUTHENTICATE -- CHECK
    AUTHENTICATE -- OK
    LOGIN -- CHECK
    LOGIN -- OK
    GET_ACCESS_LIST= (2,1)

    ENTITY (450)::
  • Ok, I tried just running your bare PHP code in a "test.php" file through my browser.  I'm getting different results than you.  The access list still doesn't show a 0.  So I guess something is just fuxxored with my Elgg installation?

    What version are you running?

    At least we can eliminate the cron plugin hook being the problem!

     

    UTIL____LOGIN_ADMIN.php

    ENGINE START
    AUTHENTICATE -- CHECK
    AUTHENTICATE -- OK
    LOGIN -- CHECK
    LOGIN -- OK
    GET_ACCESS_LIST= (2,1)
  • Well of course entity(2) will work, it has ACCESS_ID = 2 (PUBLIC).  The whole issue is trying to retrieve entities that have ACCESS_ID = 0 (PRIVATE) ;)

    You don't even need to be logged in to retrieve GUID 2.

  • Ok I GOT IT FIGURED OUT!  Finally!

    I decided to just trace through the code so I was looking in access.php, specifically at the get_access_sql_suffix() function

    And I noticed that part of the logic in creating the access SQL query does a check to see if the global variable $is_admin is TRUE;

    Then I found that this handy-dandy admin_init() function sets the global $is_admin variable.

    The solution?

    One line after the login():

    admin_init();

    Sweeeeeeeeeeeeeeeeeeeeeeet

    It's beer 'o clock now. :)