[Plugin: Joomla/Mambo To WordPress Migrator] Migrate comments
-
Last night I was working in your code to make it able to migrate the comments, I don’t know if you are thinking in add this feature in future releases, but I’m going to paste the code because could be useful to other people in the same situation.
I have added in the file joomla2wp-mig.php two new functions:
function j2wp_get_post_id_for_joomla_id( $id ) { global $CON; $j2wp_wp_tb_prefix = get_option('j2wp_wp_tb_prefix'); $j2wp_joomla_tb_prefix = get_option('j2wp_joomla_tb_prefix'); $id_numeric = intval( $id ); // get title and creation date/time in WP $j2wp_title = ''; $j2wp_date_created = ''; j2wp_do_wp_connect(); $query = 'SELECT post_title, post_date FROM ' . $j2wp_wp_tb_prefix . 'posts WHERE id = ' . $id_numeric; $result = mysql_query($query, $CON); if ( !$result ) echo mysql_error(); while ( $wp_row = mysql_fetch_array($result) ) { $j2wp_title = $wp_row['post_title']; $j2wp_date_created = $wp_row['post_date']; } // get post_id from Joomla for same title and creation date/time j2wp_do_joomla_connect(); $query = 'SELECT id FROM ' . $j2wp_joomla_tb_prefix . 'content WHERE title = "' . mysql_real_escape_string($j2wp_title) . '" AND created = "' . $j2wp_date_created . '"'; $result = mysql_query($query, $CON); if ( !$result ) echo mysql_error(); while ( $joomla_row = mysql_fetch_array($result) ) { $post_id = $joomla_row['id']; } return $post_id; }function j2wp_process_comments_by_post($joomla_id, $wp_id) { global $wpdb, $CON; j2wp_do_joomla_connect(); $j2wp_joomla_tb_prefix = get_option('j2wp_joomla_tb_prefix'); $contentid = intval($joomla_id); $query = "SELECT * FROM <code>" . $j2wp_joomla_tb_prefix . "comment</code> WHERE contentid = '" . $contentid . "' ORDER BY <code>id</code>"; $result = mysql_query($query, $CON); if ( !$result ) echo mysql_error(); $wp_comments = array(); $comment_counter = 0; while($R = mysql_fetch_object($result)) { if ( mysql_error() ) echo mysql_error(); set_time_limit(0); $wp_comments[] = array( 'comment_post_ID' => $wp_id, 'comment_author' => $R->name, 'comment_author_email' => $R->email, 'comment_author_url' => $R->website, 'comment_author_IP' => $R->ip, 'comment_date' => $R->date, 'comment_content' => $R->comment, 'comment_approved' => '1', 'comment_agent' => '', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => 0, ); $comment_counter++; set_time_limit(0); } mysql_free_result($result); j2wp_do_wp_connect(); foreach ( $wp_comments as $item ) { wp_insert_comment( $item ); } return $comment_counter; }and I call them from the function j2wp_insert_posts_to_wp( $sql_query, $wp_posts, $post_tags, $post_images, $wp_cat_id ) inside of the if($id) as
$joomla_id = j2wp_get_post_id_for_joomla_id($id); $comment_counter = j2wp_process_comments_by_post($joomla_id, $id);
The topic ‘[Plugin: Joomla/Mambo To WordPress Migrator] Migrate comments’ is closed to new replies.