Changeset 10183 for trunk/src/bp-forums/bp-forums-bbpress-sa.php
- Timestamp:
- 10/04/2015 07:29:24 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-forums/bp-forums-bbpress-sa.php
r10096 r10183 56 56 require( bp_get_option( 'bb-config-location' ) ); 57 57 58 // Setup the global database connection 58 // Setup the global database connection. 59 59 $bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST ); 60 60 61 // Set the table names 61 // Set the table names. 62 62 $bbdb->forums = $bb_table_prefix . 'forums'; 63 63 $bbdb->meta = $bb_table_prefix . 'meta'; … … 116 116 $wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' ); 117 117 118 // Set a site id if there isn't one already 118 // Set a site id if there isn't one already. 119 119 if ( !isset( $bb->site_id ) ) 120 120 $bb->site_id = bp_get_root_blog_id(); 121 121 122 // Check if the tables are installed, if not, install them 122 // Check if the tables are installed, if not, install them. 123 123 if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) ) { 124 124 require( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' ); … … 130 130 bb_update_db_version(); 131 131 132 // Set the site admins as the keymasters 132 // Set the site admins as the keymasters. 133 133 $site_admins = get_site_option( 'site_admins', array('admin') ); 134 134 foreach ( (array) $site_admins as $site_admin ) … … 138 138 bb_new_forum( array( 'forum_name' => 'Default Forum' ) ); 139 139 140 // Set the site URI 140 // Set the site URI. 141 141 bb_update_option( 'uri', BB_URL ); 142 142 } … … 173 173 * Noop. 174 174 * 175 * @param array $users 175 * @param array $users Array of users. 176 176 */ 177 177 function bb_cache_users( $users ) {} 178 178 179 179 /** 180 * bbPressneeds this class for its usermeta manipulation.180 * The bbPress plugin needs this class for its usermeta manipulation. 181 181 */ 182 182 class BP_Forums_BB_Auth { … … 191 191 192 192 /** 193 * bbPressneeds the DB class to be BPDB, but we want to use WPDB, so we can extend it and use this.193 * The bbPress plugin needs the DB class to be BPDB, but we want to use WPDB, so we can extend it and use this. 194 194 * 195 195 * The class is pluggable, so that plugins that swap out WPDB with a custom … … 202 202 203 203 /** 204 * Constructor 204 * Constructor. 205 205 * 206 206 * @see WPDB::__construct() for description of parameters. … … 247 247 * 248 248 * @see BBDB::__construct() for a description of params. 249 * 250 * @param array $args Array of args to parse. 251 * @return array $args. 249 252 */ 250 253 function init( $args ) { … … 286 289 } 287 290 } 288 endif; // class_exists( 'BPDB' )291 endif; // End class_exists( 'BPDB' ). 289 292 290 293 /** 291 294 * Convert object to given output format. 292 295 * 293 * bbPressneeds this to convert vars.296 * The bbPress plugin needs this to convert vars. 294 297 * 295 298 * @param object $object Object to convert. … … 318 321 * 319 322 * @param array $queries See {@link dbDelta()}. 320 * @param bool $execute See {@link dbDelta()}.323 * @param bool $execute See {@link dbDelta()}. 321 324 * @return array See {@link dbDelta()}. 322 325 */ … … 324 327 global $wpdb; 325 328 326 // Separate individual queries into an array 329 // Separate individual queries into an array. 327 330 if ( !is_array($queries) ) { 328 331 $queries = explode( ';', $queries ); … … 330 333 } 331 334 332 $cqueries = array(); // Creation Queries 333 $iqueries = array(); // Insertion Queries 335 $cqueries = array(); // Creation Queries. 336 $iqueries = array(); // Insertion Queries. 334 337 $for_update = array(); 335 338 336 // Create a tablename index for an array ($cqueries) of queries 339 // Create a tablename index for an array ($cqueries) of queries. 337 340 foreach($queries as $qry) { 338 341 if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) { … … 346 349 $iqueries[] = $qry; 347 350 } else { 348 // Unrecognized query type 349 } 350 } 351 352 // Check to see which tables and fields exist 351 // Unrecognized query type. 352 } 353 } 354 355 // Check to see which tables and fields exist. 353 356 if ($tables = $wpdb->get_col('SHOW TABLES;')) { 354 // For every table in the database 357 // For every table in the database. 355 358 foreach ($tables as $table) { 356 359 // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined. … … 360 363 // If a table query exists for the database table... 361 364 if ( array_key_exists(strtolower($table), $cqueries) ) { 362 // Clear the field and index arrays 365 // Clear the field and index arrays. 363 366 $cfields = $indices = array(); 364 // Get all of the field names in the query from between the parents 367 // Get all of the field names in the query from between the parents. 365 368 preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2); 366 369 $qryline = trim($match2[1]); 367 370 368 // Separate field lines into an array 371 // Separate field lines into an array. 369 372 $flds = explode("\n", $qryline); 370 373 371 374 //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>"; 372 375 373 // For every field line specified in the query 376 // For every field line specified in the query. 374 377 foreach ($flds as $fld) { 375 // Extract the field name 378 // Extract the field name. 376 379 preg_match("|^([^ ]*)|", trim($fld), $fvals); 377 380 $fieldname = trim( $fvals[1], '`' ); 378 381 379 // Verify the found field name 382 // Verify the found field name. 380 383 $validfield = true; 381 384 switch (strtolower($fieldname)) { … … 392 395 $fld = trim($fld); 393 396 394 // If it's a valid field, add it to the field array 397 // If it's a valid field, add it to the field array. 395 398 if ($validfield) { 396 399 $cfields[strtolower($fieldname)] = trim($fld, ", \n"); … … 398 401 } 399 402 400 // Fetch the table column structure from the database 403 // Fetch the table column structure from the database. 401 404 $tablefields = $wpdb->get_results("DESCRIBE {$table};"); 402 405 403 // For every field in the table 406 // For every field in the table. 404 407 foreach ($tablefields as $tablefield) { 405 408 // If the table field exists in the field array... 406 409 if (array_key_exists(strtolower($tablefield->Field), $cfields)) { 407 // Get the field type from the query 410 // Get the field type from the query. 408 411 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches); 409 412 $fieldtype = $matches[1]; … … 411 414 // Is actual field type different from the field type in query? 412 415 if ($tablefield->Type != $fieldtype) { 413 // Add a query to change the column type 416 // Add a query to change the column type. 414 417 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; 415 418 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 416 419 } 417 420 418 // Get the default value from the array 421 // Get the default value from the array. 419 422 //echo "{$cfields[strtolower($tablefield->Field)]}<br>"; 420 423 if (preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) { 421 424 $default_value = $matches[1]; 422 425 if ($tablefield->Default != $default_value) { 423 // Add a query to change the column's default value 426 // Add a query to change the column's default value. 424 427 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'"; 425 428 $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}"; … … 427 430 } 428 431 429 // Remove the field from the array (so it's not added) 432 // Remove the field from the array (so it's not added). 430 433 unset($cfields[strtolower($tablefield->Field)]); 431 434 } else { … … 434 437 } 435 438 436 // For every remaining field specified for the table 439 // For every remaining field specified for the table. 437 440 foreach ($cfields as $fieldname => $fielddef) { 438 // Push a query line into $cqueries that adds the field to that table 441 // Push a query line into $cqueries that adds the field to that table. 439 442 $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef"; 440 443 $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname; … … 442 445 443 446 // Index stuff goes here 444 // Fetch the table index structure from the database 447 // Fetch the table index structure from the database. 445 448 $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};"); 446 449 447 450 if ($tableindices) { 448 // Clear the index array 451 // Clear the index array. 449 452 unset($index_ary); 450 453 451 // For every index in the table 454 // For every index in the table. 452 455 foreach ($tableindices as $tableindex) { 453 // Add the index to the index data array 456 // Add the index to the index data array. 454 457 $keyname = $tableindex->Key_name; 455 458 $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part); … … 457 460 } 458 461 459 // For each actual index in the index array 462 // For each actual index in the index array. 460 463 foreach ($index_ary as $index_name => $index_data) { 461 // Build a create string to compare to the query 464 // Build a create string to compare to the query. 462 465 $index_string = ''; 463 466 if ($index_name == 'PRIMARY') { … … 471 474 } 472 475 $index_columns = ''; 473 // For each column in the index 476 // For each column in the index. 474 477 foreach ($index_data['columns'] as $column_data) { 475 478 if ($index_columns != '') $index_columns .= ','; 476 // Add the field to the column list string 479 // Add the field to the column list string. 477 480 $index_columns .= $column_data['fieldname']; 478 481 if ($column_data['subpart'] != '') { … … 480 483 } 481 484 } 482 // Add the column list to the index create string 485 // Add the column list to the index create string. 483 486 $index_string .= ' ('.$index_columns.')'; 484 487 if (!(($aindex = array_search($index_string, $indices)) === false)) { … … 490 493 } 491 494 492 // For every remaining index specified for the table 495 // For every remaining index specified for the table. 493 496 foreach ( (array) $indices as $index ) { 494 // Push a query line into $cqueries that adds the index to that table 497 // Push a query line into $cqueries that adds the index to that table. 495 498 $cqueries[] = "ALTER TABLE {$table} ADD $index"; 496 499 $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index; 497 500 } 498 501 499 // Remove the original table creation query from processing 502 // Remove the original table creation query from processing. 500 503 unset($cqueries[strtolower($table)]); 501 504 unset($for_update[strtolower($table)]);
Note: See TracChangeset
for help on using the changeset viewer.