Advertisement
Guest User

Untitled

a guest
Mar 19th, 2021
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.18 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * bbPress Converter
  5. *
  6. * Based on the hard work of Adam Ellis
  7. *
  8. * @package bbPress
  9. * @subpackage Administration
  10. */
  11.  
  12. // Exit if accessed directly
  13. defined( 'ABSPATH' ) || exit;
  14.  
  15. if ( ! class_exists( 'BBP_Converter' ) ) :
  16. /**
  17. * Main BBP_Converter Class
  18. */
  19. class BBP_Converter {
  20.  
  21. /**
  22. * @var int Number of rows
  23. */
  24. public $max = 0;
  25.  
  26. /**
  27. * @var int Start
  28. */
  29. public $start = 0;
  30.  
  31. /**
  32. * @var int Step in converter process
  33. */
  34. public $step = 0;
  35.  
  36. /**
  37. * @var int Number of rows
  38. */
  39. public $rows = 0;
  40.  
  41. /**
  42. * @var int Maximum number of converter steps
  43. */
  44. public $max_steps = 17;
  45.  
  46. /**
  47. * @var int Number of rows in the current step
  48. */
  49. public $rows_in_step = 0;
  50.  
  51. /**
  52. * @var int Percent complete of current step
  53. */
  54. public $step_percentage = 0;
  55.  
  56. /**
  57. * @var int Percent complete of all step
  58. */
  59. public $total_percentage = 0;
  60.  
  61. /**
  62. * @var int Name of source forum platform
  63. */
  64. public $platform = '';
  65.  
  66. /**
  67. * @var BBP_Converter_Base Type of converter to use
  68. */
  69. public $converter = null;
  70.  
  71. /**
  72. * @var string Path to included platforms
  73. */
  74. public $converters_dir = '';
  75.  
  76. /**
  77. * @var array Map of steps to methods
  78. */
  79. private $steps = array(
  80. 1 => 'sync_table',
  81. 2 => 'users',
  82. 3 => 'passwords',
  83. 4 => 'forums',
  84. 5 => 'forum_hierarchy',
  85. 6 => 'forum_subscriptions',
  86. 7 => 'topics',
  87. 8 => 'topics_authors',
  88. 9 => 'stickies',
  89. 10 => 'super_stickies',
  90. 11 => 'closed_topics',
  91. 12 => 'topic_tags',
  92. 13 => 'topic_subscriptions',
  93. 14 => 'topic_favorites',
  94. 15 => 'replies',
  95. 16 => 'reply_authors',
  96. 17 => 'reply_hierarchy'
  97. );
  98.  
  99. /**
  100. * The main bbPress Converter loader
  101. *
  102. * @since 2.1.0 bbPress (r3813)
  103. */
  104. public function __construct() {
  105. $this->setup_globals();
  106. $this->setup_actions();
  107. }
  108.  
  109. /**
  110. * Admin globals
  111. *
  112. * @since 2.6.0 bbPress (r6598)
  113. */
  114. public function setup_globals() {
  115. $this->converters_dir = bbp_setup_admin()->admin_dir . 'converters/';
  116. }
  117.  
  118. /**
  119. * Setup the default actions
  120. *
  121. * @since 2.1.0 bbPress (r3813)
  122. */
  123. public function setup_actions() {
  124.  
  125. // Attach to the admin head with our ajax requests cycle and css
  126. add_action( 'admin_head-tools_page_bbp-converter', array( $this, 'admin_head' ) );
  127.  
  128. // Attach to the admin ajax request to process cycles
  129. add_action( 'wp_ajax_bbp_converter_process', array( $this, 'process_callback' ) );
  130. }
  131.  
  132. /**
  133. * Admin scripts
  134. *
  135. * @since 2.1.0 bbPress (r3813)
  136. */
  137. public function admin_head() {
  138.  
  139. // Enqueue scripts
  140. wp_enqueue_script( 'bbp-converter' );
  141.  
  142. // Localize JS
  143. wp_localize_script( 'bbp-converter', 'BBP_Converter', array(
  144.  
  145. // Nonce
  146. 'ajax_nonce' => wp_create_nonce( 'bbp_converter_process' ),
  147.  
  148. // UI State
  149. 'state' => array(
  150. 'delay' => (int) get_option( '_bbp_converter_delay_time', 2 ),
  151. 'started' => (bool) get_option( '_bbp_converter_step', 0 ),
  152. 'running' => false,
  153. 'status' => false,
  154. 'step_percent' => $this->step_percentage,
  155. 'total_percent' => $this->total_percentage
  156. ),
  157.  
  158. // Strings
  159. 'strings' => array(
  160.  
  161. // Button text
  162. 'button_start' => esc_html__( 'Start', 'bbpress' ),
  163. 'button_continue' => esc_html__( 'Continue', 'bbpress' ),
  164.  
  165. // Start button clicked
  166. 'start_start' => esc_html__( 'Starting Import...', 'bbpress' ),
  167. 'start_continue' => esc_html__( 'Continuing Import...', 'bbpress' ),
  168.  
  169. // Import
  170. 'import_complete' => esc_html__( 'Import Finished.', 'bbpress' ),
  171. 'import_stopped_user' => esc_html__( 'Import Stopped (by User.)', 'bbpress' ),
  172. 'import_error_halt' => esc_html__( 'Import Halted (Error.)', 'bbpress' ),
  173. 'import_error_db' => esc_html__( 'Database Connection Failed.', 'bbpress' ),
  174.  
  175. // Status
  176. 'status_complete' => esc_html__( 'Finished', 'bbpress' ),
  177. 'status_stopped' => esc_html__( 'Stopped', 'bbpress' ),
  178. 'status_starting' => esc_html__( 'Starting', 'bbpress' ),
  179. 'status_up_next' => esc_html__( 'Doing step %s...', 'bbpress' ),
  180. 'status_counting' => esc_html__( 'Next in %s seconds...', 'bbpress' )
  181. )
  182. ) );
  183. }
  184.  
  185. /**
  186. * Callback processor
  187. *
  188. * @since 2.1.0 bbPress (r3813)
  189. */
  190. public function process_callback() {
  191.  
  192. // Ready the converter
  193. $this->check_access();
  194. $this->maybe_set_memory();
  195. $this->maybe_restart();
  196. $this->setup_options();
  197. $this->maybe_update_options();
  198.  
  199. // Bail if no converter
  200. if ( ! empty( $this->converter ) ) {
  201. $this->do_steps();
  202. }
  203. }
  204.  
  205. /**
  206. * Wrap the converter output in HTML, so styling can be applied
  207. *
  208. * @since 2.1.0 bbPress (r4052)
  209. *
  210. * @param string $output
  211. */
  212. private function converter_response( $output = '' ) {
  213.  
  214. // Sanitize output
  215. $output = wp_kses_data( $output );
  216.  
  217. // Maybe prepend the step
  218. if ( ! empty( $this->step ) ) {
  219.  
  220. // Include percentage
  221. if ( ! empty( $this->rows_in_step ) ) {
  222. $progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span><span class="mini-step">%s</span>', $this->step, $output, $this->step_percentage . '%' );
  223.  
  224. // Don't include percentage
  225. } else {
  226. $progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span>', $this->step, $output );
  227. }
  228.  
  229. // Raw text
  230. } else {
  231. $progress = $output;
  232. }
  233.  
  234. // Output
  235. wp_send_json_success( array(
  236. 'query' => get_option( '_bbp_converter_query', '' ),
  237. 'current_step' => $this->step,
  238. 'final_step' => $this->max_steps,
  239. 'rows_in_step' => $this->rows_in_step,
  240. 'step_percent' => $this->step_percentage,
  241. 'total_percent' => $this->total_percentage,
  242. 'progress' => $progress
  243. ) );
  244. }
  245.  
  246. /**
  247. * Attempt to increase memory and set other system settings
  248. *
  249. * @since 2.6.0 bbPress (r6460)
  250. */
  251. private function maybe_set_memory() {
  252.  
  253. // Filter args
  254. $r = apply_filters( 'bbp_converter_php_ini_overrides', array(
  255. 'implicit_flush' => '1',
  256. 'memory_limit' => '256M',
  257. 'max_execution_time' => HOUR_IN_SECONDS * 6
  258. ) );
  259.  
  260. // Get disabled PHP functions (to avoid using them)
  261. $disabled = explode( ',', @ini_get( 'disable_functions' ) );
  262.  
  263. // Maybe avoid terminating when the client goes away (if function is not disabled)
  264. if ( ! in_array( 'ignore_user_abort', $disabled, true ) ) {
  265. @ignore_user_abort( true );
  266. }
  267.  
  268. // Maybe set memory & time limits, and flush style (if function is not disabled)
  269. if ( ! in_array( 'ini_set', $disabled, true ) ) {
  270. foreach ( $r as $key => $value ) {
  271. @ini_set( $key, $value );
  272. }
  273. }
  274. }
  275.  
  276. /**
  277. * Maybe restart the converter
  278. *
  279. * @since 2.6.0 bbPress (r6460)
  280. */
  281. private function maybe_restart() {
  282.  
  283. // Save step and count so that it can be restarted.
  284. if ( ! get_option( '_bbp_converter_step' ) || ! empty( $_POST['_bbp_converter_restart'] ) ) {
  285. $this->step = 1;
  286. $this->start = 0;
  287. $this->step_percentage = 0;
  288. $this->total_percentage = 0;
  289. $this->rows_in_step = 0;
  290. $this->maybe_update_options();
  291. }
  292. }
  293.  
  294. /**
  295. * Maybe update options
  296. *
  297. * @since 2.6.0 bbPress (r6637)
  298. */
  299. private function maybe_update_options() {
  300.  
  301. // Default options
  302. $options = array(
  303.  
  304. // Step & Start
  305. '_bbp_converter_step' => $this->step,
  306. '_bbp_converter_start' => $this->start,
  307. '_bbp_converter_rows_in_step' => $this->rows_in_step,
  308.  
  309. // Halt
  310. '_bbp_converter_halt' => ! empty( $_POST['_bbp_converter_halt'] )
  311. ? (int) $_POST['_bbp_converter_halt']
  312. : 0,
  313.  
  314. // Rows (bound between 1 and 5000)
  315. '_bbp_converter_rows' => ! empty( $_POST['_bbp_converter_rows'] )
  316. ? min( max( (int) $_POST['_bbp_converter_rows'], 1 ), 5000 )
  317. : 0,
  318.  
  319. // Platform
  320. '_bbp_converter_platform' => ! empty( $_POST['_bbp_converter_platform' ] )
  321. ? sanitize_text_field( $_POST['_bbp_converter_platform' ] )
  322. : '',
  323.  
  324. // Convert Users
  325. '_bbp_converter_convert_users' => ! empty( $_POST['_bbp_converter_convert_users'] )
  326. ? (bool) $_POST['_bbp_converter_convert_users']
  327. : false,
  328.  
  329. // DB User
  330. '_bbp_converter_db_user' => ! empty( $_POST['_bbp_converter_db_user'] )
  331. ? sanitize_text_field( $_POST['_bbp_converter_db_user'] )
  332. : '',
  333.  
  334. // DB Password
  335. '_bbp_converter_db_pass' => ! empty( $_POST['_bbp_converter_db_pass'] )
  336. ? sanitize_text_field( $_POST['_bbp_converter_db_pass'] )
  337. : '',
  338.  
  339. // DB Name
  340. '_bbp_converter_db_name' => ! empty( $_POST['_bbp_converter_db_name'] )
  341. ? sanitize_text_field( $_POST['_bbp_converter_db_name'] )
  342. : '',
  343.  
  344. // DB Server
  345. '_bbp_converter_db_server' => ! empty( $_POST['_bbp_converter_db_server'] )
  346. ? sanitize_text_field( $_POST['_bbp_converter_db_server'] )
  347. : '',
  348.  
  349. // DB Port
  350. '_bbp_converter_db_port' => ! empty( $_POST['_bbp_converter_db_port'] )
  351. ? (int) sanitize_text_field( $_POST['_bbp_converter_db_port'] )
  352. : '',
  353.  
  354. // DB Table Prefix
  355. '_bbp_converter_db_prefix' => ! empty( $_POST['_bbp_converter_db_prefix'] )
  356. ? sanitize_text_field( $_POST['_bbp_converter_db_prefix'] )
  357. : ''
  358. );
  359.  
  360. // Update/delete options
  361. foreach ( $options as $key => $value ) {
  362. update_option( $key, $value );
  363. }
  364. }
  365.  
  366. /**
  367. * Setup converter options
  368. *
  369. * @since 2.6.0 bbPress (r6460)
  370. */
  371. private function setup_options() {
  372.  
  373. // Set starting point & rows
  374. $this->step = (int) get_option( '_bbp_converter_step', 1 );
  375. $this->start = (int) get_option( '_bbp_converter_start', 0 );
  376. $this->rows = (int) get_option( '_bbp_converter_rows', 100 );
  377. $this->rows_in_step = (int) get_option( '_bbp_converter_rows_in_step', 0 );
  378.  
  379. // Set boundaries
  380. $this->max = ( $this->start + $this->rows ) - 1;
  381.  
  382. // Set platform
  383. $this->platform = get_option( '_bbp_converter_platform' );
  384.  
  385. // Total percentage
  386. $this->total_percentage = round( ( $this->step / $this->max_steps ) * 100, 2 );
  387.  
  388. // Total mini steps
  389. if ( $this->rows_in_step > 0 ) {
  390. $total_mini_steps = ceil( $this->rows_in_step / $this->rows );
  391. $current_mini_step = ceil( $this->start / $this->rows );
  392. $this->step_percentage = round( ( $current_mini_step / $total_mini_steps ) * 100, 2 );
  393. } else {
  394. $this->step_percentage = 0;
  395. }
  396.  
  397. // Maybe include the appropriate converter.
  398. if ( ! empty( $this->platform ) ) {
  399. $this->converter = bbp_new_converter( $this->platform );
  400. }
  401. }
  402.  
  403. /**
  404. * Check that user can access the converter
  405. *
  406. * @since 2.6.0 bbPress (r6460)
  407. */
  408. private function check_access() {
  409.  
  410. // Bail if user cannot view import page
  411. if ( ! current_user_can( 'bbp_tools_import_page' ) ) {
  412. wp_die( '0' );
  413. }
  414.  
  415. // Verify intent
  416. check_ajax_referer( 'bbp_converter_process' );
  417. }
  418.  
  419. /**
  420. * Reset the converter
  421. *
  422. * @since 2.6.0 bbPress (r6460)
  423. */
  424. private function reset() {
  425. update_option( '_bbp_converter_step', 0 );
  426. update_option( '_bbp_converter_start', 0 );
  427. update_option( '_bbp_converter_rows_in_step', 0 );
  428. update_option( '_bbp_converter_query', '' );
  429. }
  430.  
  431. /**
  432. * Bump the step and reset the start
  433. *
  434. * @since 2.6.0 bbPress (r6460)
  435. */
  436. private function bump_step() {
  437.  
  438. // Next step
  439. $next_step = (int) ( $this->step + 1 );
  440.  
  441. // Don't let step go over max
  442. $step = ( $next_step <= $this->max_steps )
  443. ? $next_step
  444. : 0;
  445.  
  446. // Update step and start at 0
  447. update_option( '_bbp_converter_step', $step );
  448. update_option( '_bbp_converter_start', 0 );
  449. update_option( '_bbp_converter_rows_in_step', 0 );
  450. }
  451.  
  452. /**
  453. * Bump the start within the current step
  454. *
  455. * @since 2.6.0 bbPress (r6460)
  456. */
  457. private function bump_start() {
  458.  
  459. // Set rows in step from option
  460. $this->rows_in_step = get_option( '_bbp_converter_rows_in_step', 0 );
  461.  
  462. // Get rows to start from
  463. $start = (int) ( $this->start + $this->rows );
  464.  
  465. // Enforce maximum if exists
  466. if ( $this->rows_in_step > 0 ) {
  467.  
  468. // Start cannot be larger than total rows
  469. if ( $start > $this->rows_in_step ) {
  470. $start = $this->rows_in_step;
  471. }
  472.  
  473. // Max can't be greater than total rows
  474. if ( $this->max > $this->rows_in_step ) {
  475. $this->max = $this->rows_in_step;
  476. }
  477. }
  478.  
  479. // Update the start option
  480. update_option( '_bbp_converter_start', $start );
  481. }
  482.  
  483. /**
  484. * Do the converter step
  485. *
  486. * @since 2.6.0 bbPress (r6460)
  487. */
  488. private function do_steps() {
  489.  
  490. // Step exists in map, and method exists
  491. if ( isset( $this->steps[ $this->step ] ) && method_exists( $this, "step_{$this->steps[ $this->step ]}" ) ) {
  492. return call_user_func( array( $this, "step_{$this->steps[ $this->step ]}" ) );
  493. }
  494.  
  495. // Done!
  496. $this->step_done();
  497. }
  498.  
  499. /** Steps *****************************************************************/
  500.  
  501. /**
  502. * Maybe clean the sync table
  503. *
  504. * @since 2.6.0 bbPress (r6513)
  505. */
  506. private function step_sync_table() {
  507. if ( true === $this->converter->clean ) {
  508. if ( $this->converter->clean() ) {
  509. $this->bump_step();
  510. $this->sync_table( true );
  511.  
  512. empty( $this->start )
  513. ? $this->converter_response( esc_html__( 'Readying sync-table', 'bbpress' ) )
  514. : $this->converter_response( esc_html__( 'Sync-table ready', 'bbpress' ) );
  515. } else {
  516. $this->bump_start();
  517. $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s through %2$s)', 'bbpress' ), $this->start, $this->max ) );
  518. }
  519.  
  520. $this->converter->clean = false;
  521. } else {
  522. $this->bump_step();
  523. $this->sync_table( false );
  524. $this->converter_response( esc_html__( 'Skipping sync-table clean-up', 'bbpress' ) );
  525. }
  526. }
  527.  
  528. /**
  529. * Maybe convert users
  530. *
  531. * @since 2.6.0 bbPress (r6513)
  532. */
  533. private function step_users() {
  534. if ( true === $this->converter->convert_users ) {
  535. if ( $this->converter->convert_users( $this->start ) ) {
  536. $this->bump_step();
  537.  
  538. empty( $this->start )
  539. ? $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) )
  540. : $this->converter_response( esc_html__( 'All users imported', 'bbpress' ) );
  541. } else {
  542. $this->bump_start();
  543. $this->converter_response( sprintf( esc_html__( 'Converting users (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  544. }
  545. } else {
  546. $this->bump_step();
  547. $this->converter_response( esc_html__( 'Skipping user clean-up', 'bbpress' ) );
  548. }
  549. }
  550.  
  551. /**
  552. * Maybe clean up passwords
  553. *
  554. * @since 2.6.0 bbPress (r6513)
  555. */
  556. private function step_passwords() {
  557. if ( true === $this->converter->convert_users ) {
  558. if ( $this->converter->clean_passwords( $this->start ) ) {
  559. $this->bump_step();
  560.  
  561. empty( $this->start )
  562. ? $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) )
  563. : $this->converter_response( esc_html__( 'All passwords cleared', 'bbpress' ) );
  564. } else {
  565. $this->bump_start();
  566. $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s through %2$s)', 'bbpress' ), $this->start, $this->max ) );
  567. }
  568. } else {
  569. $this->bump_step();
  570. $this->converter_response( esc_html__( 'Skipping password clean-up', 'bbpress' ) );
  571. }
  572. }
  573.  
  574. /**
  575. * Maybe convert forums
  576. *
  577. * @since 2.6.0 bbPress (r6513)
  578. */
  579. private function step_forums() {
  580. if ( $this->converter->convert_forums( $this->start ) ) {
  581. $this->bump_step();
  582.  
  583. empty( $this->start )
  584. ? $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) )
  585. : $this->converter_response( esc_html__( 'All forums imported', 'bbpress' ) );
  586. } else {
  587. $this->bump_start();
  588. $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  589. }
  590. }
  591.  
  592. /**
  593. * Maybe walk the forum hierarchy
  594. *
  595. * @since 2.6.0 bbPress (r6513)
  596. */
  597. private function step_forum_hierarchy() {
  598. if ( $this->converter->convert_forum_parents( $this->start ) ) {
  599. $this->bump_step();
  600.  
  601. empty( $this->start )
  602. ? $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) )
  603. : $this->converter_response( esc_html__( 'All forum parents imported', 'bbpress' ) );
  604. } else {
  605. $this->bump_start();
  606. $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  607. }
  608. }
  609.  
  610. /**
  611. * Maybe convert forum subscriptions
  612. *
  613. * @since 2.6.0 bbPress (r6513)
  614. */
  615. private function step_forum_subscriptions() {
  616. if ( $this->converter->convert_forum_subscriptions( $this->start ) ) {
  617. $this->bump_step();
  618.  
  619. empty( $this->start )
  620. ? $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) )
  621. : $this->converter_response( esc_html__( 'All forum subscriptions imported', 'bbpress' ) );
  622. } else {
  623. $this->bump_start();
  624. $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  625. }
  626. }
  627.  
  628. /**
  629. * Maybe convert topics
  630. *
  631. * @since 2.6.0 bbPress (r6513)
  632. */
  633. private function step_topics() {
  634. if ( $this->converter->convert_topics( $this->start ) ) {
  635. $this->bump_step();
  636.  
  637. empty( $this->start )
  638. ? $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) )
  639. : $this->converter_response( esc_html__( 'All topics imported', 'bbpress' ) );
  640. } else {
  641. $this->bump_start();
  642. $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  643. }
  644. }
  645.  
  646. /**
  647. * Maybe convert topic authors (anonymous)
  648. *
  649. * @since 2.6.0 bbPress (r6513)
  650. */
  651. private function step_topics_authors() {
  652. if ( $this->converter->convert_anonymous_topic_authors( $this->start ) ) {
  653. $this->bump_step();
  654.  
  655. empty( $this->start )
  656. ? $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) )
  657. : $this->converter_response( esc_html__( 'All anonymous topic authors imported', 'bbpress' ) );
  658. } else {
  659. //$this->bump_start();
  660. $this->bump_step();
  661. //$this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  662. }
  663. }
  664.  
  665. /**
  666. * Maybe convert sticky topics (not super stickies)
  667. *
  668. * @since 2.6.0 bbPress (r6513)
  669. */
  670. private function step_stickies() {
  671. if ( $this->converter->convert_topic_stickies( $this->start ) ) {
  672. $this->bump_step();
  673.  
  674. empty( $this->start )
  675. ? $this->converter_response( esc_html__( 'No stickies to import', 'bbpress' ) )
  676. : $this->converter_response( esc_html__( 'All stickies imported', 'bbpress' ) );
  677. } else {
  678. $this->bump_start();
  679. $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  680. }
  681. }
  682.  
  683. /**
  684. * Maybe convert super-sticky topics (not per-forum)
  685. *
  686. * @since 2.6.0 bbPress (r6513)
  687. */
  688. private function step_super_stickies() {
  689. if ( $this->converter->convert_topic_super_stickies( $this->start ) ) {
  690. $this->bump_step();
  691.  
  692. empty( $this->start )
  693. ? $this->converter_response( esc_html__( 'No super stickies to import', 'bbpress' ) )
  694. : $this->converter_response( esc_html__( 'All super stickies imported', 'bbpress' ) );
  695. } else {
  696. $this->bump_start();
  697. $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  698. }
  699. }
  700.  
  701. /**
  702. * Maybe close converted topics
  703. *
  704. * @since 2.6.0 bbPress (r6513)
  705. */
  706. private function step_closed_topics() {
  707. if ( $this->converter->convert_topic_closed_topics( $this->start ) ) {
  708. $this->bump_step();
  709.  
  710. empty( $this->start )
  711. ? $this->converter_response( esc_html__( 'No closed topics to import', 'bbpress' ) )
  712. : $this->converter_response( esc_html__( 'All closed topics imported', 'bbpress' ) );
  713. } else {
  714. $this->bump_start();
  715. $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  716. }
  717. }
  718.  
  719. /**
  720. * Maybe convert topic tags
  721. *
  722. * @since 2.6.0 bbPress (r6513)
  723. */
  724. private function step_topic_tags() {
  725. if ( $this->converter->convert_tags( $this->start ) ) {
  726. $this->bump_step();
  727.  
  728. empty( $this->start )
  729. ? $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) )
  730. : $this->converter_response( esc_html__( 'All topic tags imported', 'bbpress' ) );
  731. } else {
  732. $this->bump_start();
  733. $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  734. }
  735. }
  736.  
  737. /**
  738. * Maybe convert topic subscriptions
  739. *
  740. * @since 2.6.0 bbPress (r6513)
  741. */
  742. private function step_topic_subscriptions() {
  743. if ( $this->converter->convert_topic_subscriptions( $this->start ) ) {
  744. $this->bump_step();
  745.  
  746. empty( $this->start )
  747. ? $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) )
  748. : $this->converter_response( esc_html__( 'All topic subscriptions imported', 'bbpress' ) );
  749. } else {
  750. $this->bump_start();
  751. $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  752. }
  753. }
  754.  
  755. /**
  756. * Maybe convert topic favorites
  757. *
  758. * @since 2.6.0 bbPress (r6513)
  759. */
  760. private function step_topic_favorites() {
  761. if ( $this->converter->convert_favorites( $this->start ) ) {
  762. $this->bump_step();
  763.  
  764. empty( $this->start )
  765. ? $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) )
  766. : $this->converter_response( esc_html__( 'All favorites imported', 'bbpress' ) );
  767. } else {
  768. $this->bump_start();
  769. $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  770. }
  771. }
  772.  
  773. /**
  774. * Maybe convert replies
  775. *
  776. * @since 2.6.0 bbPress (r6513)
  777. */
  778. private function step_replies() {
  779. if ( $this->converter->convert_replies( $this->start ) ) {
  780. $this->bump_step();
  781.  
  782. empty( $this->start )
  783. ? $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) )
  784. : $this->converter_response( esc_html__( 'All replies imported', 'bbpress' ) );
  785. } else {
  786. $this->bump_start();
  787. $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  788. }
  789. }
  790.  
  791. /**
  792. * Maybe convert reply authors (anonymous)
  793. *
  794. * @since 2.6.0 bbPress (r6513)
  795. */
  796. private function step_reply_authors() {
  797. if ( $this->converter->convert_anonymous_reply_authors( $this->start ) ) {
  798. $this->bump_step();
  799.  
  800. empty( $this->start )
  801. ? $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) )
  802. : $this->converter_response( esc_html__( 'All anonymous reply authors imported', 'bbpress' ) );
  803. } else {
  804. $this->bump_start();
  805. $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  806. }
  807. }
  808.  
  809. /**
  810. * Maybe convert the threaded reply hierarchy
  811. *
  812. * @since 2.6.0 bbPress (r6513)
  813. */
  814. private function step_reply_hierarchy() {
  815. if ( $this->converter->convert_reply_to_parents( $this->start ) ) {
  816. $this->bump_step();
  817.  
  818. empty( $this->start )
  819. ? $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) )
  820. : $this->converter_response( esc_html__( 'All threaded replies imported', 'bbpress' ) );
  821. } else {
  822. $this->bump_start();
  823. $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
  824. }
  825. }
  826.  
  827. /**
  828. * Done!
  829. *
  830. * @since 2.6.0 bbPress (r6513)
  831. */
  832. private function step_done() {
  833. $this->reset();
  834. $this->converter_response( esc_html__( 'Import Finished', 'bbpress' ) );
  835. }
  836.  
  837. /** Helper Table **********************************************************/
  838.  
  839. /**
  840. * Create Tables for fast syncing
  841. *
  842. * @since 2.1.0 bbPress (r3813)
  843. */
  844. public static function sync_table( $drop = false ) {
  845.  
  846. // Setup DB
  847. $bbp_db = bbp_db();
  848. $table_name = $bbp_db->prefix . 'bbp_converter_translator';
  849. $table_exists = $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name;
  850.  
  851. // Maybe drop the sync table
  852. if ( ( true === $drop ) && ( true === $table_exists ) ) {
  853. $bbp_db->query( "DROP TABLE {$table_name}" );
  854. }
  855.  
  856. // Maybe include the upgrade functions, for dbDelta()
  857. if ( ! function_exists( 'dbDelta' ) ) {
  858. require_once ABSPATH . '/wp-admin/includes/upgrade.php';
  859. }
  860.  
  861. // Defaults
  862. $sql = array();
  863. $charset_collate = '';
  864.  
  865. // https://bbpress.trac.wordpress.org/ticket/3145
  866. $max_index_length = 75;
  867.  
  868. // Maybe override the character set
  869. if ( ! empty( $bbp_db->charset ) ) {
  870. $charset_collate .= "DEFAULT CHARACTER SET {$bbp_db->charset}";
  871. }
  872.  
  873. // Maybe override the collation
  874. if ( ! empty( $bbp_db->collate ) ) {
  875. $charset_collate .= " COLLATE {$bbp_db->collate}";
  876. }
  877.  
  878. /** Translator ********************************************************/
  879.  
  880. $sql[] = "CREATE TABLE {$table_name} (
  881. meta_id mediumint(8) unsigned not null auto_increment,
  882. value_type varchar(25) null,
  883. value_id bigint(20) unsigned not null default '0',
  884. meta_key varchar({$max_index_length}) null,
  885. meta_value varchar({$max_index_length}) null,
  886. PRIMARY KEY (meta_id),
  887. KEY value_id (value_id),
  888. KEY meta_join (meta_key({$max_index_length}), meta_value({$max_index_length}))
  889. ) {$charset_collate}";
  890.  
  891. dbDelta( $sql );
  892. }
  893. }
  894. endif;
  895.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement