Changeset 3225
- Timestamp:
- 05/25/2011 09:30:52 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-admin/importers/bbpress.php
r3194 r3225 101 101 102 102 if ( !function_exists( 'bb_cache_users' ) ) : 103 function bb_cache_users( $users ) { }103 function bb_cache_users( $users ) { } 104 104 endif; 105 105 … … 117 117 */ 118 118 class bbPress_Importer { 119 /** 120 * @var string Path to bbPress standalone 121 */ 122 var $bb_path = ''; 123 124 /** 125 * @var bool Are we debugging? 126 */ 127 var $debug = false; 119 120 /** 121 * @var string Path to bbPress standalone configuration file (bb-config.php) 122 */ 123 var $bbconfig = ''; 128 124 129 125 /** … … 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 // Config file does not exist 146 if ( !file_exists( $this->bbconfig ) ) 141 147 return false; 142 148 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 ) ) ); 153 define( 'BACKPRESS_PATH', BB_PATH . 'bb-includes/backpress/' ); 154 define( 'BB_INC', 'bb-includes/' ); 155 } 149 // Set the path constants 150 define( 'BB_PATH', trailingslashit( dirname( $this->bbconfig ) ) ); 151 define( 'BACKPRESS_PATH', BB_PATH . 'bb-includes/backpress/' ); 152 define( 'BB_INC', 'bb-includes/' ); 156 153 157 154 require_once( BB_PATH . BB_INC . 'class.bb-query.php' ); … … 172 169 173 170 $bb = new stdClass(); 174 require_once( $this->bb _path);171 require_once( $this->bbconfig ); 175 172 176 173 // Setup the global database connection 177 174 $bbdb = new BPDB( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST ); 178 175 179 / * Set the table names */176 // Set the table names 180 177 $bbdb->forums = $bb_table_prefix . 'forums'; 181 178 $bbdb->meta = $bb_table_prefix . 'meta'; … … 186 183 $bbdb->topics = $bb_table_prefix . 'topics'; 187 184 185 // Users table 188 186 if ( isset( $bb->custom_user_table ) ) 189 187 $bbdb->users = $bb->custom_user_table; … … 191 189 $bbdb->users = $bb_table_prefix . 'users'; 192 190 191 // Users meta table 193 192 if ( isset( $bb->custom_user_meta_table ) ) 194 193 $bbdb->usermeta = $bb->custom_user_meta_table; … … 196 195 $bbdb->usermeta = $bb_table_prefix . 'usermeta'; 197 196 198 $bbdb->prefix = $bb_table_prefix; 199 197 // Table prefix 198 $bbdb->prefix = $bb_table_prefix; 199 200 // Not installing 200 201 define( 'BB_INSTALLING', false ); 201 202 203 // Ghetto role map 202 204 if ( is_object( $wp_roles ) ) { 203 205 $bb_roles = $wp_roles; … … 205 207 } 206 208 209 // Call the standard bbPress actions 207 210 do_action( 'bb_got_roles' ); 208 211 do_action( 'bb_init' ); 209 212 do_action( 'init_roles' ); 210 213 214 // Setup required objects 211 215 $bb_current_user = $current_user; 212 216 $wp_users_object = new bbPress_Importer_BB_Auth; 213 217 218 // Taxonomy object 214 219 if ( !isset( $wp_taxonomy_object ) ) 215 220 $wp_taxonomy_object = new BB_Taxonomy( $bbdb ); … … 244 249 * @return string Path, if found 245 250 */ 246 function autolocate_bb_path() { 247 248 $path = ''; 249 $dirs = array( '', 'forum', 'forums', 'board', 'discussion', 'bb', 'bbpress' ); 251 function autolocate_bbconfig() { 252 253 // BuddyPress Install 254 if ( defined( 'BP_VERSION' ) && bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() ) { 255 global $bp; 256 257 if ( !empty( $bp->forums->bbconfig ) ) 258 return $bp->forums->bbconfig; 259 } 260 261 // Normal install 262 $dirs = array( 'forum', 'forums', 'board', 'discussion', 'bbpress', 'bb', '' ); 250 263 $base = trailingslashit( ABSPATH ); 251 264 $base_dirs = array( $base, dirname( $base ) ); 252 265 266 // Loop through possible directories 253 267 foreach ( $dirs as $dir ) { 254 268 269 // Loop through base dir 255 270 foreach ( $base_dirs as $base_dir ) { 271 272 // Path to try 256 273 $test_path = $base_dir . $dir . '/bb-config.php'; 257 274 275 // File exists 258 276 if ( file_exists( $test_path ) ) { 259 $path = $test_path; 260 break; 277 return realpath( $test_path ); 261 278 } 262 279 } 263 264 } 265 266 return $path;280 } 281 282 // Nothing found 283 return ''; 267 284 } 268 285 … … 415 432 global $wpdb, $bbdb; 416 433 417 $autolocate = $this->autolocate_bb_path(); 418 419 ?> 434 // Attempt to autolocate config file 435 $autolocate = $this->autolocate_bbconfig(); ?> 420 436 421 437 <div class="narrow"> … … 467 483 <ol> 468 484 <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/' ); ?>485 <?php _e( 'If you are using the alpha version of bbPress 1.1, subscriptions will be ported automatically.', 'bbpress' ); ?> 470 486 </li> 471 487 <li> 472 <?php _e( 'If you are using the alpha version of bbPress 1.1 subscriptions will be ported automatically.', 'bbpress' ); ?>488 <?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 489 </li> 474 490 <li> … … 481 497 482 498 <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>499 <p><?php _e( 'Enter the full path to your bbPress configuration file i.e. <code>bb-config.php</code>:', 'bbpress' ); ?></p> 484 500 485 501 <table class="form-table"> 486 487 502 <tr> 488 503 <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>504 <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 505 </tr> 491 492 506 </table> 493 507 … … 522 536 */ 523 537 function setup() { 524 // Get details from form or from DB 538 539 // Get details from _POST 525 540 if ( !empty( $_POST['bbp_bbpress_path'] ) ) { 541 526 542 // Store details for later 527 $this->bb_path = $_POST['bbp_bbpress_path']; 528 529 update_option( 'bbp_bbpress_path', $this->bb_path ); 543 $this->bbconfig = realpath( $_POST['bbp_bbpress_path'] ); 544 545 // Update path 546 update_option( 'bbp_bbpress_path', $this->bbconfig ); 547 548 // Get details from DB 530 549 } else { 531 $this->bb_path = get_option( 'bbp_bbpress_path' ); 532 } 533 534 if ( empty( $this->bb_path ) ) { ?> 550 $this->bbconfig = get_option( 'bbp_bbpress_path' ); 551 } 552 553 // No config file found 554 if ( empty( $this->bbconfig ) ) { ?> 535 555 536 556 <p><?php _e( 'Please enter the path to your bbPress configuration file - <code>bb-config.php</code>.', 'bbpress' ); ?></p> … … 543 563 544 564 // 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';565 if ( is_dir( $this->bbconfig ) && file_exists( trailingslashit( $this->bbconfig ) . 'bb-config.php' ) ) { 566 $this->bbconfig = trailingslashit( $this->bbconfig ) . 'bb-config.php'; 547 567 } 548 568 549 569 // Check if the file exists 550 if ( !file_exists( $this->bb _path ) || is_dir( $this->bb_path) ) {570 if ( !file_exists( $this->bbconfig ) || is_dir( $this->bbconfig ) ) { 551 571 552 572 delete_option( 'bbp_bbpress_path' ); ?> 553 573 554 <p><?php _e( 'bbPress configuration file <code>bb-config.php</code> doesn\'t exist in the path specified! Please check the path and try again.', 'bbpress' ); ?></p> 555 <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> 556 <?php 557 return false; 574 <p><?php _e( 'bbPress configuration file <code>bb-config.php</code> doesn\'t exist in the path specified! Please check the path and try again.', 'bbpress' ); ?></p> 575 <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> 576 577 <?php 578 579 return false; 558 580 } 559 581 … … 599 621 <?php _e( 'Your WordPress blog is <strong>new</strong> and you don\'t have the fear of losing WordPress users:', 'bbpress' ); ?> 600 622 <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 w ould 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' ); ?>623 <?php printf( __( '<strong>Note</strong>: The WordPress %1$s and %2$s tables will be renamed (not deleted) so that you can restore them if something goes wrong.', 'bbpress' ), '<code>' . $wpdb->users . '</code>', '<code>' . $wpdb->usermeta . '</code>' ); ?> 624 <?php printf( __( 'Please ensure there are no tables named %1$s and %2$s to avoid renaming conflicts.', 'bbpress' ), '<code>' . $bbdb->prefix . $wpdb->users . '_tmp' . '</code>', '<code>' . $bbdb->prefix . $wpdb->usermeta . '_tmp' . '</code>' ); ?> 603 625 <?php _e( 'Also, your WordPress and bbPress installs must be in the same database.', 'bbpress' ); ?> 604 626 </li> … … 612 634 <?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 635 <?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' ); ?>636 <?php printf( __( '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 637 </li> 616 638 … … 619 641 <?php endif; ?> 620 642 621 <input type="radio" name="step" <?php if ( $this->is_integrated() ) : ?>disabled="disabled"<?php endif;?> value="2"<?php checked( $radio, 'user'); ?> id="step_user" />643 <input type="radio" name="step"<?php disabled( $this->is_integrated() ); ?> value="2"<?php checked( $radio, 'user' ); ?> id="step_user" /> 622 644 <label for="step_user"><?php _e( 'Migrate Users', 'bbpress' ); ?></label> 623 645 … … 668 690 <ol> 669 691 670 <?php 671 672 // Drop the old temp tables while debugging 673 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 table 677 678 ?> 692 <?php /* Rename the WordPress users and usermeta table */ ?> 679 693 680 694 <li> 681 695 <?php 682 if ( $wpdb->query( "RENAME TABLE $wpdb->users TO {$bbdb->prefix}{$wpdb->users}_tmp, $wpdb->usermeta TO {$bbdb->prefix}{$wpdb->usermeta}_tmp" ) !== false ) : ?> 683 <?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 <?php else : ?> 685 <?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; ?> 696 697 if ( $wpdb->query( "RENAME TABLE $wpdb->users TO {$bbdb->prefix}{$wpdb->users}_tmp, $wpdb->usermeta TO {$bbdb->prefix}{$wpdb->usermeta}_tmp" ) !== false ) : 698 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' ); 699 else : 700 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 ); ?> 701 702 </li></ol> 703 704 <?php 705 return; 706 endif; ?> 707 687 708 </li> 688 709 … … 690 711 691 712 <li> 692 <?php if ( $wpdb->query( "CREATE TABLE $wpdb->users ( `ID` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_activation_key` VARCHAR( 60 ) NOT NULL DEFAULT '', KEY ( `user_login` ), KEY( `user_nicename` ) ) SELECT * FROM $bbdb->users ORDER BY `ID`" ) !== false ) : ?> 693 <?php printf( __( 'Created the <code>%s</code> table and copied the users from bbPress.', 'bbpress' ), $wpdb->users ); ?> 694 <?php else : ?> 695 <?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; ?> 713 <?php 714 715 if ( $wpdb->query( "CREATE TABLE $wpdb->users ( `ID` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_activation_key` VARCHAR( 60 ) NOT NULL DEFAULT '', KEY ( `user_login` ), KEY( `user_nicename` ) ) SELECT * FROM $bbdb->users ORDER BY `ID`" ) !== false ) : 716 printf( __( 'Created the <code>%s</code> table and copied the users from bbPress.', 'bbpress' ), $wpdb->users ); 717 else : 718 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 ); ?> 719 720 </li></ol> 721 722 <?php 723 724 return; 725 endif; ?> 726 697 727 </li> 698 728 699 729 <li> 700 <?php if ( $wpdb->query( "CREATE TABLE $wpdb->usermeta ( `umeta_id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, KEY ( `user_id` ), KEY( `meta_key` ) ) SELECT * FROM $bbdb->usermeta ORDER BY `umeta_id`" ) !== false ) : ?> 701 <?php printf( __( 'Created the <code>%s</code> table and copied the user information from bbPress.', 'bbpress' ), $wpdb->usermeta ); ?> 702 <?php else : ?> 703 <?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; ?> 730 <?php 731 732 if ( $wpdb->query( "CREATE TABLE $wpdb->usermeta ( `umeta_id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, KEY ( `user_id` ), KEY( `meta_key` ) ) SELECT * FROM $bbdb->usermeta ORDER BY `umeta_id`" ) !== false ) : 733 printf( __( 'Created the <code>%s</code> table and copied the user information from bbPress.', 'bbpress' ), $wpdb->usermeta ); 734 else : 735 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 ); ?> 736 737 </li></ol> 738 739 <?php 740 741 return; 742 endif; ?> 743 705 744 </li> 706 745 … … 772 811 <?php 773 812 774 break;813 return; 775 814 776 815 endif; … … 796 835 <?php 797 836 798 echo $this->next_step( 3, __( 'Import byforums, topics and posts »', 'bbpress' ) ); ?>837 echo $this->next_step( 3, __( 'Import forums, topics and posts »', 'bbpress' ) ); ?> 799 838 800 839 </div> … … 833 872 if ( !$forums = bb_get_forums() ) { 834 873 echo "<li><strong>" . __( 'No forums were found!', 'bbpress' ) . "</strong></li></ol>\n"; 835 break;874 return; 836 875 } 837 876 838 if ( $this->debug == true ) 839 echo "<li>" . sprintf( __( 'Total number of forums: %s', 'bbpress' ), count( $forums ) ) . "</li>\n"; 877 echo "<li>" . sprintf( __( 'Total number of forums: %s', 'bbpress' ), count( $forums ) ) . "</li>\n"; 840 878 841 879 $forum_map = array(); … … 896 934 bb_cache_first_posts( $topics ); 897 935 898 if ( $this->debug == true ) 899 echo "<li>" . sprintf( __( 'Total number of topics in the forum: %s', 'bbpress' ), count( $topics ) ) . "</li>\n"; 936 echo "<li>" . sprintf( __( 'Total number of topics in the forum: %s', 'bbpress' ), count( $topics ) ) . "</li>\n"; 900 937 901 938 foreach ( (array) $topics as $topic ) { … … 990 1027 } 991 1028 992 $replies++;993 994 1029 if ( $post->post_status != 0 ) 995 1030 $hidden_replies++; 1031 else 1032 $replies++; 996 1033 } 997 1034 … … 1022 1059 } 1023 1060 1024 // Last active time 1025 $last_active = $post ? $post->post_time : $first_post->post_time; 1061 // Last active 1062 $last_active_id = !empty( $last_reply ) ? $last_reply : $inserted_topic; 1063 $last_active_time = !empty( $post ) ? $post->post_time : $first_post->post_time; 1026 1064 1027 1065 // 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 ); 1066 update_post_meta( $inserted_topic, '_bbp_last_reply_id', $last_reply ); 1067 update_post_meta( $inserted_topic, '_bbp_last_active_id', $last_active_id ); 1068 update_post_meta( $inserted_topic, '_bbp_last_active_time', $last_active_time ); 1069 update_post_meta( $inserted_topic, '_bbp_reply_count', $replies ); 1070 update_post_meta( $inserted_topic, '_bbp_hidden_reply_count', $hidden_replies ); 1071 1033 1072 // Voices will be done by recount 1034 1073
Note: See TracChangeset
for help on using the changeset viewer.