Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
7k views
in Q2A Core by
I have some users that proposed to close unanswered questions that are older than 3 months.

Actually, this idea I like, it keeps the "unanswered questions" list clean.

Let's say you want to close them, how would you do it?

--

pseudo code for qa_posts:

SET closedbyid = ID-of-close-NOTE

    WHERE created < NOW()-3 MONTHS

    AND ... there are no answer, i.e. Answer with parentid does not exist

--

Problem is that for each closed question we need a "post" with type=NOTE and parentid=Q and content='reason'

Anyone?
by
According to my question here => http://www.question2answer.org/qa/32544/close-question-after-x-time Is your code working to close question (with or without answer)?

 for qa_posts:
SET closedbyid = ID-of-close-NOTE
    WHERE created < NOW()-3 MONTHS
??
by
Don't use the code above, as I have written this is "pseudo code".

1 Answer

0 votes
by
edited by

This function helps for such a plugin:

    function qa_post_set_closed($questionid, $closed=true, $originalpostid=null, $note=null, $byuserid=null)
/*
Closed $questionid if $closed is true, otherwise reopen it. If $closed is true, pass either the $originalpostid of the question that it is a duplicate of, or a $note to explain why it's closed. Pass the identify of the user in $byuserid (or null for an anonymous change).*/
 

I was creating an event module that automatically closes the question, this is part of the necessary code:

        function process_event($event, $userid, $handle, $cookieid, $params) {
            // Specials for Klaustukai
            
            // if question
            $hitEvents = array('q_post', 'q_edit');
            if(in_array($event, $hitEvents)) {
                // 1. close interviu question if posted from user klaustukai with tag interviu
                if($userid == 1 && strpos($params['tags'],'interviu')!==false) {
                    $note = 'interviu';
                    require_once QA_INCLUDE_DIR.'qa-app-posts.php';
                    // qa_post_set_closed($questionid, $closed=true, $originalpostid=null, $note=null, $byuserid=null)
                    // error_log($params['postid'].','.$note.','.$userid);
                    qa_post_set_closed($params['postid'], true, null, $note, $userid);
                }
            }
        } // end process_event
 

...