Skip to content

Commit d1270c0

Browse files
Copilotswissspidy
andcommitted
Improve SQLite DB copying to handle renamed .ht.sqlite.php file
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Agent-Logs-Url: https://github.com/wp-cli/wp-cli-tests/sessions/1c7a4300-5af4-4ac1-b16c-5e0f2e9cc893
1 parent 560b9a5 commit d1270c0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/Context/FeatureContext.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,13 @@ public function install_wp( $subdir = '', $version = '' ): void {
16501650

16511651
// This is the sqlite equivalent of restoring a database dump in MySQL
16521652
if ( 'sqlite' === self::$db_type ) {
1653-
copy( "{$install_cache_path}.sqlite", "$run_dir/wp-content/database/.ht.sqlite" );
1653+
$sqlite_dest_dir = "$run_dir/wp-content/database";
1654+
if ( ! is_dir( $sqlite_dest_dir ) ) {
1655+
mkdir( $sqlite_dest_dir, 0755, true );
1656+
}
1657+
if ( file_exists( "{$install_cache_path}.sqlite" ) ) {
1658+
copy( "{$install_cache_path}.sqlite", "$sqlite_dest_dir/.ht.sqlite.php" );
1659+
}
16541660
} else {
16551661
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
16561662
self::run_sql( self::$mysql_binary . ' --no-defaults' . $ssl_flag, [ 'execute' => "source {$install_cache_path}.sql" ], true /*add_database*/ );
@@ -1679,7 +1685,11 @@ public function install_wp( $subdir = '', $version = '' ): void {
16791685

16801686
if ( 'sqlite' === self::$db_type ) {
16811687
// This is the sqlite equivalent of creating a database dump in MySQL
1682-
$sqlite_source = "$run_dir/wp-content/database/.ht.sqlite";
1688+
// Support both the new (.ht.sqlite.php) and legacy (.ht.sqlite) file names.
1689+
$sqlite_source = "$run_dir/wp-content/database/.ht.sqlite.php";
1690+
if ( ! file_exists( $sqlite_source ) ) {
1691+
$sqlite_source = "$run_dir/wp-content/database/.ht.sqlite";
1692+
}
16831693
if ( file_exists( $sqlite_source ) ) {
16841694
copy( $sqlite_source, "{$install_cache_path}.sqlite" );
16851695
} elseif ( file_exists( "{$install_cache_path}.sqlite" ) ) {

0 commit comments

Comments
 (0)