Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. <head>
  2. <meta charset="UTF-8">
  3. </head>
  4. <?php
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "MySQLr00t$";
  8. $dbname = "skillz_copy";
  9. $dbname2 = "wp_skillz_v3";
  10. // Create connection
  11. $conn = new mysqli($servername, $username, $password, $dbname);
  12. $conn2 = new mysqli($servername, $username, $password, $dbname2);
  13.  
  14. $conn->set_charset("utf8");
  15. $conn2->set_charset("utf8");
  16. // Check connection
  17. if ($conn->connect_error) {
  18. die("Connection failed: " . $conn->connect_error);
  19. }
  20. if ($conn2->connect_error) {
  21. die("Connection 2 failed: " . $conn2->connect_error);
  22. }
  23.  
  24. $sql = "SELECT
  25. news_id AS ID,
  26. lang_code AS LANGUAGE,
  27. user_id AS AUTHOR,
  28. title AS TITLE,
  29. text AS CONTENT,
  30. FROM_UNIXTIME(date) AS POST_DATE,
  31. news.discipline AS DISCILPINE
  32. FROM news_translates
  33. LEFT JOIN news ON news_translates.news_id = news.id WHERE lang_code='ru'";
  34. $result = $conn->query($sql);
  35. if ($result->num_rows > 0) {
  36. while ($row = $result->fetch_array()) {
  37. $id = $row['ID'];
  38. $sqlCnt = "SELECT COUNT('id') as CNT FROM comment_sources WHERE source_id=" . $id;
  39. $re = $conn->query($sqlCnt)->fetch_array();
  40. $count = $re['CNT'];
  41.  
  42. $post_author = $row['AUTHOR'];
  43. $post_date = $row['POST_DATE'];
  44. $post_date_gmt = $row['POST_DATE'];
  45. $post_content = htmlspecialchars($row['CONTENT']);
  46. $post_title = $row['TITLE'];
  47. $post_status = 'publish';
  48. $comment_status = 'open';
  49. $ping_status = 'open';
  50. $post_name = '';
  51. $post_modified = $row['POST_DATE'];
  52. $post_modified_gmt = $row['POST_DATE'];
  53. $guid = 'http://dev.battlegrounds.lv/?p=' . $id;
  54. $post_type = 'post';
  55. $comment_count = $count;
  56. $sqlt = "INSERT INTO sk_posts (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_name, post_modified, post_modified_gmt, guid, post_type, comment_count)
  57. VALUES ('$id', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '', '$post_status', '$comment_status', '$ping_status', '$post_name', '$post_modified', '$post_modified_gmt', '$guid', '$post_type', '$comment_count')";
  58.  
  59. if ($conn2->query($sqlt) === TRUE) {
  60. echo "New record created successfully";
  61. } else {
  62. echo "Error: " . $sqlt . "<br>" . $conn->error;
  63. }
  64. $taxSql = "INSERT INTO sk_term_relationships (object_id, term_taxonomy_id) VALUES ('$id', '9')";
  65. if ($conn2->query($taxSql) === TRUE) {
  66. echo "New record created successfully";
  67. } else {
  68. echo "Error: " . $taxSql . "<br>" . $conn->error;
  69. }
  70. }
  71. }
  72.  
  73. $sql_translated = "SELECT
  74. news_id AS ID,
  75. lang_code AS LANGUAGE,
  76. user_id AS AUTHOR,
  77. title AS TITLE,
  78. text AS CONTENT,
  79. FROM_UNIXTIME(date) AS POST_DATE,
  80. news.discipline AS DISCILPINE
  81. FROM news_translates
  82. LEFT JOIN news ON news_translates.news_id = news.id WHERE lang_code='lv'";
  83.  
  84. $resultT = $conn->query($sql_translated);
  85.  
  86. if ($resultT->num_rows > 0) {
  87. while ($rows = $resultT->fetch_array()) {
  88. $id = 10000 + intval($rows['ID']);
  89. $sqlCnt = "SELECT COUNT('id') as CNT FROM comment_sources WHERE source_id=" . $rows['ID'];
  90. $re = $conn->query($sqlCnt)->fetch_array();
  91. $count = $re['CNT'];
  92.  
  93. $post_author = $rows['AUTHOR'];
  94. $post_date = $rows['POST_DATE'];
  95. $post_date_gmt = $rows['POST_DATE'];
  96. $post_content = htmlspecialchars($rows['CONTENT']);
  97. $post_title = $rows['TITLE'];
  98. $post_status = 'publish';
  99. $comment_status = 'open';
  100. $ping_status = 'open';
  101. $post_name = '';
  102. $post_modified = $rows['POST_DATE'];
  103. $post_modified_gmt = $rows['POST_DATE'];
  104. $guid = 'http://dev.battlegrounds.lv/?p=' . $id;
  105. $post_type = 'post';
  106. $comment_count = $count;
  107. $sql = "INSERT INTO sk_posts (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_name, post_modified, post_modified_gmt, guid, post_type, comment_count)
  108. VALUES ('$id', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '', '$post_status', '$comment_status', '$ping_status', '$post_name', '$post_modified', '$post_modified_gmt', '$guid', '$post_type', '$comment_count')";
  109.  
  110. if ($conn2->query($sql) === TRUE) {
  111. echo "New record created successfully";
  112. } else {
  113. echo "Error: " . $sql . "<br>" . $conn->error;
  114. }
  115.  
  116. $taxSql2 = "INSERT INTO sk_term_relationships (object_id, term_taxonomy_id) VALUES ('$id', '5')";
  117. if ($conn2->query($taxSql2) === TRUE) {
  118. echo "New record created successfully";
  119. } else {
  120. echo "Error: " . $taxSql2 . "<br>" . $conn->error;
  121. }
  122. }
  123. }
  124.  
  125.  
  126. $conn->close();
  127. echo 'done';
  128. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement