I need to automatically create users in my gallery installation. I am well aware of the GalleryEmbed::createUser function, but this requires that I create a random userid for gallery to map. The problem is that I am not embedding Gallery, I am just creating a new user, and I don't want to have to randomly generate an external id until a collision does not occur in the external mapping table. I would prefer gallery to handle the id's itself without another mapping table. I looked in createUser and extracted the following steps to try to avoid the external entry:
1) list($ret, $user) = GalleryCoreApi::newFactoryInstance("GalleryEntity", "GalleryUser");
2) Use $user->create(username) to create a new user
3) Use various $user->set functions to set username/pass/fullName/etc.
4) Use $user->save
However, I can't seem to get the user to save in the database. Is there some sort of "handleRequest" function that needs to be called after using $user->save to commit the changes? Do I need to do any locking in order to add the user? Should I not be using the API so intimately?
Thanks.
Posts: 9
Well, I figured it out. You need to call:
GalleryMain(boolean isEmbed) to make the call finish. This is what GalleryEmbed does, but they pass true to that function. You can include the "main.php" which has GalleryMain in it without displaying the file using
function get_include_contents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return false;
}
to source in the file but not have it perform any output.
Basically, I just took all the good stuff out of GalleryEmbed.class that mattered and used it. Not sure why GalleryEmbed is needed when you aren't embedding Gallery...