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

Some mariadb client tools does not support ssl-mode option #1531

Merged
merged 4 commits into from
Oct 23, 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
6 changes: 3 additions & 3 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hooks:
use_dns_when_possible: true
composer_version: 2.2.17
web_environment:
- MAGERUN_SETUP_TEST_DEFAULT_MAGENTO_VERSION=2.4.7
- MAGERUN_SETUP_TEST_DEFAULT_MAGENTO_VERSION=2.4.7-p2
- N98_MAGERUN2_BIN=/var/www/html/bin/n98-magerun2
nodejs_version: "16"

Expand Down Expand Up @@ -58,7 +58,7 @@ nodejs_version: "16"
# "ddev xhprof" to enable xhprof and "ddev xhprof off" to disable it work better,
# as leaving xhprof enabled all the time is a big performance hit.

# webserver_type: nginx-fpm, apache-fpm, or nginx-gunicorn
# webserver_type: nginx-fpm, apache-fpm, or nginx-gunicorn

# timezone: Europe/Berlin
# This is the timezone used in the containers and by PHP;
Expand Down Expand Up @@ -100,7 +100,7 @@ nodejs_version: "16"
# Please take care with this because it can cause great confusion.

# upload_dirs: "custom/upload/dir"
#
#
# upload_dirs:
# - custom/upload/dir
# - ../private
Expand Down
3 changes: 1 addition & 2 deletions .ddev/docker-compose.elastic.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.6'
services:

# see: https://github.com/drud/ddev-contrib/blob/master/docker-compose-services/elasticsearch/docker-compose.elasticsearch.yaml
Expand Down Expand Up @@ -28,4 +27,4 @@ services:
- elasticsearch:elasticsearch

volumes:
elasticsearch:
elasticsearch:
1 change: 0 additions & 1 deletion .ddev/docker-compose.magento-volumes.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.6'
services:
web:
volumes:
Expand Down
13 changes: 7 additions & 6 deletions src/N98/Magento/Command/Database/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace N98\Magento\Command\Database;

use InvalidArgumentException;
use Magento\Framework\Exception\FileSystemException;
use N98\Magento\Command\Database\Compressor\Compressor;
use N98\Util\Console\Enabler;
use N98\Util\Console\Helper\DatabaseHelper;
Expand Down Expand Up @@ -207,7 +208,7 @@ public function getTableDefinitionHelp()

Separate each table to strip by a space.
You can use wildcards like * and ? in the table names to strip multiple
tables. In addition you can specify pre-defined table groups, that start
tables. In addition, you can specify pre-defined table groups, that start
with an @ symbol.

