Make WordPress Core

Ticket #40063: 40063.2.diff

File 40063.2.diff, 6.1 KB (added by flixos90, 7 years ago)
  • src/wp-includes/ms-blogs.php

     
    473473}
    474474
    475475/**
     476 * Cleans the site details cache for a site.
     477 *
     478 * @since 4.7.4
     479 * @private
     480 *
     481 * @param int $site_id Optional. Site ID. Default is the current site ID.
     482 */
     483function _clean_site_details_cache( $site_id = 0 ) {
     484        $site_id = (int) $site_id;
     485        if ( ! $site_id ) {
     486                $site_id = get_current_blog_id();
     487        }
     488
     489        wp_cache_delete( $site_id, 'site-details' );
     490        wp_cache_delete( $site_id, 'blog-details' );
     491}
     492
     493/**
    476494 * Retrieves site data given a site ID or site object.
    477495 *
    478496 * Site data will be cached and returned after being passed through a filter.
     
    736754        $return = update_option( $option, $value );
    737755        restore_current_blog();
    738756
    739         refresh_blog_details( $id );
    740 
    741757        return $return;
    742758}
    743759
  • src/wp-includes/ms-default-filters.php

     
    8484remove_filter( 'option_siteurl', '_config_wp_siteurl' );
    8585remove_filter( 'option_home',    '_config_wp_home'    );
    8686
    87 // Some options changes should trigger blog details refresh.
    88 add_action( 'update_option_blogname',   'refresh_blog_details', 10, 0 );
    89 add_action( 'update_option_siteurl',    'refresh_blog_details', 10, 0 );
    90 add_action( 'update_option_post_count', 'refresh_blog_details', 10, 0 );
     87// Some options changes should trigger site details refresh.
     88add_action( 'update_option_blogname',   '_clean_site_details_cache', 10, 0 );
     89add_action( 'update_option_siteurl',    '_clean_site_details_cache', 10, 0 );
     90add_action( 'update_option_post_count', '_clean_site_details_cache', 10, 0 );
     91add_action( 'update_option_home',       '_clean_site_details_cache', 10, 0 );
    9192
    9293// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used.
    9394add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );
  • tests/phpunit/tests/multisite/siteDetails.php

     
     1<?php
     2
     3if ( is_multisite() ) :
     4/**
     5 * Test 'site_details' functionality.
     6 *
     7 * @group ms-site
     8 * @group multisite
     9 */
     10class Tests_Multisite_Site_Details extends WP_UnitTestCase {
     11        /**
     12         * @dataProvider data_whitelisted_options
     13         *
     14         * @ticket 40063
     15         */
     16        public function test_update_whitelisted_option_deletes_site_details_cache( $whitelisted_option, $temporary_value ) {
     17                $site = get_site();
     18
     19                $original_value = $site->$whitelisted_option;
     20                update_option( $whitelisted_option, $temporary_value );
     21
     22                $cached_result = wp_cache_get( $site->id, 'site-details' );
     23
     24                /* Reset to original value. */
     25                update_option( $whitelisted_option, $original_value );
     26
     27                $this->assertFalse( $cached_result );
     28        }
     29
     30        /**
     31         * @dataProvider data_whitelisted_options
     32         *
     33         * @ticket 40063
     34         */
     35        public function test_update_whitelisted_option_deletes_blog_details_cache( $whitelisted_option, $temporary_value ) {
     36                $blog_details = get_blog_details();
     37
     38                $original_value = $blog_details->$whitelisted_option;
     39                update_option( $whitelisted_option, $temporary_value );
     40
     41                $cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
     42
     43                /* Reset to original value. */
     44                update_option( $whitelisted_option, $original_value );
     45
     46                $this->assertFalse( $cached_result );
     47        }
     48
     49        /**
     50         * @dataProvider data_whitelisted_options
     51         *
     52         * @ticket 40063
     53         */
     54        public function test_update_whitelisted_option_does_not_delete_site_cache( $whitelisted_option, $temporary_value ) {
     55                $site = get_site();
     56
     57                $original_value = $site->$whitelisted_option;
     58                update_option( $whitelisted_option, $temporary_value );
     59
     60                $cached_result = wp_cache_get( $site->id, 'sites' );
     61
     62                /* Reset to original value. */
     63                update_option( $whitelisted_option, $original_value );
     64
     65                $this->assertNotFalse( $cached_result );
     66        }
     67
     68        /**
     69         * @dataProvider data_whitelisted_options
     70         *
     71         * @ticket 40063
     72         */
     73        public function test_update_whitelisted_option_does_not_delete_short_blog_details_cache( $whitelisted_option, $temporary_value ) {
     74                $blog_details = get_blog_details( null, false );
     75
     76                $original_value = get_option( $whitelisted_option );
     77                update_option( $whitelisted_option, $temporary_value );
     78
     79                $cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
     80
     81                /* Reset to original value. */
     82                update_option( $whitelisted_option, $original_value );
     83
     84                $this->assertNotFalse( $cached_result );
     85        }
     86
     87        /**
     88         * @dataProvider data_whitelisted_options
     89         *
     90         * @ticket 40063
     91         */
     92        public function test_update_whitelisted_option_does_not_update_sites_last_changed( $whitelisted_option, $temporary_value ) {
     93                $last_changed = wp_cache_get_last_changed( 'sites' );
     94
     95                $original_value = get_option( $whitelisted_option );
     96                update_option( $whitelisted_option, $temporary_value );
     97
     98                $new_last_changed = wp_cache_get_last_changed( 'sites' );
     99
     100                /* Reset to original value. */
     101                update_option( $whitelisted_option, $original_value );
     102
     103                $this->assertSame( $new_last_changed, $last_changed );
     104        }
     105
     106        public function data_whitelisted_options() {
     107                return array(
     108                        array( 'blogname', 'Custom Site' ),
     109                        array( 'home', 'http://custom-site-url.org' ),
     110                        array( 'siteurl', 'http://custom-site-url.org' ),
     111                        array( 'post_count', '4' ),
     112                );
     113        }
     114
     115        /**
     116         * @ticket 40063
     117         */
     118        public function test_update_random_blog_option_does_not_delete_cache() {
     119                $site = get_site();
     120
     121                update_option( 'foobar_option', 'foobar_value' );
     122                $cached_result = wp_cache_get( $site->id, 'sites' );
     123
     124                delete_option( 'foobar_option' );
     125
     126                $this->assertNotFalse( $cached_result );
     127        }
     128}
     129
     130endif;