Ticket #37923: 37923.15.diff
File 37923.15.diff, 33.9 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/ms.php
135 135 $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); 136 136 } 137 137 138 if ( is_site_meta_supported() ) { 139 $blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $blog_id ) ); 140 foreach ( $blog_meta_ids as $mid ) { 141 delete_metadata_by_mid( 'blog', $mid ); 142 } 143 } 144 138 145 $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) ); 139 146 140 147 /** -
src/wp-admin/includes/schema.php
267 267 PRIMARY KEY (blog_id), 268 268 KEY db_version (db_version) 269 269 ) $charset_collate; 270 CREATE TABLE $wpdb->blogmeta ( 271 meta_id bigint(20) unsigned NOT NULL auto_increment, 272 blog_id bigint(20) NOT NULL default '0', 273 meta_key varchar(255) default NULL, 274 meta_value longtext, 275 PRIMARY KEY (meta_id), 276 KEY meta_key (meta_key($max_index_length)), 277 KEY blog_id (blog_id) 278 ) $charset_collate; 270 279 CREATE TABLE $wpdb->registration_log ( 271 280 ID bigint(20) NOT NULL auto_increment, 272 281 email varchar(255) NOT NULL default '', -
src/wp-admin/includes/upgrade.php
2133 2133 } 2134 2134 } 2135 2135 } 2136 2137 // 5.0 2138 if ( $wp_current_db_version < 42125 ) { 2139 $network_id = get_main_network_id(); 2140 delete_network_option( $network_id, 'site_meta_supported' ); 2141 is_site_meta_supported(); 2142 } 2136 2143 } 2137 2144 2138 2145 // -
src/wp-includes/class-wp-site-query.php
92 92 * 93 93 * @since 4.6.0 94 94 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. 95 * @since 5.0.0 Introduced the 'update_site_meta_cache' parameter. 95 96 * 96 97 * @param string|array $query { 97 98 * Optional. Array or query string of site query parameters. Default empty. 98 99 * 99 * @type array $site__in Array of site IDs to include. Default empty. 100 * @type array $site__not_in Array of site IDs to exclude. Default empty. 101 * @type bool $count Whether to return a site count (true) or array of site objects. 102 * Default false. 103 * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. 104 * Default null. 105 * @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs) 106 * or empty (returns an array of complete site objects). Default empty. 107 * @type int $ID A site ID to only return that site. Default empty. 108 * @type int $number Maximum number of sites to retrieve. Default 100. 109 * @type int $offset Number of sites to offset the query. Used to build LIMIT clause. 110 * Default 0. 111 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 112 * @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path', 113 * 'network_id', 'last_updated', 'registered', 'domain_length', 114 * 'path_length', 'site__in' and 'network__in'. Also accepts false, 115 * an empty array, or 'none' to disable `ORDER BY` clause. 116 * Default 'id'. 117 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'. 118 * @type int $network_id Limit results to those affiliated with a given network ID. If 0, 119 * include all networks. Default 0. 120 * @type array $network__in Array of network IDs to include affiliated sites for. Default empty. 121 * @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty. 122 * @type string $domain Limit results to those affiliated with a given domain. Default empty. 123 * @type array $domain__in Array of domains to include affiliated sites for. Default empty. 124 * @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty. 125 * @type string $path Limit results to those affiliated with a given path. Default empty. 126 * @type array $path__in Array of paths to include affiliated sites for. Default empty. 127 * @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty. 128 * @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty. 129 * @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty. 130 * @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. 131 * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. 132 * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. 133 * @type int $lang_id Limit results to a language ID. Default empty. 134 * @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. 135 * @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. 136 * @type string $search Search term(s) to retrieve matching sites for. Default empty. 137 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. 138 * Default empty array. 139 * @type bool $update_site_cache Whether to prime the cache for found sites. Default true. 100 * @type array $site__in Array of site IDs to include. Default empty. 101 * @type array $site__not_in Array of site IDs to exclude. Default empty. 102 * @type bool $count Whether to return a site count (true) or array of site objects. 103 * Default false. 104 * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. 105 * Default null. 106 * @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs) 107 * or empty (returns an array of complete site objects). Default empty. 108 * @type int $ID A site ID to only return that site. Default empty. 109 * @type int $number Maximum number of sites to retrieve. Default 100. 110 * @type int $offset Number of sites to offset the query. Used to build LIMIT clause. 111 * Default 0. 112 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 113 * @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path', 114 * 'network_id', 'last_updated', 'registered', 'domain_length', 115 * 'path_length', 'site__in' and 'network__in'. Also accepts false, 116 * an empty array, or 'none' to disable `ORDER BY` clause. 117 * Default 'id'. 118 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'. 119 * @type int $network_id Limit results to those affiliated with a given network ID. If 0, 120 * include all networks. Default 0. 121 * @type array $network__in Array of network IDs to include affiliated sites for. Default empty. 122 * @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty. 123 * @type string $domain Limit results to those affiliated with a given domain. Default empty. 124 * @type array $domain__in Array of domains to include affiliated sites for. Default empty. 125 * @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty. 126 * @type string $path Limit results to those affiliated with a given path. Default empty. 127 * @type array $path__in Array of paths to include affiliated sites for. Default empty. 128 * @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty. 129 * @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty. 130 * @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty. 131 * @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. 132 * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. 133 * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. 134 * @type int $lang_id Limit results to a language ID. Default empty. 135 * @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. 136 * @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. 137 * @type string $search Search term(s) to retrieve matching sites for. Default empty. 138 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. 139 * Default empty array. 140 * @type bool $update_site_cache Whether to prime the cache for found sites. Default true. 141 * @type bool $update_site_meta_cache Whether to prime the metadata cache for found comments. 142 * Default true. 140 143 * } 141 144 */ 142 145 public function __construct( $query = '' ) { 143 146 $this->query_var_defaults = array( 144 'fields' => '', 145 'ID' => '', 146 'site__in' => '', 147 'site__not_in' => '', 148 'number' => 100, 149 'offset' => '', 150 'no_found_rows' => true, 151 'orderby' => 'id', 152 'order' => 'ASC', 153 'network_id' => 0, 154 'network__in' => '', 155 'network__not_in' => '', 156 'domain' => '', 157 'domain__in' => '', 158 'domain__not_in' => '', 159 'path' => '', 160 'path__in' => '', 161 'path__not_in' => '', 162 'public' => null, 163 'archived' => null, 164 'mature' => null, 165 'spam' => null, 166 'deleted' => null, 167 'lang_id' => null, 168 'lang__in' => '', 169 'lang__not_in' => '', 170 'search' => '', 171 'search_columns' => array(), 172 'count' => false, 173 'date_query' => null, // See WP_Date_Query 174 'update_site_cache' => true, 147 'fields' => '', 148 'ID' => '', 149 'site__in' => '', 150 'site__not_in' => '', 151 'number' => 100, 152 'offset' => '', 153 'no_found_rows' => true, 154 'orderby' => 'id', 155 'order' => 'ASC', 156 'network_id' => 0, 157 'network__in' => '', 158 'network__not_in' => '', 159 'domain' => '', 160 'domain__in' => '', 161 'domain__not_in' => '', 162 'path' => '', 163 'path__in' => '', 164 'path__not_in' => '', 165 'public' => null, 166 'archived' => null, 167 'mature' => null, 168 'spam' => null, 169 'deleted' => null, 170 'lang_id' => null, 171 'lang__in' => '', 172 'lang__not_in' => '', 173 'search' => '', 174 'search_columns' => array(), 175 'count' => false, 176 'date_query' => null, // See WP_Date_Query 177 'update_site_cache' => true, 178 'update_site_meta_cache' => true, 175 179 ); 176 180 177 181 if ( ! empty( $query ) ) { … … 288 292 289 293 // Prime site network caches. 290 294 if ( $this->query_vars['update_site_cache'] ) { 291 _prime_site_caches( $site_ids );295 _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] ); 292 296 } 293 297 294 298 // Fetch full site objects from the primed cache. -
src/wp-includes/functions.php
4704 4704 } 4705 4705 4706 4706 /** 4707 * Determines whether site meta is enabled. 4708 * 4709 * This function checks whether the 'blogmeta' database table exists. The result is saved as 4710 * a setting for the main network, making it essentially a global setting. Subsequent requests 4711 * will refer to this setting instead of running the query. The $force parameter can be used 4712 * to bypass the setting, and reset it accordingly, however this is not recommended. 4713 * 4714 * The 'is_site_meta_supported' filter can be used to bypass the database checks completely. 4715 * 4716 * @since 4.9.0 4717 * 4718 * @global wpdb $wpdb WordPress database abstraction object. 4719 * 4720 * @return bool True if site meta is supported, false otherwise. 4721 */ 4722 function is_site_meta_supported() { 4723 global $wpdb; 4724 4725 if ( ! is_multisite() ) { 4726 return false; 4727 } 4728 4729 $network_id = get_main_network_id(); 4730 4731 if ( false === ( $supported = get_network_option( $network_id, 'site_meta_supported', false ) ) ) { 4732 $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0; 4733 4734 update_network_option( $network_id, 'site_meta_supported', $supported ); 4735 } 4736 4737 return (bool) $supported; 4738 } 4739 4740 /** 4707 4741 * gmt_offset modification for smart timezone handling. 4708 4742 * 4709 4743 * Overrides the gmt_offset option if we have a timezone_string available. -
src/wp-includes/load.php
567 567 } 568 568 569 569 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 570 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );570 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) ); 571 571 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 572 572 } 573 573 } -
src/wp-includes/ms-blogs.php
474 474 wp_cache_delete( $domain_path_key, 'blog-id-cache' ); 475 475 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); 476 476 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); 477 wp_cache_delete( $blog_id, 'blog_meta' ); 477 478 478 479 /** 479 480 * Fires immediately after a site has been removed from the object cache. … … 582 583 * Updates sites in cache. 583 584 * 584 585 * @since 4.6.0 586 * @since 5.0.0 Introduced the `$update_meta_cache` parameter. 585 587 * 586 * @param array $sites Array of site objects. 588 * @param array $sites Array of site objects. 589 * @param bool $update_meta_cache Whether to update site meta cache. Default true. 587 590 */ 588 function update_site_cache( $sites ) {591 function update_site_cache( $sites, $update_meta_cache = true ) { 589 592 if ( ! $sites ) { 590 593 return; 591 594 } 592 595 $site_ids = array(); 593 596 foreach ( $sites as $site ) { 597 $site_ids[] = $site->blog_id; 594 598 wp_cache_add( $site->blog_id, $site, 'sites' ); 595 599 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' ); 596 600 } 601 602 if ( $update_meta_cache ) { 603 update_sitemeta_cache( $site_ids ); 604 } 605 } 606 607 /** 608 * Updates metadata cache for list of site IDs. 609 * 610 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache. 611 * Subsequent calls to `get_site_meta()` will not need to query the database. 612 * 613 * @since 5.0.0 614 * 615 * @param array $site_ids List of site IDs. 616 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 617 */ 618 function update_sitemeta_cache( $site_ids ) { 619 if ( ! is_site_meta_supported() ) { 620 return false; 621 } 622 623 return update_meta_cache( 'blog', $site_ids ); 597 624 } 598 625 599 626 /** … … 658 685 return $query->query( $args ); 659 686 } 660 687 688 661 689 /** 662 690 * Retrieve option value for a given blog id based on name of option. 663 691 * … … 796 824 return $return; 797 825 } 798 826 827 828 829 /** 830 * Add meta data field to a site. 831 * 832 * Site meta data is called "Custom Fields" on the Administration Screen. 833 * 834 * @since 5.0.0 835 * 836 * @param int $site_id Site ID. 837 * @param string $meta_key Metadata name. 838 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 839 * @param bool $unique Optional. Whether the same key should not be added. 840 * Default false. 841 * @return int|false Meta ID on success, false on failure. 842 */ 843 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 844 // Bail if site meta table is not installed. 845 if ( ! is_site_meta_supported() ) { 846 return false; 847 } 848 849 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 850 851 // Bust site query cache. 852 if ( $added ) { 853 // @todo use clean_blog_cache here 854 wp_cache_set( 'last_changed', microtime(), 'sites' ); 855 } 856 857 return $added; 858 } 859 860 /** 861 * Remove metadata matching criteria from a site. 862 * 863 * You can match based on the key, or key and value. Removing based on key and 864 * value, will keep from removing duplicate metadata with the same key. It also 865 * allows removing all metadata matching key, if needed. 866 * 867 * @since 5.0.0 868 * 869 * @param int $site_id Site ID. 870 * @param string $meta_key Metadata name. 871 * @param mixed $meta_value Optional. Metadata value. Must be serializable if 872 * non-scalar. Default empty. 873 * @return bool True on success, false on failure. 874 */ 875 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { 876 // Bail if site meta table is not installed. 877 if ( ! is_site_meta_supported() ) { 878 return false; 879 } 880 881 $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); 882 883 // Bust site query cache. 884 if ( $deleted ) { 885 // @todo use clean_blog_cache here 886 wp_cache_set( 'last_changed', microtime(), 'sites' ); 887 } 888 889 return $deleted; 890 } 891 892 /** 893 * Retrieve site meta field for a site. 894 * 895 * @since 5.0.0 896 * 897 * @param int $site_id Site ID. 898 * @param string $key Optional. The meta key to retrieve. By default, returns 899 * data for all keys. Default empty. 900 * @param bool $single Optional. Whether to return a single value. Default false. 901 * @return mixed Will be an array if $single is false. Will be value of meta data 902 * field if $single is true. 903 */ 904 function get_site_meta( $site_id, $key = '', $single = false ) { 905 // Bail if site meta table is not installed. 906 if ( ! is_site_meta_supported() ) { 907 return false; 908 } 909 910 return get_metadata( 'blog', $site_id, $key, $single ); 911 } 912 913 /** 914 * Update site meta field based on site ID. 915 * 916 * Use the $prev_value parameter to differentiate between meta fields with the 917 * same key and site ID. 918 * 919 * If the meta field for the site does not exist, it will be added. 920 * 921 * @since 5.0.0 922 * 923 * @param int $site_id Site ID. 924 * @param string $meta_key Metadata key. 925 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 926 * @param mixed $prev_value Optional. Previous value to check before removing. 927 * Default empty. 928 * @return int|bool Meta ID if the key didn't exist, true on successful update, 929 * false on failure. 930 */ 931 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 932 // Bail if site meta table is not installed. 933 if ( ! is_site_meta_supported() ) { 934 return false; 935 } 936 937 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 938 939 // Bust site query cache. 940 if ( $updated ) { 941 // @todo use clean_blog_cache here 942 wp_cache_set( 'last_changed', microtime(), 'sites' ); 943 } 944 945 return $updated; 946 } 947 948 /** 949 * Delete everything from site meta matching meta key. 950 * 951 * @since 5.0.0 952 * 953 * @param string $meta_key Metadata key to search for when deleting. 954 * @return bool Whether the site meta key was deleted from the database. 955 */ 956 function delete_site_meta_by_key( $meta_key ) { 957 // Bail if site meta table is not installed. 958 if ( ! is_site_meta_supported() ) { 959 return false; 960 } 961 962 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 963 964 // Bust site query cache. 965 if ( $deleted ) { 966 // @todo use clean_blog_cache here 967 wp_cache_set( 'last_changed', microtime(), 'sites' ); 968 } 969 970 return $deleted; 971 } 972 799 973 /** 800 974 * Switch the current blog. 801 975 * … … 869 1043 if ( is_array( $global_groups ) ) { 870 1044 wp_cache_add_global_groups( $global_groups ); 871 1045 } else { 872 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );1046 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); 873 1047 } 874 1048 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 875 1049 } … … 937 1111 if ( is_array( $global_groups ) ) { 938 1112 wp_cache_add_global_groups( $global_groups ); 939 1113 } else { 940 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );1114 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); 941 1115 } 942 1116 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 943 1117 } -
src/wp-includes/version.php
11 11 * 12 12 * @global int $wp_db_version 13 13 */ 14 $wp_db_version = 38590;14 $wp_db_version = 42125; 15 15 16 16 /** 17 17 * Holds the TinyMCE version -
src/wp-includes/wp-db.php
283 283 */ 284 284 var $ms_global_tables = array( 285 285 'blogs', 286 'blogmeta', 286 287 'signups', 287 288 'site', 288 289 'sitemeta', … … 400 401 public $blogs; 401 402 402 403 /** 404 * Multisite Blog Metadata table 405 * 406 * @since 5.0.0 407 * @var string 408 */ 409 public $blogmeta; 410 411 /** 403 412 * Multisite Blog Versions table 404 413 * 405 414 * @since 3.0.0 -
src/wp-settings.php
95 95 // Load early WordPress files. 96 96 require( ABSPATH . WPINC . '/compat.php' ); 97 97 require( ABSPATH . WPINC . '/class-wp-list-util.php' ); 98 require( ABSPATH . WPINC . '/formatting.php' ); 99 require( ABSPATH . WPINC . '/meta.php' ); 98 100 require( ABSPATH . WPINC . '/functions.php' ); 99 101 require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' ); 100 102 require( ABSPATH . WPINC . '/class-wp.php' ); … … 143 145 // Load most of WordPress. 144 146 require( ABSPATH . WPINC . '/class-wp-walker.php' ); 145 147 require( ABSPATH . WPINC . '/class-wp-ajax-response.php' ); 146 require( ABSPATH . WPINC . '/formatting.php' );147 148 require( ABSPATH . WPINC . '/capabilities.php' ); 148 149 require( ABSPATH . WPINC . '/class-wp-roles.php' ); 149 150 require( ABSPATH . WPINC . '/class-wp-role.php' ); … … 158 159 require( ABSPATH . WPINC . '/class-wp-user-query.php' ); 159 160 require( ABSPATH . WPINC . '/class-wp-session-tokens.php' ); 160 161 require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); 161 require( ABSPATH . WPINC . '/meta.php' );162 162 require( ABSPATH . WPINC . '/class-wp-meta-query.php' ); 163 163 require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' ); 164 164 require( ABSPATH . WPINC . '/general-template.php' ); -
tests/phpunit/includes/testcase.php
328 328 $wp_object_cache->__remoteset(); 329 329 } 330 330 wp_cache_flush(); 331 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );331 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); 332 332 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 333 333 } 334 334 -
tests/phpunit/tests/multisite/siteMeta.php
1 <?php 2 3 if ( is_multisite() ) : 4 5 /** 6 * @group ms-site 7 * @group multisite 8 * @group meta 9 * @ticket 37923 10 */ 11 class Tests_Multisite_Site_Meta extends WP_UnitTestCase { 12 protected static $site_id; 13 protected static $site_id2; 14 protected static $flag_was_set; 15 16 public static function wpSetUpBeforeClass( $factory ) { 17 self::$site_id = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/' ) ); 18 self::$site_id2 = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) ); 19 20 // Populate the main network flag as necessary. 21 self::$flag_was_set = true; 22 if ( false === get_network_option( get_main_network_id(), 'site_meta_supported', false ) ) { 23 self::$flag_was_set = false; 24 is_site_meta_supported(); 25 } 26 } 27 28 public static function wpTearDownAfterClass() { 29 // Delete the possibly previously populated main network flag. 30 if ( ! self::$flag_was_set ) { 31 delete_network_option( get_main_network_id(), 'site_meta_supported' ); 32 } 33 34 wpmu_delete_blog( self::$site_id, true ); 35 wpmu_delete_blog( self::$site_id2, true ); 36 37 wp_update_network_site_counts(); 38 } 39 40 public function test_is_site_meta_supported() { 41 $setting = get_network_option( get_main_network_id(), 'site_meta_supported' ); 42 if ( $setting ) { 43 $this->assertTrue( is_site_meta_supported() ); 44 } else { 45 $this->assertFalse( is_site_meta_supported() ); 46 } 47 } 48 49 public function test_add() { 50 if ( ! is_site_meta_supported() ) { 51 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 52 } 53 54 $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) ); 55 } 56 57 public function test_add_unique() { 58 if ( ! is_site_meta_supported() ) { 59 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 60 } 61 62 $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) ); 63 $this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) ); 64 } 65 66 public function test_delete() { 67 if ( ! is_site_meta_supported() ) { 68 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 69 } 70 71 add_site_meta( self::$site_id, 'foo', 'bar' ); 72 73 $this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) ); 74 } 75 76 public function test_delete_with_invalid_meta_key_should_return_false() { 77 if ( ! is_site_meta_supported() ) { 78 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 79 } 80 81 $this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) ); 82 } 83 84 public function test_delete_should_respect_meta_value() { 85 if ( ! is_site_meta_supported() ) { 86 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 87 } 88 89 add_site_meta( self::$site_id, 'foo', 'bar' ); 90 add_site_meta( self::$site_id, 'foo', 'baz' ); 91 92 $this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) ); 93 94 $metas = get_site_meta( self::$site_id, 'foo', false ); 95 $this->assertSame( array( 'baz' ), $metas ); 96 } 97 98 public function test_get_with_no_key_should_fetch_all_keys() { 99 if ( ! is_site_meta_supported() ) { 100 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 101 } 102 103 add_site_meta( self::$site_id, 'foo', 'bar' ); 104 add_site_meta( self::$site_id, 'foo1', 'baz' ); 105 106 $found = get_site_meta( self::$site_id ); 107 $expected = array( 108 'foo' => array( 'bar' ), 109 'foo1' => array( 'baz' ), 110 ); 111 112 $this->assertEqualSets( $expected, $found ); 113 } 114 115 public function test_get_with_key_should_fetch_all_for_key() { 116 if ( ! is_site_meta_supported() ) { 117 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 118 } 119 120 add_site_meta( self::$site_id, 'foo', 'bar' ); 121 add_site_meta( self::$site_id, 'foo', 'baz' ); 122 add_site_meta( self::$site_id, 'foo1', 'baz' ); 123 124 $found = get_site_meta( self::$site_id, 'foo' ); 125 $expected = array( 'bar', 'baz' ); 126 127 $this->assertEqualSets( $expected, $found ); 128 } 129 130 public function test_get_should_respect_single_true() { 131 if ( ! is_site_meta_supported() ) { 132 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 133 } 134 135 add_site_meta( self::$site_id, 'foo', 'bar' ); 136 add_site_meta( self::$site_id, 'foo', 'baz' ); 137 138 $found = get_site_meta( self::$site_id, 'foo', true ); 139 $this->assertEquals( 'bar', $found ); 140 } 141 142 public function test_update_should_pass_to_add_when_no_value_exists_for_key() { 143 if ( ! is_site_meta_supported() ) { 144 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 145 } 146 147 $actual = update_site_meta( self::$site_id, 'foo', 'bar' ); 148 $this->assertInternalType( 'int', $actual ); 149 $this->assertNotEmpty( $actual ); 150 151 $meta = get_site_meta( self::$site_id, 'foo', true ); 152 $this->assertSame( 'bar', $meta ); 153 } 154 155 public function test_update_should_return_true_when_updating_existing_value_for_key() { 156 if ( ! is_site_meta_supported() ) { 157 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 158 } 159 160 add_site_meta( self::$site_id, 'foo', 'bar' ); 161 162 $actual = update_site_meta( self::$site_id, 'foo', 'baz' ); 163 $this->assertTrue( $actual ); 164 165 $meta = get_site_meta( self::$site_id, 'foo', true ); 166 $this->assertSame( 'baz', $meta ); 167 } 168 169 public function test_delete_by_key() { 170 if ( ! is_site_meta_supported() ) { 171 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 172 } 173 174 add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true ); 175 add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true ); 176 177 $this->assertEquals( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) ); 178 $this->assertEquals( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) ); 179 180 $this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) ); 181 182 $this->assertEquals( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) ); 183 $this->assertEquals( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) ); 184 } 185 186 public function test_site_meta_should_be_deleted_when_site_is_deleted() { 187 if ( ! is_site_meta_supported() ) { 188 $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' ); 189 } 190 191 $site_id = self::factory()->blog->create( array( 'domain' => 'foo.org', 'path' => '/' ) ); 192 193 add_site_meta( $site_id, 'foo', 'bar' ); 194 add_site_meta( $site_id, 'foo1', 'bar' ); 195 196 $this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) ); 197 $this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) ); 198 199 wpmu_delete_blog( $site_id, true ); 200 201 $this->assertSame( '', get_site_meta( $site_id, 'foo', true ) ); 202 $this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) ); 203 } 204 } 205 206 endif;