Skip to:
Content

bbPress.org


Ignore:
Timestamp:
02/19/2018 07:00:55 AM (7 years ago)
Author:
johnjamesjacoby
Message:

Converter: remove WP_SETUP_CONFIG constant setting from converter process.

This introduces a helper database class to avoid directly connecting to the external database. Instead, we'll attempt to control that connection, and provide feedback to the user in the event a connection cannot be made. The WP_SETUP_CONFIG was causing calls to the options API to fail, resulting in broken calculations and invalid offsets.

This commit includes some general load order clean-up, which also fixes a regression causing fatal errors when attempting to upgrade converted user passwords from the old platform. It also fixes the condition where boundaries being converted would display beyond their maximums.

Fixes #3191.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/tools/converter.php

    r6601 r6785  
    2121 */
    2222function bbp_get_converters() {
     23    static $files = array();
    2324
    24     // Default
    25     $files  = array();
    26     $path   = bbp_setup_converter()->converters_dir;
    27     $curdir = opendir( $path );
     25    // Only hit the file system one time per page load
     26    if ( empty( $files ) ) {
    2827
    29     // Look for the converter file in the converters directory
    30     if ( false !== $curdir ) {
    31         while ( $file = readdir( $curdir ) ) {
    32             if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === false ) {
    33                 $name = preg_replace( '/.php/', '', $file );
    34                 if ( 'Example' !== $name ) {
    35                     $files[ $name ] = $path . $file;
     28        // Open the converter directory
     29        $path   = bbp_setup_converter()->converters_dir;
     30        $curdir = opendir( $path );
     31
     32        // Look for the converter file in the converters directory
     33        if ( false !== $curdir ) {
     34            while ( $file = readdir( $curdir ) ) {
     35                if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === false ) {
     36                    $name = preg_replace( '/.php/', '', $file );
     37                    if ( 'Example' !== $name ) {
     38                        $files[ $name ] = $path . $file;
     39                    }
    3640                }
    3741            }
    3842        }
    39     }
    4043
    41     // Close the directory
    42     closedir( $curdir );
     44        // Close the directory
     45        closedir( $curdir );
    4346
    44     // Sort keys alphabetically, ignoring upper/lower casing
    45     if ( ! empty( $files ) ) {
    46         natcasesort( $files );
     47        // Sort keys alphabetically, ignoring upper/lower casing
     48        if ( ! empty( $files ) ) {
     49            natcasesort( $files );
     50        }
    4751    }
    4852
     
    6064 * @param string $platform Name of valid platform class.
    6165 */
    62 function bbp_new_converter( $platform ) {
     66function bbp_new_converter( $platform = '' ) {
    6367
    64     // Default value
    65     $converters = bbp_get_converters();
     68    // Bail if no platform
     69    if ( ! empty( $platform ) ) {
    6670
    67     // Create a new converter object if it's found
    68     if ( isset( $converters[ $platform ] ) ) {
     71        // Get the available converters
     72        $converters = bbp_get_converters();
    6973
    70         // Include & create the converter
    71         require_once $converters[ $platform ];
    72         if ( class_exists( $platform ) ) {
    73             return new $platform;
     74        // Create a new converter object if it's found
     75        if ( isset( $converters[ $platform ] ) ) {
     76
     77            // Include & create the converter
     78            require_once $converters[ $platform ];
     79            if ( class_exists( $platform ) ) {
     80                return new $platform;
     81            }
    7482        }
    7583    }
Note: See TracChangeset for help on using the changeset viewer.