User IDs from application -> g2
DaFoot
Joined: 2007-04-30
Posts: 15 |
![]() |
When I call GalleryEmbed::init(...) there is a parameter for the user id. What should I be passing in here? A number? A string (eg username)? I have users in my main application DB with numeric (int) IDs, so would use these but that would mean either setting the user ID in the g2 DB when I import users (is that doable?) to match or create a lookup table to map IDs from my application -> g2 IDs. Alternatively I could use the username (which is unique) from the application DB as the g2 userId but I don't know what is meant by g2.userId. I imagine it to be an autoinc int so using usernames from existing DB is a no go. Hope that makes sense in explaining my problem! |
|
DaFoot
Joined: 2007-04-30
Posts: 15 |
![]() |
Discovered that g2 stores a lookup/mapping in it's tables. During GalleryEmbed::createUser() with an embedApp user.id I assume that G2 will update it's own lookup without me needing to call a function to insert the IDs into the user mapping table(s)? |
|
suprsidr
![]()
Joined: 2005-04-17
Posts: 8339 |
![]() |
GalleryEmbed::createUser uses your app's userId and creates an externalIdMap // init() gallery // Make sure we are don't already have an user with the same id $ret = GalleryEmbed::isExternalIdMapped( $myApps_userId, 'GalleryUser' ); if ( !($ret && ( $ret->getErrorCode() & ERROR_MISSING_OBJECT )) ) { return; } $sql = "SELECT uid, username, fullname, passwd, email, language, UNIX_TIMESTAMP( regdate ) AS registration_ts FROM {$_TABLES['users']} WHERE uid ='{$myApps_userId}' LIMIT 1"; $result = DB_query( $sql ); $row = DB_fetchArray( $result ); $args['fullname'] = $row['fullname']; $args['username'] = $row['username']; $args['hashedpassword'] = $row['passwd']; $args['hashmethod'] = 'md5'; $args['email'] = $row['email']; $args['creationtimestamp']= $row['registration_ts']; $args['language'] = $row['language'] ; $ret = GalleryEmbed::createUser( $myApps_userId, $args ); if(!$ret) { // Record my error to my error_log COM_errorLog("GalleryEmbed::createUser for userId ". $myApps_userId); } if (($ret) && ($ret->getErrorCode() & ERROR_COLLISION )){ // If the user already exists but for some reason wasn't mapped, map them now. list( $ret, $user ) = GalleryCoreApi::fetchUserByUserName($row['username']); $ret = GalleryEmbed::addExternalIdMapEntry($myApps_userId, $user->getId(), 'GalleryUser'); if ( $ret ) { // Record my error to my error_log COM_errorLog( 'Failed to add externalIdMap for usename ['.$row['username'].']' ); return false; } // Record my error to my error_log COM_errorLog("ERROR_COLLISION, added external ID to map for userId ". $myApps_userId); return false; } GalleryEmbed::done(); Hope this helps -s |
|
DaFoot
Joined: 2007-04-30
Posts: 15 |
![]() |
It does, cheers |
|