Skip to:
Content

bbPress.org

Changeset 6640


Ignore:
Timestamp:
07/27/2017 02:56:27 AM (7 years ago)
Author:
johnjamesjacoby
Message:

Converter: Make it all work again!

  • Send a response when a step is complete (to trigger the subsequent step)
  • Remove min class variable, and use start everywhere instead
  • Move giant step switch into a steps array instead (a lot more can be done here later)
  • Break apart a few private methods to make the call stack easier to follow
  • Store the platform for use in inherited objects later

This commit makes the converter work again, tested against a few large database dumps from several platforms to confirm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/classes/class-bbp-converter.php

    r6635 r6640  
    2727     * @var int Start
    2828     */
    29     public $min = 0;
     29    public $start = 0;
    3030
    3131    /**
     
    4040
    4141    /**
     42     * @var int Maximum number of converter steps
     43     */
     44    public $max_steps = 17;
     45
     46    /**
     47     * @var int Name of source forum platform
     48     */
     49    public $platform = '';
     50
     51    /**
    4252     * @var BBP_Converter_Base Type of converter to use
    4353     */
     
    4555
    4656    /**
    47      * @var int Maximum number of converter steps
    48      */
    49     public $max_steps = 17;
    50 
    51     /**
    5257     * @var string Path to included platforms
    5358     */
    5459    public $converters_dir = '';
     60
     61    /**
     62     * @var array Map of steps to methods
     63     */
     64    private $steps = array(
     65        1  => 'sync_table',
     66        2  => 'users',
     67        3  => 'passwords',
     68        4  => 'forums',
     69        5  => 'forum_hierarchy',
     70        6  => 'forum_subscriptions',
     71        7  => 'topics',
     72        8  => 'topics_authors',
     73        9  => 'stickies',
     74        10 => 'super_stickies',
     75        11 => 'closed_topics',
     76        12 => 'topic_tags',
     77        13 => 'topic_subscriptions',
     78        14 => 'topic_favorites',
     79        15 => 'replies',
     80        16 => 'reply_authors',
     81        17 => 'reply_hierarchy'
     82    );
    5583
    5684    /**
     
    125153
    126154                // 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__( 'In step %s...', 'bbpress' ),
    131                 'status_counting'     => esc_html__( 'Next in %s...', 'bbpress' )
     155                'status_complete'     => esc_html__( 'Finished',         'bbpress' ),
     156                'status_stopped'      => esc_html__( 'Stopped',          'bbpress' ),
     157                'status_starting'     => esc_html__( 'Starting',         'bbpress' ),
     158                'status_up_next'      => esc_html__( 'Doing step %s...', 'bbpress' ),
     159                'status_counting'     => esc_html__( 'Next in %s...',    'bbpress' )
    132160            )
    133161        ) );
     
    146174        $this->maybe_restart();
    147175        $this->setup_options();
     176        $this->maybe_update_options();
    148177
    149178        // Bail if no converter
     
    199228        // Save step and count so that it can be restarted.
    200229        if ( ! get_option( '_bbp_converter_step' ) || ! empty( $_POST['_bbp_converter_restart'] ) ) {
    201             $this->maybe_update_options();
    202230            $this->step  = 1;
    203231            $this->start = 0;
    204         }
    205     }
    206 
     232            $this->maybe_update_options();
     233        }
     234    }
     235
     236    /**
     237     * Maybe update options
     238     *
     239     * @since 2.6.0 bbPress (r6637)
     240     */
    207241    private function maybe_update_options() {
    208242
     
    211245
    212246            // Step & Start
    213             '_bbp_converter_step'  => 1,
    214             '_bbp_converter_start' => 0,
     247            '_bbp_converter_step'  => $this->step,
     248            '_bbp_converter_start' => $this->start,
    215249
    216250            // Halt
     
    278312    private function setup_options() {
    279313
    280         // Get starting point & rows
    281         $this->step  = (int) get_option( '_bbp_converter_step',  1   );
    282         $this->min   = (int) get_option( '_bbp_converter_start', 0   );
    283         $this->rows  = (int) get_option( '_bbp_converter_rows',  100 );
    284 
    285         // Get boundaries
    286         $this->max   = ( $this->min + $this->rows ) - 1;
    287         $this->start = $this->min;
    288 
    289         // Look for platform
    290         $platform = get_option( '_bbp_converter_platform' );
     314        // Set starting point & rows
     315        $this->step     = (int) get_option( '_bbp_converter_step',  1   );
     316        $this->start    = (int) get_option( '_bbp_converter_start', 0   );
     317        $this->rows     = (int) get_option( '_bbp_converter_rows',  100 );
     318
     319        // Set boundaries
     320        $this->max      = ( $this->start + $this->rows ) - 1;
     321
     322        // Set platform
     323        $this->platform = get_option( '_bbp_converter_platform' );
    291324
    292325        // Maybe include the appropriate converter.
    293         if ( ! empty( $platform ) ) {
    294             $this->converter = bbp_new_converter( $platform );
     326        if ( ! empty( $this->platform ) ) {
     327            $this->converter = bbp_new_converter( $this->platform );
    295328        }
    296329    }
     
    318351     */
    319352    private function reset() {
    320         $this->start = 0;
    321         $this->step  = 0;
    322         $this->min   = 0;
    323 
    324         update_option( '_bbp_converter_step',  $this->step  );
    325         update_option( '_bbp_converter_start', $this->start );
     353        update_option( '_bbp_converter_step',  0  );
     354        update_option( '_bbp_converter_start', 0  );
    326355        update_option( '_bbp_converter_query', '' );
    327356    }
     
    334363    private function bump_step() {
    335364
    336         // Start at zero
    337         update_option( '_bbp_converter_start', 0 );
     365        // Next step
     366        $next_step = (int) ( $this->step + 1 );
    338367
    339368        // Don't let step go over max
    340         $step = ( ( $this->step + 1 ) <= $this->max_steps )
    341             ? (int) $this->step + 1
     369        $step = ( $next_step <= $this->max_steps )
     370            ? $next_step
    342371            : 0;
    343372
    344         // Update or delete
    345         update_option( '_bbp_converter_step', $step );
     373        // Update step and start at 0
     374        update_option( '_bbp_converter_step',  $step );
     375        update_option( '_bbp_converter_start', 0     );
    346376    }
    347377
     
    352382     */
    353383    private function bump_start() {
    354         update_option( '_bbp_converter_start', $this->max + 1 );
     384        $start = (int) ( $this->start + $this->rows );
     385
     386        update_option( '_bbp_converter_start', $start );
    355387    }
    356388
     
    362394    private function do_steps() {
    363395
    364         switch ( $this->step ) {
    365 
    366             // Clean all tables.
    367             case 1 :
    368                 $this->step_sync_table();
    369                 break;
    370 
    371             // Convert users.
    372             case 2 :
    373                 $this->step_users();
    374                 break;
    375 
    376             // Clean passwords.
    377             case 3 :
    378                 $this->step_passwords();
    379                 break;
    380 
    381             // Convert forums.
    382             case 4 :
    383                 $this->step_forums();
    384                 break;
    385 
    386             // Convert forum parents.
    387             case 5 :
    388                 $this->step_forum_hierarchy();
    389                 break;
    390 
    391             // Convert forum subscriptions.
    392             case 6 :
    393                 $this->step_forum_subscriptions();
    394                 break;
    395 
    396             // Convert topics.
    397             case 7 :
    398                 $this->step_topics();
    399                 break;
    400 
    401             // Convert topic authors.
    402             case 8 :
    403                 $this->step_topics_authors();
    404                 break;
    405 
    406             // Sticky topics.
    407             case 9 :
    408                 $this->step_stickies();
    409                 break;
    410 
    411             // Stick to front topics (Super Sicky).
    412             case 10 :
    413                 $this->step_super_stickies();
    414                 break;
    415 
    416             // Closed topics.
    417             case 11 :
    418                 $this->step_closed_topics();
    419                 break;
    420 
    421             // Convert topic tags.
    422             case 12 :
    423                 $this->step_topic_tags();
    424                 break;
    425 
    426             // Convert topic subscriptions.
    427             case 13 :
    428                 $this->step_topic_subscriptions();
    429                 break;
    430 
    431             // Convert topic favorites.
    432             case 14 :
    433                 $this->step_topic_favorites();
    434                 break;
    435 
    436             // Convert replies.
    437             case 15 :
    438                 $this->step_replies();
    439                 break;
    440 
    441             // Convert reply authors.
    442             case 16 :
    443                 $this->step_reply_authors();
    444                 break;
    445 
    446             // Convert threaded reply hierarchy.
    447             case 17 :
    448                 $this->step_reply_hierarchy();
    449                 break;
    450 
    451             // Done
    452             default :
    453                 $this->step_done();
    454                 break;
    455         }
     396        // Step exists in map, and method exists
     397        if ( isset( $this->steps[ $this->step ] ) && method_exists( $this, "step_{$this->steps[ $this->step ]}" ) ) {
     398            return call_user_func( array( $this, "step_{$this->steps[ $this->step ]}" ) );
     399        }
     400
     401        // Done!
     402        $this->step_done();
    456403    }
    457404
     
    459406
    460407    /**
    461      * Clean the sync table
     408     * Maybe clean the sync table
    462409     *
    463410     * @since 2.6.0 bbPress (r6513)
     
    469416                $this->sync_table( true );
    470417
    471                 if ( empty( $this->start ) ) {
    472                     $this->converter_response( esc_html__( 'Recreating sync-table', 'bbpress' ) );
    473                 }
     418                empty( $this->start )
     419                    ? $this->converter_response( esc_html__( 'Readying sync-table', 'bbpress' ) )
     420                    : $this->converter_response( esc_html__( 'Sync-table ready',    'bbpress' ) );
    474421            } else {
    475422                $this->bump_start();
    476                 $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     423                $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    477424            }
    478425
     
    495442                $this->bump_step();
    496443
    497                 if ( empty( $this->start ) ) {
    498                     $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) );
    499                 }
     444                empty( $this->start )
     445                    ? $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) )
     446                    : $this->converter_response( esc_html__( 'All users imported', 'bbpress' ) );
    500447            } else {
    501448                $this->bump_start();
    502                 $this->converter_response( sprintf(  esc_html__( 'Converting users (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     449                $this->converter_response( sprintf(  esc_html__( 'Converting users (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    503450            }
    504451        } else {
     
    518465                $this->bump_step();
    519466
    520                 if ( empty( $this->start ) ) {
    521                     $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) );
    522                 }
     467                empty( $this->start )
     468                    ? $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) )
     469                    : $this->converter_response( esc_html__( 'All passwords cleared', 'bbpress' ) );
    523470            } else {
    524471                $this->bump_start();
    525                 $this->converter_response( sprintf( esc_html__( 'Delete users WordPress default passwords (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     472                $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    526473            }
    527474        } else {
     
    540487            $this->bump_step();
    541488
    542             if ( empty( $this->start ) ) {
    543                 $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) );
    544             }
    545         } else {
    546             $this->bump_start();
    547             $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     489            empty( $this->start )
     490                ? $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) )
     491                : $this->converter_response( esc_html__( 'All forums imported', 'bbpress' ) );
     492        } else {
     493            $this->bump_start();
     494            $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    548495        }
    549496    }
     
    558505            $this->bump_step();
    559506
    560             if ( empty( $this->start ) ) {
    561                 $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) );
    562             }
    563         } else {
    564             $this->bump_start();
    565             $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     507            empty( $this->start )
     508                ? $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) )
     509                : $this->converter_response( esc_html__( 'All forum parents imported', 'bbpress' ) );
     510        } else {
     511            $this->bump_start();
     512            $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    566513        }
    567514    }
     
    576523            $this->bump_step();
    577524
    578             if ( empty( $this->start ) ) {
    579                 $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) );
    580             }
    581         } else {
    582             $this->bump_start();
    583             $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     525            empty( $this->start )
     526                ? $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) )
     527                : $this->converter_response( esc_html__( 'All forum subscriptions imported', 'bbpress' ) );
     528        } else {
     529            $this->bump_start();
     530            $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    584531        }
    585532    }
     
    594541            $this->bump_step();
    595542
    596             if ( empty( $this->start ) ) {
    597                 $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) );
    598             }
    599         } else {
    600             $this->bump_start();
    601             $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     543            empty( $this->start )
     544                ? $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) )
     545                : $this->converter_response( esc_html__( 'All topics imported', 'bbpress' ) );
     546        } else {
     547            $this->bump_start();
     548            $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    602549        }
    603550    }
     
    612559            $this->bump_step();
    613560
    614             if ( empty( $this->start ) ) {
    615                 $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) );
    616             }
    617         } else {
    618             $this->bump_start();
    619             $this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     561            empty( $this->start )
     562                ? $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) )
     563                : $this->converter_response( esc_html__( 'All anonymous topic authors imported', 'bbpress' ) );
     564        } else {
     565            $this->bump_start();
     566            $this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    620567        }
    621568    }
     
    630577            $this->bump_step();
    631578
    632             if ( empty( $this->start ) ) {
    633                 $this->converter_response( esc_html__( 'No stickies to stick', 'bbpress' ) );
    634             }
    635         } else {
    636             $this->bump_start();
    637             $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     579            empty( $this->start )
     580                ? $this->converter_response( esc_html__( 'No stickies to import', 'bbpress' ) )
     581                : $this->converter_response( esc_html__( 'All stickies imported', 'bbpress' ) );
     582        } else {
     583            $this->bump_start();
     584            $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    638585        }
    639586    }
     
    648595            $this->bump_step();
    649596
    650             if ( empty( $this->start ) ) {
    651                 $this->converter_response( esc_html__( 'No super stickies to stick', 'bbpress' ) );
    652             }
    653         } else {
    654             $this->bump_start();
    655             $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     597            empty( $this->start )
     598                ? $this->converter_response( esc_html__( 'No super stickies to import', 'bbpress' ) )
     599                : $this->converter_response( esc_html__( 'All super stickies imported', 'bbpress' ) );
     600        } else {
     601            $this->bump_start();
     602            $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    656603        }
    657604    }
     
    666613            $this->bump_step();
    667614
    668             if ( empty( $this->start ) ) {
    669                 $this->converter_response( esc_html__( 'No closed topics to close', 'bbpress' ) );
    670             }
    671         } else {
    672             $this->bump_start();
    673             $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     615            empty( $this->start )
     616                ? $this->converter_response( esc_html__( 'No closed topics to import', 'bbpress' ) )
     617                : $this->converter_response( esc_html__( 'All closed topics imported', 'bbpress' ) );
     618        } else {
     619            $this->bump_start();
     620            $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    674621        }
    675622    }
     
    684631            $this->bump_step();
    685632
    686             if ( empty( $this->start ) ) {
    687                 $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) );
    688             }
    689         } else {
    690             $this->bump_start();
    691             $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     633            empty( $this->start )
     634                ? $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) )
     635                : $this->converter_response( esc_html__( 'All topic tags imported', 'bbpress' ) );
     636        } else {
     637            $this->bump_start();
     638            $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    692639        }
    693640    }
     
    702649            $this->bump_step();
    703650
    704             if ( empty( $this->start ) ) {
    705                 $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) );
    706             }
    707         } else {
    708             $this->bump_start();
    709             $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     651            empty( $this->start )
     652                ? $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) )
     653                : $this->converter_response( esc_html__( 'All topic subscriptions imported', 'bbpress' ) );
     654        } else {
     655            $this->bump_start();
     656            $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    710657        }
    711658    }
     
    720667            $this->bump_step();
    721668
    722             if ( empty( $this->start ) ) {
    723                 $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) );
    724             }
    725         } else {
    726             $this->bump_start();
    727             $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     669            empty( $this->start )
     670                ? $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) )
     671                : $this->converter_response( esc_html__( 'All favorites imported', 'bbpress' ) );
     672        } else {
     673            $this->bump_start();
     674            $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    728675        }
    729676    }
     
    738685            $this->bump_step();
    739686
    740             if ( empty( $this->start ) ) {
    741                 $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) );
    742             }
    743         } else {
    744             $this->bump_start();
    745             $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     687            empty( $this->start )
     688                ? $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) )
     689                : $this->converter_response( esc_html__( 'All replies imported', 'bbpress' ) );
     690        } else {
     691            $this->bump_start();
     692            $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    746693        }
    747694    }
     
    756703            $this->bump_step();
    757704
    758             if ( empty( $this->start ) ) {
    759                 $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) );
    760             }
    761         } else {
    762             $this->bump_start();
    763             $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     705            empty( $this->start )
     706                ? $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) )
     707                : $this->converter_response( esc_html__( 'All anonymous reply authors imported', 'bbpress' ) );
     708        } else {
     709            $this->bump_start();
     710            $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    764711        }
    765712    }
     
    774721            $this->bump_step();
    775722
    776             if ( empty( $this->start ) ) {
    777                 $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) );
    778             }
    779         } else {
    780             $this->bump_start();
    781             $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s - %2$s)', 'bbpress' ), $this->min, $this->max ) );
     723            empty( $this->start )
     724                ? $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) )
     725                : $this->converter_response( esc_html__( 'All threaded replies imported', 'bbpress' ) );
     726        } else {
     727            $this->bump_start();
     728            $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
    782729        }
    783730    }
Note: See TracChangeset for help on using the changeset viewer.