BBP_Converter::process_callback()

Callback processor

Description

Source

File: bp-forums/admin/converter.php

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
public function process_callback() {
 
    // Verify intent
    check_ajax_referer( 'bbp_converter_process' );
 
    // Bail if user cannot view import page
    if ( ! current_user_can( 'bbp_tools_import_page' ) ) {
        wp_die( '0' );
    }
 
    if ( ! ini_get( 'safe_mode' ) ) {
        set_time_limit( 0 );
        ini_set( 'memory_limit',   '256M' );
        ini_set( 'implicit_flush', '1'    );
        ignore_user_abort( true );
    }
 
    // Save step and count so that it can be restarted.
    if ( ! get_option( '_bbp_converter_step' ) || ( !empty( $_POST['_bbp_converter_restart'] ) ) ) {
        update_option( '_bbp_converter_step',  1 );
        update_option( '_bbp_converter_start', 0 );
    }
 
    $step  = (int) get_option( '_bbp_converter_step',  1 );
    $min   = (int) get_option( '_bbp_converter_start', 0 );
    $count = ! empty( $_POST['_bbp_converter_rows'] ) ? min( max( (int) $_POST['_bbp_converter_rows'], 1 ), 5000 ) : 100;
    $max   = ( $min + $count ) - 1;
    $start = $min;
 
    // Bail if platform did not get saved
    $platform = !empty( $_POST['_bbp_converter_platform' ] ) ? sanitize_text_field( $_POST['_bbp_converter_platform' ] ) : get_option( '_bbp_converter_platform' );
    if ( empty( $platform ) )
        return;
 
    // Include the appropriate converter.
    $converter = bbp_new_converter( $platform );
 
    switch ( $step ) {
 
        // STEP 1. Clean all tables.
        case 1 :
            if ( !empty( $_POST['_bbp_converter_clean'] ) ) {
                if ( $converter->clean( $start ) ) {
                    update_option( '_bbp_converter_step'$step + 1 );
                    update_option( '_bbp_converter_start', 0         );
                    $this->sync_table( true );
                    if ( empty( $start ) ) {
                        $this->converter_output( __( 'No data to clean', 'buddyboss' ) );
                    }
                } else {
                    update_option( '_bbp_converter_start', $max + 1 );
                    $this->converter_output( sprintf( __( 'Deleting previously converted data (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
                }
            } else {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
            }
 
            break;
 
        // STEP 2. Convert users.
        case 2 :
            if ( !empty( $_POST['_bbp_converter_convert_users'] ) ) {
                if ( $converter->convert_users( $start ) ) {
                    update_option( '_bbp_converter_step'$step + 1 );
                    update_option( '_bbp_converter_start', 0         );
                    if ( empty( $start ) ) {
                        $this->converter_output( __( 'No users to convert', 'buddyboss' ) );
                    }
                } else {
                    update_option( '_bbp_converter_start', $max + 1 );
                    $this->converter_output( sprintf(  __( 'Converting users (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
                }
            } else {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
            }
 
            break;
 
        // STEP 3. Clean passwords.
        case 3 :
            if ( !empty( $_POST['_bbp_converter_convert_users'] ) ) {
                if ( $converter->clean_passwords( $start ) ) {
                    update_option( '_bbp_converter_step'$step + 1 );
                    update_option( '_bbp_converter_start', 0         );
                    if ( empty( $start ) ) {
                        $this->converter_output( __( 'No passwords to clear', 'buddyboss' ) );
                    }
                } else {
                    update_option( '_bbp_converter_start', $max + 1 );
                    $this->converter_output( sprintf( __( 'Delete users WordPress default passwords (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
                }
            } else {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
            }
 
            break;
 
        // STEP 4. Convert forums.
        case 4 :
            if ( $converter->convert_forums( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No forums to convert', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Converting forums (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        // STEP 5. Convert forum parents.
        case 5 :
            if ( $converter->convert_forum_parents( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No forum parents to convert', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Calculating forum hierarchy (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        // STEP 6. Convert discussions.
        case 6 :
            if ( $converter->convert_topics( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No discussions to convert', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Converting discussions (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        // STEP 7. Stick discussions.
        case 7 :
            if ( $converter->convert_topic_stickies( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No stickies to stick', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Calculating discussion stickies (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        // STEP 8. Stick to front discussion (Super Sicky).
        case 8 :
            if ( $converter->convert_topic_super_stickies( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No super stickies to stick', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Calculating discussion super stickies (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        // STEP 9. Convert tags.
        case 9 :
            if ( $converter->convert_tags( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No tags to convert', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Converting discussion tags (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        // STEP 10. Convert replies.
        case 10 :
            if ( $converter->convert_replies( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No replies to convert', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Converting replies (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        // STEP 11. Convert reply_to parents.
        case 11 :
            if ( $converter->convert_reply_to_parents( $start ) ) {
                update_option( '_bbp_converter_step'$step + 1 );
                update_option( '_bbp_converter_start', 0         );
                if ( empty( $start ) ) {
                    $this->converter_output( __( 'No reply_to parents to convert', 'buddyboss' ) );
                }
            } else {
                update_option( '_bbp_converter_start', $max + 1 );
                $this->converter_output( sprintf( __( 'Calculating reply_to parents (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
            }
 
            break;
 
        default :
            delete_option( '_bbp_converter_step'  );
            delete_option( '_bbp_converter_start' );
            delete_option( '_bbp_converter_query' );
 
            $this->converter_output( __( 'Conversion Complete', 'buddyboss' ) );
 
            break;
    }
}

Changelog

Changelog
Version Description
bbPress (r3813) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.