Changeset 43629
- Timestamp:
- 09/05/2018 11:01:36 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/schema.php
r43628 r43629 1293 1293 $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared 1294 1294 } 1295 1296 /** 1297 * Creates WordPress site meta and sets the default values. 1298 * 1299 * @since 5.0.0 1300 * 1301 * @global wpdb $wpdb WordPress database abstraction object. 1302 * 1303 * @param int $site_id Site ID to populate meta for. 1304 * @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array. 1305 */ 1306 function populate_site_meta( $site_id, array $meta = array() ) { 1307 global $wpdb; 1308 1309 $site_id = (int) $site_id; 1310 1311 if ( ! is_site_meta_supported() ) { 1312 return; 1313 } 1314 1315 if ( empty( $meta ) ) { 1316 return; 1317 } 1318 1319 $insert = ''; 1320 foreach ( $meta as $meta_key => $meta_value ) { 1321 if ( is_array( $meta_value ) ) { 1322 $meta_value = serialize( $meta_value ); 1323 } 1324 if ( ! empty( $insert ) ) { 1325 $insert .= ', '; 1326 } 1327 $insert .= $wpdb->prepare( '( %d, %s, %s)', $site_id, $meta_key, $meta_value ); 1328 } 1329 1330 $wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared 1331 1332 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1333 } -
trunk/tests/phpunit/tests/admin/includesSchema.php
r43628 r43629 8 8 9 9 private static $options; 10 private static $blogmeta; 10 11 private static $sitemeta; 11 12 … … 17 18 18 19 self::$options = 'testprefix_options'; 20 self::$blogmeta = 'testprefix_blogmeta'; 19 21 self::$sitemeta = 'testprefix_sitemeta'; 20 22 21 23 $options = self::$options; 24 $blogmeta = self::$blogmeta; 22 25 $sitemeta = self::$sitemeta; 23 26 … … 36 39 PRIMARY KEY (option_id), 37 40 UNIQUE KEY option_name (option_name) 41 ) {$charset_collate} 42 " 43 ); 44 $wpdb->query( 45 " 46 CREATE TABLE {$blogmeta} ( 47 meta_id bigint(20) unsigned NOT NULL auto_increment, 48 blog_id bigint(20) unsigned NOT NULL default '0', 49 meta_key varchar(255) default NULL, 50 meta_value longtext, 51 PRIMARY KEY (meta_id), 52 KEY meta_key (meta_key({$max_index_length})), 53 KEY blog_id (blog_id) 38 54 ) {$charset_collate} 39 55 " … … 61 77 62 78 $options = self::$options; 79 $blogmeta = self::$blogmeta; 63 80 $sitemeta = self::$sitemeta; 64 81 65 82 $wpdb->query( "DROP TABLE IF EXISTS {$options}" ); 83 $wpdb->query( "DROP TABLE IF EXISTS {$blogmeta}" ); 66 84 $wpdb->query( "DROP TABLE IF EXISTS {$sitemeta}" ); 67 85 } … … 158 176 159 177 /** 178 * @ticket 44896 179 * @group multisite 180 * @group ms-required 181 * @dataProvider data_populate_site_meta 182 */ 183 function test_populate_site_meta( $meta, $expected ) { 184 global $wpdb; 185 186 $orig_blogmeta = $wpdb->blogmeta; 187 $wpdb->blogmeta = self::$blogmeta; 188 189 populate_site_meta( 42, $meta ); 190 191 $results = array(); 192 foreach ( $expected as $meta_key => $value ) { 193 $results[ $meta_key ] = get_site_meta( 42, $meta_key, true ); 194 } 195 196 $wpdb->query( "TRUNCATE TABLE {$wpdb->blogmeta}" ); 197 198 $wpdb->blogmeta = $orig_blogmeta; 199 200 $this->assertEquals( $expected, $results ); 201 } 202 203 public function data_populate_site_meta() { 204 return array( 205 array( 206 array(), 207 array( 208 'unknown_value' => '', 209 ), 210 ), 211 array( 212 array( 213 'custom_meta' => '1', 214 ), 215 array( 216 'custom_meta' => '1', 217 ), 218 ), 219 ); 220 } 221 222 /** 160 223 * @ticket 44895 224 * @group multisite 161 225 * @dataProvider data_populate_network_meta 162 226 */
Note: See TracChangeset
for help on using the changeset viewer.