Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions qa-include/app/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,17 @@ function qa_get_logged_in_user_cache()
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();
Expand Down
10 changes: 9 additions & 1 deletion qa-include/db/selects.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down