Skip to:
Content

BuddyPress.org

Changeset 4254


Ignore:
Timestamp:
04/23/2011 04:23:34 PM (15 years ago)
Author:
boonebgorges
Message:

Moves bp-pages data to a single site_option, an array keyed by blog_id. Fixes #3144

Location:
trunk/bp-core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-update.php

    r4211 r4254  
    263263                else
    264264                        $blogs_slug = 'blogs';
    265 
    266                 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
    267                         $existing_pages = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
    268                 else
    269                         $existing_pages = get_option( 'bp-pages' );
     265 
     266                // Call up old bp-pages to see if a page has been previously linked to Blogs
     267                $page_blog_id           = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     268                $existing_pages_data    = get_blog_option( $page_blog_id, 'bp-pages' );
     269                $existing_pages         = $existing_pages_data[$page_blog_id];
    270270
    271271                if ( !empty( $existing_pages['blogs'] ) )
     
    362362                        return false;
    363363
    364                 // Determine where to get the pages from
    365                 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
    366                         $existing_pages = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
    367                 else
    368                         $existing_pages = get_option( 'bp-pages' );
     364                $existing_pages = bp_core_update_get_page_meta();
    369365
    370366                // Get active components
     
    774770                                        switch_to_blog( BP_ROOT_BLOG );
    775771
    776                                 $existing_pages = get_option( 'bp-pages' );
    777                                 $bp_pages       = $this->setup_pages( (array)$_POST['bp_pages'] );
    778                                 $bp_pages       = array_merge( (array)$existing_pages, (array)$bp_pages );
    779 
    780                                 update_option( 'bp-pages', $bp_pages );
     772                                // Move bp-pages data from the blog options table to site options
     773                                $page_blog_id           = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     774                                $existing_pages_data    = get_blog_option( $page_blog_id, 'bp-pages' );
     775                                $existing_pages         = $existing_pages_data[$page_blog_id];
     776                               
     777                                $bp_pages               = $this->setup_pages( (array)$_POST['bp_pages'] );
     778                                $bp_pages               = array_merge( (array)$existing_pages, (array)$bp_pages );
     779                               
     780                                $existing_pages_data[$page_blog_id] = $bp_pages;
     781
     782                                update_site_option( 'bp-pages', $existing_pages_data );
    781783
    782784                                if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != BP_ROOT_BLOG ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
     
    832834                                wp_delete_post( $page_id, true );
    833835
    834                         $bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
    835 
    836                         update_option( 'bp-pages', $bp_pages );
     836                        $blog_pages     = $this->setup_pages( (array)$_POST['bp_pages'] );
     837                        $page_blog_id   = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     838                        $bp_pages       = array( $page_blog_id => $blog_pages );
     839
     840                        update_site_option( 'bp-pages', $bp_pages );
    837841
    838842                        if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != BP_ROOT_BLOG ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
     
    12761280 */
    12771281function bp_core_update_get_page_meta() {
    1278         if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
    1279                 $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
    1280         else
    1281                 $page_ids = get_option( 'bp-pages' );
    1282 
    1283         return $page_ids;
     1282        $page_ids = get_site_option( 'bp-pages' );
     1283       
     1284        $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
     1285
     1286        $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
     1287       
     1288        $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
     1289       
     1290        return apply_filters( 'bp_core_update_get_page_meta', $blog_page_ids );
    12841291}
    12851292
  • trunk/bp-core/bp-core-functions.php

    r4203 r4254  
    1717 *
    1818 * @package BuddyPress Core
     19 * @since 1.3
     20 *
     21 * @todo Remove the "Upgrading from an earlier version of BP pre-1.3" block. Temporary measure for
     22 *       people running trunk installations. Leave for a version or two, then remove.
    1923 */
    2024function bp_core_get_page_meta() {
    21         if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
    22                 $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
    23         else
    24                 $page_ids = get_option( 'bp-pages' );
    25 
    26         return $page_ids;
     25        $page_ids = get_site_option( 'bp-pages' );
     26       
     27        $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
     28
     29        $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
     30       
     31        // Upgrading from an earlier version of BP pre-1.3
     32        if ( empty( $page_ids ) || isset( $page_ids['members'] ) ) {           
     33                if ( empty( $page_ids ) ) {             
     34                        // We're probably coming from an old multisite install
     35                        $old_page_ids = get_blog_option( $page_blog_id, 'bp-pages' );
     36                } else {
     37                        // We're probably coming from an old single-WP install
     38                        $old_page_ids = $page_ids;
     39                }
     40               
     41                /**
     42                 * If $page_ids is found in a blog_option, and it's formatted in the new way (keyed
     43                 * by blog_id), it means that this is an MS upgrade. Return false and let the
     44                 * upgrade wizard handle the migration.
     45                 */
     46                if ( !isset( $old_page_ids['members'] ) )
     47                        return false;
     48                       
     49                // Finally, move the page ids over to site options
     50                $new_page_ids = array(
     51                        $page_blog_id => $old_page_ids
     52                );
     53
     54                update_site_option( 'bp-pages', $new_page_ids );
     55        }
     56       
     57        $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
     58       
     59        return apply_filters( 'bp_core_get_page_meta', $blog_page_ids );
    2760}
    2861
     
    3063 * Stores BP pages in the meta table, depending on setup
    3164 *
    32  * bp-pages data is stored in the options table of the root blog, except when BP_ENABLE_MULTIBLOG
    33  * is turned on.
     65 * bp-pages data is stored in site_options (falls back to options on non-MS), in an array keyed by
     66 * blog_id. This allows you to change your BP_ROOT_BLOG and go through the setup process again.
    3467 *
    3568 * @package BuddyPress Core
    3669 * @since 1.3
    3770 *
    38  * @param array $page_ids The IDs of the WP pages corresponding to BP component directories
    39  */
    40 function bp_core_update_page_meta( $page_ids ) {
    41         if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
    42                 update_blog_option( BP_ROOT_BLOG, 'bp-pages', $page_ids );
    43         else
    44                 update_option( 'bp-pages', $page_ids );
     71 * @param array $blog_page_ids The IDs of the WP pages corresponding to BP component directories
     72 */
     73function bp_core_update_page_meta( $blog_page_ids ) {
     74        if ( !$page_ids = get_site_option( 'bp-pages' ) )
     75                $page_ids = array();
     76
     77        // Generally, we key by the BP_ROOT_BLOG. Exception: when BP_ENABLE_MULTIBLOG is turned on
     78        $key = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     79       
     80        $page_ids[$key] = $blog_page_ids;
     81
     82        update_site_option( 'bp-pages', $page_ids );
    4583}
    4684
     
    64102                $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;
    65103                $page_ids_sql     = implode( ',', (array)$page_ids );
    66                 $page_names       = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ) );
     104                $page_names       = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent, post_title FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ) );
    67105
    68106                foreach ( (array)$page_ids as $key => $page_id ) {
    69107                        foreach ( (array)$page_names as $page_name ) {
    70108                                if ( $page_name->ID == $page_id ) {
    71                                         $pages->{$key}->name = $page_name->post_name;
    72                                         $pages->{$key}->id   = $page_name->ID;
    73                                         $slug[]              = $page_name->post_name;
     109                                        $pages->{$key}->name  = $page_name->post_name;
     110                                        $pages->{$key}->id    = $page_name->ID;
     111                                        $pages->{$key}->title = $page_name->post_title;
     112                                        $slug[]               = $page_name->post_name;
    74113
    75114                                        // Get the slug
Note: See TracChangeset for help on using the changeset viewer.