Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/23/2017 04:21:58 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Admin/Converter: Lazy load admin & converter as needed.

  • Move admin class into its own file
  • Remove admin.php
  • Introduce _setup_ functions to make loading them on the fly easier
  • Simplify converter logic for smoother starting/stopping
  • Improved UI for timer/status updates
  • Remove double-duty variables from BBP_Converter and response data
  • Switch from text-only response value to JSON object for improved flexibility

This allows the converter to return more data, and makes it easier to work with that data.

Todo:

  • Error responses
  • Check that starts are bumping correctly inside of steps
  • Better utilize JSON responses
File:
1 edited

Legend:

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

    r6573 r6601  
    1313defined( 'ABSPATH' ) || exit;
    1414
     15if ( ! class_exists( 'BBP_Converter_Base' ) ) :
    1516/**
    1617 * Base class to be extended by specific individual importers
    … …  
    8586        public $convert_users = false;
    8687
     88        /**
     89         * @var bool Whether to clean up any old converter data. Default false.
     90         */
     91        public $clean = false;
     92
    8793        /** Methods ***************************************************************/
    8894
    … …  
    103109                /** Sanitize Options **************************************************/
    104110
     111                $this->clean         = ! empty( $_POST['_bbp_converter_clean'] );
    105112                $this->convert_users = (bool) get_option( '_bbp_converter_convert_users', false );
     113                $this->halt          = (bool) get_option( '_bbp_converter_halt',          0     );
    106114                $this->max_rows      = (int)  get_option( '_bbp_converter_rows',          100   );
    107115
    … …  
    133141                // Connection failed
    134142                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 );
    136145                }
    137146
    … …  
    140149
    141150                /**
    142                  * Error Reporting
     151                 * Don't wp_die() uncontrollably
    143152                 */
    144                 $this->wpdb->show_errors();
    145                 $this->opdb->show_errors();
     153                $this->wpdb->show_errors( false );
     154                $this->opdb->show_errors( false );
    146155
    147156                /**
    … …  
    624633         */
    625634        public function convert_forum_parents( $start = 1 ) {
    626 
    627635                $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 ) {
    640641                        $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 ) );
    642643                        $has_update = true;
    643644                }
    … …  
    652653         */
    653654        public function convert_topic_stickies( $start = 1 ) {
    654 
    655655                $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 ) {
    668661                        bbp_stick_topic( $row->value_id );
    669662                        $has_update = true;
    … …  
    679672         */
    680673        public function convert_topic_super_stickies( $start = 1 ) {
    681 
    682674                $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 ) {
    695680                        $super = true;
    696681                        bbp_stick_topic( $row->value_id, $super );
    … …  
    707692         */
    708693        public function convert_topic_closed_topics( $start = 1 ) {
    709 
    710694                $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 ) {
    723700                        bbp_close_topic( $row->value_id );
    724701                        $has_update = true;
    … …  
    734711         */
    735712        public function convert_reply_to_parents( $start = 1 ) {
    736 
    737713                $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 ) {
    750719                        $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 ) );
    752721                        $has_update = true;
    753722                }
    … …  
    781750                                                        AND wp_postmeta2.meta_key = %s
    782751                                                        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 ) {
    791755                        $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 ) );
    793757
    794758                        add_post_meta( $row->topic_id, '_bbp_anonymous_name', $row->topic_author );
    … …  
    827791                }
    828792
    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 ) {
    834794                        $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 ) );
    836796
    837797                        add_post_meta( $row->reply_id, '_bbp_anonymous_name', $row->reply_author );
    … …  
    853813                /** Delete topics/forums/posts ****************************************/
    854814
    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 );
    864820
    865821                if ( isset( $posts[0] ) && ! empty( $posts[0]['value_id'] ) ) {
    … …  
    872828                /** Delete users ******************************************************/
    873829
    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 );
    883835
    884836                if ( ! empty( $users ) ) {
    … …  
    901853         */
    902854        public function clean_passwords( $start = 1 ) {
    903 
    904855                $has_delete = false;
    905856                $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 );
    910858
    911859                if ( ! empty( $converted ) ) {
    … …  
    913861                        foreach ( $converted as $value ) {
    914862                                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'] ) );
    916864                                } 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'] ) );
    919867                                }
    920868                        }
    … …  
    944892        private function get_fields( $tablename ) {
    945893                $rval        = array();
    946                 $field_array = $this->wpdb->get_results( 'DESCRIBE ' . $tablename, ARRAY_A );
     894                $field_array = $this->get_results( 'DESCRIBE ' . $tablename, ARRAY_A );
    947895
    948896                foreach ( $field_array as $field ) {
    … …  
    960908        }
    961909
     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
    962947        /** Callbacks *************************************************************/
    963948
    … …  
    969954         */
    970955        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 ) );
    972957                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 ) );
    974959
    975960                        if ( ! empty( $usermeta ) ) {
    976961                                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 ) );
    979964                                }
    980965                        }
    … …  
    990975        private function callback_forumid( $field ) {
    991976                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
    1004986                return $this->map_forumid[ $field ];
    1005987        }
    … …  
    1013995        private function callback_topicid( $field ) {
    1014996                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
    10271006                return $this->map_topicid[ $field ];
    10281007        }
    … …  
    10381017        private function callback_reply_to( $field ) {
    10391018                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
    10521028                return $this->map_reply_to[ $field ];
    10531029        }
    … …  
    10611037        private function callback_userid( $field ) {
    10621038                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 ) );
    10681042
    10691043                        if ( ! is_null( $row ) ) {
    10701044                                $this->map_userid[ $field ] = $row->value_id;
    10711045                        } 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;
    10771049                        }
    10781050                }
     1051
    10791052                return $this->map_userid[ $field ];
    10801053        }
    … …  
    10891062         */
    10901063        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';
    10971067
    10981068                return $field;
    … …  
    11101080                        $this->map_topicid_to_forumid[ $topicid ] = 0;
    11111081                } 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;
    11191087                }
    11201088
    … …  
    11501118        }
    11511119}
     1120endif;
Note: See TracChangeset for help on using the changeset viewer.