Commit d4b74099 by pupi1985

Fix some scenarios where ^userpoints records are not present and generate issues

parent 176f6052
......@@ -456,6 +456,17 @@ if (QA_FINAL_EXTERNAL_USERS) {
require_once QA_INCLUDE_DIR . 'db/selects.php';
$qa_cached_logged_in_user = qa_db_get_pending_result('loggedinuser', qa_db_user_account_selectspec($userid, true));
// If the site is configured to share the ^users table then there might not be a record in the
// ^userpoints table so this creates it
if ($qa_cached_logged_in_user['points'] === null) {
require_once QA_INCLUDE_DIR . 'db/points.php';
require_once QA_INCLUDE_DIR . 'db/users.php';
qa_db_points_update_ifuser($userid, null);
qa_db_uapprovecount_update();
$qa_cached_logged_in_user = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
}
if (!isset($qa_cached_logged_in_user)) {
// the user can no longer be found (should only apply to deleted users)
qa_clear_session_user();
......
......@@ -1523,9 +1523,17 @@ function qa_db_top_users_selectspec($start, $count = null)
);
}
// If the site is configured to share the ^users table then there might not be a record in the ^userpoints table
if (defined('QA_MYSQL_USERS_PREFIX')) {
$basePoints = (int)qa_opt('points_base');
$source = '^users JOIN (SELECT ^users.userid, COALESCE(points,' . $basePoints . ') AS points FROM ^users LEFT JOIN ^userpoints ON ^users.userid=^userpoints.userid ORDER BY points DESC LIMIT #,#) y ON ^users.userid=y.userid';
} else {
$source = '^users JOIN (SELECT userid FROM ^userpoints ORDER BY points DESC LIMIT #,#) y ON ^users.userid=y.userid JOIN ^userpoints ON ^users.userid=^userpoints.userid';;
}
return array(
'columns' => array('^users.userid', 'handle', 'points', 'flags', '^users.email', 'avatarblobid' => 'BINARY avatarblobid', 'avatarwidth', 'avatarheight'),
'source' => '^users JOIN (SELECT userid FROM ^userpoints ORDER BY points DESC LIMIT #,#) y ON ^users.userid=y.userid JOIN ^userpoints ON ^users.userid=^userpoints.userid',
'source' => $source,
'arguments' => array($start, $count),
'arraykey' => 'userid',
'sortdesc' => 'points',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment