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; } }
function qa_answer_set_content($oldanswer, $content, $format, $text, $notify, $userid, $handle, $cookieid, $question, $name = null, $remoderate = false, $silent = false) { qa_post_unindex($oldanswer['postid']); $wasqueued = $oldanswer['type'] == 'A_QUEUED'; $contentchanged = strcmp($oldanswer['content'], $content) || strcmp($oldanswer['format'], $format); $setupdated = $contentchanged && !$wasqueued && !$silent; qa_db_post_set_content($oldanswer['postid'], $oldanswer['title'], $content, $format, $oldanswer['tags'], $notify, $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_CONTENT, $name); if ($setupdated && $remoderate) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $commentsfollows = qa_post_get_answer_commentsfollows($oldanswer['postid']); foreach ($commentsfollows as $comment) { if ($comment['basetype'] == 'C' && $comment['parentid'] == $oldanswer['postid']) { qa_post_unindex($comment['postid']); } } qa_db_post_set_type($oldanswer['postid'], 'A_QUEUED'); qa_update_q_counts_for_a($question['postid']); qa_db_queuedcount_update(); qa_db_points_update_ifuser($oldanswer['userid'], array('aposts', 'aselecteds')); if ($oldanswer['flagcount']) { qa_db_flaggedcount_update(); } } elseif ($oldanswer['type'] == 'A' && $question['type'] == 'Q') { // don't index if question or answer are hidden/queued qa_post_index($oldanswer['postid'], 'A', $question['postid'], $oldanswer['parentid'], null, $content, $format, $text, null, $oldanswer['categoryid']); } $eventparams = array('postid' => $oldanswer['postid'], 'parentid' => $oldanswer['parentid'], 'parent' => $question, 'content' => $content, 'format' => $format, 'text' => $text, 'name' => $name, 'oldanswer' => $oldanswer); qa_report_event('a_edit', $userid, $handle, $cookieid, $eventparams + array('silent' => $silent, 'oldcontent' => $oldanswer['content'], 'oldformat' => $oldanswer['format'], 'contentchanged' => $contentchanged)); if ($setupdated && $remoderate) { qa_report_event('a_requeue', $userid, $handle, $cookieid, $eventparams); } }
/** * 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; } }