Gallery-Version = 2.0.2 Kern 1.0.0.2
PHP-Version = 4.3.7 apache
Webserver = Apache
Datenbank = mysql 4.0.18-standard-log
Werkzeuge = ArchiveUpload, Exif, Ffmpeg, ImageMagick, NetPBM, Gd
Betriebssystem = Linux www7.statron.de 2.4.26 #27 Wed Apr 21 13:46:39 CEST 2004 i686
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1
Hi,
I'm trying to create new users using an external PHP script.
Looks like the user is created successfully but addUserToGroup fails with this error:
Error (ERROR_MISSING_OBJECT) : 1080 GalleryUser
* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 138 (gallerystatus::error)
* in modules/core/classes/GalleryCoreApi.class at line 2225 (galleryentityhelper_simple::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 519 (gallerycoreapi::loadentitybyexternalid)
* in gallery_register.php at line 204 (galleryembed::addusertogroup)
The new user has been created with userId 1080, which is reported missing somehow here. Any ideas?
Here's the code I use:
function g_register($username,$password,$jahrgang)
{
require_once('embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true));
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
list ($ret, $user) = GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryUser');
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
if (!isset($user)) {
print "error missing object";
exit;
}
$ret = $user->create($username);
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
// set some user data, e.g.
$user->setEmail($username);
$user->setHashedPassword($password);
// ...
$id_merker = $user->getId(); //save the user id here forlater use in addusertogroup
$ret = $user->save();
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
// commit transaction
$ret = GalleryEmbed::done();
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
//================ USER CREATED============
//don't know how to get the correct group, so I search myself, this works!
$sql = "SELECT * FROM g2_Group WHERE g_groupName='$jahrgang'";
$result = g_db($sql);
$id_group = 0;
if($g = mysql_fetch_object($result))
{
$id_group = $g->g_id;
}else{
die('no group found');
}
$ret = GalleryEmbed::init();
if ($ret->isError()) {
echo $ret->getAsHtml(); //has error details..
}
// Call GalleryEmbed as required..
// ..
$ret = GalleryEmbed::addUserToGroup($id_merker,$id_group);
if ($ret->isError()) {
echo $ret->getAsHtml(); //has error details..
}
$ret = GalleryEmbed::done();
if ($ret->isError()) {
echo $ret->getAsHtml(); //has error details..
}
}
Thanks,
Kevin.
Posts: 32509
instead of
list ($ret, $user) = GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryUser');
use GalleryEmbed::createUser
Posts: 7
Thanks, works better, but not without an error:
Warning: mysql_insert_id(): 429 is not a valid MySQL-Link resource in /home/www/web1/html/gallery2/lib/adodb/drivers/adodb-mysql.inc.php on line 216
Error (ERROR_BAD_PARAMETER)
* in modules/core/classes/helpers/GalleryUserGroupHelper_medium.class at line 47 (gallerystatus::error)
* in modules/core/classes/GalleryCoreApi.class at line 1621 (galleryusergrouphelper_medium::addusertogroup)
* in modules/core/classes/GalleryUser.class at line 239 (gallerycoreapi::addusertogroup)
* in modules/core/classes/GalleryEmbed.class at line 305 (galleryuser::save)
* in gallery_register.php at line 176 (galleryembed::createuser)
* in gallery_register.php at line 138
* in gallery_register.php at line 264
The code now looks like this:
Posts: 32509
$ret = GalleryEmbed::isExternalIdMapped($id_user, 'GalleryUser');
if ($ret->isError())
{
//not mapped - create a new user
that's not 100% correct. you should do
if ($ret->isError() && ($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
// not mapped
} else if ($ret->isError()) {
// fatal error
}
but there must be another reason for your error. haven't seen such mysql result resource issues in g2 before. must be related to your setup / integration.