Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/04/2015 07:29:24 AM (5 years ago)
Author:
tw2113
Message:

Initial documentation cleanup for the BP Forums Component.

See #6397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-forums/bp-forums-bbpress-sa.php

    r10096 r10183  
    5656    require( bp_get_option( 'bb-config-location' ) );
    5757
    58     // Setup the global database connection
     58    // Setup the global database connection.
    5959    $bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );
    6060
    61     // Set the table names
     61    // Set the table names.
    6262    $bbdb->forums             = $bb_table_prefix . 'forums';
    6363    $bbdb->meta               = $bb_table_prefix . 'meta';
     
    116116    $wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' );
    117117
    118     // Set a site id if there isn't one already
     118    // Set a site id if there isn't one already.
    119119    if ( !isset( $bb->site_id ) )
    120120        $bb->site_id = bp_get_root_blog_id();
    121121
    122     // Check if the tables are installed, if not, install them
     122    // Check if the tables are installed, if not, install them.
    123123    if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) ) {
    124124        require( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' );
     
    130130        bb_update_db_version();
    131131
    132         // Set the site admins as the keymasters
     132        // Set the site admins as the keymasters.
    133133        $site_admins = get_site_option( 'site_admins', array('admin') );
    134134        foreach ( (array) $site_admins as $site_admin )
     
    138138        bb_new_forum( array( 'forum_name' => 'Default Forum' ) );
    139139
    140         // Set the site URI
     140        // Set the site URI.
    141141        bb_update_option( 'uri', BB_URL );
    142142    }
     
    173173 * Noop.
    174174 *
    175  * @param array $users
     175 * @param array $users Array of users.
    176176 */
    177177function bb_cache_users( $users ) {}
    178178
    179179/**
    180  * bbPress needs this class for its usermeta manipulation.
     180 * The bbPress plugin needs this class for its usermeta manipulation.
    181181 */
    182182class BP_Forums_BB_Auth {
     
    191191
    192192/**
    193  * bbPress needs 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.
    194194 *
    195195 * The class is pluggable, so that plugins that swap out WPDB with a custom
     
    202202
    203203        /**
    204          * Constructor
     204         * Constructor.
    205205         *
    206206         * @see WPDB::__construct() for description of parameters.
     
    247247         *
    248248         * @see BBDB::__construct() for a description of params.
     249         *
     250         * @param array $args Array of args to parse.
     251         * @return array $args.
    249252         */
    250253        function init( $args ) {
     
    286289        }
    287290    }
    288 endif; // class_exists( 'BPDB' )
     291endif; // End class_exists( 'BPDB' ).
    289292
    290293/**
    291294 * Convert object to given output format.
    292295 *
    293  * bbPress needs this to convert vars.
     296 * The bbPress plugin needs this to convert vars.
    294297 *
    295298 * @param object $object Object to convert.
     
    318321 *
    319322 * @param array $queries See {@link dbDelta()}.
    320  * @param bool $execute See {@link dbDelta()}.
     323 * @param bool  $execute See {@link dbDelta()}.
    321324 * @return array See {@link dbDelta()}.
    322325 */
     
    324327    global $wpdb;
    325328
    326     // Separate individual queries into an array
     329    // Separate individual queries into an array.
    327330    if ( !is_array($queries) ) {
    328331        $queries = explode( ';', $queries );
     
    330333    }
    331334
    332     $cqueries = array(); // Creation Queries
    333     $iqueries = array(); // Insertion Queries
     335    $cqueries = array(); // Creation Queries.
     336    $iqueries = array(); // Insertion Queries.
    334337    $for_update = array();
    335338
    336     // Create a tablename index for an array ($cqueries) of queries
     339    // Create a tablename index for an array ($cqueries) of queries.
    337340    foreach($queries as $qry) {
    338341        if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
     
    346349            $iqueries[] = $qry;
    347350        } 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.
    353356    if ($tables = $wpdb->get_col('SHOW TABLES;')) {
    354         // For every table in the database
     357        // For every table in the database.
    355358        foreach ($tables as $table) {
    356359            // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.
     
    360363            // If a table query exists for the database table...
    361364            if ( array_key_exists(strtolower($table), $cqueries) ) {
    362                 // Clear the field and index arrays
     365                // Clear the field and index arrays.
    363366                $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.
    365368                preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);
    366369                $qryline = trim($match2[1]);
    367370
    368                 // Separate field lines into an array
     371                // Separate field lines into an array.
    369372                $flds = explode("\n", $qryline);
    370373
    371374                //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
    372375
    373                 // For every field line specified in the query
     376                // For every field line specified in the query.
    374377                foreach ($flds as $fld) {
    375                     // Extract the field name
     378                    // Extract the field name.
    376379                    preg_match("|^([^ ]*)|", trim($fld), $fvals);
    377380                    $fieldname = trim( $fvals[1], '`' );
    378381
    379                     // Verify the found field name
     382                    // Verify the found field name.
    380383                    $validfield = true;
    381384                    switch (strtolower($fieldname)) {
     
    392395                    $fld = trim($fld);
    393396
    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.
    395398                    if ($validfield) {
    396399                        $cfields[strtolower($fieldname)] = trim($fld, ", \n");
     
    398401                }
    399402
    400                 // Fetch the table column structure from the database
     403                // Fetch the table column structure from the database.
    401404                $tablefields = $wpdb->get_results("DESCRIBE {$table};");
    402405
    403                 // For every field in the table
     406                // For every field in the table.
    404407                foreach ($tablefields as $tablefield) {
    405408                    // If the table field exists in the field array...
    406409                    if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
    407                         // Get the field type from the query
     410                        // Get the field type from the query.
    408411                        preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
    409412                        $fieldtype = $matches[1];
     
    411414                        // Is actual field type different from the field type in query?
    412415                        if ($tablefield->Type != $fieldtype) {
    413                             // Add a query to change the column type
     416                            // Add a query to change the column type.
    414417                            $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
    415418                            $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
    416419                        }
    417420
    418                         // Get the default value from the array
     421                        // Get the default value from the array.
    419422                            //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
    420423                        if (preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
    421424                            $default_value = $matches[1];
    422425                            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.
    424427                                $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
    425428                                $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
     
    427430                        }
    428431
    429                         // Remove the field from the array (so it's not added)
     432                        // Remove the field from the array (so it's not added).
    430433                        unset($cfields[strtolower($tablefield->Field)]);
    431434                    } else {
     
    434437                }
    435438
    436                 // For every remaining field specified for the table
     439                // For every remaining field specified for the table.
    437440                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.
    439442                    $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
    440443                    $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
     
    442445
    443446                // Index stuff goes here
    444                 // Fetch the table index structure from the database
     447                // Fetch the table index structure from the database.
    445448                $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
    446449
    447450                if ($tableindices) {
    448                     // Clear the index array
     451                    // Clear the index array.
    449452                    unset($index_ary);
    450453
    451                     // For every index in the table
     454                    // For every index in the table.
    452455                    foreach ($tableindices as $tableindex) {
    453                         // Add the index to the index data array
     456                        // Add the index to the index data array.
    454457                        $keyname = $tableindex->Key_name;
    455458                        $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
     
    457460                    }
    458461
    459                     // For each actual index in the index array
     462                    // For each actual index in the index array.
    460463                    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.
    462465                        $index_string = '';
    463466                        if ($index_name == 'PRIMARY') {
     
    471474                        }
    472475                        $index_columns = '';
    473                         // For each column in the index
     476                        // For each column in the index.
    474477                        foreach ($index_data['columns'] as $column_data) {
    475478                            if ($index_columns != '') $index_columns .= ',';
    476                             // Add the field to the column list string
     479                            // Add the field to the column list string.
    477480                            $index_columns .= $column_data['fieldname'];
    478481                            if ($column_data['subpart'] != '') {
     
    480483                            }
    481484                        }
    482                         // Add the column list to the index create string
     485                        // Add the column list to the index create string.
    483486                        $index_string .= ' ('.$index_columns.')';
    484487                        if (!(($aindex = array_search($index_string, $indices)) === false)) {
     
    490493                }
    491494
    492                 // For every remaining index specified for the table
     495                // For every remaining index specified for the table.
    493496                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.
    495498                    $cqueries[] = "ALTER TABLE {$table} ADD $index";
    496499                    $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
    497500                }
    498501
    499                 // Remove the original table creation query from processing
     502                // Remove the original table creation query from processing.
    500503                unset($cqueries[strtolower($table)]);
    501504                unset($for_update[strtolower($table)]);
Note: See TracChangeset for help on using the changeset viewer.