| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main integration file. |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* Load the "SQLITE_DRIVER_VERSION" constant. |
| 8 |
*/ |
| 9 |
require_once __DIR__ . '/../database/version.php'; |
| 10 |
|
| 11 |
try { |
| 12 |
// Require the constants file. |
| 13 |
require_once __DIR__ . '/../../constants.php'; |
| 14 |
|
| 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 ) ); |
| 69 |
} |
| 70 |
|
| 71 |
if ( ! defined( 'DB_PATH' ) ) { |
| 72 |
define( 'DB_PATH', $database_path ); |
| 73 |
} |
| 74 |
|
| 75 |
if ( ! defined( 'FQDB' ) ) { |
| 76 |
define( 'FQDB', $database_path ); |
| 77 |
} |
| 78 |
|
| 79 |
require_once __DIR__ . '/../database/load.php'; |
| 80 |
require_once __DIR__ . '/class-wp-sqlite-db.php'; |
| 81 |
require_once __DIR__ . '/install-functions.php'; |
| 82 |
|
| 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'; |
| 88 |
|