Changeset 6601
- Timestamp:
- 06/23/2017 04:21:58 AM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 1 deleted
- 9 edited
-
bbpress.php (modified) (2 diffs)
-
includes/admin/actions.php (modified) (3 diffs)
-
includes/admin/admin.php (deleted)
-
includes/admin/assets/css/admin.css (modified) (1 diff)
-
includes/admin/assets/js/converter.js (modified) (10 diffs)
-
includes/admin/classes/class-bbp-admin.php (added)
-
includes/admin/classes/class-bbp-converter-base.php (modified) (26 diffs)
-
includes/admin/classes/class-bbp-converter.php (modified) (28 diffs)
-
includes/admin/tools/converter.php (modified) (2 diffs)
-
includes/core/abstraction.php (modified) (1 diff)
-
includes/users/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bbpress.php
r6596 r6601 204 204 /** Versions **********************************************************/ 205 205 206 $this->version = '2.6-rc-6 595';206 $this->version = '2.6-rc-6601'; 207 207 $this->db_version = '262'; 208 208 … … 375 375 // Quick admin check and load if needed 376 376 if ( is_admin() ) { 377 require $this->includes_dir . 'admin/admin.php';378 377 require $this->includes_dir . 'admin/actions.php'; 379 378 } -
trunk/src/includes/admin/actions.php
r6573 r6601 11 11 * 12 12 * - bbPress: In {@link bbPress::setup_actions()} in bbpress.php 13 * - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php13 * - Admin: More in {@link BBP_Admin::setup_actions()} in class-bbp-admin.php 14 14 * 15 15 * @package bbPress … … 62 62 63 63 // Initialize the admin area 64 add_action( 'bbp_init', 'bbp_ admin' );64 add_action( 'bbp_init', 'bbp_setup_admin' ); 65 65 66 66 // Reset the menu order … … 106 106 add_filter( 'bbp_admin_replies_column_headers', 'bbp_filter_column_headers' ); 107 107 108 // Load the converter early (page and AJAX) 109 add_action( 'load-tools_page_bbp-converter', 'bbp_setup_converter', 2 ); 110 add_action( 'wp_ajax_bbp_converter_process', 'bbp_setup_converter', 2 ); 111 112 /** 113 * Setup bbPress admin 114 * 115 * @since 2.0.0 bbPress (r1000) 116 * @since 2.6.0 bbPress (r6598) Moved to actions.php 117 */ 118 function bbp_admin() { 119 return bbp_setup_admin(); 120 } 121 108 122 /** 109 123 * When a new site is created in a multisite installation, run the activation -
trunk/src/includes/admin/assets/css/admin.css
r6542 r6601 366 366 } 367 367 368 #bbp-converter-timer { 369 position: absolute; 370 right: 10px; 371 top: 4px; 372 padding: 5px; 373 border: 1px solid #ddd; 374 background-color: #fafafa; 368 #bbp-converter-status { 369 font-weight: 400; 370 font-size: 12px; 371 color: #aaa; 372 display: block; 373 margin-top: 2px; 375 374 } 376 375 -
trunk/src/includes/admin/assets/js/converter.js
r6514 r6601 9 9 start = $( '#bbp-converter-start' ), 10 10 restart = $( '#_bbp_converter_restart' ), 11 timer = $( '#bbp-converter-timer' ), 12 settings = $( '#bbp-converter-settings' ), 13 14 // Prefetch the settings 15 options = bbp_converter_settings(); 11 status = $( '#bbp-converter-status' ), 12 settings = $( '#bbp-converter-settings' ); 16 13 17 14 /** … … 24 21 start.on( 'click', function( e ) { 25 22 bbp_converter_user_start(); 26 27 23 e.preventDefault(); 28 24 } ); … … 37 33 $( stop ).on( 'click', function( e ) { 38 34 bbp_converter_user_stop(); 39 40 35 e.preventDefault(); 41 36 } ); … … 49 44 */ 50 45 function bbp_converter_user_start() { 51 if ( ! BBP_Converter.running ) { 52 message.addClass( 'started' ); 53 start.hide(); 54 stop.show(); 55 56 if ( BBP_Converter.started ) { 57 bbp_converter_log( BBP_Converter.strings.start_continue ); 58 } else { 59 bbp_converter_log( BBP_Converter.strings.start_start ); 60 } 61 62 bbp_converter_next(); 63 } 64 65 BBP_Converter.started = true; 46 bbp_converter_start(); 66 47 } 67 48 … … 81 62 82 63 /** 83 * Database error84 *85 * @since 2.6.0 bbPress (r6470)86 *87 * @returns {void}88 */89 function bbp_converter_error_db() {90 bbp_converter_stop(91 BBP_Converter.strings.button_start,92 BBP_Converter.strings.import_error_db93 );94 }95 96 /**97 * Converter error98 *99 * @since 2.6.0 bbPress (r6470)100 *101 * @returns {void}102 */103 function bbp_converter_halt() {104 bbp_converter_stop(105 BBP_Converter.strings.button_continue,106 BBP_Converter.strings.import_error_halt107 );108 }109 110 /**111 * Converter complete112 *113 * @since 2.6.0 bbPress (r6470)114 *115 * @returns {void}116 */117 function bbp_converter_complete() {118 bbp_converter_stop(119 BBP_Converter.strings.button_start,120 BBP_Converter.strings.import_comelete121 );122 123 BBP_Converter.started = false;124 }125 126 /**127 * Handle successful ajax response128 *129 * @since 2.6.0 bbPress (r6470)130 *131 * @param {object} response Ajax response132 *133 * @returns {void}134 */135 function bbp_converter_process( response ) {136 bbp_converter_log( response );137 138 if ( response === BBP_Converter.strings.import_complete ) {139 bbp_converter_complete();140 141 } else if ( BBP_Converter.running ) {142 bbp_converter_next();143 144 } else if ( BBP_Converter.halt ) {145 bbp_converter_halt();146 }147 }148 149 /**150 64 * Return values of converter settings 151 65 * … … 166 80 167 81 if ( values['_bbp_converter_delay_time'] ) { 168 BBP_Converter.delay = values['_bbp_converter_delay_time']* 1000;82 BBP_Converter.delay = parseInt( values['_bbp_converter_delay_time'], 10 ) * 1000; 169 83 } 170 84 … … 182 96 * @returns {void} 183 97 */ 184 function bbp_converter_step() { 185 98 function bbp_converter_post() { 99 $.post( ajaxurl, bbp_converter_settings(), function( response ) { 100 101 // Parse the json response 102 try { 103 var data = response.data; 104 105 // Success 106 if ( true === response.success ) { 107 bbp_converter_step( data ); 108 109 // Failure 110 } else { 111 bbp_converter_stop(); 112 } 113 114 } catch( e ) { 115 bbp_converter_stop(); 116 } 117 }, 'json' ); 118 } 119 120 /** 121 * Process the next step 122 * 123 * @since 2.6.0 bbPress (r6600) 124 * 125 * @param {object} data 126 * @returns {void} 127 */ 128 function bbp_converter_step( data ) { 129 130 // Bail if not running 186 131 if ( ! BBP_Converter.running ) { 187 132 return; 188 133 } 189 134 190 // Check if the settings have changed 191 options = bbp_converter_settings(); 192 193 $.post( ajaxurl, options, function( response ) { 194 195 if ( 'bbp_converter_db_connection_failed' === response ) { 196 bbp_converter_error_db(); 197 return; 198 } 199 200 bbp_converter_process( response.substring( 0, response.length - 1 ) ); 201 } ); 202 } 203 204 /** 205 * Proceed to the next converter step 206 * 207 * @since 2.6.0 bbPress (r6470) 208 * 209 * @returns {void} 210 */ 211 function bbp_converter_next() { 212 bbp_converter_timer(); 213 135 // Do the step 136 bbp_converter_log( data.progress ); 137 bbp_converter_status( data ); 138 bbp_converter_wait(); 139 140 // Done 141 if ( data.current_step === data.final_step ) { 142 bbp_converter_stop( 143 BBP_Converter.strings.button_start, 144 BBP_Converter.strings.import_complete 145 ); 146 } 147 } 148 149 /** 150 * Wait to do the next AJAX request 151 * 152 * @since 2.6.0 bbPress (r6600) 153 * 154 * @returns {void} 155 */ 156 function bbp_converter_wait() { 214 157 clearTimeout( BBP_Converter.running ); 215 158 159 // Bail if not running 160 if ( ! BBP_Converter.running ) { 161 return; 162 } 163 164 // Wait, then POST 216 165 BBP_Converter.running = setTimeout( function() { 217 bbp_converter_step(); 218 }, BBP_Converter.delay ); 166 bbp_converter_post(); 167 }, parseInt( BBP_Converter.delay, 10 ) ); 168 } 169 170 /** 171 * Start the converter and set the various flags 172 * 173 * @since 2.6.0 bbPress (r6600) 174 * 175 * @returns {void} 176 */ 177 function bbp_converter_start() { 178 clearTimeout( BBP_Converter.running ); 179 clearInterval( BBP_Converter.status ); 180 181 BBP_Converter.running = true; 182 183 var log = BBP_Converter.strings.start_continue; 184 if ( BBP_Converter.started ) { 185 log = BBP_Converter.strings.start_start; 186 BBP_Converter.started = true; 187 } 188 189 bbp_converter_update( 190 BBP_Converter.strings.button_continue, 191 log, 192 BBP_Converter.strings.status_starting 193 ); 194 195 message.addClass( 'started' ); 196 start.hide(); 197 stop.show(); 198 199 bbp_converter_post(); 219 200 } 220 201 … … 230 211 */ 231 212 function bbp_converter_stop( button, log ) { 232 start.val( button ).show(); 213 clearTimeout( BBP_Converter.running ); 214 clearInterval( BBP_Converter.status ); 215 216 BBP_Converter.running = false; 217 BBP_Converter.status = false; 218 219 if ( ! button ) { 220 button = BBP_Converter.strings.button_continue; 221 } 222 223 if ( ! log ) { 224 log = BBP_Converter.strings.status_stopped; 225 } 226 227 bbp_converter_update( 228 button, 229 log, 230 BBP_Converter.strings.status_stopped 231 ); 232 233 start.show(); 233 234 stop.hide(); 234 timer.text( BBP_Converter.strings.timer_stopped ); 235 236 if ( log ) { 237 bbp_converter_log( log ); 238 } 239 240 clearTimeout( BBP_Converter.running ); 241 242 BBP_Converter.running = false; 243 } 244 245 /** 246 * Update the timer 235 } 236 237 /** 238 * Update the various screen texts 239 * 240 * @since 2.6.0 bbPress (r6600) 241 * 242 * @param {string} b_text 243 * @param {string} p_text 244 * @param {string} s_text 245 * 246 * @returns {void} 247 */ 248 function bbp_converter_update( b_text, p_text, s_text ) { 249 start.val( b_text ); 250 bbp_converter_log( p_text ); 251 status.text( s_text ); 252 } 253 254 /** 255 * Update the status 247 256 * 248 257 * @since 2.6.0 bbPress (r6513) … … 250 259 * @returns {void} 251 260 */ 252 function bbp_converter_ timer() {253 var remaining = BBP_Converter.delay / 1000;254 255 timer.text( BBP_Converter.strings.timer_counting.replace( '%s', remaining ) ); 256 257 clearInterval( BBP_Converter. timer);258 259 BBP_Converter. timer= setInterval( function() {261 function bbp_converter_status( data ) { 262 var remaining = parseInt( BBP_Converter.delay, 10 ) / 1000, 263 step = parseInt( data.current_step, 10 ) + 1; 264 265 status.text( BBP_Converter.strings.status_counting.replace( '%s', remaining ) ); 266 clearInterval( BBP_Converter.status ); 267 268 BBP_Converter.status = setInterval( function() { 260 269 remaining--; 261 timer.text( BBP_Converter.strings.timer_counting.replace( '%s', remaining ) );270 status.text( BBP_Converter.strings.status_counting.replace( '%s', remaining ) ); 262 271 263 272 if ( remaining <= 0 ) { 264 clearInterval( BBP_Converter.timer ); 265 timer.text( BBP_Converter.strings.timer_waiting ); 273 clearInterval( BBP_Converter.status ); 274 275 if ( parseInt( data.current_step, 10 ) < parseInt( data.final_step, 10 ) ) { 276 status.text( BBP_Converter.strings.status_up_next.replace( '%s', step ) ); 277 } else { 278 status.text( BBP_Converter.strings.status_complete ); 279 } 266 280 } 267 281 }, 1000 ); … … 278 292 */ 279 293 function bbp_converter_log( text ) { 280 281 if ( '<div' !== text.substring( 0, 3 ) ) { 282 text = '<p>' + text + '</p>'; 283 } 294 text = '<p>' + text + '</p>'; 284 295 285 296 message.prepend( text ); -
trunk/src/includes/admin/classes/class-bbp-converter-base.php
r6573 r6601 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 if ( ! class_exists( 'BBP_Converter_Base' ) ) : 15 16 /** 16 17 * Base class to be extended by specific individual importers … … 85 86 public $convert_users = false; 86 87 88 /** 89 * @var bool Whether to clean up any old converter data. Default false. 90 */ 91 public $clean = false; 92 87 93 /** Methods ***************************************************************/ 88 94 … … 103 109 /** Sanitize Options **************************************************/ 104 110 111 $this->clean = ! empty( $_POST['_bbp_converter_clean'] ); 105 112 $this->convert_users = (bool) get_option( '_bbp_converter_convert_users', false ); 113 $this->halt = (bool) get_option( '_bbp_converter_halt', 0 ); 106 114 $this->max_rows = (int) get_option( '_bbp_converter_rows', 100 ); 107 115 … … 133 141 // Connection failed 134 142 if ( ! $this->opdb->db_connect( false ) ) { 135 wp_die( 'bbp_converter_db_connection_failed', esc_html__( 'Database connection failed.', 'bbpress' ) ); 143 $error = new WP_Error( 'bbp_converter_db_connection_failed', esc_html__( 'Database connection failed.', 'bbpress' ) ); 144 wp_send_json_error( $error ); 136 145 } 137 146 … … 140 149 141 150 /** 142 * Error Reporting151 * Don't wp_die() uncontrollably 143 152 */ 144 $this->wpdb->show_errors( );145 $this->opdb->show_errors( );153 $this->wpdb->show_errors( false ); 154 $this->opdb->show_errors( false ); 146 155 147 156 /** … … 624 633 */ 625 634 public function convert_forum_parents( $start = 1 ) { 626 627 635 $has_update = false; 628 629 if ( ! empty( $this->sync_table ) ) { 630 $query = $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' ); 631 } else { 632 $query = $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' ); 633 } 634 635 update_option( '_bbp_converter_query', $query ); 636 637 $forum_array = $this->wpdb->get_results( $query ); 638 639 foreach ( (array) $forum_array as $row ) { 636 $query = ! empty( $this->sync_table ) 637 ? $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' ) 638 : $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' ); 639 640 foreach ( $this->get_results( $query ) as $row ) { 640 641 $parent_id = $this->callback_forumid( $row->meta_value ); 641 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_parent = %d WHERE ID = %d LIMIT 1", $parent_id, $row->value_id ) );642 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_parent = %d WHERE ID = %d LIMIT 1", $parent_id, $row->value_id ) ); 642 643 $has_update = true; 643 644 } … … 652 653 */ 653 654 public function convert_topic_stickies( $start = 1 ) { 654 655 655 $has_update = false; 656 657 if ( ! empty( $this->sync_table ) ) { 658 $query = $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' ); 659 } else { 660 $query = $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' ); 661 } 662 663 update_option( '_bbp_converter_query', $query ); 664 665 $sticky_array = $this->wpdb->get_results( $query ); 666 667 foreach ( (array) $sticky_array as $row ) { 656 $query = ! empty( $this->sync_table ) 657 ? $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' ) 658 : $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' ); 659 660 foreach ( $this->get_results( $query ) as $row ) { 668 661 bbp_stick_topic( $row->value_id ); 669 662 $has_update = true; … … 679 672 */ 680 673 public function convert_topic_super_stickies( $start = 1 ) { 681 682 674 $has_update = false; 683 684 if ( ! empty( $this->sync_table ) ) { 685 $query = $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' ); 686 } else { 687 $query = $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' ); 688 } 689 690 update_option( '_bbp_converter_query', $query ); 691 692 $sticky_array = $this->wpdb->get_results( $query ); 693 694 foreach ( (array) $sticky_array as $row ) { 675 $query = ! empty( $this->sync_table ) 676 ? $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' ) 677 : $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' ); 678 679 foreach ( $this->get_results( $query ) as $row ) { 695 680 $super = true; 696 681 bbp_stick_topic( $row->value_id, $super ); … … 707 692 */ 708 693 public function convert_topic_closed_topics( $start = 1 ) { 709 710 694 $has_update = false; 711 712 if ( ! empty( $this->sync_table ) ) { 713 $query = $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' ); 714 } else { 715 $query = $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' ); 716 } 717 718 update_option( '_bbp_converter_query', $query ); 719 720 $closed_topic = $this->wpdb->get_results( $query ); 721 722 foreach ( (array) $closed_topic as $row ) { 695 $query = ! empty( $this->sync_table ) 696 ? $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' ) 697 : $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' ); 698 699 foreach ( $this->get_results( $query ) as $row ) { 723 700 bbp_close_topic( $row->value_id ); 724 701 $has_update = true; … … 734 711 */ 735 712 public function convert_reply_to_parents( $start = 1 ) { 736 737 713 $has_update = false; 738 739 if ( ! empty( $this->sync_table ) ) { 740 $query = $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' ); 741 } else { 742 $query = $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' ); 743 } 744 745 update_option( '_bbp_converter_query', $query ); 746 747 $reply_to_array = $this->wpdb->get_results( $query ); 748 749 foreach ( (array) $reply_to_array as $row ) { 714 $query = ! empty( $this->sync_table ) 715 ? $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' ) 716 : $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' ); 717 718 foreach ( $this->get_results( $query ) as $row ) { 750 719 $reply_to = $this->callback_reply_to( $row->meta_value ); 751 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %d LIMIT 1", $reply_to, '_bbp_reply_to', $row->value_id ) );720 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %d LIMIT 1", $reply_to, '_bbp_reply_to', $row->value_id ) ); 752 721 $has_update = true; 753 722 } … … 781 750 AND wp_postmeta2.meta_key = %s 782 751 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_topic_author_name_id' ); 783 784 } 785 786 update_option( '_bbp_converter_query', $query ); 787 788 $anonymous_topics = $this->wpdb->get_results( $query ); 789 790 foreach ( (array) $anonymous_topics as $row ) { 752 } 753 754 foreach ( $this->get_results( $query ) as $row ) { 791 755 $anonymous_topic_author_id = 0; 792 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_topic_author_id, $row->topic_id ) );756 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_topic_author_id, $row->topic_id ) ); 793 757 794 758 add_post_meta( $row->topic_id, '_bbp_anonymous_name', $row->topic_author ); … … 827 791 } 828 792 829 update_option( '_bbp_converter_query', $query ); 830 831 $anonymous_replies = $this->wpdb->get_results( $query ); 832 833 foreach ( (array) $anonymous_replies as $row ) { 793 foreach ( $this->get_results( $query ) as $row ) { 834 794 $anonymous_reply_author_id = 0; 835 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_reply_author_id, $row->reply_id ) );795 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_reply_author_id, $row->reply_id ) ); 836 796 837 797 add_post_meta( $row->reply_id, '_bbp_anonymous_name', $row->reply_author ); … … 853 813 /** Delete topics/forums/posts ****************************************/ 854 814 855 if ( true === $this->sync_table ) { 856 $query = $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->posts} ON(value_id = ID) WHERE meta_key LIKE '_bbp_%' AND value_type = %s GROUP BY value_id ORDER BY value_id DESC LIMIT {$this->max_rows}", 'post' ); 857 } else { 858 $query = $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key LIKE '_bbp_%' GROUP BY post_id ORDER BY post_id DESC LIMIT {$this->max_rows}" ); 859 } 860 861 update_option( '_bbp_converter_query', $query ); 862 863 $posts = $this->wpdb->get_results( $query, ARRAY_A ); 815 $query = ! empty( $this->sync_table ) 816 ? $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->posts} ON(value_id = ID) WHERE meta_key LIKE '_bbp_%' AND value_type = %s GROUP BY value_id ORDER BY value_id DESC LIMIT {$this->max_rows}", 'post' ) 817 : $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key LIKE '_bbp_%' GROUP BY post_id ORDER BY post_id DESC LIMIT {$this->max_rows}" ); 818 819 $posts = $this->get_results( $query, ARRAY_A ); 864 820 865 821 if ( isset( $posts[0] ) && ! empty( $posts[0]['value_id'] ) ) { … … 872 828 /** Delete users ******************************************************/ 873 829 874 if ( true === $this->sync_table ) { 875 $query = $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->users} ON(value_id = ID) WHERE meta_key = %s AND value_type = %s LIMIT {$this->max_rows}", '_bbp_old_user_id', 'user' ); 876 } else { 877 $query = $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$this->max_rows}", '_bbp_old_user_id' ); 878 } 879 880 update_option( '_bbp_converter_query', $query ); 881 882 $users = $this->wpdb->get_results( $query, ARRAY_A ); 830 $query = ! empty( $this->sync_table ) 831 ? $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->users} ON(value_id = ID) WHERE meta_key = %s AND value_type = %s LIMIT {$this->max_rows}", '_bbp_old_user_id', 'user' ) 832 : $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$this->max_rows}", '_bbp_old_user_id' ); 833 834 $users = $this->get_results( $query, ARRAY_A ); 883 835 884 836 if ( ! empty( $users ) ) { … … 901 853 */ 902 854 public function clean_passwords( $start = 1 ) { 903 904 855 $has_delete = false; 905 856 $query = $this->wpdb->prepare( "SELECT user_id, meta_value FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$start}, {$this->max_rows}", '_bbp_password' ); 906 907 update_option( '_bbp_converter_query', $query ); 908 909 $converted = $this->wpdb->get_results( $query, ARRAY_A ); 857 $converted = $this->get_results( $query, ARRAY_A ); 910 858 911 859 if ( ! empty( $converted ) ) { … … 913 861 foreach ( $converted as $value ) { 914 862 if ( is_serialized( $value['meta_value'] ) ) { 915 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = '' WHERE ID = %d", $value['user_id'] ) );863 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = '' WHERE ID = %d", $value['user_id'] ) ); 916 864 } else { 917 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $value['meta_value'], $value['user_id'] ) );918 $this-> wpdb->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $value['user_id'] ) );865 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $value['meta_value'], $value['user_id'] ) ); 866 $this->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $value['user_id'] ) ); 919 867 } 920 868 } … … 944 892 private function get_fields( $tablename ) { 945 893 $rval = array(); 946 $field_array = $this-> wpdb->get_results( 'DESCRIBE ' . $tablename, ARRAY_A );894 $field_array = $this->get_results( 'DESCRIBE ' . $tablename, ARRAY_A ); 947 895 948 896 foreach ( $field_array as $field ) { … … 960 908 } 961 909 910 /** Database Wrappers *****************************************************/ 911 912 /** 913 * Update the last query option and return results 914 * 915 * @param string $query 916 * @param string $output 917 */ 918 private function get_row( $query = '' ) { 919 update_option( '_bbp_converter_query', $query ); 920 921 return $this->wpdb->get_row( $query ); 922 } 923 924 /** 925 * Update the last query option and return results 926 * 927 * @param string $query 928 * @param string $output 929 */ 930 private function get_results( $query = '', $output = OBJECT ) { 931 update_option( '_bbp_converter_query', $query ); 932 933 return (array) $this->wpdb->get_results( $query, $output ); 934 } 935 936 /** 937 * Update the last query option and do a general query 938 * 939 * @param string $query 940 */ 941 private function query( $query = '' ) { 942 update_option( '_bbp_converter_query', $query ); 943 944 return $this->wpdb->query( $query ); 945 } 946 962 947 /** Callbacks *************************************************************/ 963 948 … … 969 954 */ 970 955 public function callback_pass( $username, $password ) { 971 $user = $this-> wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->users} WHERE user_login = %s AND user_pass = '' LIMIT 1", $username ) );956 $user = $this->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->users} WHERE user_login = %s AND user_pass = '' LIMIT 1", $username ) ); 972 957 if ( ! empty( $user ) ) { 973 $usermeta = $this-> wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d LIMIT 1", '_bbp_password', $user->ID ) );958 $usermeta = $this->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d LIMIT 1", '_bbp_password', $user->ID ) ); 974 959 975 960 if ( ! empty( $usermeta ) ) { 976 961 if ( $this->authenticate_pass( $password, $usermeta->meta_value ) ) { 977 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", wp_hash_password( $password ), $user->ID ) );978 $this-> wpdb->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $user->ID ) );962 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", wp_hash_password( $password ), $user->ID ) ); 963 $this->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $user->ID ) ); 979 964 } 980 965 } … … 990 975 private function callback_forumid( $field ) { 991 976 if ( ! isset( $this->map_forumid[ $field ] ) ) { 992 if ( ! empty( $this->sync_table ) ) { 993 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 994 } else { 995 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 996 } 997 998 if ( ! is_null( $row ) ) { 999 $this->map_forumid[ $field ] = $row->value_id; 1000 } else { 1001 $this->map_forumid[ $field ] = 0; 1002 } 1003 } 977 $row = ! empty( $this->sync_table ) 978 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ) 979 : $this->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 980 981 $this->map_forumid[ $field ] = ! is_null( $row ) 982 ? $row->value_id 983 : 0; 984 } 985 1004 986 return $this->map_forumid[ $field ]; 1005 987 } … … 1013 995 private function callback_topicid( $field ) { 1014 996 if ( ! isset( $this->map_topicid[ $field ] ) ) { 1015 if ( ! empty( $this->sync_table ) ) { 1016 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1017 } else { 1018 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1019 } 1020 1021 if ( ! is_null( $row ) ) { 1022 $this->map_topicid[ $field ] = $row->value_id; 1023 } else { 1024 $this->map_topicid[ $field ] = 0; 1025 } 1026 } 997 $row = ! empty( $this->sync_table ) 998 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ) 999 : $this->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1000 1001 $this->map_topicid[ $field ] = ! is_null( $row ) 1002 ? $row->value_id 1003 : 0; 1004 } 1005 1027 1006 return $this->map_topicid[ $field ]; 1028 1007 } … … 1038 1017 private function callback_reply_to( $field ) { 1039 1018 if ( ! isset( $this->map_reply_to[ $field ] ) ) { 1040 if ( ! empty( $this->sync_table ) ) { 1041 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1042 } else { 1043 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1044 } 1045 1046 if ( ! is_null( $row ) ) { 1047 $this->map_reply_to[ $field ] = $row->value_id; 1048 } else { 1049 $this->map_reply_to[ $field ] = 0; 1050 } 1051 } 1019 $row = ! empty( $this->sync_table ) 1020 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ) 1021 : $this->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1022 1023 $this->map_reply_to[ $field ] = ! is_null( $row ) 1024 ? $row->value_id 1025 : 0; 1026 } 1027 1052 1028 return $this->map_reply_to[ $field ]; 1053 1029 } … … 1061 1037 private function callback_userid( $field ) { 1062 1038 if ( ! isset( $this->map_userid[ $field ] ) ) { 1063 if ( ! empty( $this->sync_table ) ) { 1064 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1065 } else { 1066 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1067 } 1039 $row = ! empty( $this->sync_table ) 1040 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ) 1041 : $this->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1068 1042 1069 1043 if ( ! is_null( $row ) ) { 1070 1044 $this->map_userid[ $field ] = $row->value_id; 1071 1045 } else { 1072 if ( true === $this->convert_users ) { 1073 $this->map_userid[ $field ] = 0; 1074 } else { 1075 $this->map_userid[ $field ] = $field; 1076 } 1046 $this->map_userid[ $field ] = ( true === $this->convert_users ) 1047 ? 0 1048 : $field; 1077 1049 } 1078 1050 } 1051 1079 1052 return $this->map_userid[ $field ]; 1080 1053 } … … 1089 1062 */ 1090 1063 private function callback_check_anonymous( $field ) { 1091 1092 if ( $this->callback_userid( $field ) == 0 ) { 1093 $field = 'true'; 1094 } else { 1095 $field = 'false'; 1096 } 1064 $field = ( $this->callback_userid( $field ) == 0 ) 1065 ? 'true' 1066 : 'false'; 1097 1067 1098 1068 return $field; … … 1110 1080 $this->map_topicid_to_forumid[ $topicid ] = 0; 1111 1081 } elseif ( ! isset( $this->map_topicid_to_forumid[ $topicid ] ) ) { 1112 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_parent FROM {$this->wpdb->posts} WHERE ID = %d LIMIT 1", $topicid ) ); 1113 1114 if ( ! is_null( $row ) ) { 1115 $this->map_topicid_to_forumid[ $topicid ] = $row->post_parent; 1116 } else { 1117 $this->map_topicid_to_forumid[ $topicid ] = 0; 1118 } 1082 $row = $this->get_row( $this->wpdb->prepare( "SELECT post_parent FROM {$this->wpdb->posts} WHERE ID = %d LIMIT 1", $topicid ) ); 1083 1084 $this->map_topicid_to_forumid[ $topicid ] = ! is_null( $row ) 1085 ? $row->post_parent 1086 : 0; 1119 1087 } 1120 1088 … … 1150 1118 } 1151 1119 } 1120 endif; -
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; -
trunk/src/includes/admin/tools/converter.php
r6456 r6601 24 24 // Default 25 25 $files = array(); 26 $path = bbp ress()->admin->admin_dir . 'converters/';26 $path = bbp_setup_converter()->converters_dir; 27 27 $curdir = opendir( $path ); 28 28 … … 67 67 // Create a new converter object if it's found 68 68 if ( isset( $converters[ $platform ] ) ) { 69 70 // Include & create the converter 69 71 require_once $converters[ $platform ]; 70 return new $platform; 72 if ( class_exists( $platform ) ) { 73 return new $platform; 74 } 71 75 } 72 76 -
trunk/src/includes/core/abstraction.php
r6583 r6601 16 16 // Exit if accessed directly 17 17 defined( 'ABSPATH' ) || exit; 18 19 /** 20 * Setup Admin 21 * 22 * This exists outside of "/includes/admin/" because the converter may need to 23 * be setup to convert the passwords of users that were migrated from another 24 * forum platform. 25 * 26 * @since 2.6.0 bbPress (r2596) 27 */ 28 function bbp_setup_admin() { 29 $bbp = bbpress(); 30 31 // Skip if already setup 32 if ( empty( $bbp->admin ) ) { 33 34 // Require the admin class 35 require_once $bbp->includes_dir . 'admin/classes/class-bbp-admin.php'; 36 37 // Setup 38 $bbp->admin = class_exists( 'BBP_Admin' ) 39 ? new BBP_Admin() 40 : new stdClass(); 41 } 42 43 // Return the admin object 44 return $bbp->admin; 45 } 46 47 /** 48 * Setup Converter 49 * 50 * This exists outside of "/includes/admin/" because the converter may need to 51 * be setup to convert the passwords of users that were migrated from another 52 * forum platform. 53 * 54 * @since 2.6.0 bbPress (r2596) 55 */ 56 function bbp_setup_converter() { 57 $bbp_admin = bbp_setup_admin(); 58 59 // Skip if already setup 60 if ( empty( $bbp_admin->converter ) ) { 61 62 // Require the converter classes 63 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 66 // Setup 67 $bbp_admin->converter = class_exists( 'BBP_Converter' ) 68 ? new BBP_Converter() 69 : new stdClass(); 70 } 71 72 // Return the converter 73 return $bbp_admin->converter; 74 } 18 75 19 76 /** -
trunk/src/includes/users/functions.php
r6580 r6601 984 984 } 985 985 986 // Setup admin (to include converter) 987 require_once bbpress()->includes_dir . 'admin/admin.php'; 988 989 // Create the admin object 990 bbp_admin(); 991 992 // Convert password 993 require_once bbpress()->admin->admin_dir . 'converter.php'; 994 require_once bbpress()->admin->admin_dir . 'converters/' . sanitize_key( $row->meta_value ) . '.php'; 995 996 // Create the converter 986 // Try to convert the old password for this user 997 987 $converter = bbp_new_converter( $row->meta_value ); 998 988
Note: See TracChangeset
for help on using the changeset viewer.