<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][4254] trunk/bp-core: Moves bp-pages data to a single site_option, an array keyed by blog_id.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd>4254</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2011-04-23 16:23:34 +0000 (Sat, 23 Apr 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Moves bp-pages data to a single site_option, an array keyed by blog_id. Fixes #3144</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcoreadminbpcoreupdatephp">trunk/bp-core/admin/bp-core-update.php</a></li>
<li><a href="#trunkbpcorebpcorefunctionsphp">trunk/bp-core/bp-core-functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcoreadminbpcoreupdatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/admin/bp-core-update.php (4253 => 4254)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/admin/bp-core-update.php        2011-04-23 12:30:31 UTC (rev 4253)
+++ trunk/bp-core/admin/bp-core-update.php        2011-04-23 16:23:34 UTC (rev 4254)
</span><span class="lines">@@ -262,12 +262,12 @@
</span><span class="cx">                         $blogs_slug = constant( 'BP_BLOGS_SLUG' );
</span><span class="cx">                 else
</span><span class="cx">                         $blogs_slug = 'blogs';
</span><ins>+
+                 // Call up old bp-pages to see if a page has been previously linked to Blogs
+                $page_blog_id                 = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
+                $existing_pages_data         = get_blog_option( $page_blog_id, 'bp-pages' );
+                $existing_pages         = $existing_pages_data[$page_blog_id];
</ins><span class="cx">
</span><del>-                if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
-                        $existing_pages = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
-                else
-                        $existing_pages = get_option( 'bp-pages' );
-
</del><span class="cx">                 if ( !empty( $existing_pages['blogs'] ) )
</span><span class="cx">                         $existing_blog_page = '&selected=' . $existing_pages['blogs'];
</span><span class="cx">                 else
</span><span class="lines">@@ -361,11 +361,7 @@
</span><span class="cx">                 if ( !current_user_can( 'activate_plugins' ) )
</span><span class="cx">                         return false;
</span><span class="cx">
</span><del>-                // Determine where to get the pages from
-                if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
-                        $existing_pages = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
-                else
-                        $existing_pages = get_option( 'bp-pages' );
</del><ins>+                $existing_pages = bp_core_update_get_page_meta();
</ins><span class="cx">
</span><span class="cx">                 // Get active components
</span><span class="cx">                 $active_components = apply_filters( 'bp_active_components', get_site_option( 'bp-active-components' ) );
</span><span class="lines">@@ -773,11 +769,17 @@
</span><span class="cx">                                 if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != BP_ROOT_BLOG ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
</span><span class="cx">                                         switch_to_blog( BP_ROOT_BLOG );
</span><span class="cx">
</span><del>-                                $existing_pages = get_option( 'bp-pages' );
-                                $bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
-                                $bp_pages = array_merge( (array)$existing_pages, (array)$bp_pages );
</del><ins>+                                // Move bp-pages data from the blog options table to site options
+                                $page_blog_id                 = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
+                                $existing_pages_data         = get_blog_option( $page_blog_id, 'bp-pages' );
+                                $existing_pages         = $existing_pages_data[$page_blog_id];
+                                
+                                $bp_pages         = $this->setup_pages( (array)$_POST['bp_pages'] );
+                                $bp_pages         = array_merge( (array)$existing_pages, (array)$bp_pages );
+                                
+                                $existing_pages_data[$page_blog_id] = $bp_pages;
</ins><span class="cx">
</span><del>-                                update_option( 'bp-pages', $bp_pages );
</del><ins>+                                update_site_option( 'bp-pages', $existing_pages_data );
</ins><span class="cx">
</span><span class="cx">                                 if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != BP_ROOT_BLOG ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
</span><span class="cx">                                         restore_current_blog();
</span><span class="lines">@@ -831,9 +833,11 @@
</span><span class="cx">                         foreach ( (array)$existing_pages as $page_id )
</span><span class="cx">                                 wp_delete_post( $page_id, true );
</span><span class="cx">
</span><del>-                        $bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
</del><ins>+                        $blog_pages         = $this->setup_pages( (array)$_POST['bp_pages'] );
+                        $page_blog_id         = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
+                        $bp_pages        = array( $page_blog_id => $blog_pages );
</ins><span class="cx">
</span><del>-                        update_option( 'bp-pages', $bp_pages );
</del><ins>+                        update_site_option( 'bp-pages', $bp_pages );
</ins><span class="cx">
</span><span class="cx">                         if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != BP_ROOT_BLOG ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
</span><span class="cx">                                 restore_current_blog();
</span><span class="lines">@@ -1275,12 +1279,15 @@
</span><span class="cx"> * @return array $page_ids
</span><span class="cx"> */
</span><span class="cx"> function bp_core_update_get_page_meta() {
</span><del>-        if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
-                $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
-        else
-                $page_ids = get_option( 'bp-pages' );
</del><ins>+        $page_ids = get_site_option( 'bp-pages' );
+        
+        $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
</ins><span class="cx">
</span><del>-        return $page_ids;
</del><ins>+        $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
+        
+        $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
+        
+        return apply_filters( 'bp_core_update_get_page_meta', $blog_page_ids );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkbpcorebpcorefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-functions.php (4253 => 4254)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-functions.php        2011-04-23 12:30:31 UTC (rev 4253)
+++ trunk/bp-core/bp-core-functions.php        2011-04-23 16:23:34 UTC (rev 4254)
</span><span class="lines">@@ -16,32 +16,70 @@
</span><span class="cx"> * Fetches BP pages from the meta table, depending on setup
</span><span class="cx"> *
</span><span class="cx"> * @package BuddyPress Core
</span><ins>+ * @since 1.3
+ *
+ * @todo Remove the "Upgrading from an earlier version of BP pre-1.3" block. Temporary measure for
+ * people running trunk installations. Leave for a version or two, then remove.
</ins><span class="cx"> */
</span><span class="cx"> function bp_core_get_page_meta() {
</span><del>-        if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
-                $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
-        else
-                $page_ids = get_option( 'bp-pages' );
</del><ins>+        $page_ids = get_site_option( 'bp-pages' );
+        
+        $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
</ins><span class="cx">
</span><del>-        return $page_ids;
</del><ins>+        $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
+        
+        // Upgrading from an earlier version of BP pre-1.3
+        if ( empty( $page_ids ) || isset( $page_ids['members'] ) ) {                
+                if ( empty( $page_ids ) ) {                
+                        // We're probably coming from an old multisite install
+                        $old_page_ids = get_blog_option( $page_blog_id, 'bp-pages' );
+                } else {
+                        // We're probably coming from an old single-WP install
+                        $old_page_ids = $page_ids;
+                }
+                
+                /**
+                 * If $page_ids is found in a blog_option, and it's formatted in the new way (keyed
+                 * by blog_id), it means that this is an MS upgrade. Return false and let the
+                 * upgrade wizard handle the migration.
+                 */
+                if ( !isset( $old_page_ids['members'] ) )
+                        return false;
+                        
+                // Finally, move the page ids over to site options
+                $new_page_ids = array(
+                        $page_blog_id => $old_page_ids
+                );
+
+                update_site_option( 'bp-pages', $new_page_ids );
+        }
+        
+        $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
+        
+        return apply_filters( 'bp_core_get_page_meta', $blog_page_ids );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Stores BP pages in the meta table, depending on setup
</span><span class="cx"> *
</span><del>- * bp-pages data is stored in the options table of the root blog, except when BP_ENABLE_MULTIBLOG
- * is turned on.
</del><ins>+ * bp-pages data is stored in site_options (falls back to options on non-MS), in an array keyed by
+ * blog_id. This allows you to change your BP_ROOT_BLOG and go through the setup process again.
</ins><span class="cx"> *
</span><span class="cx"> * @package BuddyPress Core
</span><span class="cx"> * @since 1.3
</span><span class="cx"> *
</span><del>- * @param array $page_ids The IDs of the WP pages corresponding to BP component directories
</del><ins>+ * @param array $blog_page_ids The IDs of the WP pages corresponding to BP component directories
</ins><span class="cx"> */
</span><del>-function bp_core_update_page_meta( $page_ids ) {
-        if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
-                update_blog_option( BP_ROOT_BLOG, 'bp-pages', $page_ids );
-        else
-                update_option( 'bp-pages', $page_ids );
</del><ins>+function bp_core_update_page_meta( $blog_page_ids ) {
+        if ( !$page_ids = get_site_option( 'bp-pages' ) )
+                $page_ids = array();
+
+        // Generally, we key by the BP_ROOT_BLOG. Exception: when BP_ENABLE_MULTIBLOG is turned on
+        $key = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
+        
+        $page_ids[$key] = $blog_page_ids;
+
+        update_site_option( 'bp-pages', $page_ids );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -63,14 +101,15 @@
</span><span class="cx">
</span><span class="cx">                 $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;
</span><span class="cx">                 $page_ids_sql = implode( ',', (array)$page_ids );
</span><del>-                $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' " ) );
</del><ins>+                $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' " ) );
</ins><span class="cx">
</span><span class="cx">                 foreach ( (array)$page_ids as $key => $page_id ) {
</span><span class="cx">                         foreach ( (array)$page_names as $page_name ) {
</span><span class="cx">                                 if ( $page_name->ID == $page_id ) {
</span><del>-                                        $pages->{$key}->name = $page_name->post_name;
-                                        $pages->{$key}->id = $page_name->ID;
-                                        $slug[] = $page_name->post_name;
</del><ins>+                                        $pages->{$key}->name = $page_name->post_name;
+                                        $pages->{$key}->id = $page_name->ID;
+                                        $pages->{$key}->title = $page_name->post_title;
+                                        $slug[] = $page_name->post_name;
</ins><span class="cx">
</span><span class="cx">                                         // Get the slug
</span><span class="cx">                                         while ( $page_name->post_parent != 0 ) {
</span></span></pre>
</div>
</div>
</body>
</html>