Having trouble auto-creating albums

rkuris

Joined: 2005-04-19
Posts: 7
Posted: Tue, 2005-04-19 23:01

Hi,

I'm trying to use the UserAlbum module to automatically create a new album when the account is created... but I'm using the embed.php "createUser" API. The combination seems to create this error:

Error (ERROR_MISSING_OBJECT) : Missing object for 14

    * in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 2041 (gallerystatus::error)
    * in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 305 (mysqldatabasestorage::_identifyentities)
    * in modules/core/classes/GalleryStorage.class at line 113 (mysqldatabasestorage::loadentities)
    * in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 82 (gallerystorage::loadentities)
    * in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 141 (galleryentityhelper_simple::loadentitiesbyid)
    * in modules/core/classes/GalleryCoreApi.class at line 2151 (galleryentityhelper_simple::loadentitybyexternalid)
    * in embed.php at line 159 (gallerycoreapi::loadentitybyexternalid)
    * in embed.php at line 75 (galleryembed::checkactiveuser)
    * in /home/rk/www/gallery2.php at line 27 (galleryembed::init)

My code looks like this (the last line of real code is line 27):

$ret = GalleryEmbed::init(array('embedUri'=>'gallery2.php',
        'embedPath'=>'/', 'relativeG2Path'=>'gallery2/',
        'activeUserId' => $activeuser));
if ( $ret->isError()) {
    if ( $ret->getErrorCode() & ERROR_MISSING_OBJECT )
        {
        GalleryEmbed::done();
        GalleryEmbed::init();
        $ret = GalleryEmbed::createUser($activeuser, array('username'=>$activeuser));
        if ( !$ret->isError() )
                GalleryEmbed::done();
                $ret = GalleryEmbed::init(array('embedUri'=>'gallery2.php',
                        'embedPath'=>'/', 'relativeG2Path'=>'gallery2/',
                        'activeUserId' => $activeuser));
        }
}   

The reason for the first ERROR_MISSING_OBJECT is because the user doesn't exist yet in the system. However, on the second attempt, the user does exist, yet I still get this error. Am I doing something obviously wrong or is this a bug?

Login or register to post comments
rkuris

Joined: 2005-04-19
Posts: 7
Posted: Tue, 2005-04-19 23:14

Just a bit more information... it looks like the ID number is messed up after the album is getting created. Here's some query results:

mysql> select * from g2_Entity;
...
|   18 |          1113950646 |            0 |     NULL |              1113950646 |              2 | GalleryAlbumItem | NULL             |
|   17 |          1113950645 |            0 |     NULL |              1113950645 |              1 | GalleryUser      | NULL             |
+------+---------------------+--------------+----------+-------------------------+----------------+------------------+------------------+
11 rows in set (0.01 sec)
mysql> select * from g2_ExternalIdMap;
+--------------+--------------+------------+
| g_externalId | g_entityType | g_entityId |
+--------------+--------------+------------+
| username     | GalleryUser  |         14 |
+--------------+--------------+------------+
Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32506
Posted: Tue, 2005-04-19 23:25

rkuris, see http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=25979&postdays=0&postorder=asc&start=150#133447

GalleryEmbed::done();
GalleryEmbed::init();
isn't required after the error.
but after the GalleryEmbed::createUser, you need to call ::done, but only if no ::handleRequest() fallows upon ::createUser.

Login or register to post comments
rkuris

Joined: 2005-04-19
Posts: 7
Posted: Tue, 2005-04-19 23:30

That was just for testing. The problem still occurs.

This patch/hack (yes, I know it is WRONG), however, works around the problem, which indicates this is some sort of bug deeper in the code than I care to venture at the moment.

Index: embed.php
===================================================================
RCS file: /cvsroot/gallery/gallery2/embed.php,v
retrieving revision 1.41
diff -u -r1.41 embed.php
--- embed.php   2 Apr 2005 00:13:22 -0000       1.41
+++ embed.php   19 Apr 2005 23:25:59 -0000
@@ -264,6 +264,7 @@
        if ($ret->isError()) {
            return $ret->wrap(__FILE__, __LINE__);
        }
+       $user->getId();
        GalleryCoreApi::requireOnce(
            dirname(__FILE__) . '/modules/core/classes/ExternalIdMap.class');
        $ret = ExternalIdMap::addMapEntry(array('externalId' => $extUserId,

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32506
Posted: Wed, 2005-04-20 12:03

?? what do you accomplish with the additional line "$user->getId(); " in GalleryEmbed::createUser?
you don't even assign the id to something, neither you print it out.
What's your intention/goal?

Login or register to post comments
rkuris

Joined: 2005-04-19
Posts: 7
Posted: Wed, 2005-04-20 13:33

Yeah, I know. Apparently, by doing this, it caches the ID number in the user structure so when it gets used later, it's correct.

I think the ID number is computed by calling mysql_insert_id or selecting LAST_INSERT_ID somewhere, but it was too late. I think it was too late because the UserAlbum module did some stuff, inserting some rows (possibly in the Entity table?) messing things up.

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32506
Posted: Wed, 2005-04-20 14:05

rkuris, I've just tested it in my xaraya integration. Useralbum + GalleryEmbed::createUser works without a problem.

Login or register to post comments
rkuris

Joined: 2005-04-19
Posts: 7
Posted: Wed, 2005-04-20 16:14

Did you turn on the "Auto create album when the account is created" option? It won't fail without it.

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32506
Posted: Wed, 2005-04-20 16:18

yes i have. it works.

what G2 version or you using? (although it should work since a long time)

Your code is slightly different from mine.
After createUser, just call checkActiveUser and then handlerequest.

Login or register to post comments
rkuris

Joined: 2005-04-19
Posts: 7
Posted: Wed, 2005-04-20 16:24

I pulled the code from CVS a few days back. I just did another update now, and I'll retest.

Login or register to post comments
rkuris

Joined: 2005-04-19
Posts: 7
Posted: Wed, 2005-04-20 16:25

Well, the update is hanging waiting on a mindless lock (interesting pun there). I'll test it once I get the update installed.

Login or register to post comments