Skip to content

Commit

Permalink
Merge pull request #705 from lucatume/v4-702-follow-up
Browse files Browse the repository at this point in the history
v4 702 follow up
  • Loading branch information
lucatume authored Mar 7, 2024
2 parents 2129898 + 6e64065 commit d2a3540
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Replace `ifsnop/mysqldump-php` with `druidfi/mysqldump-php` for better performance (thanks @staabm).
- Disable MU update routine in CLI router to speed up test execution.

## [4.1.0] 2024-02-20;

Expand Down
2 changes: 2 additions & 0 deletions config/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ parameters:
excludePaths:
- ./../src/WordPress/Version.php # Using the WordPress version file.
- ./../src/TestCase/WPTestCasePHPUnitMethodsTrait.php # Compat file has missing return types.
bootstrapFiles:
- ./phpstan/class-aliases.php
5 changes: 5 additions & 0 deletions config/phpstan/class-aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

if (!class_exists(Ifsnop\Mysqldump\Mysqldump::class) && class_exists(Druidfi\Mysqldump\Mysqldump::class)) {
class_alias(Druidfi\Mysqldump\Mysqldump::class, Ifsnop\Mysqldump\Mysqldump::class);
}
12 changes: 12 additions & 0 deletions includes/cli-server/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

define('DB_ENGINE', getenv('DB_ENGINE') ?: 'mysql');

// Add a unique request ID to the headers.
$requestId = md5( microtime() );
$_SERVER['REQUEST_ID'] = $requestId;
header( 'X-Request-ID: ' . $requestId );

// Disable the MU upgrade routine.
global $wp_filter;
$wp_filter['do_mu_upgrade'][10][] = [
'accepted_args' => 0,
'function' => '__return_false'
];

if ( file_exists( $root.$path ) ) {

// Enforces trailing slash, keeping links tidy in the admin
Expand Down
33 changes: 31 additions & 2 deletions src/WordPress/Database/MysqlDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace lucatume\WPBrowser\WordPress\Database;

use Druidfi\Mysqldump\Mysqldump;
use Ifsnop\Mysqldump\Mysqldump as LegacyMysqldump;
use Exception;
use lucatume\WPBrowser\Utils\Db as DbUtil;
use lucatume\WPBrowser\Utils\Serializer;
Expand Down Expand Up @@ -324,14 +325,42 @@ public function import(string $dumpFilePath): int
return $modifiedByQuery;
}

private function buildIfsnopMysqlDump(): LegacyMysqldump
{
return new class( $this->dsn, $this->dbUser, $this->dbPassword ) extends LegacyMysqldump {
public function start($filename = ''): void
{
// @phpstan-ignore-next-line property defined in ifsnop/mysqldump dependency.
$this->dumpSettings['add-drop-table'] = true;
$this->dumpSettings['add-drop-database'] = true;

parent::start($filename);
}
};
}

/**
* @throws Exception
*/
private function buildDruidfiMysqldump(): Mysqldump
{
$dumpSettings = [ 'add-drop-table' => true, 'add-drop-database' => true ];

return new Mysqldump($this->dsn, $this->dbUser, $this->dbPassword, $dumpSettings);
}

/**
* @throws DbException
*/
public function dump(string $dumpFile): void
{
try {
$dumpSettings = ['add-drop-table'=> true, 'add-drop-database' => true];
$dump = new Mysqldump($this->dsn, $this->dbUser, $this->dbPassword, $dumpSettings);
if (class_exists(LegacyMysqldump::class)) {
$dump = $this->buildIfsnopMysqlDump();
} else {
$dump = $this->buildDruidfiMysqldump();
}
/** @var Mysqldump $dump */
$dump->start($dumpFile);
} catch (\Exception $e) {
throw new DbException("Failed to dump database: " . $e->getMessage(), DbException::FAILED_DUMP);
Expand Down
2 changes: 1 addition & 1 deletion tests/webdriver.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ modules:
path: '/'
window_size: false
wait: 5
pageload_timeout: 5
pageload_timeout: 30
capabilities:
"goog:chromeOptions":
args:
Expand Down

0 comments on commit d2a3540

Please sign in to comment.