How can I add new user in Elgg using sql query

754 views Asked by At

I am developing a mobile app for a social network based on Elgg. Right now I have a registration form, problem is that when I register a user, I get everything like username, password, salt, etc. except guid. How can I generate this guid. Any help would be appreciated. Thanks.

3

There are 3 answers

0
Chetan Sharma On

Elgg being and EAV Database structure, You can't simply create user with your direct queries.(It is possible but will have to implement you Queries similarly like EAV). Instead of that, use Web services for mobile integration. It can use Elgg API with authenticated REST Request.

0
Itay Weiss On

As explained here the main table in elgg is the elgg_entities table, in it the guid column (the first one) is the auto incremented value which is created for every entity in elgg which is basically everything (users, pages, groups and everything else).

The entity_subtype column on that very same table represents the type of the entity (connects it to a table of the same name) and in the case of a user to the users_entity table.

in order to auto generate users outside of elgg code but straight through the Database (Not recommended at all by the way) you should start with a new entity row (In elgg_entities table) of a user sub-type and then a new row in the elgg_users_entity table.

0
Paweł Sroka On

You can simply use core register_user function that returns guid of new account. See usage here: https://github.com/Elgg/Elgg/blob/1.8/actions/register.php#L30

When you're integrating with mobile application, I'd strongly recommend using web services instead of hacking on the frontend.

Elgg makes it easy to write your own web services methods: http://docs.elgg.org/wiki/Web_Services

There are also existing plugins that implement plenty of methods already: https://github.com/Tachyon/Elgg-Web-Services