Skip to content

Commit

Permalink
Move constants to a separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Oct 26, 2022
1 parent 07636c4 commit e03afa3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
46 changes: 46 additions & 0 deletions modules/database/sqlite/constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Define constants for the SQLite implementation.
*
* @since n.e.x.t
* @package performance-lab
*/

// Temporary - This will be in wp-config.php once SQLite is merged in Core.
if ( ! defined( 'DATABASE_TYPE' ) ) {
define( 'DATABASE_TYPE', 'sqlite' );
}

/**
* Notice:
* Your scripts have the permission to create directories or files on your server.
* If you write in your wp-config.php like below, we take these definitions.
* define('DB_DIR', '/full_path_to_the_database_directory/');
* define('DB_FILE', 'database_file_name');
*/

/**
* FQDBDIR is a directory where the sqlite database file is placed.
* If DB_DIR is defined, it is used as FQDBDIR.
*/
if ( ! defined( 'FQDBDIR' ) ) {
if ( defined( 'DB_DIR' ) ) {
define( 'FQDBDIR', trailingslashit( DB_DIR ) );
} elseif ( defined( 'WP_CONTENT_DIR' ) ) {
define( 'FQDBDIR', WP_CONTENT_DIR . '/database/' );
} else {
define( 'FQDBDIR', ABSPATH . 'wp-content/database/' );
}
}

/**
* FQDB is a database file name. If DB_FILE is defined, it is used
* as FQDB.
*/
if ( ! defined( 'FQDB' ) ) {
if ( defined( 'DB_FILE' ) ) {
define( 'FQDB', FQDBDIR . DB_FILE );
} else {
define( 'FQDB', FQDBDIR . '.ht.sqlite' );
}
}
6 changes: 2 additions & 4 deletions modules/database/sqlite/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
* @since n.e.x.t
*/

// Temporary - This will be in wp-config.php once SQLite is merged in Core.
if ( ! defined( 'DATABASE_TYPE' ) ) {
define( 'DATABASE_TYPE', 'sqlite' );
}
// Require the constants file.
require_once __DIR__ . '/constants.php';

/**
* Adds the db.php file in wp-content.
Expand Down
33 changes: 3 additions & 30 deletions modules/database/sqlite/wp-includes/sqlite/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* @since n.e.x.t
*/

// Require the constants file.
require_once dirname( dirname( __DIR__ ) ) . '/constants.php';

// Bail early if DATABASE_TYPE is not defined as sqlite.
if ( ! defined( 'DATABASE_TYPE' ) || 'sqlite' !== DATABASE_TYPE ) {
return;
Expand Down Expand Up @@ -57,36 +60,6 @@ function perflab_sqlite_pdo_log_error( $message, $data = null ) {
);
}

/**
* Notice:
* Your scripts have the permission to create directories or files on your server.
* If you write in your wp-config.php like below, we take these definitions.
* define('DB_DIR', '/full_path_to_the_database_directory/');
* define('DB_FILE', 'database_file_name');
*/

/**
* FQDBDIR is a directory where the sqlite database file is placed.
* If DB_DIR is defined, it is used as FQDBDIR.
*/
if ( defined( 'DB_DIR' ) ) {
define( 'FQDBDIR', trailingslashit( DB_DIR ) );
} elseif ( defined( 'WP_CONTENT_DIR' ) ) {
define( 'FQDBDIR', WP_CONTENT_DIR . '/database/' );
} else {
define( 'FQDBDIR', ABSPATH . 'wp-content/database/' );
}

/**
* FQDB is a database file name. If DB_FILE is defined, it is used
* as FQDB.
*/
if ( defined( 'DB_FILE' ) ) {
define( 'FQDB', FQDBDIR . DB_FILE );
} else {
define( 'FQDB', FQDBDIR . '.ht.sqlite' );
}

require_once __DIR__ . '/class-perflab-sqlite-pdo-user-defined-functions.php';
require_once __DIR__ . '/class-perflab-sqlite-pdo-engine.php';
require_once __DIR__ . '/class-perflab-sqlite-object-array.php';
Expand Down

0 comments on commit e03afa3

Please sign in to comment.