PluginProbe
bbPress / 2.6.19
bbPress v2.6.19
2.6.19 2.6.18 2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 All 74 releases
bbpress / includes / admin / classes / class-bbp-converter.php

class-bbp-converter.php in bbPress 2.6.19, at includes/admin/classes/class-bbp-converter.php

955 lines 28.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 (r3816)
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 (r6601)
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 (r3816)
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 (r3816)
136 * @since 2.6.19 bbPress (r7739) Stop autoloading the saved source password.
137 */
138 public function admin_head() {
139 // WordPress 6.4+ can stop autoloading an existing option without changing it.
140 if ( function_exists( 'wp_set_option_autoload_values' ) ) {
141 wp_set_option_autoload_values( array( '_bbp_converter_db_pass' => false ) );
142 }
143
144 // Enqueue scripts
145 wp_enqueue_script( 'bbp-converter' );
146
147 // Localize JS
148 wp_localize_script(
149 'bbp-converter',
150 'BBP_Converter',
151 array(
152
153 // Nonce
154 'ajax_nonce' => wp_create_nonce( 'bbp_converter_process' ),
155
156 // UI State
157 'state' => array(
158 'delay' => (int) get_option( '_bbp_converter_delay_time', 2 ),
159 'started' => (bool) get_option( '_bbp_converter_step', 0 ),
160 'running' => false,
161 'status' => false,
162 'step_percent' => $this->step_percentage,
163 'total_percent' => $this->total_percentage
164 ),
165
166 // Strings
167 'strings' => array(
168
169 // Button text
170 'button_start' => esc_html__( 'Start', 'bbpress' ),
171 'button_continue' => esc_html__( 'Continue', 'bbpress' ),
172
173 // Start button clicked
174 'start_start' => esc_html__( 'Starting Import...', 'bbpress' ),
175 'start_continue' => esc_html__( 'Continuing Import...', 'bbpress' ),
176
177 // Import
178 'import_complete' => esc_html__( 'Import Finished.', 'bbpress' ),
179 'import_stopped_user' => esc_html__( 'Import Stopped (by User.)', 'bbpress' ),
180 'import_error_halt' => esc_html__( 'Import Halted (Error.)', 'bbpress' ),
181 'import_error_db' => esc_html__( 'Database Connection Failed.', 'bbpress' ),
182
183 // Status
184 'status_complete' => esc_html__( 'Finished', 'bbpress' ),
185 'status_stopped' => esc_html__( 'Stopped', 'bbpress' ),
186 'status_starting' => esc_html__( 'Starting', 'bbpress' ),
187 /* translators: %s: Current step number or name */
188 'status_up_next' => esc_html__( 'Doing step %s...', 'bbpress' ),
189 /* translators: %s: Number of seconds until next action */
190 'status_counting' => esc_html__( 'Next in %s seconds...', 'bbpress' )
191 )
192 )
193 );
194 }
195
196 /**
197 * Callback processor
198 *
199 * @since 2.1.0 bbPress (r3816)
200 */
201 public function process_callback() {
202
203 // Ready the converter
204 $this->check_access();
205
206 // Reject unsafe source table names before saving options or importing.
207 $db_prefix = isset( $_POST['_bbp_converter_db_prefix'] )
208 ? wp_unslash( $_POST['_bbp_converter_db_prefix'] )
209 : '';
210 if ( ! bbp_is_valid_converter_prefix( $db_prefix ) ) {
211 wp_send_json_error( array( 'message' => esc_html__( 'Invalid source database table prefix.', 'bbpress' ) ) );
212 }
213
214 $this->maybe_set_memory();
215 $this->maybe_restart();
216 $this->setup_options();
217 $this->maybe_update_options();
218
219 // A valid submitted prefix may repair an invalid saved prefix.
220 if ( empty( $this->converter ) ) {
221 $this->setup_options();
222 }
223
224 // Bail if no converter
225 if ( ! empty( $this->converter ) ) {
226 $this->do_steps();
227 }
228 }
229
230 /**
231 * Wrap the converter output in HTML, so styling can be applied
232 *
233 * @since 2.6.0 bbPress (r6601)
234 *
235 * @param string $output
236 */
237 private function converter_response( $output = '' ) {
238
239 // Sanitize output
240 $output = wp_kses_data( $output );
241
242 // Maybe prepend the step
243 if ( ! empty( $this->step ) ) {
244
245 // Include percentage
246 if ( ! empty( $this->rows_in_step ) ) {
247 $progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span><span class="mini-step">%s</span>', $this->step, $output, $this->step_percentage . '%' );
248
249 // Don't include percentage
250 } else {
251 $progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span>', $this->step, $output );
252 }
253
254 // Raw text
255 } else {
256 $progress = $output;
257 }
258
259 // Output
260 wp_send_json_success(
261 array(
262 'query' => get_option( '_bbp_converter_query', '' ),
263 'current_step' => $this->step,
264 'final_step' => $this->max_steps,
265 'rows_in_step' => $this->rows_in_step,
266 'step_percent' => $this->step_percentage,
267 'total_percent' => $this->total_percentage,
268 'progress' => $progress
269 )
270 );
271 }
272
273 /**
274 * Attempt to increase memory and set other system settings
275 *
276 * @since 2.6.0 bbPress (r6460)
277 */
278 private function maybe_set_memory() {
279
280 // Filter args
281 $r = apply_filters(
282 'bbp_converter_php_ini_overrides',
283 array(
284 'implicit_flush' => '1',
285 'memory_limit' => '256M',
286 'max_execution_time' => HOUR_IN_SECONDS * 6
287 )
288 );
289
290 // Get disabled PHP functions (to avoid using them)
291 $disabled = explode( ',', @ini_get( 'disable_functions' ) ); // phpcs:ignore
292
293 // Maybe avoid terminating when the client goes away (if function is not disabled)
294 if ( ! in_array( 'ignore_user_abort', $disabled, true ) ) {
295 @ignore_user_abort( true ); // phpcs:ignore
296 }
297
298 // Maybe set memory & time limits, and flush style (if function is not disabled)
299 if ( ! in_array( 'ini_set', $disabled, true ) ) {
300 foreach ( $r as $key => $value ) {
301 @ini_set( $key, $value ); // phpcs:ignore
302 }
303 }
304 }
305
306 /**
307 * Maybe restart the converter
308 *
309 * @since 2.6.0 bbPress (r6460)
310 */
311 private function maybe_restart() {
312
313 // Save step and count so that it can be restarted.
314 if ( ! get_option( '_bbp_converter_step' ) || ! empty( $_POST['_bbp_converter_restart'] ) ) {
315 $this->step = 1;
316 $this->start = 0;
317 $this->step_percentage = 0;
318 $this->total_percentage = 0;
319 $this->rows_in_step = 0;
320 $this->maybe_update_options();
321 }
322 }
323
324 /**
325 * Maybe update options
326 *
327 * @since 2.6.0 bbPress (r6514)
328 * @since 2.6.19 bbPress (r7739) Keep or explicitly clear a saved source password.
329 */
330 private function maybe_update_options() {
331
332 // Default options
333 $options = array(
334
335 // Step & Start
336 '_bbp_converter_step' => $this->step,
337 '_bbp_converter_start' => $this->start,
338 '_bbp_converter_rows_in_step' => $this->rows_in_step,
339
340 // Halt
341 '_bbp_converter_halt' => ! empty( $_POST['_bbp_converter_halt'] )
342 ? (int) $_POST['_bbp_converter_halt']
343 : 0,
344
345 // Rows (bound between 1 and 5000)
346 '_bbp_converter_rows' => ! empty( $_POST['_bbp_converter_rows'] )
347 ? min( max( (int) $_POST['_bbp_converter_rows'], 1 ), 5000 )
348 : 0,
349
350 // Platform
351 '_bbp_converter_platform' => ! empty( $_POST['_bbp_converter_platform'] )
352 ? sanitize_text_field( $_POST['_bbp_converter_platform'] )
353 : '',
354
355 // Convert Users
356 '_bbp_converter_convert_users' => ! empty( $_POST['_bbp_converter_convert_users'] )
357 ? (bool) $_POST['_bbp_converter_convert_users']
358 : false,
359
360 // DB User
361 '_bbp_converter_db_user' => ! empty( $_POST['_bbp_converter_db_user'] )
362 ? sanitize_text_field( $_POST['_bbp_converter_db_user'] )
363 : '',
364
365 // DB Name
366 '_bbp_converter_db_name' => ! empty( $_POST['_bbp_converter_db_name'] )
367 ? sanitize_text_field( $_POST['_bbp_converter_db_name'] )
368 : '',
369
370 // DB Server
371 '_bbp_converter_db_server' => ! empty( $_POST['_bbp_converter_db_server'] )
372 ? sanitize_text_field( $_POST['_bbp_converter_db_server'] )
373 : '',
374
375 // DB Port
376 '_bbp_converter_db_port' => ! empty( $_POST['_bbp_converter_db_port'] )
377 ? (int) sanitize_text_field( $_POST['_bbp_converter_db_port'] )
378 : '',
379
380 // DB Table Prefix
381 '_bbp_converter_db_prefix' => ! empty( $_POST['_bbp_converter_db_prefix'] )
382 ? sanitize_text_field( $_POST['_bbp_converter_db_prefix'] )
383 : ''
384 );
385
386 // Saving site-level converter settings must not change the account option.
387 if ( ! current_user_can( 'bbp_tools_import_users' ) ) {
388 unset( $options['_bbp_converter_convert_users'] );
389 }
390
391 // Update/delete options
392 foreach ( $options as $key => $value ) {
393 update_option( $key, $value );
394 }
395
396 // A blank password keeps the saved value; clearing it is explicit.
397 if ( isset( $_POST['_bbp_converter_db_pass'] ) && is_string( $_POST['_bbp_converter_db_pass'] ) && '' !== $_POST['_bbp_converter_db_pass'] ) {
398 update_option( '_bbp_converter_db_pass', wp_unslash( $_POST['_bbp_converter_db_pass'] ), false );
399 } elseif ( ! empty( $_POST['_bbp_converter_db_pass_clear'] ) || false === get_option( '_bbp_converter_db_pass', false ) ) {
400 update_option( '_bbp_converter_db_pass', '', false );
401 }
402 }
403
404 /**
405 * Setup converter options
406 *
407 * @since 2.6.0 bbPress (r6460)
408 */
409 private function setup_options() {
410
411 // Set starting point & rows
412 $this->step = (int) get_option( '_bbp_converter_step', 1 );
413 $this->start = (int) get_option( '_bbp_converter_start', 0 );
414 $this->rows = (int) get_option( '_bbp_converter_rows', 100 );
415 $this->rows_in_step = (int) get_option( '_bbp_converter_rows_in_step', 0 );
416
417 // Set boundaries
418 $this->max = ( $this->start + $this->rows ) - 1;
419
420 // Set platform
421 $this->platform = get_option( '_bbp_converter_platform' );
422
423 // Total percentage
424 $this->total_percentage = round( ( $this->step / $this->max_steps ) * 100, 2 );
425
426 // Total mini steps
427 if ( $this->rows_in_step > 0 ) {
428 $total_mini_steps = ceil( $this->rows_in_step / $this->rows );
429 $current_mini_step = ceil( $this->start / $this->rows );
430 $this->step_percentage = round( ( $current_mini_step / $total_mini_steps ) * 100, 2 );
431 } else {
432 $this->step_percentage = 0;
433 }
434
435 // Maybe include the appropriate converter.
436 if ( ! empty( $this->platform ) ) {
437 $this->converter = bbp_new_converter( $this->platform );
438 }
439 }
440
441 /**
442 * Check that user can access the converter
443 *
444 * @since 2.6.0 bbPress (r6460)
445 */
446 private function check_access() {
447
448 // Bail if user cannot view import page
449 if ( ! current_user_can( 'bbp_tools_import_page' ) ) {
450 wp_die( '0' );
451 }
452
453 // Verify intent
454 check_ajax_referer( 'bbp_converter_process' );
455 }
456
457 /**
458 * Reset the converter
459 *
460 * @since 2.6.0 bbPress (r6460)
461 */
462 private function reset() {
463 update_option( '_bbp_converter_step', 0 );
464 update_option( '_bbp_converter_start', 0 );
465 update_option( '_bbp_converter_rows_in_step', 0 );
466 update_option( '_bbp_converter_query', '' );
467 }
468
469 /**
470 * Bump the step and reset the start
471 *
472 * @since 2.6.0 bbPress (r6460)
473 */
474 private function bump_step() {
475
476 // Next step
477 $next_step = (int) ( $this->step + 1 );
478
479 // Don't let step go over max
480 $step = ( $next_step <= $this->max_steps )
481 ? $next_step
482 : 0;
483
484 // Update step and start at 0
485 update_option( '_bbp_converter_step', $step );
486 update_option( '_bbp_converter_start', 0 );
487 update_option( '_bbp_converter_rows_in_step', 0 );
488 }
489
490 /**
491 * Bump the start within the current step
492 *
493 * @since 2.6.0 bbPress (r6460)
494 */
495 private function bump_start() {
496
497 // Set rows in step from option
498 $this->rows_in_step = get_option( '_bbp_converter_rows_in_step', 0 );
499
500 // Get rows to start from
501 $start = (int) ( $this->start + $this->rows );
502
503 // Enforce maximum if exists
504 if ( $this->rows_in_step > 0 ) {
505
506 // Start cannot be larger than total rows
507 if ( $start > $this->rows_in_step ) {
508 $start = $this->rows_in_step;
509 }
510
511 // Max can't be greater than total rows
512 if ( $this->max > $this->rows_in_step ) {
513 $this->max = $this->rows_in_step;
514 }
515 }
516
517 // Update the start option
518 update_option( '_bbp_converter_start', $start );
519 }
520
521 /**
522 * Do the converter step
523 *
524 * @since 2.6.0 bbPress (r6460)
525 */
526 private function do_steps() {
527
528 // Step exists in map, and method exists
529 if ( isset( $this->steps[ $this->step ] ) && method_exists( $this, "step_{$this->steps[ $this->step ]}" ) ) {
530 return call_user_func( array( $this, "step_{$this->steps[ $this->step ]}" ) );
531 }
532
533 // Done!
534 $this->step_done();
535 }
536
537 /** Steps *****************************************************************/
538
539 /**
540 * Maybe clean the sync table
541 *
542 * @since 2.6.0 bbPress (r6514)
543 */
544 private function step_sync_table() {
545 if ( true === $this->converter->clean ) {
546 if ( $this->converter->clean() ) {
547 $this->bump_step();
548 $this->sync_table( true );
549
550 empty( $this->start )
551 ? $this->converter_response( esc_html__( 'Readying sync-table', 'bbpress' ) )
552 : $this->converter_response( esc_html__( 'Sync-table ready', 'bbpress' ) );
553 } else {
554 $this->bump_start();
555 $this->converter_response(
556 sprintf(
557 /* translators: 1: Start number, 2: End number */
558 esc_html__( 'Deleting previously converted data (%1$s through %2$s)', 'bbpress' ),
559 $this->start,
560 $this->max
561 )
562 );
563 }
564
565 $this->converter->clean = false;
566 } else {
567 $this->bump_step();
568 $this->sync_table( false );
569 $this->converter_response( esc_html__( 'Skipping sync-table clean-up', 'bbpress' ) );
570 }
571 }
572
573 /**
574 * Maybe convert users
575 *
576 * @since 2.6.0 bbPress (r6514)
577 */
578 private function step_users() {
579 if ( true === $this->converter->convert_users ) {
580 if ( $this->converter->convert_users( $this->start ) ) {
581 $this->bump_step();
582
583 empty( $this->start )
584 ? $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) )
585 : $this->converter_response( esc_html__( 'All users imported', 'bbpress' ) );
586 } else {
587 $this->bump_start();
588 /* translators: 1: Start user number, 2: End user number, 3: Total number of users */
589 $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 ) );
590 }
591 } else {
592 $this->bump_step();
593 $this->converter_response( esc_html__( 'Skipping user clean-up', 'bbpress' ) );
594 }
595 }
596
597 /**
598 * Maybe clean up passwords
599 *
600 * @since 2.6.0 bbPress (r6514)
601 */
602 private function step_passwords() {
603 if ( true === $this->converter->convert_users ) {
604 if ( $this->converter->clean_passwords( $this->start ) ) {
605 $this->bump_step();
606
607 empty( $this->start )
608 ? $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) )
609 : $this->converter_response( esc_html__( 'All passwords cleared', 'bbpress' ) );
610 } else {
611 $this->bump_start();
612 /* translators: 1: Start password number, 2: End password number */
613 $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s through %2$s)', 'bbpress' ), $this->start, $this->max ) );
614 }
615 } else {
616 $this->bump_step();
617 $this->converter_response( esc_html__( 'Skipping password clean-up', 'bbpress' ) );
618 }
619 }
620
621 /**
622 * Maybe convert forums
623 *
624 * @since 2.6.0 bbPress (r6514)
625 */
626 private function step_forums() {
627 if ( $this->converter->convert_forums( $this->start ) ) {
628 $this->bump_step();
629
630 empty( $this->start )
631 ? $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) )
632 : $this->converter_response( esc_html__( 'All forums imported', 'bbpress' ) );
633 } else {
634 $this->bump_start();
635 /* translators: 1: Start forum number, 2: End forum number, 3: Total number of forums */
636 $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 ) );
637 }
638 }
639
640 /**
641 * Maybe walk the forum hierarchy
642 *
643 * @since 2.6.0 bbPress (r6514)
644 */
645 private function step_forum_hierarchy() {
646 if ( $this->converter->convert_forum_parents( $this->start ) ) {
647 $this->bump_step();
648
649 empty( $this->start )
650 ? $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) )
651 : $this->converter_response( esc_html__( 'All forum parents imported', 'bbpress' ) );
652 } else {
653 $this->bump_start();
654 /* translators: 1: Start forum number, 2: End forum number, 3: Total number of forums */
655 $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 ) );
656 }
657 }
658
659 /**
660 * Maybe convert forum subscriptions
661 *
662 * @since 2.6.0 bbPress (r6514)
663 */
664 private function step_forum_subscriptions() {
665 if ( $this->converter->convert_forum_subscriptions( $this->start ) ) {
666 $this->bump_step();
667
668 empty( $this->start )
669 ? $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) )
670 : $this->converter_response( esc_html__( 'All forum subscriptions imported', 'bbpress' ) );
671 } else {
672 $this->bump_start();
673 /* translators: 1: Start forum subscription number, 2: End forum subscription number, 3: Total number of forum subscriptions */
674 $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 ) );
675 }
676 }
677
678 /**
679 * Maybe convert topics
680 *
681 * @since 2.6.0 bbPress (r6514)
682 */
683 private function step_topics() {
684 if ( $this->converter->convert_topics( $this->start ) ) {
685 $this->bump_step();
686
687 empty( $this->start )
688 ? $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) )
689 : $this->converter_response( esc_html__( 'All topics imported', 'bbpress' ) );
690 } else {
691 $this->bump_start();
692 /* translators: 1: Start topic number, 2: End topic number, 3: Total number of topics */
693 $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 ) );
694 }
695 }
696
697 /**
698 * Maybe convert topic authors (anonymous)
699 *
700 * @since 2.6.0 bbPress (r6514)
701 */
702 private function step_topics_authors() {
703 if ( $this->converter->convert_anonymous_topic_authors( $this->start ) ) {
704 $this->bump_step();
705
706 empty( $this->start )
707 ? $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) )
708 : $this->converter_response( esc_html__( 'All anonymous topic authors imported', 'bbpress' ) );
709 } else {
710 $this->bump_start();
711 /* translators: 1: Start anonymous topic author number, 2: End anonymous topic author number, 3: Total number of anonymous topic authors */
712 $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 ) );
713 }
714 }
715
716 /**
717 * Maybe convert sticky topics (not super stickies)
718 *
719 * @since 2.6.0 bbPress (r6514)
720 */
721 private function step_stickies() {
722 if ( $this->converter->convert_topic_stickies( $this->start ) ) {
723 $this->bump_step();
724
725 empty( $this->start )
726 ? $this->converter_response( esc_html__( 'No stickies to import', 'bbpress' ) )
727 : $this->converter_response( esc_html__( 'All stickies imported', 'bbpress' ) );
728 } else {
729 $this->bump_start();
730 /* translators: 1: Start sticky topic number, 2: End sticky topic number, 3: Total number of sticky topics */
731 $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 ) );
732 }
733 }
734
735 /**
736 * Maybe convert super-sticky topics (not per-forum)
737 *
738 * @since 2.6.0 bbPress (r6514)
739 */
740 private function step_super_stickies() {
741 if ( $this->converter->convert_topic_super_stickies( $this->start ) ) {
742 $this->bump_step();
743
744 empty( $this->start )
745 ? $this->converter_response( esc_html__( 'No super stickies to import', 'bbpress' ) )
746 : $this->converter_response( esc_html__( 'All super stickies imported', 'bbpress' ) );
747 } else {
748 $this->bump_start();
749 /* translators: 1: Start super sticky topic number, 2: End super sticky topic number, 3: Total number of super sticky topics */
750 $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 ) );
751 }
752 }
753
754 /**
755 * Maybe close converted topics
756 *
757 * @since 2.6.0 bbPress (r6514)
758 */
759 private function step_closed_topics() {
760 if ( $this->converter->convert_topic_closed_topics( $this->start ) ) {
761 $this->bump_step();
762
763 empty( $this->start )
764 ? $this->converter_response( esc_html__( 'No closed topics to import', 'bbpress' ) )
765 : $this->converter_response( esc_html__( 'All closed topics imported', 'bbpress' ) );
766 } else {
767 $this->bump_start();
768 /* translators: 1: Start closed topic number, 2: End closed topic number, 3: Total number of closed topics */
769 $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 ) );
770 }
771 }
772
773 /**
774 * Maybe convert topic tags
775 *
776 * @since 2.6.0 bbPress (r6514)
777 */
778 private function step_topic_tags() {
779 if ( $this->converter->convert_tags( $this->start ) ) {
780 $this->bump_step();
781
782 empty( $this->start )
783 ? $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) )
784 : $this->converter_response( esc_html__( 'All topic tags imported', 'bbpress' ) );
785 } else {
786 $this->bump_start();
787 /* translators: 1: Start topic tag number, 2: End topic tag number, 3: Total number of topic tags */
788 $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 ) );
789 }
790 }
791
792 /**
793 * Maybe convert topic subscriptions
794 *
795 * @since 2.6.0 bbPress (r6514)
796 */
797 private function step_topic_subscriptions() {
798 if ( $this->converter->convert_topic_subscriptions( $this->start ) ) {
799 $this->bump_step();
800
801 empty( $this->start )
802 ? $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) )
803 : $this->converter_response( esc_html__( 'All topic subscriptions imported', 'bbpress' ) );
804 } else {
805 $this->bump_start();
806 /* translators: 1: Start topic subscription number, 2: End topic subscription number, 3: Total number of topic subscriptions */
807 $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 ) );
808 }
809 }
810
811 /**
812 * Maybe convert topic favorites
813 *
814 * @since 2.6.0 bbPress (r6514)
815 */
816 private function step_topic_favorites() {
817 if ( $this->converter->convert_favorites( $this->start ) ) {
818 $this->bump_step();
819
820 empty( $this->start )
821 ? $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) )
822 : $this->converter_response( esc_html__( 'All favorites imported', 'bbpress' ) );
823 } else {
824 $this->bump_start();
825 /* translators: 1: Start favorite number, 2: End favorite number, 3: Total number of favorites */
826 $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 ) );
827 }
828 }
829
830 /**
831 * Maybe convert replies
832 *
833 * @since 2.6.0 bbPress (r6514)
834 */
835 private function step_replies() {
836 if ( $this->converter->convert_replies( $this->start ) ) {
837 $this->bump_step();
838
839 empty( $this->start )
840 ? $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) )
841 : $this->converter_response( esc_html__( 'All replies imported', 'bbpress' ) );
842 } else {
843 $this->bump_start();
844 /* translators: 1: Start reply number, 2: End reply number, 3: Total number of replies */
845 $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 ) );
846 }
847 }
848
849 /**
850 * Maybe convert reply authors (anonymous)
851 *
852 * @since 2.6.0 bbPress (r6514)
853 */
854 private function step_reply_authors() {
855 if ( $this->converter->convert_anonymous_reply_authors( $this->start ) ) {
856 $this->bump_step();
857
858 empty( $this->start )
859 ? $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) )
860 : $this->converter_response( esc_html__( 'All anonymous reply authors imported', 'bbpress' ) );
861 } else {
862 $this->bump_start();
863 /* translators: 1: Start anonymous reply author number, 2: End anonymous reply author number, 3: Total number of anonymous reply authors */
864 $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 ) );
865 }
866 }
867
868 /**
869 * Maybe convert the threaded reply hierarchy
870 *
871 * @since 2.6.0 bbPress (r6514)
872 */
873 private function step_reply_hierarchy() {
874 if ( $this->converter->convert_reply_to_parents( $this->start ) ) {
875 $this->bump_step();
876
877 empty( $this->start )
878 ? $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) )
879 : $this->converter_response( esc_html__( 'All threaded replies imported', 'bbpress' ) );
880 } else {
881 $this->bump_start();
882 /* translators: 1: Start threaded reply number, 2: End threaded reply number, 3: Total number of threaded replies */
883 $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 ) );
884 }
885 }
886
887 /**
888 * Done!
889 *
890 * @since 2.6.0 bbPress (r6514)
891 */
892 private function step_done() {
893 $this->reset();
894 $this->converter_response( esc_html__( 'Import Finished', 'bbpress' ) );
895 }
896
897 /** Helper Table **********************************************************/
898
899 /**
900 * Create Tables for fast syncing
901 *
902 * @since 2.1.0 bbPress (r3816)
903 */
904 public static function sync_table( $drop = false ) {
905
906 // Setup DB
907 $bbp_db = bbp_db();
908 $table_name = $bbp_db->prefix . 'bbp_converter_translator';
909 $table_exists = $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name;
910
911 // Maybe drop the sync table
912 if ( ( true === $drop ) && ( true === $table_exists ) ) {
913 $bbp_db->query( "DROP TABLE {$table_name}" );
914 }
915
916 // Maybe include the upgrade functions, for dbDelta()
917 if ( ! function_exists( 'dbDelta' ) ) {
918 require_once ABSPATH . '/wp-admin/includes/upgrade.php';
919 }
920
921 // Defaults
922 $sql = array();
923 $charset_collate = '';
924
925 // https://bbpress.trac.wordpress.org/ticket/3145
926 $max_index_length = 75;
927
928 // Maybe override the character set
929 if ( ! empty( $bbp_db->charset ) ) {
930 $charset_collate .= "DEFAULT CHARACTER SET {$bbp_db->charset}";
931 }
932
933 // Maybe override the collation
934 if ( ! empty( $bbp_db->collate ) ) {
935 $charset_collate .= " COLLATE {$bbp_db->collate}";
936 }
937
938 /** Translator ********************************************************/
939
940 $sql[] = "CREATE TABLE {$table_name} (
941 meta_id mediumint(8) unsigned not null auto_increment,
942 value_type varchar(25) null,
943 value_id bigint(20) unsigned not null default '0',
944 meta_key varchar({$max_index_length}) null,
945 meta_value varchar({$max_index_length}) null,
946 PRIMARY KEY (meta_id),
947 KEY value_id (value_id),
948 KEY meta_join (meta_key({$max_index_length}), meta_value({$max_index_length}))
949 ) {$charset_collate}";
950
951 dbDelta( $sql );
952 }
953 }
954 endif;
955