Support Forum

Moving comments to forum

CA Chris_Andrews
Chris_Andrews
Member

Ok, this has taken me forever to get to…

A while back I copied all my articles that included comments over to the forum as forum posts. ( https://simple-press.com/support-forum/sp5-plugin-topics/understanding-blog-linking/ )

Now, I’d like to move the comments that are on those articles over to the forum, so I have posts and comments on the forum. 

I’m thinking I need to do something along these lines, but I’m not fluent enough in php/mysql to write it myself (probably could, but it would take me another three months!).

 ————————–

grab row from wp_comments

//hold that info in array as a var

//pull out comment_post_ID as a var

from table wp_sflinks get forum_id and topic_id where post_id = comment_post_ID

//hold forum_id as a var

insert into wp_sfposts

post_id //needs to increment from previous existing
post_content // comment_content from wp_comments
post_date //comment_date from wp_comments
topic_id // topic_id from wp_sflinks
user_id //user_id from wp_comments
forum_id //forum_id from wp_sflinks
guest_name //comment_author from wp_comments
guest_email //
post_status //
post_pinned //
post_index //hmmm, need to increment from the previous with the same topic_id, maybe make this whole thing a while statement (while comment_post_ID loop through rows and increment this?)
post_edit //
poster_ip //
comment_id //
source //

 //need to put a limit on the script so it doesn’t crash server trying to move 5000+ comments.

Is there anyone available to write this?  Not sure I have all the working parts in place, so it will have to be thought out to make sure.

15 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

You are OK up to the part where you want to create the new forum data – i.e, the post record. There is a little more to it than just writing to the one table.

i would suggest you take a look at the code file /simple-press/forum/library/sp-post.php. This sets everything up to create a new topic and/or post record. It goes through the major steps for you. If you check the data requirements you will be able to trace through the new post action.

This code obviously uses POST variables but it should be pretty straightforward to adapt it for, say, using an AJAX call for each record. That gets you over the timeout issue as well of course. The main thing is to fill the required values and then pass control over to the post class.

Could we do it? I have to say straight off that certainly not very quickly or soon…

CA Chris_Andrews
Chris_Andrews
Member

Thank you… are there any freelancers that know SP well enough to do this that you would recommend?

YS Yellow Swordfish
Yellow Swordfish
Member

I’m sorry – but to be perfectly honest I do not know anyone. We always hoped that one or two people might materialise and we do know that some people do perform some customisation work on their own site, but we have never been asked to keep anyones name for such queries.

CA Chris_Andrews
Chris_Andrews
Member

I’m looking through simple-press/forum/library/sp-post.php but don’t see what data I need to put into what tables. I see the validation checks, and then the part where it says it is saving to the database, but not what data is being added to what tables….

Still studying it – 

YS Yellow Swordfish
Yellow Swordfish
Member

You would need to look at the sp-api-class-post.php file (in sp-api folder) – at the top are the variable declarations that make up the ‘newpost’ array.

YS Yellow Swordfish
Yellow Swordfish
Member

Actually forget that – I am being dumb.

Open up the file /librtary/sp-linking-comments.php.

Find the function sp_create_post_from_comment().

That function does what you want to do – saves a comment as a forum post. You wont be able to call it as is but you should be able to rewrite for your requirements.

CA Chris_Andrews
Chris_Andrews
Member

That function almost looks like if I made an edit in a comment it should add that comment as a post to the forum if it’s linked. 

I edited a comment (from the wp admin) and it didn’t do anything though…. 

On a larger scale, I was wondering if I could ‘trick’ the script into thinking a number of comments were edited so I could enter a bunch at a time…. just brainstorming since I don’t quite understand the code enough to really know what it’s doing. I’m picking through it though and may be able to figure it out – 

CA Chris_Andrews
Chris_Andrews
Member

Opps, I was looking at the function that followed the one you mentioned when I wrote that – sorry, don’t think that applies.

MP Mr Papa
Mr Papa
Member

you dont think the function Andy provided will work??

CA Chris_Andrews
Chris_Andrews
Member

It very well might…. it’s more that I’m not sure how to use it –

MP Mr Papa
Mr Papa
Member

do you have a specific question?  or section that is not understood?

CA Chris_Andrews
Chris_Andrews
Member

No, I don’t really have a starting point on how to use it.

If I would put it in a new script? and how to get the data to it….? 

YS Yellow Swordfish
Yellow Swordfish
Member

As I said in post #2 – you were pretty much there up until the post save. The code I have pointed you to ensures that part of it is performs properly. Although I would add that one thing you did not say in post #1 was to ensure you tackle the comments in ID order as  the order they are saved in will be reflected in the forum topic sequence.

CA Chris_Andrews
Chris_Andrews
Member

Ok, so I’m thinking I need to get the data from the comments table, then the sflinks table, and if there is a link, then I would use the function by feeding it the data? 

So, right now, I’m working on getting the comments data (that works). Then the information from sflinks…. but for some reason I’m not getting that information. 

Do you see what I am doing wrong here?  Thanks for your help ahead of time!

<?php 

//load wp

require_once(“wp-load.php”);

//get comments

$comments = $wpdb->get_results( $wpdb->prepare(“SELECT * FROM $wpdb->comments LIMIT 7”) );

foreach ($comments as $comment) {

$comment_post_ID = $comment->comment_post_ID;

//do I have the comments info?

echo $comment_post_ID.”<br />”; //YES!

 //find and get data from sflinks

$links = $wpdb->get_row( $wpdb->prepare( “SELECT * FROM $wpdb->sflinks WHERE post_id = $comment_post_ID” ) );

$link_info = $links->topic_id.”<br />”;

 //do I have the info from sflinks?

echo $link_info.”<br /><br />”; //NO

}

?>