[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-forums/bbpress/bb-admin/includes/ -> defaults.bb-schema.php (source)

   1  <?php
   2  
   3  // Globalise as this file is included within the functions bb_install() and bb_upgrade_all()
   4  global $bb_queries, $bbdb, $bb_schema_ignore;
   5  
   6  // Die if no database class is loaded
   7  if ( !isset($bbdb) || ( !is_a( $bbdb, 'BPDB' ) && !is_a( $bbdb, 'db' ) ) )
   8      die( __('Database class not loaded.') );
   9  
  10  // Initialise the query array
  11  $bb_queries = array();
  12  
  13  // forums
  14  $bb_queries['forums'] = "CREATE TABLE IF NOT EXISTS `$bbdb->forums` (
  15      `forum_id` int(10) NOT NULL auto_increment,
  16      `forum_name` varchar(150) NOT NULL default '',
  17      `forum_slug` varchar(255) NOT NULL default '',
  18      `forum_desc` text NOT NULL,
  19      `forum_parent` int(10) NOT NULL default 0,
  20      `forum_order` int(10) NOT NULL default 0,
  21      `topics` bigint(20) NOT NULL default 0,
  22      `posts` bigint(20) NOT NULL default 0,
  23      PRIMARY KEY (`forum_id`),
  24      KEY `forum_slug` (`forum_slug`)
  25  );";
  26  
  27  // meta
  28  $bb_queries['meta'] = "CREATE TABLE IF NOT EXISTS `$bbdb->meta` (
  29      `meta_id` bigint(20) NOT NULL auto_increment,
  30      `object_type` varchar(16) NOT NULL default 'bb_option',
  31      `object_id` bigint(20) NOT NULL default 0,
  32      `meta_key` varchar(255) default NULL,
  33      `meta_value` longtext default NULL,
  34      PRIMARY KEY (`meta_id`),
  35      KEY `object_type__meta_key` (`object_type`, `meta_key`),
  36      KEY `object_type__object_id__meta_key` (`object_type`, `object_id`, `meta_key`)
  37  );";
  38  
  39  // posts
  40  $bb_queries['posts'] = "CREATE TABLE IF NOT EXISTS `$bbdb->posts` (
  41      `post_id` bigint(20) NOT NULL auto_increment,
  42      `forum_id` int(10) NOT NULL default 1,
  43      `topic_id` bigint(20) NOT NULL default 1,
  44      `poster_id` int(10) NOT NULL default 0,
  45      `post_text` text NOT NULL,
  46      `post_time` datetime NOT NULL default '0000-00-00 00:00:00',
  47      `poster_ip` varchar(15) NOT NULL default '',
  48      `post_status` tinyint(1) NOT NULL default 0,
  49      `post_position` bigint(20) NOT NULL default 0,
  50      PRIMARY KEY (`post_id`),
  51      KEY `topic_time` (`topic_id`, `post_time`),
  52      KEY `poster_time` (`poster_id`, `post_time`),
  53      KEY `post_time` (`post_time`),
  54      FULLTEXT KEY `post_text` (`post_text`)
  55  ) ENGINE = MYISAM;";
  56  
  57  // terms
  58  $bb_queries['terms'] = "CREATE TABLE IF NOT EXISTS `$bbdb->terms` (
  59      `term_id` bigint(20) NOT NULL auto_increment,
  60      `name` varchar(55) NOT NULL default '',
  61      `slug` varchar(200) NOT NULL default '',
  62      `term_group` bigint(10) NOT NULL default 0,
  63      PRIMARY KEY (`term_id`),
  64      UNIQUE KEY `slug` (`slug`),
  65      KEY name (name)
  66  );";
  67  
  68  // term_relationships
  69  $bb_queries['term_relationships'] = "CREATE TABLE IF NOT EXISTS `$bbdb->term_relationships` (
  70      `object_id` bigint(20) NOT NULL default 0,
  71      `term_taxonomy_id` bigint(20) NOT NULL default 0,
  72      `user_id` bigint(20) NOT NULL default 0,
  73      `term_order` int(11) NOT NULL default 0,
  74      PRIMARY KEY (`object_id`, `term_taxonomy_id`),
  75      KEY `term_taxonomy_id` (`term_taxonomy_id`)
  76  );";
  77  
  78  // term_taxonomy
  79  $bb_queries['term_taxonomy'] = "CREATE TABLE IF NOT EXISTS `$bbdb->term_taxonomy` (
  80      `term_taxonomy_id` bigint(20) NOT NULL auto_increment,
  81      `term_id` bigint(20) NOT NULL default 0,
  82      `taxonomy` varchar(32) NOT NULL default '',
  83      `description` longtext NOT NULL,
  84      `parent` bigint(20) NOT NULL default 0,
  85      `count` bigint(20) NOT NULL default 0,
  86      PRIMARY KEY (`term_taxonomy_id`),
  87      UNIQUE KEY `term_id_taxonomy` (`term_id`, `taxonomy`),
  88      KEY `taxonomy` (`taxonomy`)
  89  );";
  90  
  91  // topics
  92  $bb_queries['topics'] = "CREATE TABLE IF NOT EXISTS `$bbdb->topics` (
  93      `topic_id` bigint(20) NOT NULL auto_increment,
  94      `topic_title` varchar(100) NOT NULL default '',
  95      `topic_slug` varchar(255) NOT NULL default '',
  96      `topic_poster` bigint(20) NOT NULL default 0,
  97      `topic_poster_name` varchar(40) NOT NULL default 'Anonymous',
  98      `topic_last_poster` bigint(20) NOT NULL default 0,
  99      `topic_last_poster_name` varchar(40) NOT NULL default '',
 100      `topic_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
 101      `topic_time` datetime NOT NULL default '0000-00-00 00:00:00',
 102      `forum_id` int(10) NOT NULL default 1,
 103      `topic_status` tinyint(1) NOT NULL default 0,
 104      `topic_open` tinyint(1) NOT NULL default 1,
 105      `topic_last_post_id` bigint(20) NOT NULL default 1,
 106      `topic_sticky` tinyint(1) NOT NULL default 0,
 107      `topic_posts` bigint(20) NOT NULL default 0,
 108      `tag_count` bigint(20) NOT NULL default 0,
 109      PRIMARY KEY (`topic_id`),
 110      KEY `topic_slug` (`topic_slug`),
 111      KEY `forum_time` (`forum_id`, `topic_time`),
 112      KEY `user_start_time` (`topic_poster`, `topic_start_time`),
 113      KEY `stickies` (`topic_status`, `topic_sticky`, `topic_time`)
 114  );";
 115  
 116  if ( bb_get_option( 'wp_table_prefix' ) || ( defined( 'BB_SCHEMA_IGNORE_WP_USERS_TABLES' ) && BB_SCHEMA_IGNORE_WP_USERS_TABLES ) ) {
 117      // Don't add user tables
 118  } else {
 119      // users - 'user_login', 'user_nicename' and 'user_registered' indices are inconsistent with WordPress
 120      $bb_queries['users'] = "CREATE TABLE IF NOT EXISTS `$bbdb->users` (
 121          `ID` bigint(20) unsigned NOT NULL auto_increment,
 122          `user_login` varchar(60) NOT NULL default '',
 123          `user_pass` varchar(64) NOT NULL default '',
 124          `user_nicename` varchar(50) NOT NULL default '',
 125          `user_email` varchar(100) NOT NULL default '',
 126          `user_url` varchar(100) NOT NULL default '',
 127          `user_registered` datetime NOT NULL default '0000-00-00 00:00:00',
 128          `user_status` int(11) NOT NULL default 0,
 129          `display_name` varchar(250) NOT NULL default '',
 130          PRIMARY KEY (`ID`),
 131          UNIQUE KEY `user_login` (`user_login`),
 132          UNIQUE KEY `user_nicename` (`user_nicename`),
 133          KEY `user_registered` (`user_registered`)
 134      );";
 135  
 136      // usermeta
 137      $bb_queries['usermeta'] = "CREATE TABLE IF NOT EXISTS `$bbdb->usermeta` (
 138          `umeta_id` bigint(20) NOT NULL auto_increment,
 139          `user_id` bigint(20) NOT NULL default 0,
 140          `meta_key` varchar(255),
 141          `meta_value` longtext,
 142          PRIMARY KEY (`umeta_id`),
 143          KEY `user_id` (`user_id`),
 144          KEY `meta_key` (`meta_key`)
 145      );";
 146  }
 147  
 148  $bb_queries = apply_filters( 'bb_schema_pre_charset', $bb_queries );
 149  
 150  // Set the charset and collation on each table
 151  foreach ($bb_queries as $_table_name => $_sql) {
 152      // Skip SQL that isn't creating a table
 153      if (!preg_match('@^\s*CREATE\s+TABLE\s+@im', $_sql)) {
 154          continue;
 155      }
 156      
 157      // Skip if the table's database doesn't support collation
 158      if (!$bbdb->has_cap('collation', $bbdb->$_table_name)) {
 159          continue;
 160      }
 161      
 162      // Find out if the table has a custom database set
 163      if (
 164          isset($bbdb->db_tables) &&
 165          is_array($bbdb->db_tables) &&
 166          isset($bbdb->db_tables[$bbdb->$_table_name])
 167      ) {
 168          // Set the database for this table
 169          $_database = $bbdb->db_tables[$bbdb->$_table_name];
 170      } else {
 171          // Set the default global database
 172          $_database = 'dbh_global';
 173      }
 174      
 175      // Make sure the database exists
 176      if (
 177          isset($bbdb->db_servers) &&
 178          is_array($bbdb->db_servers) &&
 179          isset($bbdb->db_servers[$_database]) &&
 180          is_array($bbdb->db_servers[$_database])
 181      ) {
 182          $_charset_collate = '';
 183          if (isset($bbdb->db_servers[$_database]['charset']) && !empty($bbdb->db_servers[$_database]['charset'])) {
 184              // Add a charset if set
 185              $_charset_collate .= ' DEFAULT CHARACTER SET \'' . $bbdb->db_servers[$_database]['charset'] . '\'';
 186          }
 187          if (isset($bbdb->db_servers[$_database]['collate']) && !empty($bbdb->db_servers[$_database]['collate'])) {
 188              // Add a collation if set
 189              $_charset_collate .= ' COLLATE \'' . $bbdb->db_servers[$_database]['collate'] . '\'';
 190          }
 191          if ($_charset_collate) {
 192              // Modify the SQL
 193              $bb_queries[$_table_name] = str_replace(';', $_charset_collate . ';', $_sql);
 194          }
 195      }
 196      unset($_database, $_charset_collate);
 197  }
 198  unset($_table_name, $_sql);
 199  
 200  $bb_queries = apply_filters( 'bb_schema', $bb_queries );
 201  
 202  // These elements in the schema may need to be ignored when doing comparisons due to inconsistencies with WordPress
 203  if ( bb_get_option('wp_table_prefix') || ( defined( 'BB_SCHEMA_IGNORE_WP_USERS_KEYS' ) && BB_SCHEMA_IGNORE_WP_USERS_KEYS ) ) {
 204      $bb_schema_ignore = array(
 205          'tables' => array(),
 206          'columns' => array(),
 207          'indices' => array(
 208              $bbdb->users => array(
 209                  'user_login',
 210                  'user_nicename',
 211                  'user_registered'
 212              )
 213          )
 214      );
 215  } else {
 216      $bb_schema_ignore = false;
 217  }
 218  
 219  if ( bb_get_option('wp_table_prefix') || ( defined( 'BB_SCHEMA_IGNORE_WP_USERS_TABLES' ) && BB_SCHEMA_IGNORE_WP_USERS_TABLES ) ) {
 220      if ( $bb_schema_ignore ) {
 221          $bb_schema_ignore['tables'] = array( $bbdb->users, $bbdb->usermeta );
 222      } else {
 223          $bb_schema_ignore = array(
 224              'tables' => array( $bbdb->users, $bbdb->usermeta ),
 225              'columns' => array(),
 226              'indices' => array()
 227          );
 228      }
 229  }
 230  
 231  $bb_schema_ignore = apply_filters( 'bb_schema_ignore', $bb_schema_ignore );
 232  
 233  do_action( 'bb_schema_defined' );
 234  
 235  ?>


Generated: Thu Dec 7 01:01:35 2017 Cross-referenced by PHPXref 0.7.1