galleryEmbed::addExternalIdMapEntry results in "ERROR_STORAGE_FAILURE"

Oldiesmann
Oldiesmann's picture

Joined: 2005-05-18
Posts: 151
Posted: Wed, 2007-02-07 23:28

Shortly after I released Beta3, numerous minor bugs popped up. I have been doing my best to fix them, but now I've run into one that I can't figure out at all.

A couple of users have decided to use their forum username for the username of their main G2 Site Admin account, and as such have no choice but to link their forum account with their G2 Site Admin account, since the other method (creating a new account with the same username as their forum account) results in an ERROR_COLLISION.

For (obvious) security reasons, I have code in place to verify that they actually entered valid information - first I have it check to see if that user account actually exists, and then it checks to make sure they entered the correct password.

If all checks pass, I call GalleryEmbed::addExternalIdMapEntry to link the forum and gallery accounts.

However, these users are reporting that this is generating an ERROR_STORAGE_FAILURE message.

Here's the function in question:

function verifyGalAccount($username = '', $password = '')
{
	global $modSettings, $context, $db_prefix;

	/* The sole purpose of this function is to verify that
		the information entered when linking to an existing
		Gallery account is valid */

	include_once($modSettings['galleryPath'] . '/embed.php');

	// Assume everything's here since we can't get here without a username or password...

	$ret = GalleryEmbed::init(array('fullInit' => true));
	if($ret)
	{
		fatal_error($ret->getAsText());
	}

	// Step 1: Find this user
	list($ret, $user) = GalleryCoreApi::fetchUserByUsername($username);

	if($ret)
	{
		// ERROR_MISSING_OBJECT means this username doesn't exist
		if($ret->getErrorCode() & ERROR_MISSING_OBJECT)
		{
			fatal_error('Invalid username!', false);
		}
		else
		{
			fatal_error($ret->getAsText());
		}
	}

	// Ok... That worked, so now we verify your password...
	$ret = $user->isCorrectPassword($password);
	
	/* This is one of the few cases where $ret isn't necessarily NULL if there weren't any errors.
		Because PHP treats == as "loose" evaluation, $ret == true will still evaluate to TRUE
		even if there's an error ($ret will be a Gallery Status object). Therefore, we have to
		use strict evaluation to make sure $ret is actually TRUE and not an error */
	if($ret === true)
	{
		// Everything checked out OK, so link their accounts...
		/* There is a very slim possibility that their account
			is already linked to another account, but it won't
			happen much (if at all), so there's no point in checking for that */

		$g2uid = $user->getId();
		$ret = GalleryEmbed::addExternalIdMapEntry($context['user']['id'], $g2uid, 'GalleryUser');
		if($ret)
		{
			fatal_error($ret->getAsText());
		}

		// Commit the transaction...
		$ret = GalleryEmbed::done();
		if($ret)
		{
			fatal_error($ret->getAsText());
		}
		// Ok... They're now a Gallery user... Update the database
		$query = db_query("UPDATE {$db_prefix}members SET is_gallery_user = '1', g2_uid='$g2uid' WHERE ID_MEMBER = '$context[user][id]'", __FILE__, __LINE__);

		// All done! Off to the gallery we go!
		redirectexit('action=gallery');
	}
	elseif($ret === false)
	{
		// Wrong password... Try again
		loadLanguage('Login');
		fatal_lang_error('39');
	}
	else
	{
		fatal_error($ret->getAsText());
	}
}

And the error message being generated:

Error (ERROR_STORAGE_FAILURE)in modules/core/classes/GalleryStorage/GalleryStorageExtras.class at line 988 (GalleryCoreApi::error)
in modules/core/classes/GalleryStorage.class at line 501 (GalleryStorageExtras::addMapEntry)
in modules/core/classes/GalleryCoreApi.class at line 2923 (GalleryStorage::addMapEntry)
in modules/core/classes/GalleryEmbed.class at line 872 (GalleryCoreApi::addMapEntry)
in /.../Sources/Gallery.php at line 583 (GalleryEmbed::addExternalIdMapEntry)
in /.../Sources/Gallery.php at line 522
in /.../Sources/Gallery.php at line 461
in ??? at line 0
in /.../index.php at line 131

Line 522 in Gallery.php is where the verifyGalleryAccount function is called with the username and password from the form
Line 461 is where the function that calls verifyGalleryAccount is called. This function loads up the information for the form (template, language strings, etc.) and also verifies that they actually entered something.

I haven't actually modified either function in this version of the beta, so I'm not sure what's causing it.

---------------------
The Oldiesmann
SMF Project Manager
SMF+G2 Integration Project - Beta3 Now Available!

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2007-02-07 23:39

- you can use gallery's debug mode to see the actual myql error
- did you check the ExternalIdMap table, is there actually a conflict?

--------------
Enter the Gallery 2 Theme Contest today!

 
Oldiesmann
Oldiesmann's picture

Joined: 2005-05-18
Posts: 151
Posted: Thu, 2007-02-08 01:19

Just heard back from the user who reported this...

Quote:
I think the storage failure and collision are related. I did a clean install to another site and this time went through the account creation errors.

So basically I just need to make sure everyone is aware of what process to use depending on the setup.

Thanks for the help anyway :)
---------------------
The Oldiesmann
SMF Project Manager
SMF+G2 Integration Project - Beta3 Now Available!

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-02-08 10:08

well, you can check if the value exists beforehand. if you really want to spend a lot of resources on that issue, i guess you could automate the detection and do the appropriate action.

--------------
Enter the Gallery 2 Theme Contest today!