Changeset 6640
- Timestamp:
- 07/27/2017 02:56:27 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/classes/class-bbp-converter.php
r6635 r6640 27 27 * @var int Start 28 28 */ 29 public $ min= 0;29 public $start = 0; 30 30 31 31 /** … … 40 40 41 41 /** 42 * @var int Maximum number of converter steps 43 */ 44 public $max_steps = 17; 45 46 /** 47 * @var int Name of source forum platform 48 */ 49 public $platform = ''; 50 51 /** 42 52 * @var BBP_Converter_Base Type of converter to use 43 53 */ … … 45 55 46 56 /** 47 * @var int Maximum number of converter steps48 */49 public $max_steps = 17;50 51 /**52 57 * @var string Path to included platforms 53 58 */ 54 59 public $converters_dir = ''; 60 61 /** 62 * @var array Map of steps to methods 63 */ 64 private $steps = array( 65 1 => 'sync_table', 66 2 => 'users', 67 3 => 'passwords', 68 4 => 'forums', 69 5 => 'forum_hierarchy', 70 6 => 'forum_subscriptions', 71 7 => 'topics', 72 8 => 'topics_authors', 73 9 => 'stickies', 74 10 => 'super_stickies', 75 11 => 'closed_topics', 76 12 => 'topic_tags', 77 13 => 'topic_subscriptions', 78 14 => 'topic_favorites', 79 15 => 'replies', 80 16 => 'reply_authors', 81 17 => 'reply_hierarchy' 82 ); 55 83 56 84 /** … … 125 153 126 154 // 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__( ' Instep %s...', 'bbpress' ),131 'status_counting' => esc_html__( 'Next in %s...', 'bbpress' )155 'status_complete' => esc_html__( 'Finished', 'bbpress' ), 156 'status_stopped' => esc_html__( 'Stopped', 'bbpress' ), 157 'status_starting' => esc_html__( 'Starting', 'bbpress' ), 158 'status_up_next' => esc_html__( 'Doing step %s...', 'bbpress' ), 159 'status_counting' => esc_html__( 'Next in %s...', 'bbpress' ) 132 160 ) 133 161 ) ); … … 146 174 $this->maybe_restart(); 147 175 $this->setup_options(); 176 $this->maybe_update_options(); 148 177 149 178 // Bail if no converter … … 199 228 // Save step and count so that it can be restarted. 200 229 if ( ! get_option( '_bbp_converter_step' ) || ! empty( $_POST['_bbp_converter_restart'] ) ) { 201 $this->maybe_update_options();202 230 $this->step = 1; 203 231 $this->start = 0; 204 } 205 } 206 232 $this->maybe_update_options(); 233 } 234 } 235 236 /** 237 * Maybe update options 238 * 239 * @since 2.6.0 bbPress (r6637) 240 */ 207 241 private function maybe_update_options() { 208 242 … … 211 245 212 246 // Step & Start 213 '_bbp_converter_step' => 1,214 '_bbp_converter_start' => 0,247 '_bbp_converter_step' => $this->step, 248 '_bbp_converter_start' => $this->start, 215 249 216 250 // Halt … … 278 312 private function setup_options() { 279 313 280 // Get starting point & rows 281 $this->step = (int) get_option( '_bbp_converter_step', 1 ); 282 $this->min = (int) get_option( '_bbp_converter_start', 0 ); 283 $this->rows = (int) get_option( '_bbp_converter_rows', 100 ); 284 285 // Get boundaries 286 $this->max = ( $this->min + $this->rows ) - 1; 287 $this->start = $this->min; 288 289 // Look for platform 290 $platform = get_option( '_bbp_converter_platform' ); 314 // Set starting point & rows 315 $this->step = (int) get_option( '_bbp_converter_step', 1 ); 316 $this->start = (int) get_option( '_bbp_converter_start', 0 ); 317 $this->rows = (int) get_option( '_bbp_converter_rows', 100 ); 318 319 // Set boundaries 320 $this->max = ( $this->start + $this->rows ) - 1; 321 322 // Set platform 323 $this->platform = get_option( '_bbp_converter_platform' ); 291 324 292 325 // Maybe include the appropriate converter. 293 if ( ! empty( $ platform ) ) {294 $this->converter = bbp_new_converter( $ platform );326 if ( ! empty( $this->platform ) ) { 327 $this->converter = bbp_new_converter( $this->platform ); 295 328 } 296 329 } … … 318 351 */ 319 352 private function reset() { 320 $this->start = 0; 321 $this->step = 0; 322 $this->min = 0; 323 324 update_option( '_bbp_converter_step', $this->step ); 325 update_option( '_bbp_converter_start', $this->start ); 353 update_option( '_bbp_converter_step', 0 ); 354 update_option( '_bbp_converter_start', 0 ); 326 355 update_option( '_bbp_converter_query', '' ); 327 356 } … … 334 363 private function bump_step() { 335 364 336 // Start at zero337 update_option( '_bbp_converter_start', 0);365 // Next step 366 $next_step = (int) ( $this->step + 1 ); 338 367 339 368 // Don't let step go over max 340 $step = ( ( $this->step + 1 )<= $this->max_steps )341 ? (int) $this->step + 1369 $step = ( $next_step <= $this->max_steps ) 370 ? $next_step 342 371 : 0; 343 372 344 // Update or delete 345 update_option( '_bbp_converter_step', $step ); 373 // Update step and start at 0 374 update_option( '_bbp_converter_step', $step ); 375 update_option( '_bbp_converter_start', 0 ); 346 376 } 347 377 … … 352 382 */ 353 383 private function bump_start() { 354 update_option( '_bbp_converter_start', $this->max + 1 ); 384 $start = (int) ( $this->start + $this->rows ); 385 386 update_option( '_bbp_converter_start', $start ); 355 387 } 356 388 … … 362 394 private function do_steps() { 363 395 364 switch ( $this->step ) { 365 366 // Clean all tables. 367 case 1 : 368 $this->step_sync_table(); 369 break; 370 371 // Convert users. 372 case 2 : 373 $this->step_users(); 374 break; 375 376 // Clean passwords. 377 case 3 : 378 $this->step_passwords(); 379 break; 380 381 // Convert forums. 382 case 4 : 383 $this->step_forums(); 384 break; 385 386 // Convert forum parents. 387 case 5 : 388 $this->step_forum_hierarchy(); 389 break; 390 391 // Convert forum subscriptions. 392 case 6 : 393 $this->step_forum_subscriptions(); 394 break; 395 396 // Convert topics. 397 case 7 : 398 $this->step_topics(); 399 break; 400 401 // Convert topic authors. 402 case 8 : 403 $this->step_topics_authors(); 404 break; 405 406 // Sticky topics. 407 case 9 : 408 $this->step_stickies(); 409 break; 410 411 // Stick to front topics (Super Sicky). 412 case 10 : 413 $this->step_super_stickies(); 414 break; 415 416 // Closed topics. 417 case 11 : 418 $this->step_closed_topics(); 419 break; 420 421 // Convert topic tags. 422 case 12 : 423 $this->step_topic_tags(); 424 break; 425 426 // Convert topic subscriptions. 427 case 13 : 428 $this->step_topic_subscriptions(); 429 break; 430 431 // Convert topic favorites. 432 case 14 : 433 $this->step_topic_favorites(); 434 break; 435 436 // Convert replies. 437 case 15 : 438 $this->step_replies(); 439 break; 440 441 // Convert reply authors. 442 case 16 : 443 $this->step_reply_authors(); 444 break; 445 446 // Convert threaded reply hierarchy. 447 case 17 : 448 $this->step_reply_hierarchy(); 449 break; 450 451 // Done 452 default : 453 $this->step_done(); 454 break; 455 } 396 // Step exists in map, and method exists 397 if ( isset( $this->steps[ $this->step ] ) && method_exists( $this, "step_{$this->steps[ $this->step ]}" ) ) { 398 return call_user_func( array( $this, "step_{$this->steps[ $this->step ]}" ) ); 399 } 400 401 // Done! 402 $this->step_done(); 456 403 } 457 404 … … 459 406 460 407 /** 461 * Clean the sync table408 * Maybe clean the sync table 462 409 * 463 410 * @since 2.6.0 bbPress (r6513) … … 469 416 $this->sync_table( true ); 470 417 471 if ( empty( $this->start ) ) {472 $this->converter_response( esc_html__( 'Recreating sync-table', 'bbpress' ) );473 }418 empty( $this->start ) 419 ? $this->converter_response( esc_html__( 'Readying sync-table', 'bbpress' ) ) 420 : $this->converter_response( esc_html__( 'Sync-table ready', 'bbpress' ) ); 474 421 } else { 475 422 $this->bump_start(); 476 $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );423 $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 477 424 } 478 425 … … 495 442 $this->bump_step(); 496 443 497 if ( empty( $this->start ) ) {498 $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) );499 }444 empty( $this->start ) 445 ? $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) ) 446 : $this->converter_response( esc_html__( 'All users imported', 'bbpress' ) ); 500 447 } else { 501 448 $this->bump_start(); 502 $this->converter_response( sprintf( esc_html__( 'Converting users (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );449 $this->converter_response( sprintf( esc_html__( 'Converting users (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 503 450 } 504 451 } else { … … 518 465 $this->bump_step(); 519 466 520 if ( empty( $this->start ) ) {521 $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) );522 }467 empty( $this->start ) 468 ? $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) ) 469 : $this->converter_response( esc_html__( 'All passwords cleared', 'bbpress' ) ); 523 470 } else { 524 471 $this->bump_start(); 525 $this->converter_response( sprintf( esc_html__( 'Delete users WordPress default passwords (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );472 $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 526 473 } 527 474 } else { … … 540 487 $this->bump_step(); 541 488 542 if ( empty( $this->start ) ) {543 $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) );544 }545 } else { 546 $this->bump_start(); 547 $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );489 empty( $this->start ) 490 ? $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) ) 491 : $this->converter_response( esc_html__( 'All forums imported', 'bbpress' ) ); 492 } else { 493 $this->bump_start(); 494 $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 548 495 } 549 496 } … … 558 505 $this->bump_step(); 559 506 560 if ( empty( $this->start ) ) {561 $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) );562 }563 } else { 564 $this->bump_start(); 565 $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );507 empty( $this->start ) 508 ? $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) ) 509 : $this->converter_response( esc_html__( 'All forum parents imported', 'bbpress' ) ); 510 } else { 511 $this->bump_start(); 512 $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 566 513 } 567 514 } … … 576 523 $this->bump_step(); 577 524 578 if ( empty( $this->start ) ) {579 $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) );580 }581 } else { 582 $this->bump_start(); 583 $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );525 empty( $this->start ) 526 ? $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) ) 527 : $this->converter_response( esc_html__( 'All forum subscriptions imported', 'bbpress' ) ); 528 } else { 529 $this->bump_start(); 530 $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 584 531 } 585 532 } … … 594 541 $this->bump_step(); 595 542 596 if ( empty( $this->start ) ) {597 $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) );598 }599 } else { 600 $this->bump_start(); 601 $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );543 empty( $this->start ) 544 ? $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) ) 545 : $this->converter_response( esc_html__( 'All topics imported', 'bbpress' ) ); 546 } else { 547 $this->bump_start(); 548 $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 602 549 } 603 550 } … … 612 559 $this->bump_step(); 613 560 614 if ( empty( $this->start ) ) {615 $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) );616 }617 } else { 618 $this->bump_start(); 619 $this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );561 empty( $this->start ) 562 ? $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) ) 563 : $this->converter_response( esc_html__( 'All anonymous topic authors imported', 'bbpress' ) ); 564 } else { 565 $this->bump_start(); 566 $this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 620 567 } 621 568 } … … 630 577 $this->bump_step(); 631 578 632 if ( empty( $this->start ) ) {633 $this->converter_response( esc_html__( 'No stickies to stick', 'bbpress' ) );634 }635 } else { 636 $this->bump_start(); 637 $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );579 empty( $this->start ) 580 ? $this->converter_response( esc_html__( 'No stickies to import', 'bbpress' ) ) 581 : $this->converter_response( esc_html__( 'All stickies imported', 'bbpress' ) ); 582 } else { 583 $this->bump_start(); 584 $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 638 585 } 639 586 } … … 648 595 $this->bump_step(); 649 596 650 if ( empty( $this->start ) ) {651 $this->converter_response( esc_html__( 'No super stickies to stick', 'bbpress' ) );652 }653 } else { 654 $this->bump_start(); 655 $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );597 empty( $this->start ) 598 ? $this->converter_response( esc_html__( 'No super stickies to import', 'bbpress' ) ) 599 : $this->converter_response( esc_html__( 'All super stickies imported', 'bbpress' ) ); 600 } else { 601 $this->bump_start(); 602 $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 656 603 } 657 604 } … … 666 613 $this->bump_step(); 667 614 668 if ( empty( $this->start ) ) {669 $this->converter_response( esc_html__( 'No closed topics to close', 'bbpress' ) );670 }671 } else { 672 $this->bump_start(); 673 $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );615 empty( $this->start ) 616 ? $this->converter_response( esc_html__( 'No closed topics to import', 'bbpress' ) ) 617 : $this->converter_response( esc_html__( 'All closed topics imported', 'bbpress' ) ); 618 } else { 619 $this->bump_start(); 620 $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 674 621 } 675 622 } … … 684 631 $this->bump_step(); 685 632 686 if ( empty( $this->start ) ) {687 $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) );688 }689 } else { 690 $this->bump_start(); 691 $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );633 empty( $this->start ) 634 ? $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) ) 635 : $this->converter_response( esc_html__( 'All topic tags imported', 'bbpress' ) ); 636 } else { 637 $this->bump_start(); 638 $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 692 639 } 693 640 } … … 702 649 $this->bump_step(); 703 650 704 if ( empty( $this->start ) ) {705 $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) );706 }707 } else { 708 $this->bump_start(); 709 $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );651 empty( $this->start ) 652 ? $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) ) 653 : $this->converter_response( esc_html__( 'All topic subscriptions imported', 'bbpress' ) ); 654 } else { 655 $this->bump_start(); 656 $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 710 657 } 711 658 } … … 720 667 $this->bump_step(); 721 668 722 if ( empty( $this->start ) ) {723 $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) );724 }725 } else { 726 $this->bump_start(); 727 $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );669 empty( $this->start ) 670 ? $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) ) 671 : $this->converter_response( esc_html__( 'All favorites imported', 'bbpress' ) ); 672 } else { 673 $this->bump_start(); 674 $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 728 675 } 729 676 } … … 738 685 $this->bump_step(); 739 686 740 if ( empty( $this->start ) ) {741 $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) );742 }743 } else { 744 $this->bump_start(); 745 $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );687 empty( $this->start ) 688 ? $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) ) 689 : $this->converter_response( esc_html__( 'All replies imported', 'bbpress' ) ); 690 } else { 691 $this->bump_start(); 692 $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 746 693 } 747 694 } … … 756 703 $this->bump_step(); 757 704 758 if ( empty( $this->start ) ) {759 $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) );760 }761 } else { 762 $this->bump_start(); 763 $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );705 empty( $this->start ) 706 ? $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) ) 707 : $this->converter_response( esc_html__( 'All anonymous reply authors imported', 'bbpress' ) ); 708 } else { 709 $this->bump_start(); 710 $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 764 711 } 765 712 } … … 774 721 $this->bump_step(); 775 722 776 if ( empty( $this->start ) ) {777 $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) );778 }779 } else { 780 $this->bump_start(); 781 $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s - %2$s)', 'bbpress' ), $this-> min, $this->max ) );723 empty( $this->start ) 724 ? $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) ) 725 : $this->converter_response( esc_html__( 'All threaded replies imported', 'bbpress' ) ); 726 } else { 727 $this->bump_start(); 728 $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) ); 782 729 } 783 730 }
Note: See TracChangeset
for help on using the changeset viewer.