diff --git a/src/Export.php b/src/Export.php index 4372111..32463c4 100644 --- a/src/Export.php +++ b/src/Export.php @@ -6,14 +6,14 @@ use WP_CLI; use WP_SQLite_Translator; -class Export extends Base { +class Export { protected $translator; protected $args = array(); protected $is_stdout = false; public function __construct() { - $this->load_dependencies(); + SQLiteDatabaseIntegrationLoader::load_plugin(); $this->translator = new WP_SQLite_Translator(); } diff --git a/src/Import.php b/src/Import.php index aaa0126..de33441 100644 --- a/src/Import.php +++ b/src/Import.php @@ -6,13 +6,13 @@ use WP_CLI; use WP_SQLite_Translator; -class Import extends Base { +class Import { protected $translator; protected $args; public function __construct() { - $this->load_dependencies(); + SQLiteDatabaseIntegrationLoader::load_plugin(); $this->translator = new WP_SQLite_Translator(); } diff --git a/src/Base.php b/src/SQLiteDatabaseIntegrationLoader.php similarity index 92% rename from src/Base.php rename to src/SQLiteDatabaseIntegrationLoader.php index 64ce2ae..4c75bde 100644 --- a/src/Base.php +++ b/src/SQLiteDatabaseIntegrationLoader.php @@ -3,7 +3,7 @@ use WP_CLI; -class Base { +final class SQLiteDatabaseIntegrationLoader { /** * Get the version of the SQLite integration plugin if it is installed @@ -11,7 +11,7 @@ class Base { * * @return false|string The version of the SQLite integration plugin or false if not found/activated. */ - public static function get_sqlite_plugin_version() { + public static function get_plugin_version() { // Check if there is a db.php file in the wp-content directory. if ( ! file_exists( ABSPATH . '/wp-content/db.php' ) ) { return false; @@ -62,13 +62,13 @@ protected static function get_plugin_directory() { * @return void * @throws WP_CLI\ExitException */ - protected function load_dependencies() { + public static function load_plugin() { $plugin_directory = self::get_plugin_directory(); if ( ! $plugin_directory ) { WP_CLI::error( 'Could not locate the SQLite integration plugin.' ); } - $sqlite_plugin_version = self::get_sqlite_plugin_version(); + $sqlite_plugin_version = self::get_plugin_version(); if ( ! $sqlite_plugin_version ) { WP_CLI::error( 'Could not determine the version of the SQLite integration plugin.' ); } @@ -83,6 +83,7 @@ protected function load_dependencies() { } // We also need to selectively load the necessary classes from the plugin. + require_once $plugin_directory . '/php-polyfills.php'; require_once $plugin_directory . '/constants.php'; require_once $plugin_directory . '/wp-includes/sqlite/class-wp-sqlite-lexer.php'; require_once $plugin_directory . '/wp-includes/sqlite/class-wp-sqlite-query-rewriter.php'; diff --git a/src/SQLite_Command.php b/src/SQLite_Command.php index 860f6ba..85d025f 100644 --- a/src/SQLite_Command.php +++ b/src/SQLite_Command.php @@ -29,10 +29,6 @@ public function import( $args, $assoc_args ) { WP_CLI::error( 'Please provide a file to import.' ); } - if ( ! Import::get_sqlite_plugin_version() ) { - WP_CLI::error( 'The SQLite integration plugin is not installed or activated.' ); - } - $import = new Import(); $import->run( $args[0], $assoc_args ); } @@ -135,10 +131,6 @@ public function export( $args, $assoc_args ) { * @when before_wp_load */ public function tables( $args, $assoc_args ) { - if ( ! Base::get_sqlite_plugin_version() ) { - WP_CLI::error( 'The SQLite integration plugin is not installed or activated.' ); - } - $tables = new Tables(); $tables->run( $assoc_args ); } diff --git a/src/Tables.php b/src/Tables.php index 5dbd283..2618ac0 100644 --- a/src/Tables.php +++ b/src/Tables.php @@ -6,12 +6,12 @@ use PDO; use WP_SQLite_Translator; -class Tables extends Base { +class Tables { protected $translator; public function __construct() { - $this->load_dependencies(); + SQLiteDatabaseIntegrationLoader::load_plugin(); $this->translator = new WP_SQLite_Translator(); }