Ticket #1523: improvements.diff
File improvements.diff, 15.0 KB (added by , 13 years ago) |
---|
-
bbpress.php
116 116 * @todo Role Mapping Options 117 117 */ 118 118 class bbPress_Importer { 119 /**120 * @var string Path to bbPress standalone121 */122 var $bb_path = '';123 119 124 120 /** 125 * @var bool Are we debugging?121 * @var string Path to bbPress standalone configuration file (bb-config.php) 126 122 */ 127 var $ debug = false;123 var $bbconfig = ''; 128 124 129 125 /** 130 126 * Load the bbPress environment 131 127 */ 132 128 function load_bbpress() { 129 130 // BuddyPress Install 131 if ( defined( 'BP_VERSION' ) && bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() ) { 132 global $bp; 133 134 if ( !empty( $bp->forums->bbconfig ) && $bp->forums->bbconfig == $this->bbconfig ) 135 bp_forums_load_bbpress(); 136 } 137 133 138 global $wpdb, $wp_roles, $current_user, $wp_users_object, $wp_taxonomy_object; 134 139 global $bb, $bbdb, $bb_table_prefix, $bb_current_user, $bb_roles, $bb_queries; 135 140 136 / * Return if we've already run this function. */141 // Return if we've already run this function or it is BuddyPress 137 142 if ( is_object( $bbdb ) ) 138 143 return; 139 144 140 if ( !file_exists( $this->bb _path) )145 if ( !file_exists( $this->bbconfig ) ) 141 146 return false; 142 147 143 // BuddyPress install 144 if ( defined( 'BP_VERSION' ) ) { 145 define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' ); 146 define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' ); 147 define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' ); 148 define( 'BB_INC', 'bb-includes/' ); 149 150 // Normal existing install 151 } else { 152 define( 'BB_PATH', trailingslashit( dirname( $this->bb_path ) ) ); 148 // Set the path constants 149 define( 'BB_PATH', trailingslashit( dirname( $this->bbconfig ) ) ); 153 150 define( 'BACKPRESS_PATH', BB_PATH . 'bb-includes/backpress/' ); 154 151 define( 'BB_INC', 'bb-includes/' ); 155 }156 152 157 153 require_once( BB_PATH . BB_INC . 'class.bb-query.php' ); 158 154 require_once( BB_PATH . BB_INC . 'class.bb-walker.php' ); … … 171 167 require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' ); 172 168 173 169 $bb = new stdClass(); 174 require_once( $this->bb _path);170 require_once( $this->bbconfig ); 175 171 176 172 // Setup the global database connection 177 173 $bbdb = new BPDB( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST ); … … 243 239 * 244 240 * @return string Path, if found 245 241 */ 246 function autolocate_bb _path() {242 function autolocate_bbconfig() { 247 243 248 $path = ''; 249 $dirs = array( '', 'forum', 'forums', 'board', 'discussion', 'bb', 'bbpress' ); 244 // BuddyPress Install 245 if ( defined( 'BP_VERSION' ) && bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() ) { 246 global $bp; 247 248 if ( !empty( $bp->forums->bbconfig ) ) 249 return $bp->forums->bbconfig; 250 } 251 252 $dirs = array( 'forum', 'forums', 'board', 'discussion', 'bbpress', 'bb', '' ); 250 253 $base = trailingslashit( ABSPATH ); 251 254 $base_dirs = array( $base, dirname( $base ) ); 252 255 … … 255 258 foreach ( $base_dirs as $base_dir ) { 256 259 $test_path = $base_dir . $dir . '/bb-config.php'; 257 260 258 if ( file_exists( $test_path ) ) { 259 $path = $test_path; 260 break; 261 if ( file_exists( $test_path ) ) 262 return realpath( $test_path ); 261 263 } 262 }263 264 264 265 } 265 266 266 return $path;267 return ''; 267 268 } 268 269 269 270 /** … … 414 415 function greet() { 415 416 global $wpdb, $bbdb; 416 417 417 $autolocate = $this->autolocate_bb _path();418 $autolocate = $this->autolocate_bbconfig(); 418 419 419 420 ?> 420 421 … … 466 467 <li><?php _e( 'Notes on compatibility:', 'bbpress' ); ?> 467 468 <ol> 468 469 <li> 469 <?php printf( __( 'If you have the <a href="%s">Subscribe to Topic</a> plugin active, please deactivate it. This script will migrate user subscriptions from that plugin.', 'bbpress' ), 'http://bbpress.org/plugins/topic/subscribe-to-topic/' ); ?>470 <?php _e( 'If you are using the alpha version of bbPress 1.1, subscriptions will be ported automatically.', 'bbpress' ); ?> 470 471 </li> 471 472 <li> 472 <?php _e( 'If you are using the alpha version of bbPress 1.1 subscriptions will be ported automatically.', 'bbpress' ); ?>473 <?php printf( __( 'If you have the <a href="%s">Subscribe to Topic</a> plugin active, then this script will migrate user subscriptions from that plugin.', 'bbpress' ), 'http://bbpress.org/plugins/topic/subscribe-to-topic/' ); ?> 473 474 </li> 474 475 <li> 475 476 <?php printf( __( 'If you are importing an existing BuddyPress Forums installation, we should have found your previous configuration file.', 'bbpress' ), 'http://bbpress.org/plugins/topic/subscribe-to-topic/' ); ?> … … 480 481 </ol> 481 482 482 483 <h3><?php _e( 'Configuration', 'bbpress' ); ?></h3> 483 <p><?php _e( 'Enter the path to your bbPress standalone install, where you\'d find your<code>bb-config.php</code>:', 'bbpress' ); ?></p>484 <p><?php _e( 'Enter the full path to your bbPress configuration file i.e. <code>bb-config.php</code>:', 'bbpress' ); ?></p> 484 485 485 486 <table class="form-table"> 486 487 487 488 <tr> 488 489 <th scope="row"><label for="bbp_bbpress_path"><?php _e( 'bbPress Standalone Path:', 'bbpress' ); ?></label></th> 489 <td><input type="text" name="bbp_bbpress_path" id="bbp_bbpress_path" class="regular-text" value="<?php echo $autolocate; ?>" /></td>490 <td><input type="text" name="bbp_bbpress_path" id="bbp_bbpress_path" class="regular-text" value="<?php echo !empty( $autolocate ) ? $autolocate : trailingslashit( ABSPATH ) . 'bb-config.php'; ?>" /></td> 490 491 </tr> 491 492 492 493 </table> … … 524 525 // Get details from form or from DB 525 526 if ( !empty( $_POST['bbp_bbpress_path'] ) ) { 526 527 // Store details for later 527 $this->bb _path = $_POST['bbp_bbpress_path'];528 $this->bbconfig = realpath( $_POST['bbp_bbpress_path'] ); 528 529 529 update_option( 'bbp_bbpress_path', $this->bb _path);530 update_option( 'bbp_bbpress_path', $this->bbconfig ); 530 531 } else { 531 $this->bb _path= get_option( 'bbp_bbpress_path' );532 $this->bbconfig = get_option( 'bbp_bbpress_path' ); 532 533 } 533 534 534 if ( empty( $this->bb _path) ) { ?>535 if ( empty( $this->bbconfig ) ) { ?> 535 536 536 537 <p><?php _e( 'Please enter the path to your bbPress configuration file - <code>bb-config.php</code>.', 'bbpress' ); ?></p> 537 538 <p><a href="<?php echo esc_url( add_query_arg( array( 'import' => 'bbpress', 'step' => '-1', '_wpnonce' => wp_create_nonce( 'bbp-bbpress-import' ), '_wp_http_referer' => esc_attr( remove_query_arg( 'step', $_SERVER['REQUEST_URI'] ) ) ) ) ); ?>" class="button"><?php _e( 'Go Back', 'bbpress' ); ?></a></p> … … 542 543 } 543 544 544 545 // Check if the user submitted a directory as the path by mistake 545 if ( is_dir( $this->bb _path ) && file_exists( trailingslashit( $this->bb_path) . 'bb-config.php' ) ) {546 $this->bb _path = trailingslashit( $this->bb_path) . 'bb-config.php';546 if ( is_dir( $this->bbconfig ) && file_exists( trailingslashit( $this->bbconfig ) . 'bb-config.php' ) ) { 547 $this->bbconfig = trailingslashit( $this->bbconfig ) . 'bb-config.php'; 547 548 } 548 549 549 550 // Check if the file exists 550 if ( !file_exists( $this->bb _path ) || is_dir( $this->bb_path) ) {551 if ( !file_exists( $this->bbconfig ) || is_dir( $this->bbconfig ) ) { 551 552 552 553 delete_option( 'bbp_bbpress_path' ); ?> 553 554 … … 598 599 <li> 599 600 <?php _e( 'Your WordPress blog is <strong>new</strong> and you don\'t have the fear of losing WordPress users:', 'bbpress' ); ?> 600 601 <label for="step_user"><?php _e( 'Go to migrating users section.', 'bbpress' ); ?></label> 601 <?php printf( __( '<strong>Note</strong>: The WordPress %1$s and %2$s tables would be renamed, but not deleted so that you could restore them if something goes wrong.', 'bbpress' ), $wpdb->users, $wpdb->usermeta); ?>602 <?php printf( __( 'Please ensure there are no tables with names %1$s and %2$s so that there is no problem in renaming.', 'bbpress' ), $bbdb->prefix . $wpdb->users . '_tmp', $bbdb->prefix . $wpdb->usermeta . '_tmp' ); ?>602 <?php printf( __( '<strong>Note</strong>: The WordPress %1$s and %2$s tables would be renamed, but not deleted so that you could restore them if something goes wrong.', 'bbpress' ), '<code>' . $wpdb->users . '</code>', '<code>' . $wpdb->usermeta . '</code>' ); ?> 603 <?php printf( __( 'Please ensure there are no tables with names %1$s and %2$s so that there is no problem in renaming.', 'bbpress' ), '<code>' . $bbdb->prefix . $wpdb->users . '_tmp' . '</code>', '<code>' . $bbdb->prefix . $wpdb->usermeta . '_tmp' . '</code>' ); ?> 603 604 <?php _e( 'Also, your WordPress and bbPress installs must be in the same database.', 'bbpress' ); ?> 604 605 </li> 605 606 … … 611 612 <li> 612 613 <?php _e( 'You have a well <strong>established</strong> WordPress user base, the user tables are not integrated and you can\'t lose your users:', 'bbpress' ); ?> 613 614 <?php _e( 'This is currently not yet supported, and will likely not be in the future also as it is highly complex to merge two user sets (which might even conflict).', 'bbpress' ); ?> 614 <?php printf( __( 'But, patches are always <a href="%s" title="The last revision containing the custom user migration code">welcome</a>. :)', 'bbpress' ), 'http:// code.google.com/p/bbpress-standalone-to-plugin/source/browse/trunk/bbs2p.php?spec=svn13&r=13' ); ?>615 <?php printf( __( 'But, patches are always <a href="%s" title="The last revision containing the custom user migration code">welcome</a>. :)', 'bbpress' ), 'http://bbpress.trac.wordpress.org/ticket/1523' ); ?> 615 616 </li> 616 617 617 618 </ol> 618 619 619 620 <?php endif; ?> 620 621 621 <input type="radio" name="step" <?php if ( $this->is_integrated() ) : ?>disabled="disabled"<?php endif;?> value="2"<?php checked( $radio, 'user'); ?> id="step_user" />622 <input type="radio" name="step"<?php disabled( $this->is_integrated() ); ?> value="2"<?php checked( $radio, 'user' ); ?> id="step_user" /> 622 623 <label for="step_user"><?php _e( 'Migrate Users', 'bbpress' ); ?></label> 623 624 624 625 <input type="radio" name="step" value="3"<?php checked( $radio, 'board' ); ?> id="step_board" /> … … 667 668 668 669 <ol> 669 670 670 <?php 671 <?php /* Rename the WordPress users and usermeta table */ ?> 671 672 672 // Drop the old temp tables while debugging673 if ( $this->debug == true )674 $wpdb->query( "DROP TABLE IF EXISTS {$bbdb->prefix}{$wpdb->users}_tmp, {$bbdb->prefix}{$wpdb->usermeta}_tmp" );675 676 // Rename the WordPress users and usermeta table677 678 ?>679 680 673 <li> 681 674 <?php 682 675 if ( $wpdb->query( "RENAME TABLE $wpdb->users TO {$bbdb->prefix}{$wpdb->users}_tmp, $wpdb->usermeta TO {$bbdb->prefix}{$wpdb->usermeta}_tmp" ) !== false ) : ?> 683 676 <?php printf( __( 'Renamed the <code>%1$s</code> and <code>%2$s</code> tables to <code>%3$s</code> and <code>%4$s</code> respectively.', 'bbpress' ), $wpdb->users, $wpdb->usermeta, $bbdb->prefix . $wpdb->users . '_tmp', $bbdb->prefix . $wpdb->usermeta . '_tmp' ); ?> 684 677 <?php else : ?> 685 678 <?php printf( __( 'There was a problem dropping the <code>%1$s</code> and <code>%2$s</code> tables. Please check and re-run the script or rename or drop the tables yourself.', 'bbpress' ), $wpdb->users, $wpdb->usermeta ); ?></li></ol> 686 <?php break; endif; ?>679 <?php return; endif; ?> 687 680 </li> 688 681 689 682 <?php /* Duplicate the WordPress users and usermeta table */ ?> … … 693 686 <?php printf( __( 'Created the <code>%s</code> table and copied the users from bbPress.', 'bbpress' ), $wpdb->users ); ?> 694 687 <?php else : ?> 695 688 <?php printf( __( 'There was a problem duplicating the table <code>%1$s</code> to <code>%2$s</code>. Please check and re-run the script or duplicate the table yourself.', 'bbpress' ), $bbdb->users, $wpdb->users ); ?></li></ol> 696 <?php break; endif; ?>689 <?php return; endif; ?> 697 690 </li> 698 691 699 692 <li> … … 701 694 <?php printf( __( 'Created the <code>%s</code> table and copied the user information from bbPress.', 'bbpress' ), $wpdb->usermeta ); ?> 702 695 <?php else : ?> 703 696 <?php printf( __( 'There was a problem duplicating the table <code>%1$s</code> to <code>%2$s</code>. Please check and re-run the script or duplicate the table yourself.', 'bbpress' ), $bbdb->usermeta, $wpdb->usermeta ); ?></li></ol> 704 <?php break; endif; ?>697 <?php return; endif; ?> 705 698 </li> 706 699 707 700 <?php … … 771 764 772 765 <?php 773 766 774 break;767 return; 775 768 776 769 endif; 777 770 … … 795 788 <p><?php _e( 'Your users have all been imported, but wait – there’s more! Now we need to import your forums, topics and posts!', 'bbpress' ); ?></p> 796 789 <?php 797 790 798 echo $this->next_step( 3, __( 'Import byforums, topics and posts »', 'bbpress' ) ); ?>791 echo $this->next_step( 3, __( 'Import forums, topics and posts »', 'bbpress' ) ); ?> 799 792 800 793 </div> 801 794 … … 832 825 833 826 if ( !$forums = bb_get_forums() ) { 834 827 echo "<li><strong>" . __( 'No forums were found!', 'bbpress' ) . "</strong></li></ol>\n"; 835 break;828 return; 836 829 } 837 830 838 if ( $this->debug == true )839 831 echo "<li>" . sprintf( __( 'Total number of forums: %s', 'bbpress' ), count( $forums ) ) . "</li>\n"; 840 832 841 833 $forum_map = array(); … … 895 887 896 888 bb_cache_first_posts( $topics ); 897 889 898 if ( $this->debug == true )899 890 echo "<li>" . sprintf( __( 'Total number of topics in the forum: %s', 'bbpress' ), count( $topics ) ) . "</li>\n"; 900 891 901 892 foreach ( (array) $topics as $topic ) { … … 989 980 bbp_update_reply_walker( $last_reply ); 990 981 } 991 982 992 $replies++;993 994 983 if ( $post->post_status != 0 ) 995 984 $hidden_replies++; 985 else 986 $replies++; 996 987 } 997 988 998 989 // Only add favorites and subscriptions if the topic is public … … 1021 1012 break; 1022 1013 } 1023 1014 1024 // Last active time 1025 $last_active = $post ? $post->post_time : $first_post->post_time; 1015 // Last active 1016 $last_active_id = !empty( $last_reply ) ? $last_reply : $inserted_topic; 1017 $last_active_time = !empty( $post ) ? $post->post_time : $first_post->post_time; 1026 1018 1027 1019 // Reply topic meta 1028 update_post_meta( $inserted_topic, '_bbp_last_reply_id', $last_reply ); 1029 update_post_meta( $inserted_topic, '_bbp_last_active_id', $last_reply ? $last_reply : $inserted_topic ); 1030 update_post_meta( $inserted_topic, '_bbp_last_active_time', $topic->topic_time ); 1031 update_post_meta( $inserted_topic, '_bbp_reply_count', $replies - $hidden_replies ); 1032 update_post_meta( $inserted_topic, '_bbp_hidden_reply_count', $hidden_replies ); 1020 update_post_meta( $inserted_topic, '_bbp_last_reply_id', $last_reply ); 1021 update_post_meta( $inserted_topic, '_bbp_last_active_id', $last_active_id ); 1022 update_post_meta( $inserted_topic, '_bbp_last_active_time', $last_active_time ); 1023 update_post_meta( $inserted_topic, '_bbp_reply_count', $replies ); 1024 update_post_meta( $inserted_topic, '_bbp_hidden_reply_count', $hidden_replies ); 1025 1033 1026 // Voices will be done by recount 1034 1027 1035 1028 bbp_update_topic_walker( $inserted_topic );