function qa_answer_delete($oldanswer, $question, $userid, $handle, $cookieid) { require_once QA_INCLUDE_DIR . 'qa-db-votes.php'; if ($oldanswer['type'] != 'A_HIDDEN') { qa_fatal_error('Tried to delete a non-hidden answer'); } $useridvotes = qa_db_uservote_post_get($oldanswer['postid']); qa_post_unindex($oldanswer['postid']); qa_db_post_delete($oldanswer['postid']); // also deletes any related voteds due to cascading if ($question['selchildid'] == $oldanswer['postid']) { qa_db_post_set_selchildid($question['postid'], null); qa_db_points_update_ifuser($question['userid'], 'aselects'); qa_db_unselqcount_update(); } qa_update_q_counts_for_a($question['postid']); qa_db_points_update_ifuser($oldanswer['userid'], array('aposts', 'aselecteds', 'avoteds', 'upvoteds', 'downvoteds')); foreach ($useridvotes as $voteruserid => $vote) { qa_db_points_update_ifuser($voteruserid, $vote > 0 ? 'aupvotes' : 'adownvotes'); } // could do this in one query like in qa_db_users_recalc_points() but this will do for now - unlikely to be many votes qa_report_event('a_delete', $userid, $handle, $cookieid, array('postid' => $oldanswer['postid'], 'parentid' => $oldanswer['parentid'], 'oldanswer' => $oldanswer)); }
function qa_answer_to_comment($oldanswer, $parentid, $content, $format, $text, $notify, $userid, $handle, $cookieid, $question, $answers, $commentsfollows, $name = null, $remoderate = false, $silent = false) { require_once QA_INCLUDE_DIR . 'db/votes.php'; $parent = isset($answers[$parentid]) ? $answers[$parentid] : $question; qa_post_unindex($oldanswer['postid']); $wasqueued = $oldanswer['type'] == 'A_QUEUED'; $contentchanged = strcmp($oldanswer['content'], $content) || strcmp($oldanswer['format'], $format); $setupdated = $contentchanged && !$wasqueued && !$silent; if ($setupdated && $remoderate) { $newtype = 'C_QUEUED'; } else { $newtype = substr_replace($oldanswer['type'], 'C', 0, 1); } qa_db_post_set_type($oldanswer['postid'], $newtype, $wasqueued || $silent ? null : $userid, $wasqueued || $silent ? null : qa_remote_ip_address(), QA_UPDATE_TYPE); qa_db_post_set_parent($oldanswer['postid'], $parentid); 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); foreach ($commentsfollows as $commentfollow) { if ($commentfollow['parentid'] == $oldanswer['postid']) { // do same thing for comments and follows qa_db_post_set_parent($commentfollow['postid'], $parentid); } } qa_update_q_counts_for_a($question['postid']); qa_db_ccount_update(); qa_db_points_update_ifuser($oldanswer['userid'], array('aposts', 'aselecteds', 'cposts', 'avoteds')); $useridvotes = qa_db_uservote_post_get($oldanswer['postid']); foreach ($useridvotes as $voteruserid => $vote) { qa_db_points_update_ifuser($voteruserid, $vote > 0 ? 'aupvotes' : 'adownvotes'); } // could do this in one query like in qa_db_users_recalc_points() but this will do for now - unlikely to be many votes if ($setupdated && $remoderate) { qa_db_queuedcount_update(); if ($oldanswer['flagcount']) { qa_db_flaggedcount_update(); } } elseif ($oldanswer['type'] == 'A' && $question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A')) { // only if all fully visible qa_post_index($oldanswer['postid'], 'C', $question['postid'], $parentid, null, $content, $format, $text, null, $oldanswer['categoryid']); } $eventparams = array('postid' => $oldanswer['postid'], 'parentid' => $parentid, 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'content' => $content, 'format' => $format, 'text' => $text, 'name' => $name, 'oldanswer' => $oldanswer); qa_report_event('a_to_c', $userid, $handle, $cookieid, $eventparams + array('silent' => $silent, 'oldcontent' => $oldanswer['content'], 'oldformat' => $oldanswer['format'], 'contentchanged' => $contentchanged)); if ($setupdated && $remoderate) { qa_report_event('c_requeue', $userid, $handle, $cookieid, $eventparams); } // a-to-c conversion can be detected by presence of $event['oldanswer'] instead of $event['oldcomment'] }