Skip to content

Commit

Permalink
Redirect to install screen or dashbord on activation
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Oct 25, 2022
1 parent 5a6d966 commit 0da3745
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
38 changes: 37 additions & 1 deletion modules/database/sqlite/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@
define( 'DATABASE_TYPE', 'sqlite' );
}

/**
* The constants defined here also exist in the db.php file.
* The duplication is intentional, and only temporary.
*/
// 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' );
}
}

/**
* Adds the db.php file in wp-content.
*
Expand Down Expand Up @@ -40,6 +64,7 @@ function perflab_sqlite_plugin_copy_db_file() {
WP_Filesystem();
}

$file_copied_successfully = false;
if ( $wp_filesystem->touch( $destination ) ) {

// Get the db.copy file contents, replace placeholders and write it to the destination.
Expand All @@ -58,7 +83,18 @@ function perflab_sqlite_plugin_copy_db_file() {
),
file_get_contents( __DIR__ . '/db.copy' )
);
$wp_filesystem->put_contents( $destination, $file_contents );

$file_copied_successfully = $wp_filesystem->put_contents( $destination, $file_contents );
}

if ( $file_copied_successfully ) {
add_action(
'admin_head',
function() use ( $file_copied_successfully ) {
$href = file_exists( FQDB ) ? self_admin_url() : wp_guess_url() . '/wp-admin/install.php';
echo '<script>window.location.href = "' . sanitize_url( $href ) . '";</script>';
}
);
}
}
add_action( 'plugins_loaded', 'perflab_sqlite_plugin_copy_db_file' );
Expand Down
36 changes: 17 additions & 19 deletions modules/database/sqlite/wp-includes/sqlite/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,24 @@ function perflab_sqlite_pdo_log_error( $message, $data = null ) {
* 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/' );
// 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( 'DB_FILE' ) ) {
define( 'FQDB', FQDBDIR . DB_FILE );
} else {
define( 'FQDB', FQDBDIR . '.ht.sqlite' );
// 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' );
}
}

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

0 comments on commit 0da3745

Please sign in to comment.