function qa_question_set_content($oldquestion, $title, $content, $format, $text, $tagstring, $notify, $userid, $handle, $cookieid, $extravalue = null, $name = null, $remoderate = false, $silent = false)
{
    qa_post_unindex($oldquestion['postid']);
    $wasqueued = $oldquestion['type'] == 'Q_QUEUED';
    $titlechanged = strcmp($oldquestion['title'], $title) ? true : false;
    $contentchanged = strcmp($oldquestion['content'], $content) || strcmp($oldquestion['format'], $format);
    $tagschanged = strcmp($oldquestion['tags'], $tagstring) ? true : false;
    $setupdated = ($titlechanged || $contentchanged || $tagschanged) && !$wasqueued && !$silent;
    qa_db_post_set_content($oldquestion['postid'], $title, $content, $format, $tagstring, $notify, $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, $titlechanged || $contentchanged ? QA_UPDATE_CONTENT : QA_UPDATE_TAGS, $name);
    if (isset($extravalue)) {
        require_once QA_INCLUDE_DIR . 'qa-db-metas.php';
        qa_db_postmeta_set($oldquestion['postid'], 'qa_q_extra', $extravalue);
    }
    if ($setupdated && $remoderate) {
        require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
        $answers = qa_post_get_question_answers($oldquestion['postid']);
        $commentsfollows = qa_post_get_question_commentsfollows($oldquestion['postid']);
        $closepost = qa_post_get_question_closepost($oldquestion['postid']);
        foreach ($answers as $answer) {
            qa_post_unindex($answer['postid']);
        }
        foreach ($commentsfollows as $comment) {
            if ($comment['basetype'] == 'C') {
                qa_post_unindex($comment['postid']);
            }
        }
        if (@$closepost['parentid'] == $oldquestion['postid']) {
            qa_post_unindex($closepost['postid']);
        }
        qa_db_post_set_type($oldquestion['postid'], 'Q_QUEUED');
        qa_update_counts_for_q($oldquestion['postid']);
        qa_db_queuedcount_update();
        qa_db_points_update_ifuser($oldquestion['userid'], array('qposts', 'aselects'));
        if ($oldquestion['flagcount']) {
            qa_db_flaggedcount_update();
        }
    } elseif ($oldquestion['type'] == 'Q') {
        // not hidden or queued
        qa_post_index($oldquestion['postid'], 'Q', $oldquestion['postid'], $oldquestion['parentid'], $title, $content, $format, $text, $tagstring, $oldquestion['categoryid']);
    }
    $eventparams = array('postid' => $oldquestion['postid'], 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'tags' => $tagstring, 'extra' => $extravalue, 'name' => $name, 'oldquestion' => $oldquestion);
    qa_report_event('q_edit', $userid, $handle, $cookieid, $eventparams + array('silent' => $silent, 'oldtitle' => $oldquestion['title'], 'oldcontent' => $oldquestion['content'], 'oldformat' => $oldquestion['format'], 'oldtags' => $oldquestion['tags'], 'titlechanged' => $titlechanged, 'contentchanged' => $contentchanged, 'tagschanged' => $tagschanged));
    if ($setupdated && $remoderate) {
        qa_report_event('q_requeue', $userid, $handle, $cookieid, $eventparams);
    }
}
Example #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;
    }
}
 /**
  * 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;
     }
 }