Skip to content

Commit 5014666

Browse files
Copilotswissspidy
andauthored
Handle renamed SQLite database file (.ht.sqlite → .ht.sqlite.php) (#318)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent 9c1aa9b commit 5014666

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/Context/FeatureContext.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use WP_CLI\Process;
2525
use WP_CLI\ProcessRun;
2626
use WP_CLI\Utils;
27+
use WP_CLI\Path;
2728
use WP_CLI\WpOrgApi;
2829

2930
/**
@@ -1650,7 +1651,13 @@ public function install_wp( $subdir = '', $version = '' ): void {
16501651

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

16801687
if ( 'sqlite' === self::$db_type ) {
16811688
// This is the sqlite equivalent of creating a database dump in MySQL
1682-
$sqlite_source = "$run_dir/wp-content/database/.ht.sqlite";
1689+
// Support both the new (.ht.sqlite.php) and legacy (.ht.sqlite) file names.
1690+
$sqlite_source = "$run_dir/wp-content/database/.ht.sqlite.php";
1691+
if ( ! file_exists( $sqlite_source ) ) {
1692+
$sqlite_source = "$run_dir/wp-content/database/.ht.sqlite";
1693+
}
16831694
if ( file_exists( $sqlite_source ) ) {
16841695
copy( $sqlite_source, "{$install_cache_path}.sqlite" );
16851696
} elseif ( file_exists( "{$install_cache_path}.sqlite" ) ) {
@@ -1901,8 +1912,8 @@ private static function get_scenario_key( $scope ): string {
19011912
$scenario_key = '';
19021913
$file = self::get_event_file( $scope, $line );
19031914
if ( isset( $file ) ) {
1904-
$scenario_grandparent = Utils\basename( dirname( $file, 2 ) );
1905-
$scenario_key = $scenario_grandparent . ' ' . Utils\basename( $file ) . ':' . $line;
1915+
$scenario_grandparent = Path::basename( dirname( $file, 2 ) );
1916+
$scenario_key = $scenario_grandparent . ' ' . Path::basename( $file ) . ':' . $line;
19061917
}
19071918
return $scenario_key;
19081919
}
@@ -1919,7 +1930,7 @@ private static function log_run_times_after_suite( AfterSuiteScope $scope ): voi
19191930
$suite = substr( $keys[0], 0, strpos( $keys[0], ' ' ) );
19201931
}
19211932

1922-
$run_from = Utils\basename( dirname( __DIR__, 2 ) );
1933+
$run_from = Path::basename( dirname( __DIR__, 2 ) );
19231934

19241935
// Format same as Behat, if have minutes.
19251936
$fmt = static function ( $time ) {

src/Context/GivenStepDefinitions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Behat\Gherkin\Node\TableNode;
77
use RuntimeException;
88
use WP_CLI\Utils;
9+
use WP_CLI\Path;
910

1011
trait GivenStepDefinitions {
1112

@@ -45,7 +46,7 @@ public function given_an_empty_directory(): void {
4546
*/
4647
public function given_a_specific_directory( $empty_or_nonexistent, $dir ): void {
4748
$dir = $this->replace_variables( $dir );
48-
if ( ! Utils\is_path_absolute( $dir ) ) {
49+
if ( ! Path::is_absolute( $dir ) ) {
4950
$dir = $this->variables['RUN_DIR'] . "/$dir";
5051
}
5152

src/Context/ThenStepDefinitions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Behat\Gherkin\Node\PyStringNode;
66
use Behat\Gherkin\Node\TableNode;
7-
use WP_CLI\Utils;
7+
use WP_CLI\Path;
88
use Exception;
99
use Requests;
1010
use RuntimeException;
@@ -457,7 +457,7 @@ public function then_a_specific_file_folder_should_exist( $path, $type, $strictl
457457
$path = $this->replace_variables( $path );
458458

459459
// If it's a relative path, make it relative to the current test dir.
460-
if ( ! Utils\is_path_absolute( $path ) ) {
460+
if ( ! Path::is_absolute( $path ) ) {
461461
$path = $this->variables['RUN_DIR'] . DIRECTORY_SEPARATOR . $path;
462462
}
463463

0 commit comments

Comments
 (0)