Changeset 42836
- Timestamp:
- 03/16/2018 02:14:04 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ms.php
r42827 r42836 134 134 foreach ( (array) $drop_tables as $table ) { 135 135 $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); 136 } 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 } 136 143 } 137 144 -
trunk/src/wp-admin/includes/schema.php
r42761 r42836 267 267 PRIMARY KEY (blog_id), 268 268 KEY db_version (db_version) 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) 269 278 ) $charset_collate; 270 279 CREATE TABLE $wpdb->registration_log ( -
trunk/src/wp-admin/includes/upgrade.php
r42343 r42836 2134 2134 } 2135 2135 } 2136 2137 // 5.0 2138 if ( $wp_current_db_version < 42836 ) { 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 -
trunk/src/wp-includes/class-wp-site-query.php
r42343 r42836 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 sites. Default true. 140 142 * } 141 143 */ 142 144 public function __construct( $query = '' ) { 143 145 $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, 146 'fields' => '', 147 'ID' => '', 148 'site__in' => '', 149 'site__not_in' => '', 150 'number' => 100, 151 'offset' => '', 152 'no_found_rows' => true, 153 'orderby' => 'id', 154 'order' => 'ASC', 155 'network_id' => 0, 156 'network__in' => '', 157 'network__not_in' => '', 158 'domain' => '', 159 'domain__in' => '', 160 'domain__not_in' => '', 161 'path' => '', 162 'path__in' => '', 163 'path__not_in' => '', 164 'public' => null, 165 'archived' => null, 166 'mature' => null, 167 'spam' => null, 168 'deleted' => null, 169 'lang_id' => null, 170 'lang__in' => '', 171 'lang__not_in' => '', 172 'search' => '', 173 'search_columns' => array(), 174 'count' => false, 175 'date_query' => null, // See WP_Date_Query 176 'update_site_cache' => true, 177 'update_site_meta_cache' => true, 175 178 ); 176 179 … … 289 292 // Prime site network caches. 290 293 if ( $this->query_vars['update_site_cache'] ) { 291 _prime_site_caches( $site_ids );294 _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] ); 292 295 } 293 296 -
trunk/src/wp-includes/functions.php
r42824 r42836 4728 4728 4729 4729 /** 4730 * Determines whether site meta is enabled. 4731 * 4732 * This function checks whether the 'blogmeta' database table exists. The result is saved as 4733 * a setting for the main network, making it essentially a global setting. Subsequent requests 4734 * will refer to this setting instead of running the query. 4735 * 4736 * @since 5.0.0 4737 * 4738 * @global wpdb $wpdb WordPress database abstraction object. 4739 * 4740 * @return bool True if site meta is supported, false otherwise. 4741 */ 4742 function is_site_meta_supported() { 4743 global $wpdb; 4744 4745 if ( ! is_multisite() ) { 4746 return false; 4747 } 4748 4749 $network_id = get_main_network_id(); 4750 4751 $supported = get_network_option( $network_id, 'site_meta_supported', false ); 4752 if ( false === $supported ) { 4753 $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0; 4754 4755 update_network_option( $network_id, 'site_meta_supported', $supported ); 4756 } 4757 4758 return (bool) $supported; 4759 } 4760 4761 /** 4730 4762 * gmt_offset modification for smart timezone handling. 4731 4763 * -
trunk/src/wp-includes/load.php
r42827 r42836 582 582 583 583 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 584 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' ) );584 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' ) ); 585 585 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 586 586 } -
trunk/src/wp-includes/ms-blogs.php
r42678 r42836 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 /** … … 561 562 * 562 563 * @since 4.6.0 564 * @since 5.0.0 Introduced the `$update_meta_cache` parameter. 563 565 * @access private 564 566 * … … 566 568 * @global wpdb $wpdb WordPress database abstraction object. 567 569 * 568 * @param array $ids ID list. 569 */ 570 function _prime_site_caches( $ids ) { 570 * @param array $ids ID list. 571 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 572 */ 573 function _prime_site_caches( $ids, $update_meta_cache = true ) { 571 574 global $wpdb; 572 575 … … 575 578 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 576 579 577 update_site_cache( $fresh_sites );580 update_site_cache( $fresh_sites, $update_meta_cache ); 578 581 } 579 582 } … … 583 586 * 584 587 * @since 4.6.0 585 * 586 * @param array $sites Array of site objects. 587 */ 588 function update_site_cache( $sites ) { 588 * @since 5.0.0 Introduced the `$update_meta_cache` parameter. 589 * 590 * @param array $sites Array of site objects. 591 * @param bool $update_meta_cache Whether to update site meta cache. Default true. 592 */ 593 function update_site_cache( $sites, $update_meta_cache = true ) { 589 594 if ( ! $sites ) { 590 595 return; 591 596 } 592 597 $site_ids = array(); 593 598 foreach ( $sites as $site ) { 599 $site_ids[] = $site->blog_id; 594 600 wp_cache_add( $site->blog_id, $site, 'sites' ); 595 601 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' ); 596 602 } 603 604 if ( $update_meta_cache ) { 605 update_sitemeta_cache( $site_ids ); 606 } 607 } 608 609 /** 610 * Updates metadata cache for list of site IDs. 611 * 612 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache. 613 * Subsequent calls to `get_site_meta()` will not need to query the database. 614 * 615 * @since 5.0.0 616 * 617 * @param array $site_ids List of site IDs. 618 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success. 619 */ 620 function update_sitemeta_cache( $site_ids ) { 621 if ( ! is_site_meta_supported() ) { 622 return false; 623 } 624 625 return update_meta_cache( 'blog', $site_ids ); 597 626 } 598 627 … … 798 827 799 828 /** 829 * Adds metadata to a site. 830 * 831 * @since 5.0.0 832 * 833 * @param int $site_id Site ID. 834 * @param string $meta_key Metadata name. 835 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 836 * @param bool $unique Optional. Whether the same key should not be added. 837 * Default false. 838 * @return int|false Meta ID on success, false on failure. 839 */ 840 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { 841 // Bail if site meta table is not installed. 842 if ( ! is_site_meta_supported() ) { 843 /* translators: %s: database table name */ 844 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 845 return false; 846 } 847 848 $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); 849 850 // Bust site query cache. 851 if ( $added ) { 852 wp_cache_set( 'last_changed', microtime(), 'sites' ); 853 } 854 855 return $added; 856 } 857 858 /** 859 * Removes metadata matching criteria from a site. 860 * 861 * You can match based on the key, or key and value. Removing based on key and 862 * value, will keep from removing duplicate metadata with the same key. It also 863 * allows removing all metadata matching key, if needed. 864 * 865 * @since 5.0.0 866 * 867 * @param int $site_id Site ID. 868 * @param string $meta_key Metadata name. 869 * @param mixed $meta_value Optional. Metadata value. Must be serializable if 870 * non-scalar. Default empty. 871 * @return bool True on success, false on failure. 872 */ 873 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { 874 // Bail if site meta table is not installed. 875 if ( ! is_site_meta_supported() ) { 876 /* translators: %s: database table name */ 877 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 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 wp_cache_set( 'last_changed', microtime(), 'sites' ); 886 } 887 888 return $deleted; 889 } 890 891 /** 892 * Retrieves metadata for a site. 893 * 894 * @since 5.0.0 895 * 896 * @param int $site_id Site ID. 897 * @param string $key Optional. The meta key to retrieve. By default, returns 898 * data for all keys. Default empty. 899 * @param bool $single Optional. Whether to return a single value. Default false. 900 * @return mixed Will be an array if $single is false. Will be value of meta data 901 * field if $single is true. 902 */ 903 function get_site_meta( $site_id, $key = '', $single = false ) { 904 // Bail if site meta table is not installed. 905 if ( ! is_site_meta_supported() ) { 906 /* translators: %s: database table name */ 907 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 908 return false; 909 } 910 911 return get_metadata( 'blog', $site_id, $key, $single ); 912 } 913 914 /** 915 * Updates metadata for a site. 916 * 917 * Use the $prev_value parameter to differentiate between meta fields with the 918 * same key and site ID. 919 * 920 * If the meta field for the site does not exist, it will be added. 921 * 922 * @since 5.0.0 923 * 924 * @param int $site_id Site ID. 925 * @param string $meta_key Metadata key. 926 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 927 * @param mixed $prev_value Optional. Previous value to check before removing. 928 * Default empty. 929 * @return int|bool Meta ID if the key didn't exist, true on successful update, 930 * false on failure. 931 */ 932 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { 933 // Bail if site meta table is not installed. 934 if ( ! is_site_meta_supported() ) { 935 /* translators: %s: database table name */ 936 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 937 return false; 938 } 939 940 $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); 941 942 // Bust site query cache. 943 if ( $updated ) { 944 wp_cache_set( 'last_changed', microtime(), 'sites' ); 945 } 946 947 return $updated; 948 } 949 950 /** 951 * Deletes everything from site meta matching meta key. 952 * 953 * @since 5.0.0 954 * 955 * @param string $meta_key Metadata key to search for when deleting. 956 * @return bool Whether the site meta key was deleted from the database. 957 */ 958 function delete_site_meta_by_key( $meta_key ) { 959 // Bail if site meta table is not installed. 960 if ( ! is_site_meta_supported() ) { 961 /* translators: %s: database table name */ 962 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' ); 963 return false; 964 } 965 966 $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); 967 968 // Bust site query cache. 969 if ( $deleted ) { 970 wp_cache_set( 'last_changed', microtime(), 'sites' ); 971 } 972 973 return $deleted; 974 } 975 976 /** 800 977 * Switch the current blog. 801 978 * … … 870 1047 wp_cache_add_global_groups( $global_groups ); 871 1048 } 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' ) );1049 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 1050 } 874 1051 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); … … 938 1115 wp_cache_add_global_groups( $global_groups ); 939 1116 } 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' ) );1117 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 1118 } 942 1119 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); -
trunk/src/wp-includes/version.php
r42576 r42836 12 12 * @global int $wp_db_version 13 13 */ 14 $wp_db_version = 38590;14 $wp_db_version = 42836; 15 15 16 16 /** -
trunk/src/wp-includes/wp-db.php
r42827 r42836 298 298 var $ms_global_tables = array( 299 299 'blogs', 300 'blogmeta', 300 301 'signups', 301 302 'site', … … 413 414 */ 414 415 public $blogs; 416 417 /** 418 * Multisite Blog Metadata table 419 * 420 * @since 5.0.0 421 * @var string 422 */ 423 public $blogmeta; 415 424 416 425 /** -
trunk/tests/phpunit/includes/testcase.php
r42379 r42836 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 }
Note: See TracChangeset
for help on using the changeset viewer.