Changeset 6601 for trunk/src/includes/admin/classes/class-bbp-converter.php
- Timestamp:
- 06/23/2017 04:21:58 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/classes/class-bbp-converter.php
r6573 r6601 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 if ( ! class_exists( 'BBP_Converter' ) ) : 15 16 /** 16 17 * Main BBP_Converter Class … … 49 50 50 51 /** 52 * @var string Path to included platforms 53 */ 54 public $converters_dir = ''; 55 56 /** 51 57 * The main bbPress Converter loader 52 58 * … … 54 60 */ 55 61 public function __construct() { 62 $this->setup_globals(); 56 63 $this->setup_actions(); 64 } 65 66 /** 67 * Admin globals 68 * 69 * @since 2.6.0 bbPress (r6598) 70 */ 71 public function setup_globals() { 72 $this->converters_dir = bbp_setup_admin()->admin_dir . 'converters/'; 57 73 } 58 74 … … 86 102 // Vars 87 103 'ajax_nonce' => wp_create_nonce( 'bbp_converter_process' ), 88 'halt' => (bool) defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY, 89 'started' => (bool) get_option( '_bbp_converter_step', false ), 90 'delay' => (int) get_option( '_bbp_converter_delay_time', 1 ), 104 'delay' => (int) get_option( '_bbp_converter_delay_time', 2 ), 91 105 'running' => false, 92 ' complete'=> false,93 ' timer' => false,106 'status' => false, 107 'started' => (bool) get_option( '_bbp_converter_step', 0 ), 94 108 95 109 // Strings … … 97 111 98 112 // Button text 99 'button_start' => esc_html__( 'Start', 'bbpress' ),100 'button_continue' => esc_html__( 'Continue', 'bbpress' ),113 'button_start' => esc_html__( 'Start', 'bbpress' ), 114 'button_continue' => esc_html__( 'Continue', 'bbpress' ), 101 115 102 116 // Start button clicked 103 'start_start' => esc_html__( 'Starting Import', 'bbpress' ),104 'start_continue' => esc_html__( 'Continuing Import', 'bbpress' ),117 'start_start' => esc_html__( 'Starting Import...', 'bbpress' ), 118 'start_continue' => esc_html__( 'Continuing Import...', 'bbpress' ), 105 119 106 120 // Import 107 'import_complete' => esc_html__( 'Import Finished', 'bbpress' ), 108 'import_stopped_user' => esc_html__( 'Import Stopped (by User)', 'bbpress' ), 109 'import_error_db' => esc_html__( 'Database Connection Failed', 'bbpress' ), 110 'import_error_halt' => esc_html__( 'Import Halted (Error)', 'bbpress' ), 111 112 // Timer 113 'timer_stopped' => esc_html__( 'Timer: Stopped', 'bbpress' ), 114 'timer_waiting' => esc_html__( 'Timer: Waiting...', 'bbpress' ), 115 'timer_counting' => esc_html__( 'Timer: %s', 'bbpress' ) 121 'import_complete' => esc_html__( 'Import Finished.', 'bbpress' ), 122 'import_stopped_user' => esc_html__( 'Import Stopped (by User.)', 'bbpress' ), 123 'import_error_halt' => esc_html__( 'Import Halted (Error.)', 'bbpress' ), 124 'import_error_db' => esc_html__( 'Database Connection Failed.', 'bbpress' ), 125 126 // Status 127 'status_complete' => esc_html__( 'Finished', 'bbpress' ), 128 'status_stopped' => esc_html__( 'Stopped', 'bbpress' ), 129 'status_starting' => esc_html__( 'Starting', 'bbpress' ), 130 'status_up_next' => esc_html__( 'Up next: Step %s...', 'bbpress' ), 131 'status_counting' => esc_html__( 'Next in %s...', 'bbpress' ) 116 132 ) 117 133 ) ); … … 138 154 139 155 /** 140 * Wrap the converter output in paragraph tags, so styling can be applied156 * Wrap the converter output in HTML, so styling can be applied 141 157 * 142 158 * @since 2.1.0 bbPress (r4052) … … 144 160 * @param string $output 145 161 */ 146 private function converter_output( $output = '' ) { 147 148 // Maybe include last query 149 $query = get_option( '_bbp_converter_query' ); 150 if ( ! empty( $query ) ) { 151 $output = $output . '<span class="query">' . esc_attr( $query ) . '</span>'; 152 } 162 private function converter_response( $output = '' ) { 153 163 154 164 // Maybe prepend the step 155 $ step= ! empty( $this->step )156 ? sprintf( '<span class="step">%s:</span> ', $this->step)157 : '';165 $output = ! empty( $this->step ) 166 ? sprintf( '<span class="step">%s:</span> %s', $this->step, $output ) 167 : $output; 158 168 159 169 // Output 160 echo $step . $output; 170 wp_send_json_success( array( 171 'query' => get_option( '_bbp_converter_query', '' ), 172 'current_step' => $this->step, 173 'final_step' => $this->max_steps, 174 'progress' => $output 175 ) ); 161 176 } 162 177 … … 202 217 '_bbp_converter_start' => 0, 203 218 219 // Halt 220 '_bbp_converter_halt' => ! empty( $_POST['_bbp_converter_halt'] ) 221 ? (int) $_POST['_bbp_converter_halt'] 222 : 0, 223 204 224 // Rows 205 225 '_bbp_converter_rows' => ! empty( $_POST['_bbp_converter_rows'] ) … … 322 342 */ 323 343 private function bump_step() { 324 update_option( '_bbp_converter_step', $this->step + 1 ); 325 update_option( '_bbp_converter_start', 0 ); 344 345 // Start at zero 346 update_option( '_bbp_converter_start', 0 ); 347 348 // Don't let step go over max 349 $step = ( ( $this->step + 1 ) <= $this->max_steps ) 350 ? (int) $this->step + 1 351 : 0; 352 353 // Update or delete 354 ! empty( $step ) 355 ? update_option( '_bbp_converter_step', $step ) 356 : delete_option( '_bbp_converter_step' ); 326 357 } 327 358 … … 444 475 */ 445 476 private function step_sync_table() { 446 if ( ! empty( $_POST['_bbp_converter_clean'] )) {477 if ( true === $this->converter->clean ) { 447 478 if ( $this->converter->clean( $this->start ) ) { 479 $this->bump_step(); 448 480 $this->sync_table( true ); 449 $this->bump_step();450 481 451 482 if ( empty( $this->start ) ) { 452 $this->converter_ output( esc_html__( 'Recreating sync-table', 'bbpress' ) );483 $this->converter_response( esc_html__( 'Recreating sync-table', 'bbpress' ) ); 453 484 } 454 485 } else { 455 $this->converter_output( sprintf( esc_html__( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );456 486 $this->bump_start(); 457 } 458 } else { 459 $this->converter_output( esc_html__( 'Skipping sync-table clean-up', 'bbpress' ) ); 487 $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 488 } 489 490 $this->converter->clean = false; 491 } else { 492 $this->bump_step(); 460 493 $this->sync_table( false ); 461 $this-> bump_step();494 $this->converter_response( esc_html__( 'Skipping sync-table clean-up', 'bbpress' ) ); 462 495 } 463 496 } … … 474 507 475 508 if ( empty( $this->start ) ) { 476 $this->converter_ output( esc_html__( 'No users to import', 'bbpress' ) );509 $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) ); 477 510 } 478 511 } else { 479 512 $this->bump_start(); 480 $this->converter_ output( sprintf( esc_html__( 'Converting users (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );481 } 482 } else { 483 $this->bump_step(); 484 $this->converter_ output( esc_html__( 'Skipping user clean-up', 'bbpress' ) );513 $this->converter_response( sprintf( esc_html__( 'Converting users (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 514 } 515 } else { 516 $this->bump_step(); 517 $this->converter_response( esc_html__( 'Skipping user clean-up', 'bbpress' ) ); 485 518 } 486 519 } … … 497 530 498 531 if ( empty( $this->start ) ) { 499 $this->converter_ output( esc_html__( 'No passwords to clear', 'bbpress' ) );532 $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) ); 500 533 } 501 534 } else { 502 535 $this->bump_start(); 503 $this->converter_ output( sprintf( esc_html__( 'Delete users WordPress default passwords (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );504 } 505 } else { 506 $this->bump_step(); 507 $this->converter_ output( esc_html__( 'Skipping password clean-up', 'bbpress' ) );536 $this->converter_response( sprintf( esc_html__( 'Delete users WordPress default passwords (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 537 } 538 } else { 539 $this->bump_step(); 540 $this->converter_response( esc_html__( 'Skipping password clean-up', 'bbpress' ) ); 508 541 } 509 542 } … … 519 552 520 553 if ( empty( $this->start ) ) { 521 $this->converter_ output( esc_html__( 'No forums to import', 'bbpress' ) );522 } 523 } else { 524 $this->bump_start(); 525 $this->converter_ output( sprintf( esc_html__( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );554 $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) ); 555 } 556 } else { 557 $this->bump_start(); 558 $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 526 559 } 527 560 } … … 537 570 538 571 if ( empty( $this->start ) ) { 539 $this->converter_ output( esc_html__( 'No forum parents to import', 'bbpress' ) );540 } 541 } else { 542 $this->bump_start(); 543 $this->converter_ output( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );572 $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) ); 573 } 574 } else { 575 $this->bump_start(); 576 $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 544 577 } 545 578 } … … 555 588 556 589 if ( empty( $this->start ) ) { 557 $this->converter_ output( esc_html__( 'No forum subscriptions to import', 'bbpress' ) );558 } 559 } else { 560 $this->bump_start(); 561 $this->converter_ output( sprintf( esc_html__( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );590 $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) ); 591 } 592 } else { 593 $this->bump_start(); 594 $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 562 595 } 563 596 } … … 573 606 574 607 if ( empty( $this->start ) ) { 575 $this->converter_ output( esc_html__( 'No topics to import', 'bbpress' ) );576 } 577 } else { 578 $this->bump_start(); 579 $this->converter_ output( sprintf( esc_html__( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );608 $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) ); 609 } 610 } else { 611 $this->bump_start(); 612 $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 580 613 } 581 614 } … … 591 624 592 625 if ( empty( $this->start ) ) { 593 $this->converter_ output( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) );594 } 595 } else { 596 $this->bump_start(); 597 $this->converter_ output( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );626 $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) ); 627 } 628 } else { 629 $this->bump_start(); 630 $this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 598 631 } 599 632 } … … 609 642 610 643 if ( empty( $this->start ) ) { 611 $this->converter_ output( esc_html__( 'No stickies to stick', 'bbpress' ) );612 } 613 } else { 614 $this->bump_start(); 615 $this->converter_ output( sprintf( esc_html__( 'Calculating topic stickies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );644 $this->converter_response( esc_html__( 'No stickies to stick', 'bbpress' ) ); 645 } 646 } else { 647 $this->bump_start(); 648 $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 616 649 } 617 650 } … … 627 660 628 661 if ( empty( $this->start ) ) { 629 $this->converter_ output( esc_html__( 'No super stickies to stick', 'bbpress' ) );630 } 631 } else { 632 $this->bump_start(); 633 $this->converter_ output( sprintf( esc_html__( 'Calculating topic super stickies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );662 $this->converter_response( esc_html__( 'No super stickies to stick', 'bbpress' ) ); 663 } 664 } else { 665 $this->bump_start(); 666 $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 634 667 } 635 668 } … … 645 678 646 679 if ( empty( $this->start ) ) { 647 $this->converter_ output( esc_html__( 'No closed topics to close', 'bbpress' ) );648 } 649 } else { 650 $this->bump_start(); 651 $this->converter_ output( sprintf( esc_html__( 'Calculating closed topics (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );680 $this->converter_response( esc_html__( 'No closed topics to close', 'bbpress' ) ); 681 } 682 } else { 683 $this->bump_start(); 684 $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 652 685 } 653 686 } … … 663 696 664 697 if ( empty( $this->start ) ) { 665 $this->converter_ output( esc_html__( 'No topic tags to import', 'bbpress' ) );666 } 667 } else { 668 $this->bump_start(); 669 $this->converter_ output( sprintf( esc_html__( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );698 $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) ); 699 } 700 } else { 701 $this->bump_start(); 702 $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 670 703 } 671 704 } … … 681 714 682 715 if ( empty( $this->start ) ) { 683 $this->converter_ output( esc_html__( 'No topic subscriptions to import', 'bbpress' ) );684 } 685 } else { 686 $this->bump_start(); 687 $this->converter_ output( sprintf( esc_html__( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );716 $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) ); 717 } 718 } else { 719 $this->bump_start(); 720 $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 688 721 } 689 722 } … … 699 732 700 733 if ( empty( $this->start ) ) { 701 $this->converter_ output( esc_html__( 'No favorites to import', 'bbpress' ) );702 } 703 } else { 704 $this->bump_start(); 705 $this->converter_ output( sprintf( esc_html__( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );734 $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) ); 735 } 736 } else { 737 $this->bump_start(); 738 $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 706 739 } 707 740 } … … 717 750 718 751 if ( empty( $this->start ) ) { 719 $this->converter_ output( esc_html__( 'No replies to import', 'bbpress' ) );720 } 721 } else { 722 $this->bump_start(); 723 $this->converter_ output( sprintf( esc_html__( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );752 $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) ); 753 } 754 } else { 755 $this->bump_start(); 756 $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 724 757 } 725 758 } … … 735 768 736 769 if ( empty( $this->start ) ) { 737 $this->converter_ output( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) );738 } 739 } else { 740 $this->bump_start(); 741 $this->converter_ output( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );770 $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) ); 771 } 772 } else { 773 $this->bump_start(); 774 $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 742 775 } 743 776 } … … 753 786 754 787 if ( empty( $this->start ) ) { 755 $this->converter_ output( esc_html__( 'No threaded replies to import', 'bbpress' ) );756 } 757 } else { 758 $this->bump_start(); 759 $this->converter_ output( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );788 $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) ); 789 } 790 } else { 791 $this->bump_start(); 792 $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) ); 760 793 } 761 794 } … … 768 801 private function step_done() { 769 802 $this->reset(); 770 $this->converter_ output( esc_html__( 'Import Finished', 'bbpress' ) );803 $this->converter_response( esc_html__( 'Import Finished', 'bbpress' ) ); 771 804 } 772 805 … … 826 859 } 827 860 } 861 endif;
Note:
See TracChangeset
for help on using the changeset viewer.