Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "skillzdev";
  5. $dbname1 = "skillz";
  6. $dbname2 = "skillz_dev";
  7. // Create connection
  8. $conn1 = new mysqli($servername, $username, $password, $dbname1);
  9. // Check connection
  10. if ($conn1->connect_error) {
  11. die("Connection failed: " . $conn1->connect_error);
  12. }
  13.  
  14.  
  15. $conn2 = new mysqli($servername, $username, $password, $dbname2);
  16. // Check connection
  17. if ($conn2->connect_error) {
  18. die("Connection failed: " . $conn2->connect_error);
  19. }
  20.  
  21. $sql = "SELECT
  22. news_id AS id,
  23. lang_code AS locale,
  24. user_id AS author,
  25. title AS title,
  26. text AS content,
  27. FROM_UNIXTIME(date) AS posted,
  28. news.comments AS comments
  29. FROM news_translates
  30. LEFT JOIN news ON news_translates.news_id = news.id
  31. WHERE lang_code='lv' AND active=1";
  32.  
  33. $result = $conn1->query($sql);
  34.  
  35. foreach ($result as $key => $translate_lv) {
  36. $id = $translate_lv['id'];
  37. $lang = $translate_lv['local'];
  38. $author = $translate_lv['author'];
  39. $title = $translate_lv['title'];
  40. $text = $translate_lv['content'];
  41. $posted = $translate_lv['posted'];
  42. $comments = $translate_lv['comments'];
  43.  
  44. $sql_lat = "INSERT INTO sk_posts (post_author,post_date,post_date_gmt,post_content,post_title,post_excerpt,post_status,comment_status,ping_status,post_password,post_name,to_ping,pinged,post_modified,post_modified_gmt,post_content_filtered,post_parent,guid,menu_order,post_type,post_mime_type,comment_count)
  45. VALUES ($author, $posted, $posted, $text, $title, '', 'publish', 'open', 'open', $id, '', '' , $posted, $posted, '', 0, 'http://skillz.dev/?p='.$id, 0, 'post', '', $comments)";
  46. $conn2->query($sql_lat);
  47. $latId = $conn2->insert_id;
  48.  
  49. $sql2 = $sql = "SELECT
  50. news_id AS id,
  51. lang_code AS locale,
  52. user_id AS author,
  53. title AS title,
  54. text AS content,
  55. FROM_UNIXTIME(date) AS posted,
  56. news.comments AS comments
  57. FROM news_translates
  58. LEFT JOIN news ON news_translates.news_id = news.id
  59. WHERE lang_code='ru' AND active=1 AND news_id=$latId";
  60. $result = $conn1->query($sql2);
  61.  
  62. $id = $result['id'];
  63. $lang = $result['local'];
  64. $author = $result['author'];
  65. $title = $result['title'];
  66. $text = $result['content'];
  67. $posted = $result['posted'];
  68. $comments = $result['comments'];
  69.  
  70. $sql_ru = "INSERT INTO sk_posts (post_author,post_date,post_date_gmt,post_content,post_title,post_excerpt,post_status,comment_status,ping_status,post_password,post_name,to_ping,pinged,post_modified,post_modified_gmt,post_content_filtered,post_parent,guid,menu_order,post_type,post_mime_type,comment_count)
  71. VALUES ($author, $posted, $posted, $text, $title, '', 'publish', 'open', 'open', $id, '', '' , $posted, $posted, '', 0, 'http://skillz.dev/?p='.$id, 0, 'post', '', $comments)";
  72. $conn2->query($sql_ru);
  73. $ruId = $conn2->insert_id;
  74.  
  75. $poly = 'pll_'.md5(uniqid(rand(), true));
  76. $pollyIns = "INSERT INTO sk_terms (name, slug, term_group)
  77. VALUES ($poly, $poly, 0)";
  78. $conn2->query($pollyIns);
  79. $pollyId = $conn2->insert_id;
  80.  
  81. $translations = ['lv'=>$latId, 'ru'=>$ruId]
  82. $dbTranslations = serialize($translations);
  83. $sqlTransl = "INSERT INTO sk_term_taxonomy (term_id, taxonomy, description, parent, count)
  84. VALUES ($pollyId, 'post_translations', $dbTranslations, 0, 2)";
  85. $conn2->query($sqlTransl);
  86. }
  87. echo 'DOne';
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement