From b5b7d96db05cca4e1adfdf7869a36a3b4888084d Mon Sep 17 00:00:00 2001 From: uckelman Date: Thu, 15 Jul 2010 10:34:13 +0000 Subject: * Use isset() instead of array_key_exists (faster). * There might be several accounts per email address, use the account which was most recently active when looking up user id by email address. git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6985 67b53d14-2c14-4ace-a08f-0dab2b34000c --- src/PhpBB3.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/PhpBB3.php b/src/PhpBB3.php index c19df00..7e1b148 100644 --- a/src/PhpBB3.php +++ b/src/PhpBB3.php @@ -20,8 +20,15 @@ class PhpBB3 { global $db; - $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' ' . - 'WHERE user_email = "' . $db->sql_escape($from) . '"'; + # NB: There might be multiple user accounts associated with one email + # address. We can only return one user id, so we decide in favor of + # the account which was most recently used to visit the forum. + $sql = 'SELECT u1.user_id FROM ' . USERS_TABLE . ' AS u1 ' . + 'LEFT OUTER JOIN ' . USERS_TABLE . ' AS u2 ON (' . + 'u1.user_email = u2.user_email AND ' . + 'u1.user_lastvisit < u2.user_lastvisit' . + ') WHERE u1.user_email = "' . $db->sql_escape($from) . '" AND ' . + 'u2.user_email IS NULL'; $row = $this->get_exactly_one_row($sql); return $row ? $row['user_id'] : false; @@ -38,7 +45,7 @@ class PhpBB3 { throw new Exception("Could not resolve user id $id: $err"); } - if (!array_key_exists($id, $names)) { + if (!isset($names[$id])) { throw new Exception("Unknown user id: $id"); } -- cgit v1.2.3