if (qa_page_q_close_q_submit($question, $closepost, $closein, $closeerrors)) {
            qa_page_q_refresh($pagestart);
        } else {
            $formtype = 'q_close';
        }
        // keep editing if an error
    } elseif ($pagestate == 'close' && qa_page_q_permit_edit($question, 'permit_close_q', $pageerror)) {
        $formtype = 'q_close';
    }
}
//	Process any single click operations or delete button for question
if (qa_page_q_single_click_q($question, $answers, $commentsfollows, $closepost, $pageerror)) {
    qa_page_q_refresh($pagestart);
}
if (qa_clicked('q_dodelete') && $question['deleteable'] && qa_page_q_click_check_form_code($question, $pageerror)) {
    qa_question_delete($question, $userid, qa_get_logged_in_handle(), $cookieid, $closepost);
    qa_redirect('');
    // redirect since question has gone
}
//	Process edit or save button for question
if ($question['editbutton'] || $question['retagcatbutton']) {
    if (qa_clicked('q_doedit')) {
        qa_page_q_refresh($pagestart, 'edit-' . $questionid);
    } elseif (qa_clicked('q_dosave') && qa_page_q_permit_edit($question, 'permit_edit_q', $pageerror, 'permit_retag_cat')) {
        if (qa_page_q_edit_q_submit($question, $answers, $commentsfollows, $closepost, $qin, $qerrors)) {
            qa_redirect(qa_q_request($questionid, $qin['title']));
        } else {
            $formtype = 'q_edit';
            // keep editing if an error
            $pageerror = @$qerrors['page'];
            // for security code failure
Exemplo n.º 2
0
function qa_post_delete($postid)
{
    $oldpost = qa_post_get_full($postid, 'QAC');
    if (!$oldpost['hidden']) {
        qa_post_set_hidden($postid, true, null);
        $oldpost = qa_post_get_full($postid, 'QAC');
    }
    switch ($oldpost['basetype']) {
        case 'Q':
            $answers = qa_post_get_question_answers($postid);
            $commentsfollows = qa_post_get_question_commentsfollows($postid);
            $closepost = qa_post_get_question_closepost($postid);
            if (count($answers) || count($commentsfollows)) {
                qa_fatal_error('Could not delete question ID due to dependents: ' . $postid);
            }
            qa_question_delete($oldpost, null, null, null, $closepost);
            break;
        case 'A':
            $question = qa_post_get_full($oldpost['parentid'], 'Q');
            $commentsfollows = qa_post_get_answer_commentsfollows($postid);
            if (count($commentsfollows)) {
                qa_fatal_error('Could not delete answer ID due to dependents: ' . $postid);
            }
            qa_answer_delete($oldpost, $question, null, null, null);
            break;
        case 'C':
            $parent = qa_post_get_full($oldpost['parentid'], 'QA');
            $question = qa_post_parent_to_question($parent);
            qa_comment_delete($oldpost, $question, $parent, null, null, null);
            break;
    }
}
Exemplo n.º 3
0
function qa_recalc_perform_step(&$state)
{
    $continue = false;
    @(list($operation, $length, $next, $done) = explode(',', $state));
    switch ($operation) {
        case 'doreindexposts':
            qa_recalc_transition($state, 'doreindexposts_postcount');
            break;
        case 'doreindexposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'doreindexposts_reindex');
            break;
        case 'doreindexposts_reindex':
            $posts = qa_db_posts_get_for_reindexing($next, 10);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'qa-app-format.php';
                $lastpostid = max(array_keys($posts));
                qa_db_prepare_for_reindexing($next, $lastpostid);
                foreach ($posts as $postid => $post) {
                    qa_post_index($postid, $post['type'], $post['questionid'], $post['title'], qa_viewer_text($post['content'], $post['format']), $post['tags'], true);
                }
                $next = 1 + $lastpostid;
                $done += count($posts);
                $continue = true;
            } else {
                qa_db_truncate_indexes($next);
                qa_recalc_transition($state, 'doreindexposts_wordcount');
            }
            break;
        case 'doreindexposts_wordcount':
            $wordids = qa_db_words_prepare_for_recounting($next, 1000);
            if (count($wordids)) {
                $lastwordid = max($wordids);
                qa_db_words_recount($next, $lastwordid);
                $next = 1 + $lastwordid;
                $done += count($wordids);
                $continue = true;
            } else {
                qa_db_tagcount_update();
                // this is quick so just do it here
                qa_recalc_transition($state, 'doreindexposts_complete');
            }
            break;
        case 'dorecountposts':
            qa_recalc_transition($state, 'dorecountposts_postcount');
            break;
        case 'dorecountposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_db_unaqcount_update();
            qa_recalc_transition($state, 'dorecountposts_recount');
            break;
        case 'dorecountposts_recount':
            $postids = qa_db_posts_get_for_recounting($next, 1000);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recount($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecountposts_complete');
            }
            break;
        case 'dorecalcpoints':
            qa_recalc_transition($state, 'dorecalcpoints_usercount');
            break;
        case 'dorecalcpoints_usercount':
            qa_db_userpointscount_update();
            // for progress update - not necessarily accurate
            qa_recalc_transition($state, 'dorecalcpoints_recalc');
            break;
        case 'dorecalcpoints_recalc':
            $userids = qa_db_users_get_for_recalc_points($next, 10);
            if (count($userids)) {
                $lastuserid = max($userids);
                qa_db_users_recalc_points($next, $lastuserid);
                $next = 1 + $lastuserid;
                $done += count($userids);
                $continue = true;
            } else {
                qa_db_truncate_userpoints($next);
                qa_db_userpointscount_update();
                // quick so just do it here
                qa_recalc_transition($state, 'dorecalcpoints_complete');
            }
            break;
        case 'dorecalccategories':
            qa_recalc_transition($state, 'dorecalccategories_postcount');
            break;
        case 'dorecalccategories_postcount':
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'dorecalccategories_postupdate');
            break;
        case 'dorecalccategories_postupdate':
            $postids = qa_db_posts_get_for_recategorizing($next, 100);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recalc_categoryid($next, $lastpostid);
                qa_db_posts_calc_category_path($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_recount');
            }
            break;
        case 'dorecalccategories_recount':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                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');
            }
            break;
        case 'dorecalccategories_backpaths':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                qa_db_categories_recalc_backpaths($next, $lastcategoryid);
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_complete');
            }
            break;
        case 'dodeletehidden':
            qa_recalc_transition($state, 'dodeletehidden_comments');
            break;
        case 'dodeletehidden_comments':
            $posts = qa_db_posts_get_for_deleting('C', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldcomment = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                $parent = qa_db_single_select(qa_db_full_post_selectspec(null, $oldcomment['parentid']));
                if ($parent['basetype'] == 'Q') {
                    $question = $parent;
                    $answer = null;
                } else {
                    $question = qa_db_single_select(qa_db_full_post_selectspec(null, $parent['parentid']));
                    $answer = $parent;
                }
                qa_comment_delete($oldcomment, $question, $answer, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_answers');
            }
            break;
        case 'dodeletehidden_answers':
            $posts = qa_db_posts_get_for_deleting('A', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldanswer = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                $question = qa_db_single_select(qa_db_full_post_selectspec(null, $oldanswer['parentid']));
                qa_answer_delete($oldanswer, $question, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_questions');
            }
            break;
        case 'dodeletehidden_questions':
            $posts = qa_db_posts_get_for_deleting('Q', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldquestion = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                qa_question_delete($oldquestion, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_complete');
            }
            break;
        default:
            $state = '';
            break;
    }
    if ($continue) {
        $state = $operation . ',' . $length . ',' . $next . ',' . $done;
    }
    return $continue && $done < $length;
}
 /**
  * Fetches the child posts of the question and delete them recursively
  *
  * @param $postid
  */
 function ami_dhp_post_delete_recursive($postid)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-admin.php';
     require_once QA_INCLUDE_DIR . 'qa-db-admin.php';
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     require_once QA_INCLUDE_DIR . 'qa-app-format.php';
     require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
     global $ami_dhp_posts_deleted;
     if (is_null($ami_dhp_posts_deleted)) {
         $ami_dhp_posts_deleted = array();
     }
     if (in_array($postid, $ami_dhp_posts_deleted)) {
         return;
     }
     $oldpost = qa_post_get_full($postid, 'QAC');
     if (!$oldpost['hidden']) {
         qa_post_set_hidden($postid, true, null);
         $oldpost = qa_post_get_full($postid, 'QAC');
     }
     switch ($oldpost['basetype']) {
         case 'Q':
             $answers = qa_post_get_question_answers($postid);
             $commentsfollows = qa_post_get_question_commentsfollows($postid);
             $closepost = qa_post_get_question_closepost($postid);
             if (count($answers)) {
                 foreach ($answers as $answer) {
                     ami_dhp_post_delete_recursive($answer['postid']);
                 }
             }
             if (count($commentsfollows)) {
                 foreach ($commentsfollows as $commentsfollow) {
                     ami_dhp_post_delete_recursive($commentsfollow['postid']);
                 }
             }
             if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) {
                 qa_question_delete($oldpost, null, null, null, $closepost);
                 $ami_dhp_posts_deleted[] = $oldpost['postid'];
             }
             break;
         case 'A':
             $question = qa_post_get_full($oldpost['parentid'], 'Q');
             $commentsfollows = qa_post_get_answer_commentsfollows($postid);
             if (count($commentsfollows)) {
                 foreach ($commentsfollows as $commentsfollow) {
                     ami_dhp_post_delete_recursive($commentsfollow['postid']);
                 }
             }
             if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) {
                 qa_answer_delete($oldpost, $question, null, null, null);
                 $ami_dhp_posts_deleted[] = $oldpost['postid'];
             }
             break;
         case 'C':
             $parent = qa_post_get_full($oldpost['parentid'], 'QA');
             $question = qa_post_parent_to_question($parent);
             if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) {
                 qa_comment_delete($oldpost, $question, $parent, null, null, null);
                 $ami_dhp_posts_deleted[] = $oldpost['postid'];
             }
             break;
     }
 }
        qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid));
    }
}
//	Process hiding or showing or claiming or comment on a question
if (qa_clicked('dohideq') && $question['hideable']) {
    qa_question_set_hidden($question, true, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $answers, $commentsfollows);
    qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_hide', $questionid, null, null);
    qa_redirect($qa_request);
}
if (qa_clicked('doshowq') && $question['reshowable']) {
    qa_question_set_hidden($question, false, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $answers, $commentsfollows);
    qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_reshow', $questionid, null, null);
    qa_redirect($qa_request);
}
if (qa_clicked('dodeleteq') && $question['deleteable']) {
    qa_question_delete($question, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid);
    qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_delete', $questionid, null, null);
    qa_redirect('');
    // redirect since question has gone
}
if (qa_clicked('doclaimq') && $question['claimable']) {
    if (qa_limits_remaining($qa_login_userid, 'Q')) {
        // already checked 'permit_post_q'
        qa_question_set_userid($question, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid);
        qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_claim', $questionid, null, null);
        qa_redirect($qa_request);
    } else {
        $pageerror = qa_lang_html('question/ask_limit');
    }
}
//	Process flag or unflag button for question