Skip to content

Commit

Permalink
Merge pull request #704 from lucatume/v35-update-mysql-dump
Browse files Browse the repository at this point in the history
v35 update mysql dump
  • Loading branch information
lucatume authored Mar 7, 2024
2 parents 28afecd + e451edb commit f259537
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Changed

- Refactor `MysqlDatabase` class following merge of #702.
- Disable MU update routine in CLI router to speed up test execution.

## [3.5.0] 2024-02-20;

### Breaking change
Expand Down
2 changes: 1 addition & 1 deletion bin/setup-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
$extraPHP = <<< PHP
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'DISABLE_CRON', true );
define( 'DISABLE_WP_CRON', true );
PHP;
$configData->setExtraPHP($extraPHP);
$installation = $installation->configure(
Expand Down
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
41 changes: 32 additions & 9 deletions src/WordPress/Database/MysqlDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace lucatume\WPBrowser\WordPress\Database;

use Druidfi\Mysqldump\Mysqldump;
use Ifsnop\Mysqldump\Mysqldump as LegacyMysqldump;
use Exception;
use Ifsnop\Mysqldump\Mysqldump;
use lucatume\WPBrowser\Utils\Db as DbUtil;
use lucatume\WPBrowser\Utils\Serializer;
use lucatume\WPBrowser\WordPress\DbException;
Expand Down Expand Up @@ -368,20 +369,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 {
$dump = new class($this->dsn, $this->dbUser, $this->dbPassword) extends Mysqldump {
public function start($filename = '')
{
$this->dumpSettings['add-drop-table'] = true;
$this->dumpSettings['add-drop-database'] = true;
return parent::start($filename);
}
};
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
14 changes: 7 additions & 7 deletions tests/_data/dump.sql

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions tests/_data/wploader-wpdb-dump.sql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/acceptance.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ modules:
X_WPBROWSER_REQUEST: 1
X_TEST_REQUEST: 1
X_APM_REQUEST: 1
connect_timeout: 3
lucatume\WPBrowser\Module\WPDb:
dsn: '%WORDPRESS_DB_DSN%'
user: %WORDPRESS_DB_USER%
Expand Down
1 change: 1 addition & 0 deletions tests/climodule.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ modules:
adminUsername: '%WORDPRESS_ADMIN_USER%'
adminPassword: '%WORDPRESS_ADMIN_PASSWORD%'
adminPath: '/wp-admin'
connect_timeout: 3
1 change: 1 addition & 0 deletions tests/webdriver.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ modules:
path: '/'
window_size: false
wait: 5
pageload_timeout: 30
capabilities:
"goog:chromeOptions":
args:
Expand Down

0 comments on commit f259537

Please sign in to comment.