WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/03/2017 06:40:32 PM (3 years ago)
Author:
flixos90
Message:

Multisite: Establish clean_blog_cache() as a replacement for refresh_blog_details().

Going forward, clean_blog_cache() is recommended to be used instead of refresh_blog_details(). It has been adjusted to match the functionality of the latter, with the exception that it always requires a site ID or object to be passed. The refresh_blog_details action has been deprecated in favor of the clean_site_cache action. The function itself is not formally deprecated at this point, but will likely be in the near future.

Props spacedmonkey.
Fixes #40201.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/site.php

    r41715 r41716  
    10871087    /**
    10881088     * @ticket 40201
     1089     * @dataProvider data_get_site_caches
     1090     */
     1091    public function test_clean_blog_cache_with_id( $key, $group ) {
     1092        $site = get_site( self::$site_ids['make.wordpress.org/'] );
     1093
     1094        $replacements = array(
     1095            '%blog_id%'         => $site->blog_id,
     1096            '%domain%'          => $site->domain,
     1097            '%path%'            => $site->path,
     1098            '%domain_path_key%' => md5( $site->domain . $site->path ),
     1099        );
     1100
     1101        $key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
     1102
     1103        if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
     1104            wp_cache_set( $key, (object) $site->to_array(), $group );
     1105        } else {
     1106            wp_cache_set( $key, 'something', $group );
     1107        }
     1108
     1109        clean_blog_cache( $site->blog_id );
     1110        $this->assertFalse( wp_cache_get( $key, $group ) );
     1111    }
     1112
     1113    /**
     1114     * @ticket 40201
    10891115     */
    10901116    public function test_clean_blog_cache_resets_last_changed() {
     
    11211147        wp_suspend_cache_invalidation( $suspend );
    11221148        $this->assertEquals( $old_count, did_action( 'clean_site_cache' ) );
     1149    }
     1150
     1151    /**
     1152     * @ticket 40201
     1153     */
     1154    public function test_clean_blog_cache_bails_on_empty_input() {
     1155        $old_count = did_action( 'clean_site_cache' );
     1156
     1157        clean_blog_cache( null );
     1158        $this->assertEquals( $old_count, did_action( 'clean_site_cache' ) );
     1159    }
     1160
     1161    /**
     1162     * @ticket 40201
     1163     */
     1164    public function test_clean_blog_cache_bails_on_non_numeric_input() {
     1165        $old_count = did_action( 'clean_site_cache' );
     1166
     1167        clean_blog_cache( 'something' );
     1168        $this->assertEquals( $old_count, did_action( 'clean_site_cache' ) );
     1169    }
     1170
     1171    /**
     1172     * @ticket 40201
     1173     */
     1174    public function test_clean_blog_cache_works_with_deleted_site() {
     1175        $site_id = 12345;
     1176
     1177        wp_cache_set( $site_id, 'something', 'site-details' );
     1178
     1179        clean_blog_cache( $site_id );
     1180        $this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
    11231181    }
    11241182
Note: See TracChangeset for help on using the changeset viewer.