Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/22/2014 11:23:49 AM (11 years ago)
Author:
netweb
Message:

Add support to converter.php to allow importing Subscribed Forums, Subscribed Topics and Favourite Topics
Props netweb. See #2668

File:
1 edited

Legend:

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

    r5544 r5571  
    3737            // Converter is converting
    3838            case 'POST' :
    39                 if ( ( empty( $_POST['action'] ) || ( 'bbconverter_process' !=  $_POST['action'] ) ) ) {
     39                if ( ( empty( $_POST['action'] ) || ( 'bbconverter_process' != $_POST['action'] ) ) ) {
    4040                    return;
    4141                }
     
    4545            // Some other admin page
    4646            case 'GET'  :
    47                 if ( ( empty( $_GET['page'] ) || ( 'bbp-converter' !=  $_GET['page'] ) ) ) {
     47                if ( ( empty( $_GET['page'] ) || ( 'bbp-converter' != $_GET['page'] ) ) ) {
    4848                    return;
    4949                }
     
    428428                break;
    429429
    430             // STEP 6. Convert topics.
     430            // STEP 6. Convert forum subscriptions.
    431431            case 6 :
     432                if ( $converter->convert_forum_subscriptions( $start ) ) {
     433                    update_option( '_bbp_converter_step',  $step + 1 );
     434                    update_option( '_bbp_converter_start', 0         );
     435                    if ( empty( $start ) ) {
     436                        $this->converter_output( __( 'No forum subscriptions to convert', 'bbpress' ) );
     437                    }
     438                } else {
     439                    update_option( '_bbp_converter_start', $max + 1 );
     440                    $this->converter_output( sprintf( __( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $min, $max ) );
     441                }
     442
     443                break;
     444
     445            // STEP 7. Convert topics.
     446            case 7 :
    432447                if ( $converter->convert_topics( $start ) ) {
    433448                    update_option( '_bbp_converter_step',  $step + 1 );
     
    443458                break;
    444459
    445             // STEP 7. Convert anonymous topic authors.
    446             case 7 :
     460            // STEP 8. Convert anonymous topic authors.
     461            case 8 :
    447462                if ( $converter->convert_anonymous_topic_authors( $start ) ) {
    448463                    update_option( '_bbp_converter_step',  $step + 1 );
     
    458473                break;
    459474
    460             // STEP 8. Stick topics.
    461             case 8 :
     475            // STEP 9. Stick topics.
     476            case 9 :
    462477                if ( $converter->convert_topic_stickies( $start ) ) {
    463478                    update_option( '_bbp_converter_step',  $step + 1 );
     
    473488                break;
    474489
    475             // STEP 9. Stick to front topics (Super Sicky).
    476             case 9 :
     490            // STEP 10. Stick to front topics (Super Sicky).
     491            case 10 :
    477492                if ( $converter->convert_topic_super_stickies( $start ) ) {
    478493                    update_option( '_bbp_converter_step',  $step + 1 );
     
    488503                break;
    489504
    490             // STEP 10. Closed Topics.
    491             case 10 :
     505            // STEP 11. Closed topics.
     506            case 11 :
    492507                if ( $converter->convert_topic_closed_topics( $start ) ) {
    493508                    update_option( '_bbp_converter_step',  $step + 1 );
     
    503518                break;
    504519
    505             // STEP 11. Convert topic tags.
    506             case 11 :
     520            // STEP 12. Convert topic tags.
     521            case 12 :
    507522                if ( $converter->convert_tags( $start ) ) {
    508523                    update_option( '_bbp_converter_step',  $step + 1 );
     
    518533                break;
    519534
    520             // STEP 12. Convert replies.
    521             case 12 :
     535            // STEP 13. Convert topic subscriptions.
     536            case 13 :
     537                if ( $converter->convert_topic_subscriptions( $start ) ) {
     538                    update_option( '_bbp_converter_step',  $step + 1 );
     539                    update_option( '_bbp_converter_start', 0         );
     540                    if ( empty( $start ) ) {
     541                        $this->converter_output( __( 'No topic subscriptions to convert', 'bbpress' ) );
     542                    }
     543                } else {
     544                    update_option( '_bbp_converter_start', $max + 1 );
     545                    $this->converter_output( sprintf( __( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $min, $max ) );
     546                }
     547
     548                break;
     549
     550            // STEP 14. Convert topic favorites.
     551            case 14 :
     552                if ( $converter->convert_favorites( $start ) ) {
     553                    update_option( '_bbp_converter_step',  $step + 1 );
     554                    update_option( '_bbp_converter_start', 0         );
     555                    if ( empty( $start ) ) {
     556                        $this->converter_output( __( 'No favorites to convert', 'bbpress' ) );
     557                    }
     558                } else {
     559                    update_option( '_bbp_converter_start', $max + 1 );
     560                    $this->converter_output( sprintf( __( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $min, $max ) );
     561                }
     562
     563                break;
     564
     565            // STEP 15. Convert replies.
     566            case 15 :
    522567                if ( $converter->convert_replies( $start ) ) {
    523568                    update_option( '_bbp_converter_step',  $step + 1 );
     
    533578                break;
    534579
    535             // STEP 13. Convert anonymous reply authors.
    536             case 13 :
     580            // STEP 16. Convert anonymous reply authors.
     581            case 16 :
    537582                if ( $converter->convert_anonymous_reply_authors( $start ) ) {
    538583                    update_option( '_bbp_converter_step',  $step + 1 );
     
    548593                break;
    549594
    550             // STEP 14. Convert threaded replies parents.
    551             case 14 :
     595            // STEP 17. Convert threaded replies parents.
     596            case 17 :
    552597                if ( $converter->convert_reply_to_parents( $start ) ) {
    553598                    update_option( '_bbp_converter_step',  $step + 1 );
     
    842887
    843888    /**
     889     * Convert Forum Subscriptions
     890     */
     891    public function convert_forum_subscriptions( $start = 1 ) {
     892        return $this->convert_table( 'forum_subscriptions', $start );
     893    }
     894
     895    /**
     896     * Convert Topic Subscriptions
     897     */
     898    public function convert_topic_subscriptions( $start = 1 ) {
     899        return $this->convert_table( 'topic_subscriptions', $start );
     900    }
     901
     902    /**
     903     * Convert Favorites
     904     */
     905    public function convert_favorites( $start = 1 ) {
     906        return $this->convert_table( 'favorites', $start );
     907    }
     908
     909    /**
    844910     * Convert Table
    845911     *
     
    871937                break;
    872938
     939            case 'forum_subscriptions' :
     940                $tablename = $this->wpdb->usermeta;
     941                break;
     942
     943            case 'topic_subscriptions' :
     944                $tablename = $this->wpdb->usermeta;
     945                break;
     946
     947            case 'favorites' :
     948                $tablename = $this->wpdb->usermeta;
     949                break;
     950
    873951            default :
    874952                $tablename = $this->wpdb->posts;
     
    9451023                    foreach ( $this->field_map as $row ) {
    9461024
    947                         // Types matchand to_fieldname is present. This means
     1025                        // Types match and to_fieldname is present. This means
    9481026                        // we have some work to do here.
    9491027                        if ( ( $row['to_type'] == $to_type ) && ! is_null( $row['to_fieldname'] ) ) {
     
    10381116                                    ) );
    10391117                                }
    1040                                 break;
     1118                                break;
     1119
     1120                            /** Forum Subscriptions *********************************/
     1121
     1122                            case 'forum_subscriptions':
     1123                                $user_id = $insert_post['user_id'];
     1124                                if ( is_numeric( $user_id ) ) {
     1125                                    foreach ($insert_postmeta as $key => $value) {
     1126
     1127                                        // Only extract values from the key _bbp_forum_subscriptions
     1128                                        if ( '_bbp_forum_subscriptions' == $key ) {
     1129
     1130                                            // Get the new forum ID
     1131                                            $forum_id = $this->callback_forumid( $value );
     1132
     1133                                            // Add the topic ID to the users subscribed forums
     1134                                            bbp_add_user_forum_subscription( $user_id, $forum_id );
     1135                                        }
     1136                                    }
     1137                                }
     1138                                break;
     1139
     1140                            /** Subscriptions *********************************/
     1141
     1142                            case 'topic_subscriptions':
     1143                                $user_id = $insert_post['user_id'];
     1144                                if ( is_numeric( $user_id ) ) {
     1145                                    foreach ($insert_postmeta as $key => $value) {
     1146
     1147                                        // Only extract values from the key _bbp_subscriptions
     1148                                        if ( '_bbp_subscriptions' == $key ) {
     1149
     1150                                            // Get the new topic ID
     1151                                            $topic_id = $this->callback_topicid( $value );
     1152
     1153                                            // Add the topic ID to the users subscribed topics
     1154                                            bbp_add_user_topic_subscription( $user_id, $topic_id );
     1155                                        }
     1156                                    }
     1157                                }
     1158                                break;
     1159
     1160                            /** Favorites *********************************/
     1161
     1162                            case 'favorites':
     1163                                $user_id = $insert_post['user_id'];
     1164                                if ( is_numeric( $user_id ) ) {
     1165
     1166                                    // Loop through the array
     1167                                    foreach ($insert_postmeta as $key => $value) {
     1168
     1169                                        // Only extract values from the key _bbp_favorites
     1170                                        if ( '_bbp_favorites' == $key ) {
     1171
     1172                                            // Our array may contain comma delimited favorites so lets explode these
     1173                                            $insert_postmeta = explode(",", $insert_postmeta['_bbp_favorites']);
     1174
     1175                                            // Loop through our updated exploded array
     1176                                            foreach ($insert_postmeta as $key => $value) {
     1177
     1178                                                // Get the new topic ID
     1179                                                $topic_id = $this->callback_topicid( $value );
     1180
     1181                                                // Add the topic ID to the users favorites
     1182                                                bbp_add_user_favorite( $user_id, $topic_id );
     1183                                            }
     1184                                        }
     1185                                    }
     1186                                }
     1187                                break;
    10411188
    10421189                            /** Forum, Topic, Reply ***************************/
Note: See TracChangeset for help on using the changeset viewer.