PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
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 2.2 2.2.1 All 72 releases
bbpress / includes / admin / classes / class-bbp-converter.php

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

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