| @@ -7,42 +7,74 @@ | ||
| 7 | 7 | * Load the "SQLITE_DRIVER_VERSION" constant. |
| 8 | 8 | */ |
| 9 | 9 | require_once __DIR__ . '/../database/version.php'; |
| 10 | 10 | |
| 11 | -// Require the constants file. | |
| 12 | -require_once __DIR__ . '/../../constants.php'; | |
| 11 | +try { | |
| 12 | + // Require the constants file. | |
| 13 | + require_once __DIR__ . '/../../constants.php'; | |
| 13 | 14 | |
| 14 | -// Bail early if DB_ENGINE is not defined as sqlite. | |
| 15 | -if ( ! defined( 'DB_ENGINE' ) || 'sqlite' !== DB_ENGINE ) { | |
| 16 | - 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 ) ); | |
| 17 | 69 | } |
| 18 | 70 | |
| 19 | -if ( ! extension_loaded( 'pdo' ) ) { | |
| 20 | - wp_die( | |
| 21 | - new WP_Error( | |
| 22 | - 'pdo_not_loaded', | |
| 23 | - sprintf( | |
| 24 | - '<h1>%1$s</h1><p>%2$s</p>', | |
| 25 | - 'PHP PDO Extension is not loaded', | |
| 26 | - '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.' | |
| 27 | - ) | |
| 28 | - ), | |
| 29 | - 'PHP PDO Extension is not loaded.' | |
| 30 | - ); | |
| 71 | +if ( ! defined( 'DB_PATH' ) ) { | |
| 72 | + define( 'DB_PATH', $database_path ); | |
| 31 | 73 | } |
| 32 | 74 | |
| 33 | -if ( ! extension_loaded( 'pdo_sqlite' ) ) { | |
| 34 | - wp_die( | |
| 35 | - new WP_Error( | |
| 36 | - 'pdo_driver_not_loaded', | |
| 37 | - sprintf( | |
| 38 | - '<h1>%1$s</h1><p>%2$s</p>', | |
| 39 | - 'PDO Driver for SQLite is missing', | |
| 40 | - '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.' | |
| 41 | - ) | |
| 42 | - ), | |
| 43 | - 'PDO Driver for SQLite is missing.' | |
| 44 | - ); | |
| 75 | +if ( ! defined( 'FQDB' ) ) { | |
| 76 | + define( 'FQDB', $database_path ); | |
| 45 | 77 | } |
| 46 | 78 | |
| 47 | 79 | require_once __DIR__ . '/../database/load.php'; |
| 48 | 80 | require_once __DIR__ . '/class-wp-sqlite-db.php'; |