Commit 0687afb2 by pupi1985

Fix closed questions by selected answer not displayed as closed

parent 40f15d44
...@@ -37,7 +37,7 @@ list($question, $childposts) = qa_db_select_with_pending( ...@@ -37,7 +37,7 @@ list($question, $childposts) = qa_db_select_with_pending(
// Check if the question exists, is not closed, and whether the user has permission to do this // Check if the question exists, is not closed, and whether the user has permission to do this
if (@$question['basetype'] == 'Q' && !isset($question['closedbyid']) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) { if (@$question['basetype'] == 'Q' && !isset($question['closedbyid']) && (!qa_opt('do_close_on_select') || !isset($question['selchildid'])) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) {
require_once QA_INCLUDE_DIR . 'app/captcha.php'; require_once QA_INCLUDE_DIR . 'app/captcha.php';
require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/post-create.php'; require_once QA_INCLUDE_DIR . 'app/post-create.php';
......
...@@ -320,7 +320,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt ...@@ -320,7 +320,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
$fields['tags'] = 'id="' . qa_html($elementid) . '"'; $fields['tags'] = 'id="' . qa_html($elementid) . '"';
$fields['classes'] = ($isquestion && $favoritedview && @$post['userfavoriteq']) ? 'qa-q-favorited' : ''; $fields['classes'] = ($isquestion && $favoritedview && @$post['userfavoriteq']) ? 'qa-q-favorited' : '';
if ($isquestion && isset($post['closedbyid'])) if ($isquestion && (isset($post['closedbyid']) || (qa_opt('do_close_on_select') && isset($post['selchildid']))))
$fields['classes'] = ltrim($fields['classes'] . ' qa-q-closed'); $fields['classes'] = ltrim($fields['classes'] . ' qa-q-closed');
if ($microdata) { if ($microdata) {
...@@ -617,7 +617,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt ...@@ -617,7 +617,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
( // otherwise check if one of these conditions is fulfilled... ( // otherwise check if one of these conditions is fulfilled...
(!isset($post['created'])) || // ... we didn't show the created time (should never happen in practice) (!isset($post['created'])) || // ... we didn't show the created time (should never happen in practice)
($post['hidden'] && ($post['updatetype'] == QA_UPDATE_VISIBLE)) || // ... the post was hidden as the last action ($post['hidden'] && ($post['updatetype'] == QA_UPDATE_VISIBLE)) || // ... the post was hidden as the last action
(isset($post['closedbyid']) && ($post['updatetype'] == QA_UPDATE_CLOSED)) || // ... the post was closed as the last action ((isset($post['closedbyid']) || (qa_opt('do_close_on_select') && isset($post['selchildid']))) && $post['updatetype'] == QA_UPDATE_CLOSED) || // ... the post was closed as the last action
(abs($post['updated'] - $post['created']) > 300) || // ... or over 5 minutes passed between create and update times (abs($post['updated'] - $post['created']) > 300) || // ... or over 5 minutes passed between create and update times
($post['lastuserid'] != $post['userid']) // ... or it was updated by a different user ($post['lastuserid'] != $post['userid']) // ... or it was updated by a different user
) )
...@@ -637,7 +637,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt ...@@ -637,7 +637,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
break; break;
case QA_UPDATE_CLOSED: case QA_UPDATE_CLOSED:
$langstring = isset($post['closedbyid']) ? 'main/closed' : 'main/reopened'; $langstring = isset($post['closedbyid']) || (qa_opt('do_close_on_select') && isset($post['selchildid'])) ? 'main/closed' : 'main/reopened';
break; break;
case QA_UPDATE_TAGS: case QA_UPDATE_TAGS:
...@@ -838,10 +838,11 @@ function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $d ...@@ -838,10 +838,11 @@ function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $d
break; break;
case 'Q-' . QA_UPDATE_CLOSED: case 'Q-' . QA_UPDATE_CLOSED:
$isClosed = isset($question['closedbyid']) || (qa_opt('do_close_on_select') && isset($question['selchildid']));
if (@$question['opersonal']) if (@$question['opersonal'])
$langstring = isset($question['closedbyid']) ? 'misc/your_q_closed' : 'misc/your_q_reopened'; $langstring = $isClosed ? 'misc/your_q_closed' : 'misc/your_q_reopened';
else else
$langstring = isset($question['closedbyid']) ? 'main/closed' : 'main/reopened'; $langstring = $isClosed ? 'main/closed' : 'main/reopened';
break; break;
case 'Q-' . QA_UPDATE_TAGS: case 'Q-' . QA_UPDATE_TAGS:
......
...@@ -155,7 +155,9 @@ function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $ ...@@ -155,7 +155,9 @@ function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $
{ {
$oldselchildid = $oldquestion['selchildid']; $oldselchildid = $oldquestion['selchildid'];
qa_db_post_set_selchildid($oldquestion['postid'], isset($selchildid) ? $selchildid : null, $userid, qa_remote_ip_address()); $lastip = qa_remote_ip_address();
qa_db_post_set_selchildid($oldquestion['postid'], isset($selchildid) ? $selchildid : null, $userid, $lastip);
qa_db_points_update_ifuser($oldquestion['userid'], 'aselects'); qa_db_points_update_ifuser($oldquestion['userid'], 'aselects');
qa_db_unselqcount_update(); qa_db_unselqcount_update();
...@@ -168,6 +170,15 @@ function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $ ...@@ -168,6 +170,15 @@ function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $
'postid' => $oldselchildid, 'postid' => $oldselchildid,
'answer' => $answers[$oldselchildid], 'answer' => $answers[$oldselchildid],
)); ));
if (!empty($oldquestion['closed']) && empty($oldquestion['closedbyid'])) {
qa_db_post_set_closed($oldquestion['postid'], null, $userid, $lastip);
qa_report_event('q_reopen', $userid, $handle, $cookieid, array(
'postid' => $oldquestion['postid'],
'oldquestion' => $oldquestion,
));
}
} }
if (isset($selchildid)) { if (isset($selchildid)) {
...@@ -179,6 +190,17 @@ function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $ ...@@ -179,6 +190,17 @@ function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $
'postid' => $selchildid, 'postid' => $selchildid,
'answer' => $answers[$selchildid], 'answer' => $answers[$selchildid],
)); ));
if (empty($oldquestion['closed'])) {
qa_db_post_set_closed($oldquestion['postid'], null, $userid, $lastip);
qa_report_event('q_close', $userid, $handle, $cookieid, array(
'postid' => $oldquestion['postid'],
'oldquestion' => $oldquestion,
'reason' => 'answer-selected',
'originalid' => $answers[$selchildid],
));
}
} }
} }
......
...@@ -89,7 +89,7 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl ...@@ -89,7 +89,7 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl
$qa_content['q_list']['qs'] = array(); $qa_content['q_list']['qs'] = array();
if (count($questions)) { if (!empty($questions)) {
$qa_content['title'] = $sometitle; $qa_content['title'] = $sometitle;
$defaults = qa_post_html_defaults('Q'); $defaults = qa_post_html_defaults('Q');
...@@ -97,10 +97,11 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl ...@@ -97,10 +97,11 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl
$defaults['categorypathprefix'] = $categorypathprefix; $defaults['categorypathprefix'] = $categorypathprefix;
} }
$closeOnSelect = qa_opt('do_close_on_select');
foreach ($questions as $question) { foreach ($questions as $question) {
$fields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults)); $fields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults));
if (!empty($fields['raw']['closedbyid'])) { if (!empty($fields['raw']['closedbyid']) || (!empty($fields['raw']['selchildid']) && $closeOnSelect)) {
$fields['closed'] = array( $fields['closed'] = array(
'state' => qa_lang_html('main/closed'), 'state' => qa_lang_html('main/closed'),
); );
......
...@@ -184,7 +184,7 @@ function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $ ...@@ -184,7 +184,7 @@ function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $
$rules['closeable'] = qa_opt('allow_close_questions') && $post['type'] == 'Q' && !$rules['closed'] && $permiterror_close_open === false; $rules['closeable'] = qa_opt('allow_close_questions') && $post['type'] == 'Q' && !$rules['closed'] && $permiterror_close_open === false;
// cannot reopen a question if it's been hidden, or if it was closed by someone else and you don't have global closing permissions // cannot reopen a question if it's been hidden, or if it was closed by someone else and you don't have global closing permissions
$rules['reopenable'] = $rules['closed'] && isset($post['closedbyid']) && $permiterror_close_open === false && !$post['hidden'] $rules['reopenable'] = $rules['closed'] && $permiterror_close_open === false && !$post['hidden']
&& ($notclosedbyother || !qa_user_permit_error('permit_close_q', null, $userlevel, true, $userfields)); && ($notclosedbyother || !qa_user_permit_error('permit_close_q', null, $userlevel, true, $userfields));
$rules['moderatable'] = $post['queued'] && !$permiterror_moderate; $rules['moderatable'] = $post['queued'] && !$permiterror_moderate;
...@@ -428,7 +428,7 @@ function qa_page_q_question_view($question, $parentquestion, $closepost, $usersh ...@@ -428,7 +428,7 @@ function qa_page_q_question_view($question, $parentquestion, $closepost, $usersh
// Information about the question that this question is a duplicate of (if appropriate) // Information about the question that this question is a duplicate of (if appropriate)
if (isset($closepost)) { if (isset($closepost) || (!empty($q_view['raw']['selchildid']) && qa_opt('do_close_on_select'))) {
if ($closepost['basetype'] == 'Q') { if ($closepost['basetype'] == 'Q') {
if ($closepost['hidden']) { if ($closepost['hidden']) {
// don't show link for hidden questions // don't show link for hidden questions
...@@ -456,6 +456,12 @@ function qa_page_q_question_view($question, $parentquestion, $closepost, $usersh ...@@ -456,6 +456,12 @@ function qa_page_q_question_view($question, $parentquestion, $closepost, $usersh
'blockwordspreg' => qa_get_block_words_preg(), 'blockwordspreg' => qa_get_block_words_preg(),
)), )),
); );
} else { // If closed by a selected answer due to the do_close_on_select setting being enabled
$q_view['closed'] = array(
'state' => qa_lang_html('main/closed'),
'label' => qa_lang_html('main/closed'),
'content' => '',
);
} }
} }
......
...@@ -337,7 +337,7 @@ foreach ($questions as $question) { ...@@ -337,7 +337,7 @@ foreach ($questions as $question) {
break; break;
case 'Q-' . QA_UPDATE_CLOSED: case 'Q-' . QA_UPDATE_CLOSED:
$langstring = isset($question['closedbyid']) ? 'misc/feed_closed_prefix' : 'misc/feed_reopened_prefix'; $langstring = isset($question['closedbyid']) || ($question['selchildid'] && qa_opt('do_close_on_select')) ? 'misc/feed_closed_prefix' : 'misc/feed_reopened_prefix';
break; break;
case 'Q-' . QA_UPDATE_TAGS: case 'Q-' . QA_UPDATE_TAGS:
......
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