PluginProbe
SQLite Database Integration / 3.1.0
SQLite Database Integration v3.1.0
3.1.0 3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 All 33 releases
← All changes | constants.php +58 -25 2.2.18 → 3.1.0 View file →
@@ -1,10 +1,7 @@
1 1 <?php
2 2 /**
3 3 * Define constants for the SQLite implementation.
4 - *
5 - * @since 1.0.0
6 - * @package wp-sqlite-integration
7 4 */
8 5
9 6 // Temporary - This will be in wp-config.php once SQLite is merged in Core.
10 7 if ( ! defined( 'DB_ENGINE' ) ) {
@@ -9,11 +6,8 @@
9 6 // Temporary - This will be in wp-config.php once SQLite is merged in Core.
10 7 if ( ! defined( 'DB_ENGINE' ) ) {
11 8 if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
12 9 define( 'DB_ENGINE', 'sqlite' );
13 - } elseif ( defined( 'DATABASE_ENGINE' ) ) {
14 - // backwards compatibility with previous versions of the plugin.
15 - define( 'DB_ENGINE', DATABASE_ENGINE );
16 10 } else {
17 11 define( 'DB_ENGINE', 'mysql' );
18 12 }
19 13 }
@@ -18,22 +12,61 @@
18 12 }
19 13 }
20 14
21 15 /**
22 - * Notice:
23 - * Your scripts have the permission to create directories or files on your server.
24 - * If you write in your wp-config.php like below, we take these definitions.
25 - * define('DB_DIR', '/full_path_to_the_database_directory/');
26 - * define('DB_FILE', 'database_file_name');
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' );
27 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 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 +
29 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 +/**
30 59 * FQDBDIR is a directory where the sqlite database file is placed.
31 - * If DB_DIR is defined, it is used as FQDBDIR.
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.
32 63 */
33 64 if ( ! defined( 'FQDBDIR' ) ) {
34 - if ( defined( 'DB_DIR' ) ) {
35 - define( 'FQDBDIR', trailingslashit( DB_DIR ) );
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, '/\\' ) . '/' );
36 69 } elseif ( defined( 'WP_CONTENT_DIR' ) ) {
37 70 define( 'FQDBDIR', WP_CONTENT_DIR . '/database/' );
38 71 } else {
39 72 define( 'FQDBDIR', ABSPATH . 'wp-content/database/' );
@@ -40,19 +73,19 @@
40 73 }
41 74 }
42 75
43 76 /**
44 - * FQDB is a database file name. If DB_FILE is defined, it is used
45 - * as FQDB.
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.
46 83 */
47 84 if ( ! defined( 'FQDB' ) ) {
48 - if ( defined( 'DB_FILE' ) ) {
49 - define( 'FQDB', FQDBDIR . DB_FILE );
50 - } else {
51 - define( 'FQDB', FQDBDIR . '.ht.sqlite' );
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' ) );
52 90 }
53 -}
54 -
55 -// Allow enabling the SQLite AST driver via environment variable.
56 -if ( ! defined( 'WP_SQLITE_AST_DRIVER' ) && isset( $_ENV['WP_SQLITE_AST_DRIVER'] ) && 'true' === $_ENV['WP_SQLITE_AST_DRIVER'] ) {
57 - define( 'WP_SQLITE_AST_DRIVER', true );
58 91 }