Changeset 8563
- Timestamp:
- 07/09/2014 12:53:00 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/admin/bp-core-schema.php
r8310 r8563 1 1 <?php 2 2 3 /** 3 4 * BuddyPress DB schema … … 10 11 if ( !defined( 'ABSPATH' ) ) exit; 11 12 13 /** 14 * Get the DB schema to use for BuddyPress components 15 * 16 * @since BuddyPress (1.1.0) 17 * 18 * @global $wpdb $wpdb 19 * @return string The default database character-set, if set 20 */ 12 21 function bp_core_set_charset() { 13 22 global $wpdb; … … 15 24 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 16 25 17 // BuddyPress component DB schema18 26 return !empty( $wpdb->charset ) ? "DEFAULT CHARACTER SET {$wpdb->charset}" : ''; 19 27 } 20 28 29 /** 30 * Main installer 31 * 32 * Can be passed an optional array of components to explicitly run installation 33 * routines on, typically the first time a component is activated in Settings. 34 * 35 * @since BuddyPress (1.0.0) 36 * 37 * @param array $active_components Components to install 38 */ 21 39 function bp_core_install( $active_components = false ) { 22 40 23 if ( empty( $active_components ) ) 41 // If no components passed, get all the active components from the main site 42 if ( empty( $active_components ) ) { 24 43 $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) ); 25 26 // Activity Streams 27 // Install tables even when inactive, to store last_activity data44 } 45 46 // Install Activity Streams even when inactive (to store last_activity data) 28 47 bp_core_install_activity_streams(); 29 30 // Notifications31 if ( !empty( $active_components['notifications'] ) )32 bp_core_install_notifications();33 34 // Friend Connections35 if ( !empty( $active_components['friends'] ) )36 bp_core_install_friends();37 38 // Extensible Groups39 if ( !empty( $active_components['groups'] ) )40 bp_core_install_groups();41 42 // Private Messaging43 if ( !empty( $active_components['messages'] ) )44 bp_core_install_private_messaging();45 46 // Extended Profiles47 if ( !empty( $active_components['xprofile'] ) )48 bp_core_install_extended_profiles();49 50 // Blog tracking51 if ( !empty( $active_components['blogs'] ) )52 bp_core_install_blog_tracking();53 48 54 49 // Install the signups table 55 50 bp_core_maybe_install_signups(); 56 51 57 } 58 52 // Notifications 53 if ( !empty( $active_components['notifications'] ) ) { 54 bp_core_install_notifications(); 55 } 56 57 // Friend Connections 58 if ( !empty( $active_components['friends'] ) ) { 59 bp_core_install_friends(); 60 } 61 62 // Extensible Groups 63 if ( !empty( $active_components['groups'] ) ) { 64 bp_core_install_groups(); 65 } 66 67 // Private Messaging 68 if ( !empty( $active_components['messages'] ) ) { 69 bp_core_install_private_messaging(); 70 } 71 72 // Extended Profiles 73 if ( !empty( $active_components['xprofile'] ) ) { 74 bp_core_install_extended_profiles(); 75 } 76 77 // Blog tracking 78 if ( !empty( $active_components['blogs'] ) ) { 79 bp_core_install_blog_tracking(); 80 } 81 } 82 83 /** 84 * Install database tables for the Notifications component 85 * 86 * @since BuddyPress (1.0.0) 87 * 88 * @uses bp_core_set_charset() 89 * @uses bp_core_get_table_prefix() 90 * @uses dbDelta() 91 */ 59 92 function bp_core_install_notifications() { 60 61 93 $sql = array(); 62 94 $charset_collate = bp_core_set_charset(); … … 64 96 65 97 $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications ( 66 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 67 user_id bigint(20) NOT NULL, 68 item_id bigint(20) NOT NULL, 69 secondary_item_id bigint(20), 70 component_name varchar(75) NOT NULL, 71 component_action varchar(75) NOT NULL, 72 date_notified datetime NOT NULL, 73 is_new bool NOT NULL DEFAULT 0, 74 KEY item_id (item_id), 75 KEY secondary_item_id (secondary_item_id), 76 KEY user_id (user_id), 77 KEY is_new (is_new), 78 KEY component_name (component_name), 79 KEY component_action (component_action), 80 KEY useritem (user_id,is_new) 81 ) {$charset_collate};"; 82 83 dbDelta( $sql ); 84 } 85 98 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 99 user_id bigint(20) NOT NULL, 100 item_id bigint(20) NOT NULL, 101 secondary_item_id bigint(20), 102 component_name varchar(75) NOT NULL, 103 component_action varchar(75) NOT NULL, 104 date_notified datetime NOT NULL, 105 is_new bool NOT NULL DEFAULT 0, 106 KEY item_id (item_id), 107 KEY secondary_item_id (secondary_item_id), 108 KEY user_id (user_id), 109 KEY is_new (is_new), 110 KEY component_name (component_name), 111 KEY component_action (component_action), 112 KEY useritem (user_id,is_new) 113 ) {$charset_collate};"; 114 115 dbDelta( $sql ); 116 } 117 118 /** 119 * Install database tables for the Activity component 120 * 121 * @since BuddyPress (1.0.0) 122 * 123 * @uses bp_core_set_charset() 124 * @uses bp_core_get_table_prefix() 125 * @uses dbDelta() 126 */ 86 127 function bp_core_install_activity_streams() { 87 88 128 $sql = array(); 89 129 $charset_collate = bp_core_set_charset(); … … 124 164 KEY activity_id (activity_id), 125 165 KEY meta_key (meta_key) 126 ) {$charset_collate};"; 127 128 dbDelta( $sql ); 129 } 130 166 ) {$charset_collate};"; 167 168 dbDelta( $sql ); 169 } 170 171 /** 172 * Install database tables for the Notifications component 173 * 174 * @since BuddyPress (1.0.0) 175 * 176 * @uses bp_core_set_charset() 177 * @uses bp_core_get_table_prefix() 178 * @uses dbDelta() 179 */ 131 180 function bp_core_install_friends() { 132 133 181 $sql = array(); 134 182 $charset_collate = bp_core_set_charset(); … … 136 184 137 185 $sql[] = "CREATE TABLE {$bp_prefix}bp_friends ( 138 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 139 initiator_user_id bigint(20) NOT NULL, 140 friend_user_id bigint(20) NOT NULL, 141 is_confirmed bool DEFAULT 0, 142 is_limited bool DEFAULT 0, 143 date_created datetime NOT NULL, 144 KEY initiator_user_id (initiator_user_id), 145 KEY friend_user_id (friend_user_id) 146 ) {$charset_collate};"; 147 148 dbDelta( $sql ); 149 } 150 186 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 187 initiator_user_id bigint(20) NOT NULL, 188 friend_user_id bigint(20) NOT NULL, 189 is_confirmed bool DEFAULT 0, 190 is_limited bool DEFAULT 0, 191 date_created datetime NOT NULL, 192 KEY initiator_user_id (initiator_user_id), 193 KEY friend_user_id (friend_user_id) 194 ) {$charset_collate};"; 195 196 dbDelta( $sql ); 197 } 198 199 /** 200 * Install database tables for the Groups component 201 * 202 * @since BuddyPress (1.0.0) 203 * 204 * @uses bp_core_set_charset() 205 * @uses bp_core_get_table_prefix() 206 * @uses dbDelta() 207 */ 151 208 function bp_core_install_groups() { 152 153 209 $sql = array(); 154 210 $charset_collate = bp_core_set_charset(); … … 156 212 157 213 $sql[] = "CREATE TABLE {$bp_prefix}bp_groups ( 158 214 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 159 215 creator_id bigint(20) NOT NULL, 160 161 162 216 name varchar(100) NOT NULL, 217 slug varchar(200) NOT NULL, 218 description longtext NOT NULL, 163 219 status varchar(10) NOT NULL DEFAULT 'public', 164 220 enable_forum tinyint(1) NOT NULL DEFAULT '1', 165 221 date_created datetime NOT NULL, 166 167 168 222 KEY creator_id (creator_id), 223 KEY status (status) 224 ) {$charset_collate};"; 169 225 170 226 $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_members ( 171 227 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 172 228 group_id bigint(20) NOT NULL, 173 229 user_id bigint(20) NOT NULL, … … 184 240 KEY is_admin (is_admin), 185 241 KEY is_mod (is_mod), 186 242 KEY user_id (user_id), 187 243 KEY inviter_id (inviter_id), 188 244 KEY is_confirmed (is_confirmed) 189 245 ) {$charset_collate};"; 190 246 191 247 $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_groupmeta ( … … 196 252 KEY group_id (group_id), 197 253 KEY meta_key (meta_key) 198 ) {$charset_collate};"; 199 200 dbDelta( $sql ); 201 } 202 203 function bp_core_install_private_messaging() { 204 254 ) {$charset_collate};"; 255 256 dbDelta( $sql ); 257 } 258 259 /** 260 * Install database tables for the Messsages component 261 * 262 * @since BuddyPress (1.0.0) 263 * 264 * @uses bp_core_set_charset() 265 * @uses bp_core_get_table_prefix() 266 * @uses dbDelta() 267 */ 268 function bp_core_install_messages() { 205 269 $sql = array(); 206 270 $charset_collate = bp_core_set_charset(); … … 208 272 209 273 $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages ( 210 211 212 213 214 215 216 217 218 274 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 275 thread_id bigint(20) NOT NULL, 276 sender_id bigint(20) NOT NULL, 277 subject varchar(200) NOT NULL, 278 message longtext NOT NULL, 279 date_sent datetime NOT NULL, 280 KEY sender_id (sender_id), 281 KEY thread_id (thread_id) 282 ) {$charset_collate};"; 219 283 220 284 $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_recipients ( 221 222 223 224 285 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 286 user_id bigint(20) NOT NULL, 287 thread_id bigint(20) NOT NULL, 288 unread_count int(10) NOT NULL DEFAULT '0', 225 289 sender_only tinyint(1) NOT NULL DEFAULT '0', 226 290 is_deleted tinyint(1) NOT NULL DEFAULT '0', 227 228 291 KEY user_id (user_id), 292 KEY thread_id (thread_id), 229 293 KEY is_deleted (is_deleted), 230 294 KEY sender_only (sender_only), 231 232 295 KEY unread_count (unread_count) 296 ) {$charset_collate};"; 233 297 234 298 $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_notices ( 235 236 237 238 299 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 300 subject varchar(200) NOT NULL, 301 message longtext NOT NULL, 302 date_sent datetime NOT NULL, 239 303 is_active tinyint(1) NOT NULL DEFAULT '0', 240 KEY is_active (is_active) 241 ) {$charset_collate};"; 242 243 dbDelta( $sql ); 244 } 245 304 KEY is_active (is_active) 305 ) {$charset_collate};"; 306 307 dbDelta( $sql ); 308 } 309 310 /** 311 * Install database tables for the Profiles component 312 * 313 * @since BuddyPress (1.0.0) 314 * 315 * @uses bp_core_set_charset() 316 * @uses bp_core_get_table_prefix() 317 * @uses dbDelta() 318 */ 246 319 function bp_core_install_extended_profiles() { 247 320 global $wpdb; … … 261 334 262 335 $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups ( 263 264 265 266 267 268 269 336 id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, 337 name varchar(150) NOT NULL, 338 description mediumtext NOT NULL, 339 group_order bigint(20) NOT NULL DEFAULT '0', 340 can_delete tinyint(1) NOT NULL, 341 KEY can_delete (can_delete) 342 ) {$charset_collate};"; 270 343 271 344 $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields ( 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 345 id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, 346 group_id bigint(20) unsigned NOT NULL, 347 parent_id bigint(20) unsigned NOT NULL, 348 type varchar(150) NOT NULL, 349 name varchar(150) NOT NULL, 350 description longtext NOT NULL, 351 is_required tinyint(1) NOT NULL DEFAULT '0', 352 is_default_option tinyint(1) NOT NULL DEFAULT '0', 353 field_order bigint(20) NOT NULL DEFAULT '0', 354 option_order bigint(20) NOT NULL DEFAULT '0', 355 order_by varchar(15) NOT NULL DEFAULT '', 356 can_delete tinyint(1) NOT NULL DEFAULT '1', 357 KEY group_id (group_id), 358 KEY parent_id (parent_id), 359 KEY field_order (field_order), 360 KEY can_delete (can_delete), 361 KEY is_required (is_required) 362 ) {$charset_collate};"; 290 363 291 364 $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data ( 292 293 294 295 296 297 298 299 365 id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, 366 field_id bigint(20) unsigned NOT NULL, 367 user_id bigint(20) unsigned NOT NULL, 368 value longtext NOT NULL, 369 last_updated datetime NOT NULL, 370 KEY field_id (field_id), 371 KEY user_id (user_id) 372 ) {$charset_collate};"; 300 373 301 374 $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta ( … … 307 380 KEY object_id (object_id), 308 381 KEY meta_key (meta_key) 309 382 ) {$charset_collate};"; 310 383 311 384 dbDelta( $sql ); … … 314 387 $insert_sql = array(); 315 388 316 if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) )389 if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) ) { 317 390 $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );"; 318 319 if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) ) 391 } 392 393 if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) ) { 320 394 $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );"; 395 } 321 396 322 397 dbDelta( $insert_sql ); 323 398 } 324 399 400 /** 401 * Install database tables for the Sites component 402 * 403 * @since BuddyPress (1.0.0) 404 * 405 * @uses bp_core_set_charset() 406 * @uses bp_core_get_table_prefix() 407 * @uses dbDelta() 408 */ 325 409 function bp_core_install_blog_tracking() { 326 327 410 $sql = array(); 328 411 $charset_collate = bp_core_set_charset(); … … 330 413 331 414 $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs ( 332 333 334 335 336 337 415 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 416 user_id bigint(20) NOT NULL, 417 blog_id bigint(20) NOT NULL, 418 KEY user_id (user_id), 419 KEY blog_id (blog_id) 420 ) {$charset_collate};"; 338 421 339 422 $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta ( … … 344 427 KEY blog_id (blog_id), 345 428 KEY meta_key (meta_key) 346 429 ) {$charset_collate};"; 347 430 348 431 dbDelta( $sql );
Note: See TracChangeset
for help on using the changeset viewer.