createUser doesn't reset

cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Mon, 2005-09-19 07:37

Hi there,

I'm trying to reset my User table.

I'm in the process of trying to embed gallery into my little cms system.

first step is to port the users it seems.

when I use GalleryEmbed::createUser() it keeps the numbers going even if I have just deleted the database.

any ideas?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-09-19 10:50

do you want to keep your albums/photos etc. in g2, do you want to keep your live installation? and you just want to get rid of all G2 users??
or is this supposed to be a fresh start?

please describe the whole process / the goal you have in mind a little more, else i cannot help.

and i don't understand what you mean with "numbers going even" "evn if i have just deleted the database".
do you mean: you have truncated g2_User but new users still have an ID which is very high? that's because of G2's architecture. users are also entities and we have a single sequence of IDs in g2, for everything.

if you want to keep your installation and just deleted the g2 users table, then this was a super bad idea. i hope you have a backup.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Mon, 2005-09-19 17:23

This is a pretty fresh gallery installation.
My users have not had a gallery up till this time.

I am trying to create an itegration so that my users can all have a personal album under their control to upload whatever personal pictures they want to them.

I also have a table full of events that I want to create albums for so that anyone who was at that event can upload photos of it to the gallery archive.

Currently I have no information in my gallery other than a few small test albums that I would like to keep.
however it won't be a big deal to import them again.

I made a first attempt at porting my users from my own CMS system of my creation.

The user information in G2 is currently of no consequence to me until the info is sync'ed from my own user table.

I thought I should have the userID's in the g2_Users the same as my UserID's in my Users table.
It seems that this assumption was incorrect?

This is the method I call in a loop as I go through my users.

Quote:
$args = array ("username" => $udata[username],
"email"=>$udata[email]);

GalleryEmbed::createUser($udata[user_id],$args);

After the first attempt i noticed they were off so I deleted all of them and started again.
I realize I also deleted my admin user but i figured I could make another user the admin anyway manually in the g2_UserGroupMap table.

On my second attempt my port script actually timed out so I deleted them all again and ran the script again.

My g_id in the g2_Users table is up around 7000 now even though it was only around 2200 after my first run.
I only have around 1800 users.

I was using the GalleryEmbed::createUser() to port the users. Is this the right way to do it?
On my second try I noticed that my users actually didn't start back on g_id 1 in the g2_Users table.
Instead it started where it left off the first time.

Is there some docs somewhere on this function?
What is the proper way to remove users from the database to make another import attempt?

thanks

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-09-19 20:01

please read docs/EMBEDDING
g2 integration doesn't work the way you think it would.
your CMS users and the G2 users don't have to have the same ID.
you map the IDs.
say you have a CMS user John with ID 15, in G2 there exists also a user John, with g_Id 1011.
in externalIdMap there's then a row
externalId (CMS user Id): 15, entityId (g2 user id): 1011, entityType: GalleryUser

if user John is logged in into your CMS, just call GalleryEmbed::init(array('activeUserId' => 15, ...)); and G2 will automatically know that you mean user 1011 = John, because G2 looks up the mapping in the database.

so much for theory.

what does that mean?
- do NOT touch any G2 database table.
- do NOT write any SQL that uses G2 database tables
- the GalleryCore API and the GalleryEmbed API is all what you need.

as a first step, you need to import all CMS users into G2. the result will be that all CMS users exist in G2 and all G2 users exist in the CMS and each of them is mapped with an entry in the externalIdMap.

assume g2 doesn't already have users. all it has is: admin user, anonymous users.
then you just have to create a for loop over all CMS users and call for each of them;
$ret = GalleryEmbed::createUser($cmsUser['id'], $cmsUser); whereas i assume that $cmsUser is an array as expected by GalleryEmbed.class function createUser().
this function creates a G2 user AND inserts a mapping into externalIdMap.

so, now all users are in g2. now you may also want to map G2's admin user with the CMS admin user.
call GalleryEmbed::addexternalIdMap($cmsAdminUser['id'], $g2AdminUser->getId(), 'GalleryUser'); to insert a mapping in the externalIdMap. Maybe you get here an error, if you already called GalleryEmbed::createUser() for the same externalId in the loop before.

at this point, you can call GalleryEmbed::init(array('activeUserId' => $cmsUser['id'], ...)); in your cms and then GalleryEmbed::handleRequest(); and your integration is almost done.

the last problem to solve:
what about future / new users? new users have to register with your CMS, not with G2. just don't deactivate the g2 register module. also, users login with your CMS and not with G2. G2 automatically disables the login link when embedded.
so what happens when a new user registers with your CMS? in your CMS, you have to call GalleryEmbed::createUser($cmsUser['id'], $cmsUser); in the user registration code / or where ever users are created. as described, this will create a corresponding G2 user and automatically map the CMS with the G2 user.

and what about user data updates?
in the update user / user data code of your CMS, add GalleryEmbed::updateUser($cmsUser['id'], $cmsUser); to update the corresponding g2 user.

same for delete user. call GalleryEmbed::deleteUser($cmsUser['id']); in the CMS delete user code.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Mon, 2005-09-19 20:27

Thank you.

That helps alot.

Big question now.

How do I reset all the user information in my gallery right now so i can do this from scratch more cleanly with more proper low ID's?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-09-19 20:35

the first i've learnt when studying relational databases is that the value of the ID / primary key doesn't matter, as long it's unique. i wouldn't care about how high the value is.
if you don't have a backup of the GalleryUser table, i'd care about it. without restoring the GalleryUser table with all its rows from before, I don't know if you really should keep your current G2. i'd just do a fresh install (drop all G2 tables, clean g2data/, run installer again).

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Mon, 2005-09-19 22:54

did the fresh install.
no problems there.

thanks so much. I'm starting a new thread for other questions I have.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Mon, 2005-09-19 23:22

When I am porting users do passwords matter?

if there is a hashed password in the array sent to GalleryEmbed::createUser or GalleryEmbed::updateUser does it do anything with it?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-09-19 23:28

G2 doesn't authentication when it is embedded. you just tell G2 the activeUserId and it trusts you. in that regard, passwords don't matter.
but if you want to use your G2 embedded and in standalone, passwords matter, since you still want to access g2 directly, and then it needs to do authentication.