Skip to content

Commit eb77632

Browse files
committed
address issues with site-health when db.php is missing
1 parent d019817 commit eb77632

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

modules/database/sqlite/constants.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
// Temporary - This will be in wp-config.php once SQLite is merged in Core.
1010
if ( ! defined( 'DATABASE_TYPE' ) ) {
11-
define( 'DATABASE_TYPE', 'sqlite' );
11+
if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) {
12+
define( 'DATABASE_TYPE', 'sqlite' );
13+
} else {
14+
define( 'DATABASE_TYPE', 'mysql' );
15+
}
1216
}
1317

1418
/**

modules/database/sqlite/site-health.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* @since n.e.x.t
77
*/
88

9+
// Require the constants file.
10+
require_once __DIR__ . '/constants.php';
11+
912
/**
1013
* Filter debug data in site-health screen.
1114
*
@@ -19,9 +22,6 @@
1922
*/
2023
function perflab_sqlite_plugin_filter_debug_data( $info ) {
2124
$database_type = defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ? 'sqlite' : 'mysql';
22-
if ( 'sqlite' !== $database_type ) {
23-
return $info;
24-
}
2525

2626
$info['wp-constants']['fields']['DATABASE_TYPE'] = array(
2727
'label' => 'DATABASE_TYPE',
@@ -34,32 +34,34 @@ function perflab_sqlite_plugin_filter_debug_data( $info ) {
3434
'value' => 'sqlite' === $database_type ? 'SQLite' : 'MySQL/MariaDB',
3535
);
3636

37-
$info['wp-database']['fields']['database_version'] = array(
38-
'label' => __( 'SQLite version', 'performance-lab' ),
39-
'value' => class_exists( 'SQLite3' ) ? SQLite3::version()['versionString'] : null,
40-
);
37+
if ( 'sqlite' === $database_type ) {
38+
$info['wp-database']['fields']['database_version'] = array(
39+
'label' => __( 'SQLite version', 'performance-lab' ),
40+
'value' => class_exists( 'SQLite3' ) ? SQLite3::version()['versionString'] : null,
41+
);
4142

42-
$info['wp-database']['fields']['database_file'] = array(
43-
'label' => __( 'Database file', 'performance-lab' ),
44-
'value' => FQDB,
45-
'private' => true,
46-
);
43+
$info['wp-database']['fields']['database_file'] = array(
44+
'label' => __( 'Database file', 'performance-lab' ),
45+
'value' => FQDB,
46+
'private' => true,
47+
);
4748

48-
$info['wp-database']['fields']['database_size'] = array(
49-
'label' => __( 'Database size', 'performance-lab' ),
50-
'value' => size_format( filesize( FQDB ) ),
51-
);
49+
$info['wp-database']['fields']['database_size'] = array(
50+
'label' => __( 'Database size', 'performance-lab' ),
51+
'value' => size_format( filesize( FQDB ) ),
52+
);
5253

53-
unset( $info['wp-database']['fields']['extension'] );
54-
unset( $info['wp-database']['fields']['server_version'] );
55-
unset( $info['wp-database']['fields']['client_version'] );
56-
unset( $info['wp-database']['fields']['database_host'] );
57-
unset( $info['wp-database']['fields']['database_user'] );
58-
unset( $info['wp-database']['fields']['database_name'] );
59-
unset( $info['wp-database']['fields']['database_charset'] );
60-
unset( $info['wp-database']['fields']['database_collate'] );
61-
unset( $info['wp-database']['fields']['max_allowed_packet'] );
62-
unset( $info['wp-database']['fields']['max_connections'] );
54+
unset( $info['wp-database']['fields']['extension'] );
55+
unset( $info['wp-database']['fields']['server_version'] );
56+
unset( $info['wp-database']['fields']['client_version'] );
57+
unset( $info['wp-database']['fields']['database_host'] );
58+
unset( $info['wp-database']['fields']['database_user'] );
59+
unset( $info['wp-database']['fields']['database_name'] );
60+
unset( $info['wp-database']['fields']['database_charset'] );
61+
unset( $info['wp-database']['fields']['database_collate'] );
62+
unset( $info['wp-database']['fields']['max_allowed_packet'] );
63+
unset( $info['wp-database']['fields']['max_connections'] );
64+
}
6365

6466
return $info;
6567
}

0 commit comments

Comments
 (0)