| @@ -1,70 +1,87 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Main integration file. |
| 4 | - * | |
| 5 | - * @package wp-sqlite-integration | |
| 6 | - * @since 1.0.0 | |
| 7 | 4 | */ |
| 8 | 5 | |
| 9 | 6 | /** |
| 10 | 7 | * Load the "SQLITE_DRIVER_VERSION" constant. |
| 11 | 8 | */ |
| 12 | -require_once dirname( __DIR__, 2 ) . '/version.php'; | |
| 9 | +require_once __DIR__ . '/../database/version.php'; | |
| 13 | 10 | |
| 14 | -// Require the constants file. | |
| 15 | -require_once dirname( __DIR__, 2 ) . '/constants.php'; | |
| 11 | +try { | |
| 12 | + // Require the constants file. | |
| 13 | + require_once __DIR__ . '/../../constants.php'; | |
| 16 | 14 | |
| 17 | -// Bail early if DB_ENGINE is not defined as sqlite. | |
| 18 | -if ( ! defined( 'DB_ENGINE' ) || 'sqlite' !== DB_ENGINE ) { | |
| 19 | - return; | |
| 15 | + // Bail early if DB_ENGINE is not defined as sqlite. | |
| 16 | + if ( ! defined( 'DB_ENGINE' ) || 'sqlite' !== DB_ENGINE ) { | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + | |
| 20 | + if ( ! extension_loaded( 'pdo' ) ) { | |
| 21 | + wp_die( | |
| 22 | + new WP_Error( | |
| 23 | + 'pdo_not_loaded', | |
| 24 | + sprintf( | |
| 25 | + '<h1>%1$s</h1><p>%2$s</p>', | |
| 26 | + 'PHP PDO Extension is not loaded', | |
| 27 | + 'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress and the type of database you have specified.' | |
| 28 | + ) | |
| 29 | + ), | |
| 30 | + 'PHP PDO Extension is not loaded.' | |
| 31 | + ); | |
| 32 | + } | |
| 33 | + | |
| 34 | + if ( ! extension_loaded( 'pdo_sqlite' ) ) { | |
| 35 | + wp_die( | |
| 36 | + new WP_Error( | |
| 37 | + 'pdo_driver_not_loaded', | |
| 38 | + sprintf( | |
| 39 | + '<h1>%1$s</h1><p>%2$s</p>', | |
| 40 | + 'PDO Driver for SQLite is missing', | |
| 41 | + 'Your PHP installation appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.' | |
| 42 | + ) | |
| 43 | + ), | |
| 44 | + 'PDO Driver for SQLite is missing.' | |
| 45 | + ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + require_once __DIR__ . '/class-wp-sqlite-storage.php'; | |
| 49 | + | |
| 50 | + if ( defined( 'DB_PATH' ) ) { | |
| 51 | + $database_storage = WP_SQLite_Storage::with_explicit_path( DB_PATH ); | |
| 52 | + } elseif ( defined( 'FQDB' ) ) { | |
| 53 | + $database_storage = WP_SQLite_Storage::with_explicit_path( FQDB ); | |
| 54 | + } else { | |
| 55 | + $database_storage = WP_SQLite_Storage::with_secret_path( FQDBDIR ); | |
| 56 | + } | |
| 57 | + $database_path = $database_storage->initialize(); | |
| 58 | +} catch ( Throwable $exception ) { | |
| 59 | + error_log( 'SQLite database error: ' . (string) $exception ); | |
| 60 | + | |
| 61 | + // WP-CLI can load the drop-in before wp_die() dependencies are available. | |
| 62 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 63 | + WP_CLI::error( $exception->getMessage() ); | |
| 64 | + } | |
| 65 | + | |
| 66 | + // Use htmlspecialchars() with an explicit charset because esc_html() reads the | |
| 67 | + // blog_charset option, but the database and object cache are not initialized yet. | |
| 68 | + wp_die( htmlspecialchars( $exception->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8' ), 'SQLite database error', array( 'response' => 503 ) ); | |
| 20 | 69 | } |
| 21 | 70 | |
| 22 | -if ( ! extension_loaded( 'pdo' ) ) { | |
| 23 | - wp_die( | |
| 24 | - new WP_Error( | |
| 25 | - 'pdo_not_loaded', | |
| 26 | - sprintf( | |
| 27 | - '<h1>%1$s</h1><p>%2$s</p>', | |
| 28 | - 'PHP PDO Extension is not loaded', | |
| 29 | - 'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress and the type of database you have specified.' | |
| 30 | - ) | |
| 31 | - ), | |
| 32 | - 'PHP PDO Extension is not loaded.' | |
| 33 | - ); | |
| 71 | +if ( ! defined( 'DB_PATH' ) ) { | |
| 72 | + define( 'DB_PATH', $database_path ); | |
| 34 | 73 | } |
| 35 | 74 | |
| 36 | -if ( ! extension_loaded( 'pdo_sqlite' ) ) { | |
| 37 | - wp_die( | |
| 38 | - new WP_Error( | |
| 39 | - 'pdo_driver_not_loaded', | |
| 40 | - sprintf( | |
| 41 | - '<h1>%1$s</h1><p>%2$s</p>', | |
| 42 | - 'PDO Driver for SQLite is missing', | |
| 43 | - 'Your PHP installation appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.' | |
| 44 | - ) | |
| 45 | - ), | |
| 46 | - 'PDO Driver for SQLite is missing.' | |
| 47 | - ); | |
| 75 | +if ( ! defined( 'FQDB' ) ) { | |
| 76 | + define( 'FQDB', $database_path ); | |
| 48 | 77 | } |
| 49 | 78 | |
| 50 | -require_once __DIR__ . '/class-wp-sqlite-lexer.php'; | |
| 51 | -require_once __DIR__ . '/class-wp-sqlite-query-rewriter.php'; | |
| 52 | -require_once __DIR__ . '/class-wp-sqlite-translator.php'; | |
| 53 | -require_once __DIR__ . '/class-wp-sqlite-token.php'; | |
| 54 | -require_once __DIR__ . '/class-wp-sqlite-pdo-user-defined-functions.php'; | |
| 79 | +require_once __DIR__ . '/../database/load.php'; | |
| 55 | 80 | require_once __DIR__ . '/class-wp-sqlite-db.php'; |
| 56 | 81 | require_once __DIR__ . '/install-functions.php'; |
| 57 | 82 | |
| 58 | -/* | |
| 59 | - * Debug: Cross-check with MySQL. | |
| 60 | - * This is for debugging purpose only and requires files | |
| 61 | - * that are present in the GitHub repository | |
| 62 | - * but not the plugin published on WordPress.org. | |
| 63 | - */ | |
| 64 | -$crosscheck_tests_file_path = dirname( __DIR__, 2 ) . '/tests/class-wp-sqlite-crosscheck-db.php'; | |
| 65 | -if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK && file_exists( $crosscheck_tests_file_path ) ) { | |
| 66 | - require_once $crosscheck_tests_file_path; | |
| 67 | - $GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( DB_NAME ); | |
| 68 | -} else { | |
| 69 | - $GLOBALS['wpdb'] = new WP_SQLite_DB( DB_NAME ); | |
| 70 | -} | |
| 83 | +$db_name = defined( 'DB_NAME' ) ? DB_NAME : ''; | |
| 84 | +$GLOBALS['wpdb'] = new WP_SQLite_DB( $db_name ); | |
| 85 | + | |
| 86 | +// Boot the Query Monitor plugin if it is active. | |
| 87 | +require_once __DIR__ . '/../../integrations/query-monitor/boot.php'; | |