GalleryEmbed::createUser - can it lock the user on creation?

cowmoo

Joined: 2007-07-18
Posts: 20
Posted: Thu, 2007-11-08 01:37

I am trying to create a user with all info sent to createUser (username, password, fullname, etc) but couldn't find a way to make the user locked (can't change password), is there a way to do this?

On a side note, when I delete users (through site admin -> users) that have been created through GalleryEmbed::createUser(), I cannot create the same user again through GalleryEmbed::createUser() (I get a STORAGE_FAILURE or COLLISION). I'm guessing this is because the entry already exists in g2_ExternalIdMap.
Would I simply be able to add in some code to delete the entry in g2_ExternalIdMap when a user gets deleted?
Is there other places that would need to be updated?

Thanks,
cOwMoO

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-11-08 01:47

no, createUser won't lock the user.

if you want to lock the user, load the user object after creating it, acquire a write lock (list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($use->getId())) on the object.
then set the user-locked status with $user->setLocked(true); save it with $user->save(); and then release your write lock with GalleryCoreApi::releaseLocks($lockId);

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
cowmoo

Joined: 2007-07-18
Posts: 20
Posted: Thu, 2007-11-08 04:43

Thanks for the response valiant, worked like a charm.

For reference, here's the code I used:


list ($ret, $user) = GalleryCoreApi::loadEntityByExternalId($uid, 'GalleryUser');
if($ret)
{
    print "An error occurred while loading the user object<br>";
    print $ret->getAsHtml();
} else {
    list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($user->getId());
    if($ret)
    {
        print "An error occurred while loading the user object<br>";
        print $ret->getAsHtml();
    } else {
        $user->setLocked(true);
        $user->save();
    }
}
GalleryCoreApi::releaseLocks($lockId);

Anyone know about the other question in my first post? It seems like I should just be able to delete the entry from g2_ExternalIdMap, is there an API I can use for this? I'm hesitant to manually edit the database.

cOwMoO

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2007-11-13 16:44

see:
http://sourceforge.net/tracker/index.php?func=detail&aid=1274398&group_id=7130&atid=107130

you should be deleting users with GalleryEmbed::deleteUser().

and if that's not an option, you can delete rows from the externalIdMap with GalleryCoreApi::removeMapEntry('ExternalIdMap', array('externalId' => $id, 'entityType' => 'GalleryUser'));
or alternatively with the 'entityId' => $g2UserId.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
cowmoo

Joined: 2007-07-18
Posts: 20
Posted: Wed, 2007-11-14 04:47

Thanks again valiant, always appreciated.

cOwMoO