<!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>[41719] trunk: Multisite: Improve `get_blog_details()` by using `get_site_by()`.</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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41719">41719</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41719","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>flixos90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-10-03 19:40:01 +0000 (Tue, 03 Oct 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Multisite: Improve `get_blog_details()` by using `get_site_by()`.
`get_site_by()` is now the preferred way to retrieve a site object by lookup for identifying data. By using a coherent structure and `get_sites()` internally, it has several advantages over the direct database queries and complex code in `get_blog_details()`. Therefore `get_blog_details()` is now a wrapper for `get_site_by()`, providing backward compatibility fixes where necessary.
Unit tests have been adjusted to account for the `blog-details` and `blog-lookup` cache groups, which are no longer needed.
Props spacedmonkey, jeremyfelt, flixos90.
Fixes <a href="https://core.trac.wordpress.org/ticket/40228">#40228</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpsitephp">trunk/src/wp-includes/class-wp-site.php</a></li>
<li><a href="#trunksrcwpincludesmsblogsphp">trunk/src/wp-includes/ms-blogs.php</a></li>
<li><a href="#trunktestsphpunittestsmultisitesitephp">trunk/tests/phpunit/tests/multisite/site.php</a></li>
<li><a href="#trunktestsphpunittestsmultisitesiteDetailsphp">trunk/tests/phpunit/tests/multisite/siteDetails.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpsitephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-site.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-site.php 2017-10-03 19:26:01 UTC (rev 41718)
+++ trunk/src/wp-includes/class-wp-site.php 2017-10-03 19:40:01 UTC (rev 41719)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -330,7 +330,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $this->blog_id, $details, 'site-details' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /** This filter is documented in wp-includes/ms-blogs.php */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters a blog's details.
+ *
+ * @since MU (3.0.0)
+ * @deprecated 4.7.0 Use site_details
+ *
+ * @param object $details The blog details.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> $details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpincludesmsblogsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/ms-blogs.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/ms-blogs.php 2017-10-03 19:26:01 UTC (rev 41718)
+++ trunk/src/wp-includes/ms-blogs.php 2017-10-03 19:40:01 UTC (rev 41719)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -108,9 +108,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Retrieve the details for a blog from the blogs table and blog options.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since MU (3.0.0)
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.0 Use get_site_by() internally.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global wpdb $wpdb WordPress database abstraction object.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against.
</span><span class="cx" style="display: block; padding: 0 10px"> * If not specified the current blog ID is used.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $get_all Whether to retrieve all details or only the details in the blogs table.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,138 +117,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Site|false Blog details on success. False on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_blog_details( $fields = null, $get_all = true ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $wpdb;
-
- if ( is_array($fields ) ) {
- if ( isset($fields['blog_id']) ) {
- $blog_id = $fields['blog_id'];
- } elseif ( isset($fields['domain']) && isset($fields['path']) ) {
- $key = md5( $fields['domain'] . $fields['path'] );
- $blog = wp_cache_get($key, 'blog-lookup');
- if ( false !== $blog )
- return $blog;
- if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
- $nowww = substr( $fields['domain'], 4 );
- $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
- } else {
- $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
- }
- if ( $blog ) {
- wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
- $blog_id = $blog->blog_id;
- } else {
- return false;
- }
- } elseif ( isset($fields['domain']) && is_subdomain_install() ) {
- $key = md5( $fields['domain'] );
- $blog = wp_cache_get($key, 'blog-lookup');
- if ( false !== $blog )
- return $blog;
- if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
- $nowww = substr( $fields['domain'], 4 );
- $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
- } else {
- $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
- }
- if ( $blog ) {
- wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
- $blog_id = $blog->blog_id;
- } else {
- return false;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_array( $fields ) ) {
+ if ( isset( $fields['blog_id'] ) ) {
+ $field = 'id';
+ $value = (int) $fields['blog_id'];
+ } elseif ( isset( $fields['domain'] ) && isset( $fields['path'] ) ) {
+ $field = 'url';
+ $value = $fields['domain'] . '/' . ltrim( $fields['path'], '/' );
+ } elseif ( isset( $fields['domain'] ) && is_subdomain_install() ) {
+ $field = 'domain';
+ $value = $fields['domain'];
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $fields )
- $blog_id = get_current_blog_id();
- elseif ( ! is_numeric( $fields ) )
- $blog_id = get_id_from_blogname( $fields );
- else
- $blog_id = $fields;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $fields ) {
+ $field = 'id';
+ $value = get_current_blog_id();
+ } elseif ( ! is_numeric( $fields ) ) {
+ $field = 'slug';
+ $value = $fields;
+ } else {
+ $field = 'id';
+ $value = (int) $fields;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $blog_id = (int) $blog_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $site = get_site_by( $field, $value );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $all = $get_all == true ? '' : 'short';
- $details = wp_cache_get( $blog_id . $all, 'blog-details' );
-
- if ( $details ) {
- if ( ! is_object( $details ) ) {
- if ( $details == -1 ) {
- return false;
- } else {
- // Clear old pre-serialized objects. Cache clients do better with that.
- wp_cache_delete( $blog_id . $all, 'blog-details' );
- unset($details);
- }
- } else {
- return $details;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $site ) {
+ return false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Try the other cache.
</del><span class="cx" style="display: block; padding: 0 10px"> if ( $get_all ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $details = wp_cache_get( $blog_id . 'short', 'blog-details' );
- } else {
- $details = wp_cache_get( $blog_id, 'blog-details' );
- // If short was requested and full cache is set, we can return.
- if ( $details ) {
- if ( ! is_object( $details ) ) {
- if ( $details == -1 ) {
- return false;
- } else {
- // Clear old pre-serialized objects. Cache clients do better with that.
- wp_cache_delete( $blog_id, 'blog-details' );
- unset($details);
- }
- } else {
- return $details;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Prepopulate magic properties for backward compatibility.
+ foreach ( array( 'blogname', 'siteurl', 'post_count', 'home' ) as $detail ) {
+ $site->$detail = $site->$detail;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty($details) ) {
- $details = WP_Site::get_instance( $blog_id );
- if ( ! $details ) {
- // Set the full cache.
- wp_cache_set( $blog_id, -1, 'blog-details' );
- return false;
- }
- }
-
- if ( ! $details instanceof WP_Site ) {
- $details = new WP_Site( $details );
- }
-
- if ( ! $get_all ) {
- wp_cache_set( $blog_id . $all, $details, 'blog-details' );
- return $details;
- }
-
- switch_to_blog( $blog_id );
- $details->blogname = get_option( 'blogname' );
- $details->siteurl = get_option( 'siteurl' );
- $details->post_count = get_option( 'post_count' );
- $details->home = get_option( 'home' );
- restore_current_blog();
-
- /**
- * Filters a blog's details.
- *
- * @since MU (3.0.0)
- * @deprecated 4.7.0 Use site_details
- *
- * @param object $details The blog details.
- */
- $details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );
-
- wp_cache_set( $blog_id . $all, $details, 'blog-details' );
-
- $key = md5( $details->domain . $details->path );
- wp_cache_set( $key, $details, 'blog-lookup' );
-
- return $details;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $site;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestsmultisitesitephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/multisite/site.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/multisite/site.php 2017-10-03 19:26:01 UTC (rev 41718)
+++ trunk/tests/phpunit/tests/multisite/site.php 2017-10-03 19:40:01 UTC (rev 41719)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,22 +118,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // $get_all = false, only retrieve details from the blogs table
</span><span class="cx" style="display: block; padding: 0 10px"> $details = get_blog_details( $blog_id, false );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Combine domain and path for a site specific cache key.
- $key = md5( $details->domain . $details->path );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $cached_details = wp_cache_get( $blog_id, 'sites' );
+ $this->assertNotFalse( $cached_details );
+ $this->assertEqualSets( get_object_vars( $details ), get_object_vars( $cached_details ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // get_blogaddress_by_name()
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // These are empty until get_blog_details() is called with $get_all = true
- $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // This is empty until get_blog_details() is called with $get_all = true
+ $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // $get_all = true, populate the full blog-details cache and the blog slug lookup cache
</span><span class="cx" style="display: block; padding: 0 10px"> $details = get_blog_details( $blog_id, true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $cached_details = wp_cache_get( $blog_id, 'site-details' );
+ $this->assertNotFalse( $cached_details );
+ $this->assertEqualSets( get_object_vars( $details ), get_object_vars( $cached_details ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Check existence of each database table for the created site.
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $wpdb->tables( 'blog', false ) as $table ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -196,9 +195,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Delete the site without forcing a table drop.
</span><span class="cx" style="display: block; padding: 0 10px"> wpmu_delete_blog( $blog_id, false );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
- $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
+ $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,9 +232,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Delete the site and force a table drop.
</span><span class="cx" style="display: block; padding: 0 10px"> wpmu_delete_blog( $blog_id, true );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
- $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
+ $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -272,9 +269,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Delete the site and force a table drop.
</span><span class="cx" style="display: block; padding: 0 10px"> wpmu_delete_blog( $blog_id, true );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
- $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
+ $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -390,19 +386,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Prime the cache for an invalid site.
</span><span class="cx" style="display: block; padding: 0 10px"> get_blog_details( $blog_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // When the cache is primed with an invalid site, the value is set to -1.
- $this->assertEquals( -1, wp_cache_get( $blog_id, 'blog-details' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // When the cache is primed with an invalid site, the value is not set.
+ $this->assertFalse( wp_cache_get( $blog_id, 'site-details' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Create a site in the invalid site's place.
</span><span class="cx" style="display: block; padding: 0 10px"> self::factory()->blog->create();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // When a new site is created, its cache is cleared through refresh_blog_details.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertFalse( wp_cache_get( $blog_id, 'site-details' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $blog = get_blog_details( $blog_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // When the cache is refreshed, it should now equal the site data.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $cached_blog = wp_cache_get( $blog_id, 'site-details' );
+ $this->assertNotFalse( $cached_blog );
+ $this->assertEqualSets( get_object_vars( $blog ), get_object_vars( $cached_blog ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestsmultisitesiteDetailsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/multisite/siteDetails.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/multisite/siteDetails.php 2017-10-03 19:26:01 UTC (rev 41718)
+++ trunk/tests/phpunit/tests/multisite/siteDetails.php 2017-10-03 19:40:01 UTC (rev 41719)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,25 +32,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 40063
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_update_whitelisted_option_deletes_blog_details_cache( $whitelisted_option, $temporary_value ) {
- $blog_details = get_blog_details();
-
- $original_value = $blog_details->$whitelisted_option;
- update_option( $whitelisted_option, $temporary_value );
-
- $cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
-
- /* Reset to original value. */
- update_option( $whitelisted_option, $original_value );
-
- $this->assertFalse( $cached_result );
- }
-
- /**
- * @dataProvider data_whitelisted_options
- *
- * @ticket 40063
- */
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_update_whitelisted_option_does_not_delete_site_cache( $whitelisted_option, $temporary_value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $site = get_site();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -70,25 +51,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 40063
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_update_whitelisted_option_does_not_delete_short_blog_details_cache( $whitelisted_option, $temporary_value ) {
- $blog_details = get_blog_details( null, false );
-
- $original_value = get_option( $whitelisted_option );
- update_option( $whitelisted_option, $temporary_value );
-
- $cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
-
- /* Reset to original value. */
- update_option( $whitelisted_option, $original_value );
-
- $this->assertNotFalse( $cached_result );
- }
-
- /**
- * @dataProvider data_whitelisted_options
- *
- * @ticket 40063
- */
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_update_whitelisted_option_does_not_update_sites_last_changed( $whitelisted_option, $temporary_value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $last_changed = wp_cache_get_last_changed( 'sites' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>