Last active
November 30, 2017 08:55
-
-
Save chiliec/2fe23849c24b3c2fb587d7982b25efd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set("memory_limit", "1024M"); | |
set_time_limit(0); | |
// setup the WordPress environment | |
define( "WP_INSTALLING", true ); | |
require( dirname(__FILE__) . '/wp-load.php' ); | |
require( 'wp-blog-header.php' ); | |
require_once( ABSPATH . WPINC . '/registration.php' ); | |
require_once(ABSPATH . "wp-admin/includes/taxonomy.php"); | |
require_once(ABSPATH . "wp-content/plugins/cyr3lat/cyr-to-lat.php"); | |
require_once(ABSPATH . "wp-admin/includes/comment.php"); | |
global $domain, $base; | |
$connection = mysql_connect("localhost", "root", ""); | |
mysql_select_db("lastqalib", $connection) or die(mysql_error()); | |
mysql_query("SET NAMES 'utf8'"); | |
mysql_query("set character_set_client='utf8'"); | |
mysql_query("set character_set_results='utf8'"); | |
mysql_query("set collation_connection='utf8'"); | |
// Categories | |
// $array = []; | |
// $sql = "SELECT * FROM questions_category"; | |
// $result = mysql_query($sql); | |
// while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
// $array[$rows['cat_id']]['term_id'] = $rows['cat_id']; | |
// $array[$rows['cat_id']]['name'] = $rows['cat_name']; | |
// $array[$rows['cat_id']]['parent'] = $rows['parent_id']; | |
// $array[$rows['cat_id']]['count'] = $rows['total_questions']; | |
// | |
// } | |
// foreach ($array as $key => $value) { | |
// $term_id = $value['term_id']; | |
// $name = $value['name']; | |
// $parent = $value['parent']; | |
// $count = $value['count']; | |
// wp_insert_term($name, 'category', array( | |
// 'description'=>$name, | |
// 'slug'=>ctl_sanitize_title($name), | |
// 'parent'=>$parent | |
// )); | |
// } | |
// print_r('Категории созданы' . '<br /><br />'); | |
// Users step 1 | |
// $array = []; | |
// $sql = "SELECT * FROM users"; | |
// $result = mysql_query($sql); | |
// while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
// $array[$rows['user_id']]['user_id'] = $rows['user_id']; | |
// $array[$rows['user_id']]['name'] = mysql_real_escape_string($rows['name']); | |
// $array[$rows['user_id']]['display_name'] = mysql_real_escape_string($rows['display_name']); | |
// $array[$rows['user_id']]['email'] = mysql_real_escape_string($rows['email']); | |
// $array[$rows['user_id']]['doj'] = mysql_real_escape_string($rows['doj']); | |
// } | |
// // print_r($array); | |
// mysql_select_db("qalibwp", $connection) or die(mysql_error()); | |
// foreach ($array as $key => $value) { | |
// $ID = $value['user_id']; | |
// if ($ID == 1) {continue;} | |
// $user_login = $value['name']; | |
// $user_pass = '$P$B0ygy5lypB.lLGpAgQQ2/TqDcOvO8B.'; | |
// $user_email = $value['email']; | |
// $user_registered = $value['doj']; | |
// $display_name = $value['display_name']; | |
// $res = mysql_query("INSERT INTO `qlb_users` VALUES ( | |
// '$ID', | |
// '$user_login', | |
// '$user_pass', | |
// '$user_login', | |
// '$user_email', | |
// '', | |
// '$user_registered', | |
// '', | |
// '0', | |
// '$display_name' | |
// )"); | |
// if ($res) { | |
// echo $res; | |
// } else { | |
// echo mysql_error(); | |
// } | |
// } | |
// Users step 2 | |
// $array = []; | |
// $sql = "SELECT * FROM users"; | |
// $result = mysql_query($sql); | |
// while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
// $array[$rows['user_id']]['user_id'] = $rows['user_id']; | |
// $array[$rows['user_id']]['name'] = mysql_real_escape_string($rows['name']); | |
// $array[$rows['user_id']]['display_name'] = mysql_real_escape_string($rows['display_name']); | |
// $array[$rows['user_id']]['email'] = mysql_real_escape_string($rows['email']); | |
// $array[$rows['user_id']]['doj'] = mysql_real_escape_string($rows['doj']); | |
// } | |
// foreach ($array as $key => $value) { | |
// $ID = $value['user_id']; if ($ID == 1) {continue;} | |
// $user_login = $value['name']; | |
// $password = wp_generate_password(12, true); | |
// $user_email = $value['email']; | |
// $user_registered = $value['doj']; | |
// $display_name = $value['display_name']; | |
// $userdata = array( | |
// 'ID' => $ID, | |
// 'user_pass' => $password, | |
// 'user_login' => $user_login, | |
// 'nickname' => $user_login, | |
// 'display_name' => $display_name, | |
// 'user_email' => $user_email, | |
// 'user_registered' => $user_registered, | |
// 'role' => 'contributor' | |
// ); | |
// $user_id = wp_update_user($userdata, WP_Error); | |
// print_r($user_id); | |
// } | |
// print_r('Пользователи созданы' . '<br /><br />'); | |
// Posts | |
// $array = []; | |
// $sql = "SELECT * FROM questions"; | |
// $result = mysql_query($sql); | |
// while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
// $array[$rows['ques_id']]['ques_id'] = $rows['ques_id']; | |
// $array[$rows['ques_id']]['user_id'] = $rows['user_id']; | |
// $array[$rows['ques_id']]['date_answered'] = $rows['date_answered']; | |
// $array[$rows['ques_id']]['question'] = $rows['question']; | |
// $array[$rows['ques_id']]['description'] = $rows['description']; | |
// $array[$rows['ques_id']]['cat_id'] = $rows['cat_id']; // pcat_id | |
// $array[$rows['ques_id']]['seo_title'] = $rows['seo_title']; | |
// } | |
// foreach ($array as $key => $value) { | |
// $post_data = array( | |
// 'import_id' => $value['ques_id'], | |
// 'post_author' => $value['user_id'], | |
// 'post_date' => $value['date_answered'], | |
// 'post_content' => $value['description'], | |
// 'post_title' => wp_strip_all_tags($value['question']), | |
// 'post_status' => 'publish', | |
// 'post_type' => 'post', | |
// 'post_category' => array($value['cat_id']), | |
// 'post_name' => $value['seo_title'], | |
// ); | |
// $result = wp_insert_post($post_data, WP_Error); | |
// print_r($result); | |
// } | |
// print_r('Вопросы созданы' . '<br /><br />'); | |
// Answers oldschool | |
// $array = []; | |
// $sql = "SELECT * FROM answers"; | |
// $result = mysql_query($sql); | |
// while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
// $array[$rows['ans_id']]['ans_id'] = $rows['ans_id']; | |
// $array[$rows['ans_id']]['user_id'] = $rows['user_id']; | |
// $array[$rows['ans_id']]['ques_id'] = $rows['ques_id']; | |
// $array[$rows['ans_id']]['answer'] = $rows['answer']; | |
// $array[$rows['ans_id']]['date_answered'] = $rows['date_answered']; | |
// $array[$rows['ans_id']]['votes'] = $rows['votes']; | |
// } | |
// $comments_array = array(); | |
// mysql_select_db("qalibwp", $connection) or die(mysql_error()); | |
// foreach ($array as $key => $value) { | |
// $ID = $value['ans_id']; | |
// $comment_post_ID = $value['ques_id']; | |
// $comment_author = ''; | |
// $comment_author_email = ''; | |
// $comment_author_url = ''; | |
// $comment_author_IP = ''; | |
// $comment_date = $value['date_answered']; | |
// $comment_date_gmt = $value['date_answered']; | |
// $comment_content = mysql_real_escape_string($value['answer']); | |
// $comment_karma = $value['votes']; | |
// $comment_approved = 1; | |
// $comment_agent = ''; | |
// $comment_type = ''; | |
// $comment_parent = 0; | |
// $user_id = $value['user_id']; | |
// if (!in_array($value['ans_id'], $comments_array)) { | |
// $res = mysql_query("INSERT INTO `qlb_comments` VALUES ( | |
// '$ID', | |
// '$comment_post_ID', | |
// '$comment_author', | |
// '$comment_author_email', | |
// '$comment_author_url', | |
// '$comment_author_IP', | |
// '$comment_date', | |
// '$comment_date_gmt', | |
// '$comment_content', | |
// '$comment_karma', | |
// '$comment_approved', | |
// '$comment_agent', | |
// '$comment_type', | |
// '$comment_parent', | |
// '$user_id' | |
// )"); | |
// if ($res) { | |
// echo $value['ans_id'].' '; | |
// } else { | |
// // echo mysql_error(); | |
// } | |
// } | |
// $comments_array[] = $value['ans_id']; | |
// } | |
// print_r('Ответы созданы' . '<br /><br />'); | |
// Answers | |
$array = []; | |
$sql = "SELECT * FROM answers"; | |
$result = mysql_query($sql); | |
while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
$array[$rows['ans_id']]['ans_id'] = $rows['ans_id']; | |
$array[$rows['ans_id']]['user_id'] = $rows['user_id']; | |
$array[$rows['ans_id']]['ques_id'] = $rows['ques_id']; | |
$array[$rows['ans_id']]['answer'] = $rows['answer']; | |
$array[$rows['ans_id']]['date_answered'] = $rows['date_answered']; | |
$array[$rows['ans_id']]['votes'] = $rows['votes']; | |
} | |
$comments_array = array(); | |
foreach ($array as $key => $value) { | |
$commentdata = array( | |
'comment_ID' => $value['ans_id'], | |
'comment_post_ID' => $value['ques_id'], | |
'comment_content' => $value['answer'], //fixed value - can be dynamic | |
'comment_type' => '', //empty for regular comments, 'pingback' for pingbacks, 'trackback' for trackbacks | |
'comment_parent' => 0, //0 if it's not a reply to another comment; if it's a reply, mention the parent comment ID here | |
'user_id' => $value['user_id'], //passing current user ID or any predefined as per the demand | |
'comment_approved' => 1, | |
'comment_date' => $value['date_answered'], | |
'comment_karma' => $value['votes'] | |
); | |
if (!in_array($value['answer'], $comments_array)) { | |
if (!get_comment($value['ans_id'])) { | |
wp_insert_comment($commentdata); | |
} else { | |
wp_update_comment($commentdata); | |
} | |
} | |
$comments_array[] = $value['answer']; | |
} | |
print_r('Ответы созданы' . '<br /><br />'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment