Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
1.7k views
in Plugins by
There is a plugin for it but it does it individually.
Q2A version: 1.8.5

2 Answers

+4 votes
by
edited by
 
Best answer

The distinction between comment and answer is merely the value of the field type in the database table qa_posts. To convert all comments to answers do this:

UPDATE qa_posts SET type='A' WHERE type='C';

To convert just the comments for a particular question do this (replace 42 with the actual post ID of the question at hand):

UPDATE qa_posts SET type='A' WHERE parentid=42 AND type='C';


Edit: For converting comments on answers you can use a slightly modified version of the query for converting comments on questions that I posted in the comments. Change the post type from "Q" to "A" and also change the parent ID of the comment to the parent ID of the answer (i.e. the ID of its grandparent, which is the question).

UPDATE qa_posts c INNER JOIN qa_posts p ON c.parentid = p.postid SET c.type = 'A', c.parentid = p.parentid WHERE c.type = 'C' AND p.type = 'A';

If you want to convert comments for a particular post add a clause for the parent post ID:

... AND p.type = 'A' AND p.postid = 42;

by
+1
Modifying the database directly might bring some issues. For example: wrong points for users, wrong cache information or answers will appear and plugins will not be notified about that (might be relevant or not).

The first 2 issues can be dodged by recalculating points and recounting posts. The last one would require a completely different and longer approach
by
edited by
+1
I think there will also some issues by querying the first SQL command.In fact, it coverts all comments to answers (even comments of answers too). So you have to convert just those comments what are belonged to a question (A post with type=Q).
So actually, it will not work as wished..
by
It might cause issues, yes. But since we don't know more about the OPs situation and requirements this is all I can suggest.
by
edited by
+2
@fazleysabbir O ye of little faith ... UPDATE qa_posts c INNER JOIN qa_posts q ON c.parentid = q.postid SET c.type = 'A' WHERE c.type = 'C' AND q.type = 'Q';
by
Oh..That's great!You killed it with only SQL.I thought we have to use php..
by
Thank you for the answers.
by
But the comments below the answers are a bigger problem for me
by
+1
You can take care of those with a minor change to the query from my previous comment. See updated answer.
by
UPDATE qa_posts c INNER JOIN qa_posts p ON c.parentid = p.postid SET c.type = 'A' WHERE c.type = 'C' AND p.type = 'A';

must be -- p.type = 'Q';
by
@sonsuz That would convert the comments on *questions* to answers. You said you needed to convert the comments on *answers* to answers.
by
I said is not same

@fazleysabbir O ye of little faith ... UPDATE qa_posts c INNER JOIN qa_posts q ON c.parentid = q.postid SET c.type = 'A' WHERE c.type = 'C' AND q.type = 'Q';

UPDATE qa_posts c INNER JOIN qa_posts p ON c.parentid = p.postid SET c.type = 'A' WHERE c.type = 'C' AND p.type = 'A';
by
do they both work?
by
+1
Of course they're not the same. Did you not read what I wrote in my answer? type='Q' is for CONVERTING COMMENTS ON QUESTIONS. type='A' is for CONVERTING COMMENTS ON ANSWERS.

If you want to convert comments on answers rather than questions YOU MUST USE THE LATTER INSTEAD OF THE FORMER.
by
+2
should that be?

UPDATE qa_posts c INNER JOIN qa_posts p ON c.parentid = p.postid SET c.type = 'A', c.parentid=p.parentid WHERE c.type = 'C' AND p.type = 'A';
by
+1
Ah, now I understand the problem. Yes, you're right, you need to update the parent ID of the comment to the parent ID of the answer (i.e. the question ID). Updated my answer.
by
+1
Yes, did work.. 20.000 comment is now answer, just add
AND length(c.content)>100
+3 votes
by
https://github.com/q2apro/q2apro-comment-to-answer/blob/master/q2apro-comment-to-answer-page.php

It's okay to do it one by one. Is it possible to do all of them?
by
maybe it can be done again for all comments in this plugin
...