Skip to content

Commit

Permalink
backport constant rename
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Mar 13, 2023
1 parent b6e6168 commit 6bfc9a6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function sqlite_integration_admin_screen() {
function sqlite_plugin_adminbar_item( $admin_bar ) {
global $wpdb;

if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) && defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ) {
if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) && defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) {
$title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'performance-lab' ) . '</span>';
} elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
$title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'performance-lab' ) . '</span>';
Expand Down
9 changes: 6 additions & 3 deletions constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
*/

// Temporary - This will be in wp-config.php once SQLite is merged in Core.
if ( ! defined( 'DATABASE_TYPE' ) ) {
if ( ! defined( 'DB_ENGINE' ) ) {
if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
define( 'DATABASE_TYPE', 'sqlite' );
define( 'DB_ENGINE', 'sqlite' );
} elseif ( defined( 'DATABASE_ENGINE' ) ) {
// backwards compatibility with previous versions of the plugin.
define( 'DB_ENGINE', DATABASE_ENGINE );
} else {
define( 'DATABASE_TYPE', 'mysql' );
define( 'DB_ENGINE', 'mysql' );
}
}

Expand Down
6 changes: 5 additions & 1 deletion db.copy
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ if ( ! file_exists( '{SQLITE_IMPLEMENTATION_FOLDER_PATH}/wp-includes/sqlite/db.p
return;
}

// Define SQLite constant.
// Constant for backward compatibility.
if ( ! defined( 'DATABASE_TYPE' ) ) {
define( 'DATABASE_TYPE', 'sqlite' );
}
// Define SQLite constant.
if ( ! defined( 'DB_ENGINE' ) ) {
define( 'DB_ENGINE', 'sqlite' );
}

// Require the implementation from the plugin.
require_once '{SQLITE_IMPLEMENTATION_FOLDER_PATH}/wp-includes/sqlite/db.php';
Expand Down
20 changes: 10 additions & 10 deletions health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
* @param array $info The debug data.
*/
function sqlite_plugin_filter_debug_data( $info ) {
$database_type = defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ? 'sqlite' : 'mysql';
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql';

$info['wp-constants']['fields']['DATABASE_TYPE'] = array(
'label' => 'DATABASE_TYPE',
'value' => ( defined( 'DATABASE_TYPE' ) ? DATABASE_TYPE : __( 'Undefined', 'sqlite-database-integration' ) ),
'debug' => ( defined( 'DATABASE_TYPE' ) ? DATABASE_TYPE : 'undefined' ),
$info['wp-constants']['fields']['DB_ENGINE'] = array(
'label' => 'DB_ENGINE',
'value' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : __( 'Undefined', 'sqlite-database-integration' ) ),
'debug' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : 'undefined' ),
);

$info['wp-database']['fields']['database_type'] = array(
$info['wp-database']['fields']['db_engine'] = array(
'label' => __( 'Database type', 'sqlite-database-integration' ),
'value' => 'sqlite' === $database_type ? 'SQLite' : 'MySQL/MariaDB',
'value' => 'sqlite' === $db_engine ? 'SQLite' : 'MySQL/MariaDB',
);

if ( 'sqlite' === $database_type ) {
if ( 'sqlite' === $db_engine ) {
$info['wp-database']['fields']['database_version'] = array(
'label' => __( 'SQLite version', 'sqlite-database-integration' ),
'value' => class_exists( 'SQLite3' ) ? SQLite3::version()['versionString'] : null,
Expand Down Expand Up @@ -70,9 +70,9 @@ function sqlite_plugin_filter_debug_data( $info ) {
* @return array
*/
function sqlite_plugin_filter_site_status_tests( $tests ) {
$database_type = defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ? 'sqlite' : 'mysql';
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql';

if ( 'sqlite' === $database_type ) {
if ( 'sqlite' === $db_engine ) {
unset( $tests['direct']['utf8mb4_support'] );
unset( $tests['direct']['sql_server'] );
}
Expand Down
4 changes: 2 additions & 2 deletions wp-includes/sqlite/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Require the constants file.
require_once dirname( dirname( __DIR__ ) ) . '/constants.php';

// Bail early if DATABASE_TYPE is not defined as sqlite.
if ( ! defined( 'DATABASE_TYPE' ) || 'sqlite' !== DATABASE_TYPE ) {
// Bail early if DB_ENGINE is not defined as sqlite.
if ( ! defined( 'DB_ENGINE' ) || 'sqlite' !== DB_ENGINE ) {
return;
}

Expand Down

0 comments on commit 6bfc9a6

Please sign in to comment.