Example: "dataflow_batch_export unimportant_module_* @log"
Expand Down Expand Up @@ -263,7 +264,7 @@ public function getHelp()
* @param OutputInterface $output
*
* @return int
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -290,7 +291,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @param InputInterface $input
* @param OutputInterface $output
* @return Execs
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
private function createExecs(InputInterface $input, OutputInterface $output)
{
Expand Down Expand Up @@ -432,7 +433,7 @@ private function runExec($command, InputInterface $input, OutputInterface $outpu
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
private function stripTables(InputInterface $input, OutputInterface $output)
{
Expand All @@ -455,7 +456,7 @@ private function stripTables(InputInterface $input, OutputInterface $output)
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
private function excludeTables(InputInterface $input, OutputInterface $output)
{
Expand Down Expand Up @@ -487,7 +488,7 @@ private function excludeTables(InputInterface $input, OutputInterface $output)
/**
* @param string $list space separated list of tables
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
private function resolveDatabaseTables($list)
{
Expand Down
74 changes: 49 additions & 25 deletions src/N98/Util/Console/Helper/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace N98\Util\Console\Helper;

use InvalidArgumentException;
use Magento\Framework\Exception\FileSystemException;
use N98\Util\Exec;
use PDO;
use PDOException;
use PDOStatement;
Expand Down Expand Up @@ -57,7 +59,7 @@ public function setConnectionType($connectionType)
* @param OutputInterface|null $output
*
* @throws RuntimeException
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
* @return void
*/
public function detectDbSettings(OutputInterface $output)
Expand Down Expand Up @@ -113,7 +115,7 @@ public function detectDbSettings(OutputInterface $output)
* @param bool $reconnect = false
* @return PDO
* @throws RuntimeException pdo mysql extension is not installed
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getConnection(OutputInterface $output = null, bool $reconnect = false)
{
Expand Down Expand Up @@ -160,7 +162,7 @@ public function getConnection(OutputInterface $output = null, bool $reconnect =
$this->dbSettings['password'],
$connectionOptions
);
$this->_connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

/** @link http://bugs.mysql.com/bug.php?id=18551 */
$this->_connection->query("SET SQL_MODE=''");
Expand Down Expand Up @@ -201,7 +203,7 @@ public function getTableName($tableName)
*
* @see Zend_Db_Adapter_Pdo_Abstract
* @return string
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function dsn()
{
Expand Down Expand Up @@ -240,7 +242,7 @@ public function dsn()
* @param string $privilege
*
* @return bool
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function mysqlUserHasPrivilege($privilege)
{
Expand All @@ -258,9 +260,31 @@ public function mysqlUserHasPrivilege($privilege)
return false;
}

/**
* Check if the toolstack is using mariadb
*
* @return bool
*/
public function isMariaDbClientToolUsed(): bool
{
Exec::run('mysqldump --help', $output, $exitCode);
return strpos($output, 'MariaDB') !== false;
}

/**
* Some versions of mysqldump shipped by MariaDB are not able to handle the --ssl-mode option
*
* @return bool
*/
public function isSslModeOptionSupported(): bool
{
Exec::run('mysqldump --help', $output, $exitCode);
return strpos($output, '--ssl-mode') !== false;
}

/**
* @return string
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getMysqlClientToolConnectionString()
{
Expand Down Expand Up @@ -303,15 +327,15 @@ public function getMysqlClientToolConnectionString()
}
}

$isSslModeSupported = $this->isSslModeOptionSupported();

// see https://dev.mysql.com/doc/refman/8.0/en/connection-options.html#option_general_ssl-mode
if (array_key_exists(PDO::MYSQL_ATTR_SSL_CA, $connectionOptions)) {
if (!array_key_exists(PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT, $connectionOptions)
|| $connectionOptions[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]
) {
$sslOptions[] = '--ssl-mode=VERIFY_CA';
} else {
$sslOptions[] = '--ssl-mode=REQUIRED';
}
// see https://dev.mysql.com/doc/refman/8.0/en/connection-options.html#option_general_ssl-mode
if ($isSslModeSupported && array_key_exists(PDO::MYSQL_ATTR_SSL_CA, $connectionOptions)) {
$sslOptions[] = !array_key_exists(PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT, $connectionOptions)
|| $connectionOptions[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]
? '--ssl-mode=VERIFY_CA'
: '--ssl-mode=REQUIRED';
}

$string .= ' ' . implode(' ', $sslOptions)
Expand All @@ -333,7 +357,7 @@ public function getMysqlClientToolConnectionString()
* @param string $variable
*
* @return bool|array returns array on success, false on failure
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getMysqlVariableValue($variable)
{
Expand Down Expand Up @@ -363,7 +387,7 @@ public function getMysqlVariableValue($variable)
* @return string variable value, null if variable was not defined
* @throws RuntimeException in case a system variable is unknown (SQLSTATE[HY000]: 1193: Unknown system variable
* 'nonexistent')
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getMysqlVariable($name, $type = null)
{
Expand Down Expand Up @@ -455,7 +479,7 @@ public function getTableDefinitions(array $commandConfig)
*
* @return array
* @throws RuntimeException
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function resolveTables(array $list, array $definitions = [], array $resolved = [])
{
Expand Down Expand Up @@ -566,7 +590,7 @@ private function resolveTablesArray(array $carry = null, $item = null)
*
* @return array
* @throws RuntimeException
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getTables($withoutPrefix = null)
{
Expand Down Expand Up @@ -658,7 +682,7 @@ private function quoteLike($string, $escape = '=')
* @param bool $withoutPrefix
*
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getTablesStatus($withoutPrefix = false)
{
Expand Down Expand Up @@ -719,7 +743,7 @@ public function getName()

/**
* @param OutputInterface $output
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function dropDatabase(OutputInterface $output)
{
Expand All @@ -731,7 +755,7 @@ public function dropDatabase(OutputInterface $output)

/**
* @param OutputInterface $output
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function dropTables(OutputInterface $output)
{
Expand All @@ -749,7 +773,7 @@ public function dropTables(OutputInterface $output)

/**
* @param OutputInterface $output
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function createDatabase(OutputInterface $output)
{
Expand All @@ -764,7 +788,7 @@ public function createDatabase(OutputInterface $output)
* @param string|null $variable [optional]
*
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
private function runShowCommand($command, $variable = null)
{
Expand Down Expand Up @@ -800,7 +824,7 @@ private function runShowCommand($command, $variable = null)
* @param string|null $variable [optional]
*
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getGlobalVariables($variable = null)
{
Expand All @@ -811,7 +835,7 @@ public function getGlobalVariables($variable = null)
* @param string|null $variable [optional]
*
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
public function getGlobalStatus($variable = null)
{
Expand Down