Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "";
  4. $password = "";
  5. $dbname1 = "";
  6. $dbname2 = "";
  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. news.discipline AS category
  30. FROM news_translates
  31. LEFT JOIN news ON news_translates.news_id = news.id
  32. WHERE lang_code='lv' AND (news.discipline='CounterStrike' OR news.discipline='CounterStrike_fe' OR news.discipline='CounterStrike_go')";
  33.  
  34. $result = $conn1->query($sql);
  35.  
  36. $conn2->query($term_relation_sql);
  37. $term_relation_id = $conn2->insert_id;
  38.  
  39.  
  40. foreach ($result as $key => $translate_lv) {
  41. $id = $translate_lv['id'];
  42. $lang = $translate_lv['local'];
  43. $author = $translate_lv['author'];
  44. $title = $translate_lv['title'];
  45. $text = $translate_lv['content'];
  46. $posted = $translate_lv['posted'];
  47. $comments = $translate_lv['comments'];
  48.  
  49. $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)
  50. VALUES ($author, $posted, $posted, $text, $title, '', 'publish', 'open', 'open', $id, '', '' , $posted, $posted, '', 0, 'http://skillz.dev/?p='.$id, 0, 'post', '', $comments)";
  51. $conn2->query($sql_lat);
  52. $latId = $conn2->insert_id;
  53.  
  54. $term_relation_sql = "INSERT INTO sk_term_relationships (object_id,term_taxonomy_id,term_order)
  55. VALUES ($latId, '66',0)";
  56.  
  57. $sql2 = $sql = "SELECT
  58. news_id AS id,
  59. lang_code AS locale,
  60. user_id AS author,
  61. title AS title,
  62. text AS content,
  63. FROM_UNIXTIME(date) AS posted,
  64. news.comments AS comments
  65. FROM news_translates
  66. LEFT JOIN news ON news_translates.news_id = news.id
  67. WHERE lang_code='ru' AND news_id=$latId";
  68. $result = $conn1->query($sql2);
  69.  
  70. $id = $result['id'];
  71. $lang = $result['local'];
  72. $author = $result['author'];
  73. $title = $result['title'];
  74. $text = $result['content'];
  75. $posted = $result['posted'];
  76. $comments = $result['comments'];
  77.  
  78. $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)
  79. VALUES ($author, $posted, $posted, $text, $title, '', 'publish', 'open', 'open', $id, '', '' , $posted, $posted, '', 0, 'http://skillz.dev/?p='.$id, 0, 'post', '', $comments)";
  80. $conn2->query($sql_ru);
  81. $ruId = $conn2->insert_id;
  82.  
  83. $term_relation_sql = "INSERT INTO sk_term_relationships (object_id,term_taxonomy_id,term_order)
  84. VALUES ($ruId, '66',0)";
  85.  
  86. $poly = 'pll_' . md5(uniqid(rand(), true));
  87. $pollyIns = "INSERT INTO sk_terms (name, slug, term_group)
  88. VALUES ($poly, $poly, 0)";
  89. $conn2->query($pollyIns);
  90. $pollyId = $conn2->insert_id;
  91.  
  92. $translations = ['lv' => $latId, 'ru' => $ruId];
  93. $dbTranslations = serialize($translations);
  94. $sqlTransl = "INSERT INTO sk_term_taxonomy (term_id, taxonomy, description, parent, count)
  95. VALUES ($pollyId, 'post_translations', $dbTranslations, 0, 2)";
  96. $conn2->query($sqlTransl);
  97. }
  98. echo 'DOne';
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement