191
191
$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) );
193
193
// Default comment
194
$first_comment_author = __('Mr WordPress');
194
$first_comment_author = __( 'A WordPress Commenter' );
195
$first_comment_email = 'wapuu@wordpress.example';
195
196
$first_comment_url = 'https://wordpress.org/';
196
$first_comment = __('Hi, this is a comment.
197
To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.');
197
$first_comment = __( 'Hi, this is a comment.
198
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
199
Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' );
198
200
if ( is_multisite() ) {
199
201
$first_comment_author = get_site_option( 'first_comment_author', $first_comment_author );
202
$first_comment_email = get_site_option( 'first_comment_email', $first_comment_email );
200
203
$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
201
204
$first_comment = get_site_option( 'first_comment', $first_comment );
203
206
$wpdb->insert( $wpdb->comments, array(
204
207
'comment_post_ID' => 1,
205
208
'comment_author' => $first_comment_author,
206
'comment_author_email' => '',
209
'comment_author_email' => $first_comment_email,
207
210
'comment_author_url' => $first_comment_url,
208
211
'comment_date' => $now,
209
212
'comment_date_gmt' => $now_gmt,
2183
2222
// Separate field lines into an array.
2184
2223
$flds = explode("\n", $qryline);
2186
// todo: Remove this?
2187
//echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
2189
2225
// For every field line specified in the query.
2190
foreach ($flds as $fld) {
2226
foreach ( $flds as $fld ) {
2227
$fld = trim( $fld, " \t\n\r\0\x0B," ); // Default trim characters, plus ','.
2192
2229
// Extract the field name.
2193
preg_match("|^([^ ]*)|", trim($fld), $fvals);
2230
preg_match( '|^([^ ]*)|', $fld, $fvals );
2194
2231
$fieldname = trim( $fvals[1], '`' );
2232
$fieldname_lowercased = strtolower( $fieldname );
2196
2234
// Verify the found field name.
2197
2235
$validfield = true;
2198
switch (strtolower($fieldname)) {
2205
$validfield = false;
2206
$indices[] = trim(trim($fld), ", \n");
2236
switch ( $fieldname_lowercased ) {
2244
$validfield = false;
2247
* Normalize the index definition.
2249
* This is done so the definition can be compared against the result of a
2250
* `SHOW INDEX FROM $table_name` query which returns the current table
2251
* index information.
2254
// Extract type, name and columns from the definition.
2257
. '(?P<index_type>' // 1) Type of the index.
2258
. 'PRIMARY\s+KEY|(?:UNIQUE|FULLTEXT|SPATIAL)\s+(?:KEY|INDEX)|KEY|INDEX'
2260
. '\s+' // Followed by at least one white space character.
2261
. '(?:' // Name of the index. Optional if type is PRIMARY KEY.
2262
. '`?' // Name can be escaped with a backtick.
2263
. '(?P<index_name>' // 2) Name of the index.
2264
. '(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+'
2266
. '`?' // Name can be escaped with a backtick.
2267
. '\s+' // Followed by at least one white space character.
2269
. '\(' // Opening bracket for the columns.
2270
. '(?P<index_columns>'
2271
. '.+?' // 3) Column names, index prefixes, and orders.
2273
. '\)' // Closing bracket for the columns.
2279
// Uppercase the index type and normalize space characters.
2280
$index_type = strtoupper( preg_replace( '/\s+/', ' ', trim( $index_matches['index_type'] ) ) );
2282
// 'INDEX' is a synonym for 'KEY', standardize on 'KEY'.
2283
$index_type = str_replace( 'INDEX', 'KEY', $index_type );
2285
// Escape the index name with backticks. An index for a primary key has no name.
2286
$index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . $index_matches['index_name'] . '`';
2288
// Parse the columns. Multiple columns are separated by a comma.
2289
$index_columns = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );
2291
// Normalize columns.
2292
foreach ( $index_columns as &$index_column ) {
2293
// Extract column name and number of indexed characters (sub_part).
2296
. '`?' // Name can be escaped with a backtick.
2297
. '(?P<column_name>' // 1) Name of the column.
2298
. '(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+'
2300
. '`?' // Name can be escaped with a backtick.
2301
. '(?:' // Optional sub part.
2302
. '\s*' // Optional white space character between name and opening bracket.
2303
. '\(' // Opening bracket for the sub part.
2304
. '\s*' // Optional white space character after opening bracket.
2306
. '\d+' // 2) Number of indexed characters.
2308
. '\s*' // Optional white space character before closing bracket.
2309
. '\)' // Closing bracket for the sub part.
2313
$index_column_matches
2316
// Escape the column name with backticks.
2317
$index_column = '`' . $index_column_matches['column_name'] . '`';
2319
// Append the optional sup part with the number of indexed characters.
2320
if ( isset( $index_column_matches['sub_part'] ) ) {
2321
$index_column .= '(' . $index_column_matches['sub_part'] . ')';
2325
// Build the normalized index definition and add it to the list of indices.
2326
$indices[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns ) . ")";
2328
// Destroy no longer needed variables.
2329
unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns );
2211
2334
// If it's a valid field, add it to the field array.
2213
$cfields[strtolower($fieldname)] = trim($fld, ", \n");
2335
if ( $validfield ) {
2336
$cfields[ $fieldname_lowercased ] = $fld;
2217
2340
// For every field in the table.
2218
foreach ($tablefields as $tablefield) {
2341
foreach ( $tablefields as $tablefield ) {
2342
$tablefield_field_lowercased = strtolower( $tablefield->Field );
2343
$tablefield_type_lowercased = strtolower( $tablefield->Type );
2220
2345
// If the table field exists in the field array ...
2221
if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
2346
if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
2223
2348
// Get the field type from the query.
2224
preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
2349
preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
2225
2350
$fieldtype = $matches[1];
2351
$fieldtype_lowercased = strtolower( $fieldtype );
2227
2353
// Is actual field type different from the field type in query?
2228
2354
if ($tablefield->Type != $fieldtype) {
2229
2355
$do_change = true;
2230
if ( in_array( strtolower( $fieldtype ), $text_fields ) && in_array( strtolower( $tablefield->Type ), $text_fields ) ) {
2231
if ( array_search( strtolower( $fieldtype ), $text_fields ) < array_search( strtolower( $tablefield->Type ), $text_fields ) ) {
2356
if ( in_array( $fieldtype_lowercased, $text_fields ) && in_array( $tablefield_type_lowercased, $text_fields ) ) {
2357
if ( array_search( $fieldtype_lowercased, $text_fields ) < array_search( $tablefield_type_lowercased, $text_fields ) ) {
2232
2358
$do_change = false;
2236
if ( in_array( strtolower( $fieldtype ), $blob_fields ) && in_array( strtolower( $tablefield->Type ), $blob_fields ) ) {
2237
if ( array_search( strtolower( $fieldtype ), $blob_fields ) < array_search( strtolower( $tablefield->Type ), $blob_fields ) ) {
2362
if ( in_array( $fieldtype_lowercased, $blob_fields ) && in_array( $tablefield_type_lowercased, $blob_fields ) ) {
2363
if ( array_search( $fieldtype_lowercased, $blob_fields ) < array_search( $tablefield_type_lowercased, $blob_fields ) ) {
2238
2364
$do_change = false;
2242
2368
if ( $do_change ) {
2243
// Add a query to change the column type
2244
$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
2369
// Add a query to change the column type.
2370
$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
2245
2371
$for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
2249
// Get the default value from the array
2250
// todo: Remove this?
2251
//echo "{$cfields[strtolower($tablefield->Field)]}<br>";
2252
if (preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
2375
// Get the default value from the array.
2376
if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
2253
2377
$default_value = $matches[1];
2254
2378
if ($tablefield->Default != $default_value) {
2255
2379
// Add a query to change the column's default value
2256
$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
2380
$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
2257
2381
$for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
2261
2385
// Remove the field from the array (so it's not added).
2262
unset($cfields[strtolower($tablefield->Field)]);
2386
unset( $cfields[ $tablefield_field_lowercased ] );
2264
2388
// This field exists in the table, but not in the creation queries?