-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport the SQLite rewrite from the standalone plugin #677
Changes from all commits
590a89a
93ae4dc
64df26d
1bc9ee0
26f72ab
073ef34
8ad6a79
4652949
68ec7a1
5cfa86d
8948766
6489f32
ac0dad1
d7e7538
35abe35
560f4df
710eddf
8dc116f
5e6d474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,23 @@ | |
* @package performance-lab | ||
*/ | ||
|
||
// Backwards-compatibility. | ||
if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && defined( 'SQLITE_DB_DROPIN_VERSION' ) ) { | ||
define( 'PERFLAB_SQLITE_DB_DROPIN_VERSION', SQLITE_DB_DROPIN_VERSION ); | ||
} | ||
|
||
// Temporary - This will be in wp-config.php once SQLite is merged in Core. | ||
if ( ! defined( 'DATABASE_TYPE' ) ) { | ||
if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) { | ||
define( 'DATABASE_TYPE', 'sqlite' ); | ||
if ( ! defined( 'DB_ENGINE' ) ) { | ||
if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the code above in line 10-12, we would need to use |
||
define( 'DB_ENGINE', 'sqlite' ); | ||
} elseif ( defined( 'DATABASE_ENGINE' ) ) { | ||
// Backwards compatibility with previous versions of the standalone plugin. | ||
define( 'DB_ENGINE', DATABASE_ENGINE ); | ||
} elseif ( defined( 'DATABASE_TYPE' ) ) { | ||
// Backwards compatibility with previous versions of the performance-lab plugin. | ||
define( 'DB_ENGINE', DATABASE_TYPE ); | ||
} else { | ||
define( 'DATABASE_TYPE', 'mysql' ); | ||
define( 'DB_ENGINE', 'mysql' ); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,34 @@ | ||
<?php | ||
/** | ||
* Adds and filters data in the site-health screen. | ||
* Tweaks for the health-check screens. | ||
* | ||
* @package performance-lab | ||
* @since 1.8.0 | ||
* @package performance-lab | ||
*/ | ||
|
||
// Require the constants file. | ||
require_once __DIR__ . '/constants.php'; | ||
|
||
/** | ||
* Filter debug data in site-health screen. | ||
* | ||
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-debug-data.php | ||
* See https://github.com/WordPress/wordpress-develop/pull/3220/files | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @param array $info The debug data. | ||
* @return array The filtered debug data. | ||
*/ | ||
function perflab_sqlite_plugin_filter_debug_data( $info ) { | ||
$database_type = defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ? 'sqlite' : 'mysql'; | ||
function sqlite_plugin_filter_debug_data( $info ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the doc block here? Not having a doc block is worse than having one :) Additionally, we should be careful about prefixing our code properly. |
||
$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', 'performance-lab' ) ), | ||
'debug' => ( defined( 'DATABASE_TYPE' ) ? DATABASE_TYPE : 'undefined' ), | ||
$info['wp-constants']['fields']['DB_ENGINE'] = array( | ||
'label' => 'DB_ENGINE', | ||
'value' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : __( 'Undefined', 'performance-lab' ) ), | ||
'debug' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : 'undefined' ), | ||
); | ||
|
||
$info['wp-database']['fields']['database_type'] = array( | ||
$info['wp-database']['fields']['db_engine'] = array( | ||
'label' => __( 'Database type', 'performance-lab' ), | ||
'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', 'performance-lab' ), | ||
'value' => class_exists( 'SQLite3' ) ? SQLite3::version()['versionString'] : null, | ||
|
@@ -65,4 +59,24 @@ function perflab_sqlite_plugin_filter_debug_data( $info ) { | |
|
||
return $info; | ||
} | ||
add_filter( 'debug_information', 'perflab_sqlite_plugin_filter_debug_data' ); // Filter debug data in site-health screen. | ||
add_filter( 'debug_information', 'sqlite_plugin_filter_debug_data' ); // Filter debug data in site-health screen. | ||
|
||
/** | ||
* Filter site_status tests in site-health screen. | ||
* | ||
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-site-health.php | ||
* | ||
* @param array $tests The tests. | ||
* @return array | ||
*/ | ||
function sqlite_plugin_filter_site_status_tests( $tests ) { | ||
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql'; | ||
|
||
if ( 'sqlite' === $db_engine ) { | ||
unset( $tests['direct']['utf8mb4_support'] ); | ||
unset( $tests['direct']['sql_server'] ); | ||
} | ||
|
||
return $tests; | ||
} | ||
add_filter( 'site_status_tests', 'sqlite_plugin_filter_site_status_tests' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment, we also need to ensure backward compatibility the other direction, especially as I'm assuming
SQLITE_DB_DROPIN_VERSION
will be our main constant going forward.