Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v35 update mysql dump #704

Merged
merged 7 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading