Exemplo n.º 1
0
function qa_question_create($followanswer, $userid, $handle, $cookieid, $title, $content, $format, $text, $tagstring, $notify, $email, $categoryid = null, $extravalue = null, $queued = false, $name = null)
{
    require_once QA_INCLUDE_DIR . 'db/selects.php';
    $postid = qa_db_post_create($queued ? 'Q_QUEUED' : 'Q', @$followanswer['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), $title, $content, $format, $tagstring, qa_combine_notify_email($userid, $notify, $email), $categoryid, isset($userid) ? null : $name);
    if (isset($extravalue)) {
        require_once QA_INCLUDE_DIR . 'db/metas.php';
        qa_db_postmeta_set($postid, 'qa_q_extra', $extravalue);
    }
    qa_db_posts_calc_category_path($postid);
    qa_db_hotness_update($postid);
    if ($queued) {
        qa_db_queuedcount_update();
    } else {
        qa_post_index($postid, 'Q', $postid, @$followanswer['postid'], $title, $content, $format, $text, $tagstring, $categoryid);
        qa_update_counts_for_q($postid);
        qa_db_points_update_ifuser($userid, 'qposts');
    }
    qa_report_event($queued ? 'q_queue' : 'q_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => @$followanswer['postid'], 'parent' => $followanswer, 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'tags' => $tagstring, 'categoryid' => $categoryid, 'extra' => $extravalue, 'name' => $name, 'notify' => $notify, 'email' => $email));
    return $postid;
}
function qa_question_delete($oldquestion, $userid, $handle, $cookieid, $oldclosepost = null)
{
    require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
    if ($oldquestion['type'] != 'Q_HIDDEN') {
        qa_fatal_error('Tried to delete a non-hidden question');
    }
    if (isset($oldclosepost) && $oldclosepost['parentid'] == $oldquestion['postid']) {
        qa_db_post_set_closed($oldquestion['postid'], null);
        // for foreign key constraint
        qa_post_unindex($oldclosepost['postid']);
        qa_db_post_delete($oldclosepost['postid']);
    }
    $useridvotes = qa_db_uservote_post_get($oldquestion['postid']);
    $oldpath = qa_db_post_get_category_path($oldquestion['postid']);
    qa_post_unindex($oldquestion['postid']);
    qa_db_post_delete($oldquestion['postid']);
    // also deletes any related voteds due to foreign key cascading
    qa_update_counts_for_q(null);
    qa_db_category_path_qcount_update($oldpath);
    // don't do inside qa_update_counts_for_q() since post no longer exists
    qa_db_points_update_ifuser($oldquestion['userid'], array('qposts', 'aselects', 'qvoteds', 'upvoteds', 'downvoteds'));
    foreach ($useridvotes as $voteruserid => $vote) {
        qa_db_points_update_ifuser($voteruserid, $vote > 0 ? 'qupvotes' : 'qdownvotes');
    }
    // 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('q_delete', $userid, $handle, $cookieid, array('postid' => $oldquestion['postid'], 'oldquestion' => $oldquestion));
}