| 1 |
<?php |
| 2 |
/** |
| 3 |
* Define constants for the SQLite implementation. |
| 4 |
*/ |
| 5 |
|
| 6 |
// Temporary - This will be in wp-config.php once SQLite is merged in Core. |
| 7 |
if ( ! defined( 'DB_ENGINE' ) ) { |
| 8 |
if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) { |
| 9 |
define( 'DB_ENGINE', 'sqlite' ); |
| 10 |
} else { |
| 11 |
define( 'DB_ENGINE', 'mysql' ); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* DB_PATH is the absolute database file path, or ":memory:" for an in-memory database. |
| 17 |
* |
| 18 |
* Conflicting deprecated constants trigger a warning. DB_PATH takes precedence. |
| 19 |
* The database directory is also used for storage locks and must be writable by PHP. |
| 20 |
* When not configured, the drop-in defines DB_PATH after initializing the storage. |
| 21 |
* |
| 22 |
* Example: define( 'DB_PATH', '/private/wordpress/database.sqlite' ); |
| 23 |
*/ |
| 24 |
if ( 'sqlite' === DB_ENGINE && defined( 'DB_PATH' ) ) { |
| 25 |
if ( ! is_string( DB_PATH ) ) { |
| 26 |
throw new RuntimeException( 'DB_PATH must be a string.' ); |
| 27 |
} |
| 28 |
|
| 29 |
$database_directory = ':memory:' === DB_PATH ? null : rtrim( dirname( DB_PATH ), '/' . DIRECTORY_SEPARATOR ); |
| 30 |
|
| 31 |
if ( defined( 'DB_DIR' ) && rtrim( (string) DB_DIR, '/' . DIRECTORY_SEPARATOR ) !== $database_directory ) { |
| 32 |
trigger_error( 'DB_DIR conflicts with DB_PATH.', E_USER_WARNING ); |
| 33 |
} |
| 34 |
if ( defined( 'DB_FILE' ) && ( ':memory:' === DB_PATH || DB_FILE !== basename( DB_PATH ) ) ) { |
| 35 |
trigger_error( 'DB_FILE conflicts with DB_PATH.', E_USER_WARNING ); |
| 36 |
} |
| 37 |
if ( defined( 'FQDBDIR' ) && rtrim( (string) FQDBDIR, '/' . DIRECTORY_SEPARATOR ) !== $database_directory ) { |
| 38 |
trigger_error( 'FQDBDIR conflicts with DB_PATH.', E_USER_WARNING ); |
| 39 |
} |
| 40 |
if ( defined( 'FQDB' ) && FQDB !== DB_PATH ) { |
| 41 |
trigger_error( 'FQDB conflicts with DB_PATH.', E_USER_WARNING ); |
| 42 |
} |
| 43 |
unset( $database_directory ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* DB_DIR selects the database directory when DB_PATH is not configured. |
| 48 |
* |
| 49 |
* @deprecated 3.1.0 Define DB_PATH instead. |
| 50 |
*/ |
| 51 |
|
| 52 |
/** |
| 53 |
* DB_FILE selects a filename inside DB_DIR or FQDBDIR. |
| 54 |
* |
| 55 |
* @deprecated 3.1.0 Define DB_PATH instead. |
| 56 |
*/ |
| 57 |
|
| 58 |
/** |
| 59 |
* FQDBDIR is a directory where the sqlite database file is placed. |
| 60 |
* Defaults to the directory containing DB_PATH, or the legacy directory setting. |
| 61 |
* |
| 62 |
* @deprecated 3.0.0 Define DB_PATH instead of overriding FQDBDIR. |
| 63 |
*/ |
| 64 |
if ( ! defined( 'FQDBDIR' ) ) { |
| 65 |
if ( defined( 'DB_PATH' ) && is_string( DB_PATH ) && ':memory:' !== DB_PATH ) { |
| 66 |
define( 'FQDBDIR', rtrim( dirname( DB_PATH ), '/\\' ) . '/' ); |
| 67 |
} elseif ( ! defined( 'DB_PATH' ) && defined( 'DB_DIR' ) ) { |
| 68 |
define( 'FQDBDIR', rtrim( DB_DIR, '/\\' ) . '/' ); |
| 69 |
} elseif ( defined( 'WP_CONTENT_DIR' ) ) { |
| 70 |
define( 'FQDBDIR', WP_CONTENT_DIR . '/database/' ); |
| 71 |
} else { |
| 72 |
define( 'FQDBDIR', ABSPATH . 'wp-content/database/' ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* FQDB is the absolute path to the SQLite database file. |
| 78 |
* |
| 79 |
* Defaults to DB_PATH, or FQDBDIR combined with DB_FILE. Otherwise, the drop-in |
| 80 |
* defines FQDB after resolving the secret database path. |
| 81 |
* |
| 82 |
* @deprecated 3.0.0 Define DB_PATH instead of overriding FQDB. |
| 83 |
*/ |
| 84 |
if ( ! defined( 'FQDB' ) ) { |
| 85 |
if ( defined( 'DB_PATH' ) ) { |
| 86 |
define( 'FQDB', DB_PATH ); |
| 87 |
} elseif ( defined( 'DB_FILE' ) ) { |
| 88 |
// Avoid compile-time warnings for invalid constants on PHP 7.2. |
| 89 |
define( 'FQDB', constant( 'FQDBDIR' ) . constant( 'DB_FILE' ) ); |
| 90 |
} |
| 91 |
} |
| 92 |
|