Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 1, 2018
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