Make everyone friends with specific user

I have imported a large number of users from a Drupal based site into an newly created Elgg install. Everything went resonably well and the Elgg community has been really helpful when I bumped up against a couple of issues. So hopefully you can help me with this one... I have utilised the post_login_update plugin to make any new users registering automatically become a friend of a specific user which works perfectly but obviously this did not work with users I imported.

Is there anything I can do in the database to make all users be friends with a specific user or is there a plugin which does this and I missed?

  • If you know PHP, it should just be a few lines of code to do this (add relationships). Something like:

    $users = get_entities("user", "", 0, "", 9999);   

    foreach($users as $user) {



  • Dear Cash,

    Splendid, but please explain what the values represent in ("user", "", 0, "", 9999)

    "user" is obvious. And the rest?

  • @shillo

    The second parameter is "subtype" which is not applicable for entities of type "user" (first parameter), The third parameter is owner_guid, and the 4th parameter is the limit (of items you want on this call).

    Which brings up a coding issue that has bothered me in all of the elgg engine calls regarding "limit". If you set the limit to 9999, then if you happen to have more than that number of users, you will miss the rest. In general the way I get around this is to have two loops as follows:

        $total = 0;

        for (  ;  ;  ) 


             $newcount = 0;

             $users = get_entities("user", "", 0, "", 9999);

             foreach($users as $user)


                 // check to make sure relationship does not already exist then add it




             if ( $newcount == 0 )


             $total += $newcount;




  • That's wonderful, ChungNg.

    I had the intution is that "9999" is the member limit, but don't worry, my site will never hit that barrier. There are not that many intelligent people on the planet :) hahaha.

  • Ok, thanks for this. I understand what is going on with code I can see the function referenced in elgg/lib/relationships.php but how best to go about running this. Sorry, I am a newbie!