Changeset 6785
- Timestamp:
- 02/19/2018 07:00:55 AM (7 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/classes/class-bbp-converter-base.php
r6780 r6785 139 139 // Maybe add port to server 140 140 if ( ! empty( $db_port ) && ! empty( $db_host ) && ! strstr( $db_host, ':' ) ) { 141 $db_host = $db_host . ':' . $db_port;141 $db_host = "{$db_host}:{$db_port}"; 142 142 } 143 143 … … 147 147 $this->wpdb = bbp_db(); 148 148 149 // Control WPDB db_connect() bailing150 define( 'WP_SETUP_CONFIG', true );151 152 149 // Setup old forum Database 153 $this->opdb = new wpdb( $db_user, $db_pass, $db_name, $db_host );150 $this->opdb = new BBP_Converter_DB( $db_user, $db_pass, $db_name, $db_host ); 154 151 155 152 // Connection failed … … 499 496 /** New user **************************************/ 500 497 501 case 'user' :498 case 'user' : 502 499 if ( username_exists( $insert_post['user_login'] ) ) { 503 $insert_post['user_login'] = 'imported_' . $insert_post['user_login'];500 $insert_post['user_login'] = "imported_{$insert_post['user_login']}"; 504 501 } 505 502 506 503 if ( email_exists( $insert_post['user_email'] ) ) { 507 $insert_post['user_email'] = 'imported_' . $insert_post['user_email'];504 $insert_post['user_email'] = "imported_{$insert_post['user_email']}"; 508 505 } 509 506 … … 523 520 524 521 if ( '_id' == substr( $key, -3 ) && ( true === $this->sync_table ) ) { 525 $this->wpdb->insert( $this->sync_table_name, array( 'value_type' => 'user', 'value_id' => $post_id, 'meta_key' => $key, 'meta_value' => $value ) ); 522 $this->wpdb->insert( $this->sync_table_name, array( 523 'value_type' => 'user', 524 'value_id' => $post_id, 525 'meta_key' => $key, 526 'meta_value' => $value 527 ) ); 526 528 } 527 529 } … … 531 533 /** New Topic-Tag *********************************/ 532 534 533 case 'tags' :535 case 'tags' : 534 536 $post_id = wp_set_object_terms( $insert_postmeta['objectid'], $insert_postmeta['name'], 'topic-tag', true ); 535 537 $term = get_term_by( 'name', $insert_postmeta['name'], 'topic-tag'); … … 544 546 /** Forum Subscriptions ***************************/ 545 547 546 case 'forum_subscriptions' :548 case 'forum_subscriptions' : 547 549 $user_id = $insert_post['user_id']; 548 550 $items = wp_list_pluck( $insert_postmeta, '_bbp_forum_subscriptions' ); … … 565 567 /** Subscriptions *********************************/ 566 568 567 case 'topic_subscriptions' :569 case 'topic_subscriptions' : 568 570 $user_id = $insert_post['user_id']; 569 571 $items = wp_list_pluck( $insert_postmeta, '_bbp_subscriptions' ); … … 586 588 /** Favorites *************************************/ 587 589 588 case 'favorites' :590 case 'favorites' : 589 591 $user_id = $insert_post['user_id']; 590 592 $items = wp_list_pluck( $insert_postmeta, '_bbp_favorites' ); … … 607 609 /** Forum, Topic, Reply ***************************/ 608 610 609 default :611 default : 610 612 $post_id = wp_insert_post( $insert_post, true ); 611 613 … … 634 636 */ 635 637 if ( '_id' === substr( $key, -3 ) && ( true === $this->sync_table ) ) { 636 $this->wpdb->insert( $this->sync_table_name, array( 'value_type' => 'post', 'value_id' => $post_id, 'meta_key' => $key, 'meta_value' => $value ) ); 638 $this->wpdb->insert( $this->sync_table_name, array( 639 'value_type' => 'post', 640 'value_id' => $post_id, 641 'meta_key' => $key, 642 'meta_value' => $value 643 ) ); 637 644 } 638 645 … … 665 672 $has_update = false; 666 673 $query = ! empty( $this->sync_table ) 667 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' )674 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ) 668 675 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ); 669 676 … … 685 692 $has_update = false; 686 693 $query = ! empty( $this->sync_table ) 687 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' )694 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ) 688 695 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ); 689 696 … … 704 711 $has_update = false; 705 712 $query = ! empty( $this->sync_table ) 706 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' )713 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ) 707 714 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ); 708 715 … … 724 731 $has_update = false; 725 732 $query = ! empty( $this->sync_table ) 726 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' )733 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ) 727 734 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ); 728 735 … … 743 750 $has_update = false; 744 751 $query = ! empty( $this->sync_table ) 745 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' )752 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ) 746 753 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ); 747 754 … … 766 773 if ( ! empty( $this->sync_table ) ) { 767 774 $query = $this->wpdb->prepare( "SELECT sync_table1.value_id AS topic_id, sync_table1.meta_value AS topic_is_anonymous, sync_table2.meta_value AS topic_author 768 769 770 771 772 773 775 FROM {$this->sync_table_name} AS sync_table1 776 INNER JOIN {$this->sync_table_name} AS sync_table2 777 ON ( sync_table1.value_id = sync_table2.value_id ) 778 WHERE sync_table1.meta_value = %s 779 AND sync_table2.meta_key = %s 780 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_topic_author_name_id' ); 774 781 } else { 775 782 $query = $this->wpdb->prepare( "SELECT wp_postmeta1.post_id AS topic_id, wp_postmeta1.meta_value AS topic_is_anonymous, wp_postmeta2.meta_value AS topic_author 776 777 778 779 780 781 783 FROM {$this->wpdb->postmeta} AS wp_postmeta1 784 INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2 785 ON ( wp_postmeta1.post_id = wp_postmeta2.post_id ) 786 WHERE wp_postmeta1.meta_value = %s 787 AND wp_postmeta2.meta_key = %s 788 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_topic_author_name_id' ); 782 789 } 783 790 … … 805 812 if ( ! empty( $this->sync_table ) ) { 806 813 $query = $this->wpdb->prepare( "SELECT sync_table1.value_id AS reply_id, sync_table1.meta_value AS reply_is_anonymous, sync_table2.meta_value AS reply_author 807 808 809 810 811 812 814 FROM {$this->sync_table_name} AS sync_table1 815 INNER JOIN {$this->sync_table_name} AS sync_table2 816 ON ( sync_table1.value_id = sync_table2.value_id ) 817 WHERE sync_table1.meta_value = %s 818 AND sync_table2.meta_key = %s 819 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_reply_author_name_id' ); 813 820 } else { 814 821 $query = $this->wpdb->prepare( "SELECT wp_postmeta1.post_id AS reply_id, wp_postmeta1.meta_value AS reply_is_anonymous, wp_postmeta2.meta_value AS reply_author 815 816 817 818 819 820 822 FROM {$this->wpdb->postmeta} AS wp_postmeta1 823 INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2 824 ON ( wp_postmeta1.post_id = wp_postmeta2.post_id ) 825 WHERE wp_postmeta1.meta_value = %s 826 AND wp_postmeta2.meta_key = %s 827 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_reply_author_name_id' ); 821 828 } 822 829 … … 928 935 * @param string The table name to grab fields from 929 936 */ 930 private function get_fields( $tablename ) { 931 $rval = array(); 932 $field_array = $this->get_results( 'DESCRIBE ' . $tablename, ARRAY_A ); 933 937 private function get_fields( $tablename = '' ) { 938 $retval = array(); 939 $field_array = $this->get_results( "DESCRIBE {$tablename}", ARRAY_A ); 940 941 // Bail if no fields 942 if ( empty( $field_array ) ) { 943 return $retval; 944 } 945 946 // Add fields to array 934 947 foreach ( $field_array as $field ) { 935 $rval[] = $field['Field']; 936 } 937 948 if ( ! empty( $field['Field'] ) ) { 949 $retval[] = $field['Field']; 950 } 951 } 952 953 // Add social fields for users table 938 954 if ( $tablename === $this->wpdb->users ) { 939 $r val[] = 'role';940 $r val[] = 'yim';941 $r val[] = 'aim';942 $r val[] = 'jabber';943 } 944 945 return $r val;955 $retval[] = 'role'; 956 $retval[] = 'yim'; 957 $retval[] = 'aim'; 958 $retval[] = 'jabber'; 959 } 960 961 return $retval; 946 962 } 947 963 -
trunk/src/includes/admin/classes/class-bbp-converter.php
r6681 r6785 216 216 217 217 // Maybe prepend the step 218 $progress = ! empty( $this->step ) 219 ? sprintf( '<span class="step">%s.</span><span class="output">%s</span><span class="mini-step">%s</span>', $this->step, $output, $this->step_percentage . '%' ) 220 : $output; 218 if ( ! empty( $this->step ) ) { 219 220 // Include percentage 221 if ( ! empty( $this->rows_in_step ) ) { 222 $progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span><span class="mini-step">%s</span>', $this->step, $output, $this->step_percentage . '%' ); 223 224 // Don't include percentage 225 } else { 226 $progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span>', $this->step, $output ); 227 } 228 229 // Raw text 230 } else { 231 $progress = $output; 232 } 221 233 222 234 // Output … … 428 440 */ 429 441 private function bump_start() { 442 443 // Set rows in step from option 444 $this->rows_in_step = get_option( '_bbp_converter_rows_in_step', 0 ); 445 446 // Get rows to start from 430 447 $start = (int) ( $this->start + $this->rows ); 431 448 449 // Enforce maximum if exists 450 if ( $this->rows_in_step > 0 ) { 451 452 // Start cannot be larger than total rows 453 if ( $start > $this->rows_in_step ) { 454 $start = $this->rows_in_step; 455 } 456 457 // Max can't be greater than total rows 458 if ( $this->max > $this->rows_in_step ) { 459 $this->max = $this->rows_in_step; 460 } 461 } 462 463 // Update the start option 432 464 update_option( '_bbp_converter_start', $start ); 433 465 } … … 467 499 } else { 468 500 $this->bump_start(); 469 $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step) );501 $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s through %2$s)', 'bbpress' ), $this->start, $this->max ) ); 470 502 } 471 503 … … 493 525 } else { 494 526 $this->bump_start(); 495 $this->converter_response( sprintf( 527 $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 ) ); 496 528 } 497 529 } else { … … 516 548 } else { 517 549 $this->bump_start(); 518 $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step) );550 $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s through %2$s)', 'bbpress' ), $this->start, $this->max ) ); 519 551 } 520 552 } else { -
trunk/src/includes/admin/tools/converter.php
r6601 r6785 21 21 */ 22 22 function bbp_get_converters() { 23 static $files = array(); 23 24 24 // Default 25 $files = array(); 26 $path = bbp_setup_converter()->converters_dir; 27 $curdir = opendir( $path ); 25 // Only hit the file system one time per page load 26 if ( empty( $files ) ) { 28 27 29 // Look for the converter file in the converters directory 30 if ( false !== $curdir ) { 31 while ( $file = readdir( $curdir ) ) { 32 if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === false ) { 33 $name = preg_replace( '/.php/', '', $file ); 34 if ( 'Example' !== $name ) { 35 $files[ $name ] = $path . $file; 28 // Open the converter directory 29 $path = bbp_setup_converter()->converters_dir; 30 $curdir = opendir( $path ); 31 32 // Look for the converter file in the converters directory 33 if ( false !== $curdir ) { 34 while ( $file = readdir( $curdir ) ) { 35 if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === false ) { 36 $name = preg_replace( '/.php/', '', $file ); 37 if ( 'Example' !== $name ) { 38 $files[ $name ] = $path . $file; 39 } 36 40 } 37 41 } 38 42 } 39 }40 43 41 // Close the directory42 closedir( $curdir );44 // Close the directory 45 closedir( $curdir ); 43 46 44 // Sort keys alphabetically, ignoring upper/lower casing 45 if ( ! empty( $files ) ) { 46 natcasesort( $files ); 47 // Sort keys alphabetically, ignoring upper/lower casing 48 if ( ! empty( $files ) ) { 49 natcasesort( $files ); 50 } 47 51 } 48 52 … … 60 64 * @param string $platform Name of valid platform class. 61 65 */ 62 function bbp_new_converter( $platform ) {66 function bbp_new_converter( $platform = '' ) { 63 67 64 // Default value65 $converters = bbp_get_converters();68 // Bail if no platform 69 if ( ! empty( $platform ) ) { 66 70 67 // Create a new converter object if it's found68 if ( isset( $converters[ $platform ] ) ) {71 // Get the available converters 72 $converters = bbp_get_converters(); 69 73 70 // Include & create the converter 71 require_once $converters[ $platform ]; 72 if ( class_exists( $platform ) ) { 73 return new $platform; 74 // Create a new converter object if it's found 75 if ( isset( $converters[ $platform ] ) ) { 76 77 // Include & create the converter 78 require_once $converters[ $platform ]; 79 if ( class_exists( $platform ) ) { 80 return new $platform; 81 } 74 82 } 75 83 } -
trunk/src/includes/core/abstraction.php
r6768 r6785 60 60 if ( empty( $bbp_admin->converter ) ) { 61 61 62 // Require the converter classes 62 // Require the converter files 63 require_once $bbp_admin->admin_dir . 'tools/converter.php'; 64 require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter.php'; 65 require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter-db.php'; 63 66 require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter-base.php'; 64 require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter.php';65 67 66 68 // Setup -
trunk/src/includes/users/functions.php
r6740 r6785 982 982 983 983 // Try to call the conversion method 984 if ( is_a( $converter, 'BBP_Converter_Base') && method_exists( $converter, 'callback_pass' ) ) {984 if ( ( $converter instanceof BBP_Converter_Base ) && method_exists( $converter, 'callback_pass' ) ) { 985 985 $converter->callback_pass( $username, $_POST['pwd'] ); 986 986 }
Note: See TracChangeset
for help on using the changeset viewer.