Skip to content

Commit 78537bb

Browse files
committed
Migrate database file from a possible legacy path
1 parent 21827ee commit 78537bb

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

wp-includes/sqlite/class-wp-sqlite-db.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,26 @@ public function db_connect( $allow_bail = true ) {
306306
if ( isset( $GLOBALS['@pdo'] ) ) {
307307
$pdo = $GLOBALS['@pdo'];
308308
}
309+
310+
// Migrate the database file from a legacy path, if it exists.
311+
if ( ! defined( 'DB_FILE' ) && ! file_exists( FQDB ) ) {
312+
$old_db_path = FQDBDIR . '.ht.sqlite.php';
313+
314+
if ( file_exists( $old_db_path ) ) {
315+
if ( ! rename( $old_db_path, FQDB ) ) {
316+
wp_die( 'Failed to rename database file.', 'Error!' );
317+
}
318+
319+
foreach ( array( '-wal', '-shm', '-journal' ) as $suffix ) {
320+
if ( file_exists( $old_db_path . $suffix ) ) {
321+
if ( ! rename( $old_db_path . $suffix, FQDB . $suffix ) ) {
322+
wp_die( 'Failed to rename database file.', 'Error!' );
323+
}
324+
}
325+
}
326+
}
327+
}
328+
309329
if ( defined( 'WP_SQLITE_AST_DRIVER' ) && WP_SQLITE_AST_DRIVER ) {
310330
if ( null === $this->dbname || '' === $this->dbname ) {
311331
$this->bail(

0 commit comments

Comments
 (0)