예제 #1
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;
    }
}
 /**
  * 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;
     }
 }