Skip to content

Commit

Permalink
Update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Apr 18, 2023
1 parent bb3ba4b commit cf88177
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions db.copy
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@

define( 'SQLITE_DB_DROPIN_VERSION', '1.8.0' );

// Tweak to allow copy-pasting the file without having to run string-replacements.
$sqlite_plugin_implementation_folder_path = '{SQLITE_IMPLEMENTATION_FOLDER_PATH}';
if ( ! file_exists( $sqlite_plugin_implementation_folder_path ) ) { // Check that the folder exists.
$sqlite_plugin_implementation_folder_path = realpath( __DIR__ . '/plugins/sqlite-database-integration' );
}

// Bail early if the SQLite implementation was not located in the plugin.
$sqlite_db_plugin_folder = '{SQLITE_IMPLEMENTATION_FOLDER_PATH}';
$sqlite_db_plugin_db_file = $sqlite_db_plugin_folder . '/wp-includes/sqlite/db.php';
$sqlite_db_plugin_main_file = WP_PLUGIN_DIR . '/{SQLITE_PLUGIN}';
if ( ! file_exists( $sqlite_db_plugin_db_file ) ) {
$sqlite_db_plugin_folder = WP_PLUGIN_DIR . '/sqlite-database-integration';
$sqlite_db_plugin_db_file = $sqlite_db_plugin_folder . '/wp-includes/sqlite/db.php';
$sqlite_db_plugin_main_file = $sqlite_db_plugin_folder . '/load.php';
if ( ! file_exists( $sqlite_db_plugin_db_file ) ) {
return;
}
if ( ! $sqlite_plugin_implementation_folder_path || ! file_exists( $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php' ) ) {
return;
}

// Constant for backward compatibility.
Expand All @@ -36,23 +34,24 @@ if ( ! defined( 'DB_ENGINE' ) ) {
}

// Require the implementation from the plugin.
require_once $sqlite_db_plugin_db_file;
require_once $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php';

// Activate the performance-lab plugin if it is not already activated.
add_action(
'admin_footer',
function() use ( $sqlite_db_plugin_main_file ) {
function() {
if ( defined( 'SQLITE_MAIN_FILE' ) ) {
return;
}
if ( ! function_exists( 'activate_plugin' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

if ( file_exists( $sqlite_db_plugin_main_file ) ) {
$plugin_file = str_replace( WP_PLUGIN_DIR . '/', '', $sqlite_db_plugin_main_file );
if ( is_plugin_inactive( $plugin_file ) ) {
activate_plugin( $plugin_file );
if ( is_plugin_inactive( '{SQLITE_PLUGIN}' ) ) {
// If `activate_plugin()` returns a value other than null (like WP_Error),
// the plugin could not be found. Try with a hardcoded string,
// because that probably means the file was directly copy-pasted.
if ( null !== activate_plugin( '{SQLITE_PLUGIN}', '', false, true ) ) {
activate_plugin( 'sqlite-database-integration/load.php', '', false, true );
}
}
}
Expand Down

0 comments on commit cf88177

Please sign in to comment.