Commit 9aed0ff9 by Scott

Coding style (misc voting code)

parent f54156e6
......@@ -33,8 +33,9 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$state = qa_post_text('state');
$stoptime = time() + 3;
while (qa_recalc_perform_step($state) && time() < $stoptime)
;
while (qa_recalc_perform_step($state) && time() < $stoptime) {
// wait
}
$message = qa_recalc_get_message($state);
}
......
......@@ -35,10 +35,9 @@ $code = qa_post_text('code');
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
if (!qa_check_form_security_code('vote', $code))
if (!qa_check_form_security_code('vote', $code)) {
$voteerror = qa_lang_html('misc/form_security_reload');
else {
} else {
$post = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
$voteerror = qa_vote_error_html($post, $vote, $userid, qa_request());
}
......
......@@ -100,8 +100,9 @@ function qa_recalc_perform_step(&$state)
foreach ($pages as $pageid => $page) {
if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) {
$searchmodules = qa_load_modules_with('search', 'unindex_page');
foreach ($searchmodules as $searchmodule)
foreach ($searchmodules as $searchmodule) {
$searchmodule->unindex_page($pageid);
}
$searchmodules = qa_load_modules_with('search', 'index_page');
if (count($searchmodules)) {
......@@ -117,8 +118,9 @@ function qa_recalc_perform_step(&$state)
$done += count($pages);
$continue = true;
} else
} else {
qa_recalc_transition($state, 'doreindexcontent_postcount');
}
break;
case 'doreindexcontent_postcount':
......@@ -200,8 +202,9 @@ function qa_recalc_perform_step(&$state)
$done += count($postids);
$continue = true;
} else
} else {
qa_recalc_transition($state, 'dorecountposts_acount');
}
break;
case 'dorecountposts_acount':
......@@ -243,13 +246,13 @@ function qa_recalc_perform_step(&$state)
qa_db_users_recalc_points($next, $lastuserid);
$done += $recalccount;
} else
} else {
$lastuserid = $next; // for truncation
}
if ($gotcount > $recalccount) { // more left to do
$next = $userids[$recalccount]; // start next round at first one not recalculated
$continue = true;
} else {
qa_db_truncate_userpoints($lastuserid);
qa_db_userpointscount_update(); // quick so just do it here
......@@ -289,30 +292,34 @@ function qa_recalc_perform_step(&$state)
$posts = array($questionid => $question);
foreach ($childposts as $postid => $post)
foreach ($childposts as $postid => $post) {
$posts[$postid] = $post;
}
foreach ($achildposts as $postid => $post)
foreach ($achildposts as $postid => $post) {
$posts[$postid] = $post;
}
// Creation and editing of each post
foreach ($posts as $postid => $post) {
$followonq = ($post['basetype'] == 'Q') && ($postid != $questionid);
if ($followonq)
if ($followonq) {
$updatetype = QA_UPDATE_FOLLOWS;
elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q')
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q') {
$updatetype = QA_UPDATE_C_FOR_Q;
elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A')
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A') {
$updatetype = QA_UPDATE_C_FOR_A;
else
} else {
$updatetype = null;
}
qa_create_event_for_q_user($questionid, $postid, $updatetype, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']);
if (isset($post['updated']) && !$followonq)
if (isset($post['updated']) && !$followonq) {
qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']);
}
}
// Tags and categories of question
......@@ -324,9 +331,11 @@ function qa_recalc_perform_step(&$state)
$parentidcomments = array();
foreach ($posts as $postid => $post)
if ($post['basetype'] == 'C')
foreach ($posts as $postid => $post) {
if ($post['basetype'] == 'C') {
$parentidcomments[$post['parentid']][$postid] = $post;
}
}
// For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
......@@ -342,8 +351,9 @@ function qa_recalc_perform_step(&$state)
}
}
if (isset($comment['userid']))
if (isset($comment['userid'])) {
$keyuserids[$comment['userid']] = true;
}
}
}
}
......@@ -352,8 +362,9 @@ function qa_recalc_perform_step(&$state)
$done += count($questionids);
$continue = true;
} else
} else {
qa_recalc_transition($state, 'dorefillevents_complete');
}
break;
case 'dorecalccategories':
......@@ -379,7 +390,6 @@ function qa_recalc_perform_step(&$state)
$next = 1 + $lastpostid;
$done += count($postids);
$continue = true;
} else {
qa_recalc_transition($state, 'dorecalccategories_recount');
}
......@@ -391,13 +401,13 @@ function qa_recalc_perform_step(&$state)
if (count($categoryids)) {
$lastcategoryid = max($categoryids);
foreach ($categoryids as $categoryid)
foreach ($categoryids as $categoryid) {
qa_db_ifcategory_qcount_update($categoryid);
}
$next = 1 + $lastcategoryid;
$done += count($categoryids);
$continue = true;
} else {
qa_recalc_transition($state, 'dorecalccategories_backpaths');
}
......@@ -431,15 +441,14 @@ function qa_recalc_perform_step(&$state)
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$next = 1 + $postid;
$done++;
$continue = true;
} else
} else {
qa_recalc_transition($state, 'dodeletehidden_answers');
}
break;
case 'dodeletehidden_answers':
......@@ -449,15 +458,15 @@ function qa_recalc_perform_step(&$state)
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$next = 1 + $postid;
$done++;
$continue = true;
} else
} else {
qa_recalc_transition($state, 'dodeletehidden_questions');
}
break;
case 'dodeletehidden_questions':
......@@ -467,15 +476,15 @@ function qa_recalc_perform_step(&$state)
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$next = 1 + $postid;
$done++;
$continue = true;
} else
} else {
qa_recalc_transition($state, 'dodeletehidden_complete');
}
break;
case 'doblobstodisk':
......@@ -489,15 +498,16 @@ function qa_recalc_perform_step(&$state)
require_once QA_INCLUDE_DIR . 'app/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
if (qa_write_blob_file($blob['blobid'], $blob['content'], $blob['format']))
if (qa_write_blob_file($blob['blobid'], $blob['content'], $blob['format'])) {
qa_db_blob_set_content($blob['blobid'], null);
}
$next = 1 + $blob['blobid'];
$done++;
$continue = true;
} else
} else {
qa_recalc_transition($state, 'doblobstodisk_complete');
}
break;
case 'doblobstodb':
......@@ -518,9 +528,9 @@ function qa_recalc_perform_step(&$state)
$next = 1 + $blob['blobid'];
$done++;
$continue = true;
} else
} else {
qa_recalc_transition($state, 'doblobstodb_complete');
}
break;
case 'docachetrim':
......@@ -551,8 +561,9 @@ function qa_recalc_perform_step(&$state)
break;
}
if ($continue)
if ($continue) {
$state = $operation . "\t" . $length . "\t" . $next . "\t" . $done;
}
return $continue && $done < $length;
}
......@@ -678,8 +689,8 @@ function qa_recalc_get_message($state)
@list($operation, $length, $next, $done) = explode("\t", $state);
$done = (int)$done;
$length = (int)$length;
$done = (int) $done;
$length = (int) $length;
switch ($operation) {
case 'doreindexcontent_postcount':
......
......@@ -143,25 +143,29 @@ function qa_vote_set($post, $userid, $handle, $cookieid, $vote)
$columns = array();
if ($vote > 0 || $oldvote > 0)
if ($vote > 0 || $oldvote > 0) {
$columns[] = $prefix . 'upvotes';
}
if ($vote < 0 || $oldvote < 0)
if ($vote < 0 || $oldvote < 0) {
$columns[] = $prefix . 'downvotes';
}
qa_db_points_update_ifuser($userid, $columns);
qa_db_points_update_ifuser($post['userid'], array($prefix . 'voteds', 'upvoteds', 'downvoteds'));
if ($prefix === 'q')
if ($prefix === 'q') {
qa_db_hotness_update($post['postid']);
}
if ($vote < 0)
if ($vote < 0) {
$event = $prefix . '_vote_down';
elseif ($vote > 0)
} elseif ($vote > 0) {
$event = $prefix . '_vote_up';
else
} else {
$event = $prefix . '_vote_nil';
}
qa_report_event($event, $userid, $handle, $cookieid, array(
'postid' => $post['postid'],
......@@ -215,9 +219,9 @@ function qa_flag_error_html($post, $userid, $topage)
case false:
return false;
}
} else
} else {
return qa_lang_html('question/flag_not_allowed'); // flagging option should not have been presented
}
}
......
......@@ -173,14 +173,15 @@ function qa_db_points_update_ifuser($userid, $columns)
$calculations = qa_db_points_calculations();
if ($columns === true)
if ($columns === true) {
$keycolumns = $calculations;
elseif (empty($columns))
} elseif (empty($columns)) {
$keycolumns = array();
elseif (is_array($columns))
} elseif (is_array($columns)) {
$keycolumns = array_flip($columns);
else
} else {
$keycolumns = array($columns => true);
}
$insertfields = 'userid, ';
$insertvalues = '$, ';
......@@ -208,8 +209,9 @@ function qa_db_points_update_ifuser($userid, $columns)
// build like this so that a #, $ or ^ character in the $userid (if external integration) isn't substituted
qa_db_query_raw(str_replace('~', "='" . qa_db_escape_string($userid) . "'", qa_db_apply_sub($query, array($userid))));
if (qa_db_insert_on_duplicate_inserted())
if (qa_db_insert_on_duplicate_inserted()) {
qa_db_userpointscount_update();
}
}
}
......
......@@ -252,16 +252,17 @@ function qa_db_posts_answers_recount($firstpostid, $lastpostid)
*/
function qa_db_users_get_for_recalc_points($startuserid, $count)
{
if (QA_FINAL_EXTERNAL_USERS)
if (QA_FINAL_EXTERNAL_USERS) {
return qa_db_read_all_values(qa_db_query_sub(
'SELECT userid FROM ((SELECT DISTINCT userid FROM ^posts WHERE userid>=# ORDER BY userid LIMIT #) UNION (SELECT DISTINCT userid FROM ^uservotes WHERE userid>=# ORDER BY userid LIMIT #)) x ORDER BY userid LIMIT #',
$startuserid, $count, $startuserid, $count, $count
));
else
} else {
return qa_db_read_all_values(qa_db_query_sub(
'SELECT DISTINCT userid FROM ^users WHERE userid>=# ORDER BY userid LIMIT #',
$startuserid, $count
));
}
}
......
......@@ -94,11 +94,12 @@ function qa_db_userflags_clear_all($postid)
*/
function qa_db_post_recount_votes($postid)
{
if (qa_should_update_counts())
if (qa_should_update_counts()) {
qa_db_query_sub(
'UPDATE ^posts AS x, (SELECT COALESCE(SUM(GREATEST(0,vote)),0) AS upvotes, -COALESCE(SUM(LEAST(0,vote)),0) AS downvotes FROM ^uservotes WHERE postid=#) AS a SET x.upvotes=a.upvotes, x.downvotes=a.downvotes, x.netvotes=a.upvotes-a.downvotes WHERE x.postid=#',
$postid, $postid
);
}
}
......@@ -108,11 +109,12 @@ function qa_db_post_recount_votes($postid)
*/
function qa_db_post_recount_flags($postid)
{
if (qa_should_update_counts())
if (qa_should_update_counts()) {
qa_db_query_sub(
'UPDATE ^posts AS x, (SELECT COALESCE(SUM(IF(flag, 1, 0)),0) AS flagcount FROM ^uservotes WHERE postid=#) AS a SET x.flagcount=a.flagcount WHERE x.postid=#',
$postid, $postid
);
}
}
......
......@@ -34,8 +34,9 @@ require_once QA_INCLUDE_DIR . 'util/sort.php';
// Check admin privileges
if (!qa_admin_check_privileges($qa_content))
if (!qa_admin_check_privileges($qa_content)) {
return $qa_content;
}
// Process user actions
......@@ -47,25 +48,23 @@ $optionnames = qa_db_points_option_names();
if (qa_clicked('doshowdefaults')) {
$options = array();
foreach ($optionnames as $optionname)
foreach ($optionnames as $optionname) {
$options[$optionname] = qa_default_option($optionname);
}
} else {
if (qa_clicked('docancel'))
;
elseif (qa_clicked('dosaverecalc')) {
if (!qa_check_form_security_code('admin/points', qa_post_text('code')))
if (qa_clicked('dosaverecalc')) {
if (!qa_check_form_security_code('admin/points', qa_post_text('code'))) {
$securityexpired = true;
else {
foreach ($optionnames as $optionname)
} else {
foreach ($optionnames as $optionname) {
qa_set_option($optionname, (int)qa_post_text('option_' . $optionname));
}
if (!qa_post_text('has_js'))
if (!qa_post_text('has_js')) {
qa_redirect('admin/recalc', array('dorecalcpoints' => 1));
else
} else {
$recalculate = true;
}
}
}
......@@ -107,7 +106,6 @@ if (qa_clicked('doshowdefaults')) {
'tags' => 'name="docancel"',
'label' => qa_lang_html('main/cancel_button'),
);
} else {
if ($recalculate) {
$qa_content['form']['ok'] = '<span id="recalc_ok"></span>';
......
......@@ -27,8 +27,9 @@ class qa_event_limits
// Don't increment limits or report user actions for events that were delayed. For example, a 'q_post'
// event sent when a post is approved by the admin, for which a 'q_queue' event was already sent.
if (isset($params['delayed']))
if (isset($params['delayed'])) {
return;
}
require_once QA_INCLUDE_DIR . 'app/limits.php';
......@@ -92,12 +93,10 @@ class qa_event_limits
) {
if (isset($userid)) {
require_once QA_INCLUDE_DIR . 'app/users.php';
qa_user_report_action($userid, $event);
} elseif (isset($cookieid)) {
require_once QA_INCLUDE_DIR . 'app/cookies.php';
qa_cookie_report_action($cookieid, $event);
}
}
......
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