PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/convert/resources/modules/posts.php

https://gitlab.com/mybbpl/merge-1.6-pl
PHP | 234 lines | 164 code | 44 blank | 26 comment | 20 complexity | 67716f1cb25c8874bae59394e8573705 MD5 | raw file
  1. <?php
  2. /**
  3. * Polish Language File developed by mybboard.pl for MyBB Merge System
  4. * Tłumaczenie: szulcu, Gigi
  5. * Poprawki: Ekipa Polskiego Supportu MyBB (mybboard.pl)
  6. * Wersja 1.0
  7. **/
  8. /**
  9. * MyBB 1.6
  10. * Copyright 2009 MyBB Group, All Rights Reserved
  11. *
  12. * Website: http://www.mybb.com
  13. * License: http://www.mybb.com/about/license
  14. */
  15. class Converter_Module_Posts extends Converter_Module
  16. {
  17. public $default_values = array(
  18. 'tid' => 0,
  19. 'replyto' => 0,
  20. 'subject' => '',
  21. 'username' => '',
  22. 'fid' => 0,
  23. 'uid' => 0,
  24. 'import_uid' => 0,
  25. 'username' => 0,
  26. 'dateline' => 0,
  27. 'message' => '',
  28. 'ipaddress' => '',
  29. 'longipaddress' => 0,
  30. 'includesig' => 1,
  31. 'smilieoff' => 0,
  32. 'edituid' => 0,
  33. 'edittime' => 0,
  34. 'icon' => 0,
  35. 'visible' => 1,
  36. 'posthash' => '',
  37. );
  38. /**
  39. * Insert post into database
  40. *
  41. * @param post The insert array going into the MyBB database
  42. */
  43. public function insert($data)
  44. {
  45. global $db, $output;
  46. $this->debug->log->datatrace('$data', $data);
  47. $output->print_progress("start", $data[$this->settings['progress_column']]);
  48. $unconverted_values = $data;
  49. // Call our currently module's process function
  50. $data = $converted_values = $this->convert_data($data);
  51. // Should loop through and fill in any values that aren't set based on the MyBB db schema or other standard default values
  52. $data = $this->process_default_values($data);
  53. foreach($data as $key => $value)
  54. {
  55. $insert_array[$key] = $db->escape_string($value);
  56. }
  57. unset($insert_array['import_pid']);
  58. unset($insert_array['import_uid']);
  59. $this->debug->log->datatrace('$insert_array', $insert_array);
  60. $db->insert_query("posts", $insert_array);
  61. $pid = $db->insert_id();
  62. $db->insert_query("post_trackers", array(
  63. 'pid' => intval($pid),
  64. 'import_pid' => intval($data['import_pid']),
  65. 'import_uid' => intval($data['import_uid'])
  66. ));
  67. $this->cache_posts[$data['import_pid']] = $pid;
  68. if(method_exists($this, "after_import"))
  69. {
  70. $this->after_import($unconverted_values, $converted_values, $pid);
  71. }
  72. $this->increment_tracker('posts');
  73. $output->print_progress("end");
  74. return $pid;
  75. }
  76. /**
  77. * Rebuild counters, and lastpost information right after importing posts
  78. *
  79. */
  80. public function counters_cleanup()
  81. {
  82. global $db, $output, $import_session;
  83. $output->print_header("Przebudowa liczników");
  84. $this->debug->log->trace0("Przebudowa liczników wątków, działów i statystyk");
  85. $output->construct_progress_bar();
  86. echo "<br />\nPrzebudowywanie liczników wątków, działów i statystyk...(To może chwilę potrwać)<br /><br />\n";
  87. echo "<br />\nPrzebudowywanie liczników wątków... ";
  88. flush();
  89. // Rebuild thread counters, forum counters, user post counters, last post* and thread username
  90. $query = $db->simple_select("threads", "COUNT(*) as count", "import_tid != 0");
  91. $num_imported_threads = $db->fetch_field($query, "count");
  92. $progress = $last_percent = 0;
  93. if($import_session['counters_cleanup_start'] < $num_imported_threads)
  94. {
  95. $this->debug->log->trace1("Rebuilding thread counters");
  96. $progress = $import_session['counters_cleanup_start'];
  97. $query = $db->simple_select("threads", "tid", "import_tid != 0", array('order_by' => 'tid', 'order_dir' => 'asc', 'limit_start' => intval($import_session['counters_cleanup_start']), 'limit' => 1000));
  98. while($thread = $db->fetch_array($query))
  99. {
  100. rebuild_thread_counters($thread['tid']);
  101. ++$progress;
  102. if(($progress % 5) == 0)
  103. {
  104. if(($progress % 100) == 0)
  105. {
  106. check_memory();
  107. }
  108. $percent = round(($progress/$num_imported_threads)*100, 1);
  109. if($percent != $last_percent)
  110. {
  111. $output->update_progress_bar($percent, "Przebudowa liczników dla wątku #{$thread['tid']}");
  112. }
  113. $last_percent = $percent;
  114. }
  115. }
  116. $import_session['counters_cleanup_start'] += $progress;
  117. if($import_session['counters_cleanup_start'] >= $num_imported_threads)
  118. {
  119. $this->debug->log->trace1("Zakończono przebudowę liczników wątków");
  120. $import_session['counters_cleanup'] = 0;
  121. echo "Zakończono.";
  122. flush();
  123. return;
  124. }
  125. $import_session['counters_cleanup'] = 1;
  126. return;
  127. }
  128. if($import_session['counters_cleanup_start'] >= $num_imported_threads)
  129. {
  130. $this->debug->log->trace1("Przebudowa liczników działów");
  131. echo "zakończono. <br />Przebudowywanie liczników działów... ";
  132. flush();
  133. $query = $db->simple_select("forums", "COUNT(*) as count", "import_fid != 0");
  134. $num_imported_forums = $db->fetch_field($query, "count");
  135. $progress = 0;
  136. $query = $db->simple_select("forums", "fid", "import_fid != 0", array('order_by' => 'fid', 'order_dir' => 'asc'));
  137. while($forum = $db->fetch_array($query))
  138. {
  139. rebuild_forum_counters($forum['fid']);
  140. ++$progress;
  141. $output->update_progress_bar(round((($progress/$num_imported_forums)*50), 1)+100, "Przebudowa liczników dla działu #{$forum['fid']}");
  142. }
  143. $output->update_progress_bar(150);
  144. $query = $db->simple_select("forums", "fid", "usepostcounts = 0");
  145. while($forum = $db->fetch_array($query))
  146. {
  147. $fids[] = $forum['fid'];
  148. }
  149. if(is_array($fids))
  150. {
  151. $fids = implode(',', $fids);
  152. }
  153. if($fids)
  154. {
  155. $fids = " AND fid NOT IN($fids)";
  156. }
  157. else
  158. {
  159. $fids = "";
  160. }
  161. $this->debug->log->trace1("Przebudowywanie liczników użytkowników");
  162. echo "zakończono. <br />Przebudowywanie liczników użytkowników... ";
  163. flush();
  164. $query = $db->simple_select("users", "COUNT(*) as count", "import_uid != 0");
  165. $num_imported_users = $db->fetch_field($query, "count");
  166. $progress = $last_percent = 0;
  167. $query = $db->simple_select("users", "uid", "import_uid != 0");
  168. while($user = $db->fetch_array($query))
  169. {
  170. $query2 = $db->simple_select("posts", "COUNT(*) AS post_count", "uid='{$user['uid']}' AND visible > 0{$fids}");
  171. $num_posts = $db->fetch_field($query2, "post_count");
  172. $db->free_result($query2);
  173. $db->update_query("users", array("postnum" => intval($num_posts)), "uid='{$user['uid']}'");
  174. ++$progress;
  175. $percent = round((($progress/$num_imported_users)*50)+150, 1);
  176. if($percent != $last_percent)
  177. {
  178. $output->update_progress_bar($percent, "Przebudowywanie licznika dla użytkownika #{$user['uid']}");
  179. }
  180. $last_percent = $percent;
  181. }
  182. // TODO: recount user posts doesn't seem to work
  183. $output->update_progress_bar(200, "Proszę czekać...");
  184. echo "zakończono.<br />";
  185. flush();
  186. sleep(3);
  187. }
  188. }
  189. }
  190. ?>