Changeset 4053 for branches/plugin/bbp-admin/bbp-converter.php
- Timestamp:
- 07/04/2012 02:17:31 AM (14 years ago)
- File:
-
- 1 edited
-
branches/plugin/bbp-admin/bbp-converter.php (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-admin/bbp-converter.php
r4007 r4053 26 26 */ 27 27 public function __construct() { 28 29 // Bail if request is not correct 30 switch ( strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 31 32 // Converter is converting 33 case 'POST' : 34 if ( ( empty( $_POST['action'] ) || ( 'bbconverter_process' != $_POST['action'] ) ) ) 35 return; 36 37 break; 38 39 // Some other admin page 40 case 'GET' : 41 if ( ( empty( $_GET['page'] ) || ( 'bbp-converter' != $_GET['page'] ) ) ) 42 return; 43 44 break; 45 } 46 47 // Proceed with the actions 28 48 $this->setup_actions(); 29 49 } … … 61 81 62 82 // Add the main section 63 add_settings_section( 'bbpress_converter_main', __( ' Main Settings','bbpress' ), 'bbp_converter_setting_callback_main_section', 'bbpress_converter' );83 add_settings_section( 'bbpress_converter_main', __( 'Database Settings', 'bbpress' ), 'bbp_converter_setting_callback_main_section', 'bbpress_converter' ); 64 84 65 85 // System Select … … 140 160 border-color: #E6DB55; 141 161 font-family: monospace; 162 font-weight: bold; 142 163 } 143 164 … … 145 166 margin: 0.5em 0; 146 167 padding: 2px; 147 } 148 149 div.bbp-converter-updated p strong.loading { 150 padding: 2px 20px 2px 0; 168 float: left; 169 clear: left; 170 } 171 172 div.bbp-converter-updated p.loading { 173 padding: 2px 20px 2px 2px; 151 174 background-image: url('<?php echo admin_url(); ?>images/wpspin_light.gif'); 152 175 background-repeat: no-repeat; … … 186 209 187 210 values['action'] = 'bbconverter_process'; 211 values['_ajax_nonce'] = '<?php echo wp_create_nonce( 'bbp_converter_process' ); ?>'; 212 188 213 return values; 189 214 } … … 195 220 jQuery('#bbp-converter-stop').show(); 196 221 jQuery('#bbp-converter-progress').show(); 197 bbconverter_log( "Starting Conversion...");222 bbconverter_log( '<p class="loading"><?php _e( 'Starting Conversion', 'bbpress' ); ?></p>' ); 198 223 bbconverter_run(); 199 224 } … … 209 234 210 235 function bbconverter_stop() { 236 jQuery('#bbp-converter-start').show(); 237 jQuery('#bbp-converter-stop').hide(); 238 jQuery('#bbp-converter-progress').hide(); 239 jQuery('#bbp-converter-message p').removeClass( 'loading' ); 211 240 bbconverter_is_running = false; 212 jQuery('#bbp-converter-message strong').removeClass( 'loading');241 clearTimeout( bbconverter_run_timer ); 213 242 } 214 243 … … 216 245 bbconverter_log(response); 217 246 218 if ( response == 'Conversion Complete' || response.indexOf('error') > -1 ) { 219 bbconverter_log('<b>Repair any missing information: <a href="<?php echo admin_url(); ?>tools.php?page=bbp-repair">Continue</a></b>'); 220 jQuery('#bbp-converter-start').show(); 221 jQuery('#bbp-converter-stop').hide(); 222 jQuery('#bbp-converter-progress').hide(); 247 if ( response == '<p class="loading"><?php _e( 'Conversion Complete', 'bbpress' ); ?></p>' || response.indexOf('error') > -1 ) { 248 bbconverter_log('<p>Repair any missing information: <a href="<?php echo admin_url(); ?>tools.php?page=bbp-repair">Continue</a></p>'); 223 249 bbconverter_stop(); 224 clearTimeout( bbconverter_run_timer );225 250 } else if( bbconverter_is_running ) { // keep going 226 251 jQuery('#bbp-converter-progress').show(); … … 228 253 bbconverter_run_timer = setTimeout( 'bbconverter_run()', bbconverter_delay_time ); 229 254 } else { 230 jQuery('#bbp-converter-start').show(); 231 jQuery('#bbp-converter-stop').hide(); 232 jQuery('#bbp-converter-progress').hide(); 233 clearTimeout( bbconverter_run_timer ); 255 bbconverter_stop(); 234 256 } 235 257 } … … 240 262 } 241 263 if ( text ) { 242 jQuery('#bbp-converter-message strong').removeClass( 'loading' );243 jQuery('#bbp-converter-message').prepend( '<p><strong class="loading">' + text + '</strong></p>');264 jQuery('#bbp-converter-message p').removeClass( 'loading' ); 265 jQuery('#bbp-converter-message').prepend( text ); 244 266 } 245 267 } … … 251 273 252 274 /** 275 * Wrap the converter output in paragraph tags, so styling can be applied 276 * 277 * @since bbPress (r4052) 278 * 279 * @param string $output 280 */ 281 private static function converter_output( $output = '' ) { 282 283 // Get the last query 284 $before = '<p class="loading">'; 285 $after = '</p>'; 286 $query = get_option( '_bbp_converter_query' ); 287 288 if ( ! empty( $query ) ) 289 $before = '<p class="loading" title="' . esc_attr( $query ) . '">'; 290 291 echo $before . $output . $after; 292 } 293 294 /** 253 295 * Callback processor 254 296 * … … 256 298 */ 257 299 public function process_callback() { 300 301 // Verify intent 302 check_ajax_referer( 'bbp_converter_process' ); 258 303 259 304 if ( ! ini_get( 'safe_mode' ) ) { … … 294 339 $this->sync_table(); 295 340 if ( empty( $start ) ) { 296 _e( 'No data to clean', 'bbpress');341 $this->converter_output( __( 'No data to clean', 'bbpress' ) ); 297 342 } 298 343 } else { 299 344 update_option( '_bbp_converter_start', $max + 1 ); 300 printf( __( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $min, $max);345 $this->converter_output( sprintf( __( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 301 346 } 302 347 } else { … … 314 359 update_option( '_bbp_converter_start', 0 ); 315 360 if ( empty( $start ) ) { 316 _e( 'No users to convert', 'bbpress');361 $this->converter_output( __( 'No users to convert', 'bbpress' ) ); 317 362 } 318 363 } else { 319 364 update_option( '_bbp_converter_start', $max + 1 ); 320 printf( __( 'Converting users (%1$s - %2$s)', 'bbpress' ), $min, $max);365 $this->converter_output( sprintf( __( 'Converting users (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 321 366 } 322 367 } else { … … 334 379 update_option( '_bbp_converter_start', 0 ); 335 380 if ( empty( $start ) ) { 336 _e( 'No passwords to clear', 'bbpress');381 $this->converter_output( __( 'No passwords to clear', 'bbpress' ) ); 337 382 } 338 383 } else { 339 384 update_option( '_bbp_converter_start', $max + 1 ); 340 printf( __( 'Delete users wordpress default passwords (%1$s - %2$s)', 'bbpress' ), $min, $max);385 $this->converter_output( sprintf( __( 'Delete users wordpress default passwords (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 341 386 } 342 387 } else { … … 353 398 update_option( '_bbp_converter_start', 0 ); 354 399 if ( empty( $start ) ) { 355 _e( 'No forums to convert', 'bbpress');400 $this->converter_output( __( 'No forums to convert', 'bbpress' ) ); 356 401 } 357 402 } else { 358 403 update_option( '_bbp_converter_start', $max + 1 ); 359 printf( __( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $min, $max);404 $this->converter_output( sprintf( __( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 360 405 } 361 406 … … 364 409 // STEP 5. Convert forum parents. 365 410 case 5 : 366 367 411 if ( $converter->convert_forum_parents( $start ) ) { 368 412 update_option( '_bbp_converter_step', $step + 1 ); 369 413 update_option( '_bbp_converter_start', 0 ); 370 414 if ( empty( $start ) ) { 371 _e( 'No forum parents to convert', 'bbpress');415 $this->converter_output( __( 'No forum parents to convert', 'bbpress' ) ); 372 416 } 373 417 } else { 374 418 update_option( '_bbp_converter_start', $max + 1 ); 375 printf( __( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $min, $max);419 $this->converter_output( sprintf( __( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 376 420 } 377 421 … … 380 424 // STEP 6. Convert topics. 381 425 case 6 : 382 383 426 if ( $converter->convert_topics( $start ) ) { 384 427 update_option( '_bbp_converter_step', $step + 1 ); 385 428 update_option( '_bbp_converter_start', 0 ); 386 429 if ( empty( $start ) ) { 387 _e( 'No topics to convert', 'bbpress');430 $this->converter_output( __( 'No topics to convert', 'bbpress' ) ); 388 431 } 389 432 } else { 390 433 update_option( '_bbp_converter_start', $max + 1 ); 391 printf( __( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $min, $max);434 $this->converter_output( sprintf( __( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 392 435 } 393 436 … … 396 439 // STEP 7. Convert tags. 397 440 case 7 : 398 399 441 if ( $converter->convert_tags( $start ) ) { 400 442 update_option( '_bbp_converter_step', $step + 1 ); 401 443 update_option( '_bbp_converter_start', 0 ); 402 444 if ( empty( $start ) ) { 403 _e( 'No tags to convert', 'bbpress');445 $this->converter_output( __( 'No tags to convert', 'bbpress' ) ); 404 446 } 405 447 } else { 406 448 update_option( '_bbp_converter_start', $max + 1 ); 407 printf( __( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $min, $max);449 $this->converter_output( sprintf( __( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 408 450 } 409 451 … … 416 458 update_option( '_bbp_converter_start', 0 ); 417 459 if ( empty( $start ) ) { 418 _e( 'No replies to convert', 'bbpress');460 $this->converter_output( __( 'No replies to convert', 'bbpress' ) ); 419 461 } 420 462 } else { 421 463 update_option( '_bbp_converter_start', $max + 1 ); 422 printf( __( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $min, $max);464 $this->converter_output( sprintf( __( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); 423 465 } 424 466 … … 426 468 427 469 default : 428 delete_option( '_bbp_converter_step' );470 delete_option( '_bbp_converter_step' ); 429 471 delete_option( '_bbp_converter_start' ); 430 431 _e( 'Conversion Complete', 'bbpress' ); 472 delete_option( '_bbp_converter_query' ); 473 474 $this->converter_output( __( 'Conversion Complete', 'bbpress' ) ); 432 475 433 476 break; 434 435 477 } 436 478 } … … 813 855 $forum_array = $this->opdb->get_results( $forum_query, ARRAY_A ); 814 856 815 // Output the query, for better debugging816 printf( __( '<span title="%s">View Query</span>%s', 'bbpress' ), esc_attr( $forum_query ), '<br />');857 // Set this query as the last one ran 858 update_option( '_bbp_converter_query', $forum_query ); 817 859 818 860 // Query returned some results … … 958 1000 959 1001 public function convert_forum_parents( $start ) { 1002 960 1003 $has_update = false; 961 1004 962 if ( !empty( $this->sync_table ) ) { 963 $forum_array = $this->wpdb->get_results( 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_forum_parent_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows ); 964 } else { 965 $forum_array = $this->wpdb->get_results( 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_forum_parent_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows ); 966 } 1005 if ( !empty( $this->sync_table ) ) 1006 $query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_forum_parent_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows; 1007 else 1008 $query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_forum_parent_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows; 1009 1010 update_option( '_bbp_converter_query', $query ); 1011 1012 $forum_array = $this->wpdb->get_results( $query ); 967 1013 968 1014 foreach ( (array) $forum_array as $row ) { … … 979 1025 */ 980 1026 public function clean( $start ) { 1027 981 1028 $start = 0; 982 1029 $has_delete = false; … … 984 1031 /** Delete bbconverter topics/forums/posts ****************************/ 985 1032 986 if ( true === $this->sync_table ) { 987 $bbconverter = $this->wpdb->get_results( '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 = "post" GROUP BY value_id ORDER BY value_id DESC LIMIT ' . $this->max_rows, ARRAY_A ); 988 } else { 989 $bbconverter = $this->wpdb->get_results( '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, ARRAY_A ); 990 } 991 992 if ( !empty( $bbconverter ) ) { 993 foreach ( (array) $bbconverter as $value ) { 1033 if ( true === $this->sync_table ) 1034 $query = '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 = "post" GROUP BY value_id ORDER BY value_id DESC LIMIT ' . $this->max_rows; 1035 else 1036 $query = '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; 1037 1038 update_option( '_bbp_converter_query', $query ); 1039 1040 $posts = $this->wpdb->get_results( $query, ARRAY_A ); 1041 1042 if ( !empty( $posts ) ) { 1043 foreach ( (array) $posts as $value ) { 994 1044 wp_delete_post( $value['value_id'], true ); 995 1045 } … … 999 1049 /** Delete bbconverter users ******************************************/ 1000 1050 1001 if ( true === $this->sync_table ) { 1002 $bbconverter = $this->wpdb->get_results( 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->users . ' ON(value_id = ID) WHERE meta_key = "_bbp_user_id" AND value_type = "user" LIMIT ' . $this->max_rows, ARRAY_A ); 1003 } else { 1004 $bbconverter = $this->wpdb->get_results( 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_user_id" LIMIT ' . $this->max_rows, ARRAY_A ); 1005 } 1006 1007 if ( !empty( $bbconverter ) ) { 1008 foreach ( $bbconverter as $value ) { 1051 if ( true === $this->sync_table ) 1052 $query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->users . ' ON(value_id = ID) WHERE meta_key = "_bbp_user_id" AND value_type = "user" LIMIT ' . $this->max_rows; 1053 else 1054 $query = 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_user_id" LIMIT ' . $this->max_rows; 1055 1056 update_option( '_bbp_converter_query', $query ); 1057 1058 $users = $this->wpdb->get_results( $query, ARRAY_A ); 1059 1060 if ( !empty( $users ) ) { 1061 foreach ( $users as $value ) { 1009 1062 wp_delete_user( $value['value_id'] ); 1010 1063 } … … 1012 1065 } 1013 1066 1067 unset( $posts ); 1068 unset( $users ); 1069 1014 1070 return ! $has_delete; 1015 1071 } … … 1021 1077 */ 1022 1078 public function clean_passwords( $start ) { 1079 1023 1080 $has_delete = false; 1024 1081 1025 1082 /** Delete bbconverter passwords **************************************/ 1026 1083 1027 $bbconverter = $this->wpdb->get_results( 'SELECT user_id, meta_value FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" LIMIT ' . $start . ', ' . $this->max_rows, ARRAY_A ); 1084 $query = 'SELECT user_id, meta_value FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" LIMIT ' . $start . ', ' . $this->max_rows; 1085 update_option( '_bbp_converter_query', $query ); 1086 1087 $bbconverter = $this->wpdb->get_results( $query, ARRAY_A ); 1088 1028 1089 if ( !empty( $bbconverter ) ) { 1029 1090 … … 1038 1099 $has_delete = true; 1039 1100 } 1101 1040 1102 return ! $has_delete; 1041 1103 }
Note: See TracChangeset
for help on using the changeset viewer.