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.