From ddc749868c1e0de3c63b2de395f3b81e784b9d52 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 26 Apr 2023 15:10:23 +0000 Subject: [PATCH] Coding Standards: Remove an empty `else` statement in `dbDelta()`. Use `continue` to help separate each case for better readability, instead of having a wall of `if`/`elseif`. Includes simplifying a similar fragment in `make_site_theme_from_default()`. Follow-up to [1575], [2037], [2040], [2044], [2346], [7999], [14080], [14485]. Props costdev, krunal265, hellofromTonya, brookedot, SergeyBiryukov. Fixes #56982. Built from https://develop.svn.wordpress.org/trunk@55688 git-svn-id: http://core.svn.wordpress.org/trunk@55200 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/upgrade.php | 79 +++++++++++++++++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 8aa16ac7a3..5692e36e81 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -2742,19 +2742,27 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N $iqueries = array(); // Insertion queries. $for_update = array(); - // Create a tablename index for an array ($cqueries) of queries. + // Create a tablename index for an array ($cqueries) of recognized query types. foreach ( $queries as $qry ) { if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) { $cqueries[ trim( $matches[1], '`' ) ] = $qry; $for_update[ $matches[1] ] = 'Created table ' . $matches[1]; - } elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) { + continue; + } + + if ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) { array_unshift( $cqueries, $qry ); - } elseif ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) { + continue; + } + + if ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) { $iqueries[] = $qry; - } elseif ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) { + continue; + } + + if ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) { $iqueries[] = $qry; - } else { - // Unrecognized query type. + continue; } } @@ -3073,16 +3081,20 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N } elseif ( $index_data['unique'] ) { $index_string .= 'UNIQUE '; } + if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) { $index_string .= 'FULLTEXT '; } + if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) { $index_string .= 'SPATIAL '; } + $index_string .= 'KEY '; if ( 'primary' !== $index_name ) { $index_string .= '`' . $index_name . '`'; } + $index_columns = ''; // For each column in the index. @@ -3179,8 +3191,9 @@ function make_db_current_silent( $tables = 'all' ) { * @return bool */ function make_site_theme_from_oldschool( $theme_name, $template ) { - $home_path = get_home_path(); - $site_dir = WP_CONTENT_DIR . "/themes/$template"; + $home_path = get_home_path(); + $site_dir = WP_CONTENT_DIR . "/themes/$template"; + $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME; if ( ! file_exists( "$home_path/index.php" ) ) { return false; @@ -3208,7 +3221,7 @@ function make_site_theme_from_oldschool( $theme_name, $template ) { if ( 'index.php' === $oldfile ) { $index = implode( '', file( "$oldpath/$oldfile" ) ); if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) { - if ( ! copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) { + if ( ! copy( "$default_dir/$oldfile", "$site_dir/$newfile" ) ) { return false; } @@ -3234,10 +3247,18 @@ function make_site_theme_from_oldschool( $theme_name, $template ) { } // Update stylesheet references. - $line = str_replace( "/wp-layout.css", "", $line ); + $line = str_replace( + "/wp-layout.css", + "", + $line + ); // Update comments template inclusion. - $line = str_replace( "", '', $line ); + $line = str_replace( + "", + '', + $line + ); fwrite( $f, "{$line}\n" ); } @@ -3246,7 +3267,13 @@ function make_site_theme_from_oldschool( $theme_name, $template ) { } // Add a theme header. - $header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option( 'siteurl' ) . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n"; + $header = "/*\n" . + "Theme Name: $theme_name\n" . + 'Theme URI: ' . __get_option( 'siteurl' ) . "\n" . + "Description: A theme automatically created by the update.\n" . + "Version: 1.0\n" . + "Author: Moi\n" . + "*/\n"; $stylelines = file_get_contents( "$site_dir/style.css" ); if ( $stylelines ) { @@ -3284,9 +3311,11 @@ function make_site_theme_from_default( $theme_name, $template ) { if ( is_dir( "$default_dir/$theme_file" ) ) { continue; } + if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) { return; } + chmod( "$site_dir/$theme_file", 0777 ); } @@ -3298,20 +3327,24 @@ function make_site_theme_from_default( $theme_name, $template ) { if ( $stylelines ) { $f = fopen( "$site_dir/style.css", 'w' ); + $headers = array( + 'Theme Name:' => $theme_name, + 'Theme URI:' => __get_option( 'url' ), + 'Description:' => 'Your theme.', + 'Version:' => '1', + 'Author:' => 'You', + ); + foreach ( $stylelines as $line ) { - if ( strpos( $line, 'Theme Name:' ) !== false ) { - $line = 'Theme Name: ' . $theme_name; - } elseif ( strpos( $line, 'Theme URI:' ) !== false ) { - $line = 'Theme URI: ' . __get_option( 'url' ); - } elseif ( strpos( $line, 'Description:' ) !== false ) { - $line = 'Description: Your theme.'; - } elseif ( strpos( $line, 'Version:' ) !== false ) { - $line = 'Version: 1'; - } elseif ( strpos( $line, 'Author:' ) !== false ) { - $line = 'Author: You'; + foreach ( $headers as $header => $value ) { + if ( strpos( $line, $header ) !== false ) { + $line = $header . ' ' . $value; + } } + fwrite( $f, $line . "\n" ); } + fclose( $f ); } @@ -3327,9 +3360,11 @@ function make_site_theme_from_default( $theme_name, $template ) { if ( is_dir( "$default_dir/images/$image" ) ) { continue; } + if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) { return; } + chmod( "$site_dir/images/$image", 0777 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 0c14628ab8..b094c6c3f1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55687'; +$wp_version = '6.3-alpha-55688'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.