Skip to:
Content

BuddyPress.org

Changeset 8563


Ignore:
Timestamp:
07/09/2014 12:53:00 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Add phpdoc blocks and brackets to installation functions in bp-core-schema.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/admin/bp-core-schema.php

    r8310 r8563  
    11<?php
     2
    23/**
    34 * BuddyPress DB schema
     
    1011if ( !defined( 'ABSPATH' ) ) exit;
    1112
     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 */
    1221function bp_core_set_charset() {
    1322        global $wpdb;
     
    1524        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    1625
    17         // BuddyPress component DB schema
    1826        return !empty( $wpdb->charset ) ? "DEFAULT CHARACTER SET {$wpdb->charset}" : '';
    1927}
    2028
     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 */
    2139function bp_core_install( $active_components = false ) {
    2240
    23         if ( empty( $active_components ) )
     41        // If no components passed, get all the active components from the main site
     42        if ( empty( $active_components ) ) {
    2443                $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 data
     44        }
     45
     46        // Install Activity Streams even when inactive (to store last_activity data)
    2847        bp_core_install_activity_streams();
    29 
    30         // Notifications
    31         if ( !empty( $active_components['notifications'] ) )
    32                 bp_core_install_notifications();
    33 
    34         // Friend Connections
    35         if ( !empty( $active_components['friends'] ) )
    36                 bp_core_install_friends();
    37 
    38         // Extensible Groups
    39         if ( !empty( $active_components['groups'] ) )
    40                 bp_core_install_groups();
    41 
    42         // Private Messaging
    43         if ( !empty( $active_components['messages'] ) )
    44                 bp_core_install_private_messaging();
    45 
    46         // Extended Profiles
    47         if ( !empty( $active_components['xprofile'] ) )
    48                 bp_core_install_extended_profiles();
    49 
    50         // Blog tracking
    51         if ( !empty( $active_components['blogs'] ) )
    52                 bp_core_install_blog_tracking();
    5348
    5449        // Install the signups table
    5550        bp_core_maybe_install_signups();
    5651
    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 */
    5992function bp_core_install_notifications() {
    60 
    6193        $sql             = array();
    6294        $charset_collate = bp_core_set_charset();
     
    6496
    6597        $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 */
    86127function bp_core_install_activity_streams() {
    87 
    88128        $sql             = array();
    89129        $charset_collate = bp_core_set_charset();
     
    124164                                KEY activity_id (activity_id),
    125165                                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 */
    131180function bp_core_install_friends() {
    132 
    133181        $sql             = array();
    134182        $charset_collate = bp_core_set_charset();
     
    136184
    137185        $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 */
    151208function bp_core_install_groups() {
    152 
    153209        $sql             = array();
    154210        $charset_collate = bp_core_set_charset();
     
    156212
    157213        $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
    158                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     214                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    159215                                creator_id bigint(20) NOT NULL,
    160                                 name varchar(100) NOT NULL,
    161                                 slug varchar(200) NOT NULL,
    162                                 description longtext NOT NULL,
     216                                name varchar(100) NOT NULL,
     217                                slug varchar(200) NOT NULL,
     218                                description longtext NOT NULL,
    163219                                status varchar(10) NOT NULL DEFAULT 'public',
    164220                                enable_forum tinyint(1) NOT NULL DEFAULT '1',
    165221                                date_created datetime NOT NULL,
    166                             KEY creator_id (creator_id),
    167                             KEY status (status)
    168                            ) {$charset_collate};";
     222                                KEY creator_id (creator_id),
     223                                KEY status (status)
     224                        ) {$charset_collate};";
    169225
    170226        $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_members (
    171                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     227                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    172228                                group_id bigint(20) NOT NULL,
    173229                                user_id bigint(20) NOT NULL,
     
    184240                                KEY is_admin (is_admin),
    185241                                KEY is_mod (is_mod),
    186                                 KEY user_id (user_id),
     242                                KEY user_id (user_id),
    187243                                KEY inviter_id (inviter_id),
    188244                                KEY is_confirmed (is_confirmed)
    189                            ) {$charset_collate};";
     245                        ) {$charset_collate};";
    190246
    191247        $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_groupmeta (
     
    196252                                KEY group_id (group_id),
    197253                                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 */
     268function bp_core_install_messages() {
    205269        $sql             = array();
    206270        $charset_collate = bp_core_set_charset();
     
    208272
    209273        $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
    210                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    211                                 thread_id bigint(20) NOT NULL,
    212                                 sender_id bigint(20) NOT NULL,
    213                                 subject varchar(200) NOT NULL,
    214                                 message longtext NOT NULL,
    215                                 date_sent datetime NOT NULL,
    216                             KEY sender_id (sender_id),
    217                             KEY thread_id (thread_id)
    218                            ) {$charset_collate};";
     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};";
    219283
    220284        $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_recipients (
    221                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    222                                 user_id bigint(20) NOT NULL,
    223                                 thread_id bigint(20) NOT NULL,
    224                                 unread_count int(10) NOT NULL DEFAULT '0',
     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',
    225289                                sender_only tinyint(1) NOT NULL DEFAULT '0',
    226290                                is_deleted tinyint(1) NOT NULL DEFAULT '0',
    227                             KEY user_id (user_id),
    228                             KEY thread_id (thread_id),
     291                                KEY user_id (user_id),
     292                                KEY thread_id (thread_id),
    229293                                KEY is_deleted (is_deleted),
    230294                                KEY sender_only (sender_only),
    231                             KEY unread_count (unread_count)
    232                            ) {$charset_collate};";
     295                                KEY unread_count (unread_count)
     296                        ) {$charset_collate};";
    233297
    234298        $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_notices (
    235                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    236                                 subject varchar(200) NOT NULL,
    237                                 message longtext NOT NULL,
    238                                 date_sent datetime NOT NULL,
     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,
    239303                                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 */
    246319function bp_core_install_extended_profiles() {
    247320        global $wpdb;
     
    261334
    262335        $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
    263                             id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    264                             name varchar(150) NOT NULL,
    265                             description mediumtext NOT NULL,
    266                             group_order bigint(20) NOT NULL DEFAULT '0',
    267                             can_delete tinyint(1) NOT NULL,
    268                             KEY can_delete (can_delete)
    269                            ) {$charset_collate};";
     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};";
    270343
    271344        $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields (
    272                             id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    273                             group_id bigint(20) unsigned NOT NULL,
    274                             parent_id bigint(20) unsigned NOT NULL,
    275                             type varchar(150) NOT NULL,
    276                             name varchar(150) NOT NULL,
    277                             description longtext NOT NULL,
    278                             is_required tinyint(1) NOT NULL DEFAULT '0',
    279                             is_default_option tinyint(1) NOT NULL DEFAULT '0',
    280                             field_order bigint(20) NOT NULL DEFAULT '0',
    281                             option_order bigint(20) NOT NULL DEFAULT '0',
    282                             order_by varchar(15) NOT NULL DEFAULT '',
    283                             can_delete tinyint(1) NOT NULL DEFAULT '1',
    284                             KEY group_id (group_id),
    285                             KEY parent_id (parent_id),
    286                             KEY field_order (field_order),
    287                             KEY can_delete (can_delete),
    288                             KEY is_required (is_required)
    289                            ) {$charset_collate};";
     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};";
    290363
    291364        $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data (
    292                             id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    293                             field_id bigint(20) unsigned NOT NULL,
    294                             user_id bigint(20) unsigned NOT NULL,
    295                             value longtext NOT NULL,
    296                             last_updated datetime NOT NULL,
    297                             KEY field_id (field_id),
    298                             KEY user_id (user_id)
    299                            ) {$charset_collate};";
     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};";
    300373
    301374        $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta (
     
    307380                                KEY object_id (object_id),
    308381                                KEY meta_key (meta_key)
    309                            ) {$charset_collate};";
     382                        ) {$charset_collate};";
    310383
    311384        dbDelta( $sql );
     
    314387        $insert_sql = array();
    315388
    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" ) ) {
    317390                $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" ) ) {
    320394                $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        }
    321396
    322397        dbDelta( $insert_sql );
    323398}
    324399
     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 */
    325409function bp_core_install_blog_tracking() {
    326 
    327410        $sql             = array();
    328411        $charset_collate = bp_core_set_charset();
     
    330413
    331414        $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
    332                             id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    333                             user_id bigint(20) NOT NULL,
    334                             blog_id bigint(20) NOT NULL,
    335                             KEY user_id (user_id),
    336                             KEY blog_id (blog_id)
    337                        ) {$charset_collate};";
     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};";
    338421
    339422        $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta (
     
    344427                                KEY blog_id (blog_id),
    345428                                KEY meta_key (meta_key)
    346                        ) {$charset_collate};";
     429                        ) {$charset_collate};";
    347430
    348431        dbDelta( $sql );
Note: See TracChangeset for help on using the changeset viewer.