Skip to content

Commit

Permalink
Default to localhost on empty database host, fixes #880
Browse files Browse the repository at this point in the history
When nost setting the database host, the Mysql command-line string was
not properly concatenated resulting in mysql connecting to the username
switch as hostname.

A space was missing, fix is to add that space after "-h" and before the
host parameter value.

Additionally the order of the datbase configuration values is a bit more
controlled so that it becomes more obvious with db:info that the host-
name is not set.

Refs:

- #880

- Command: db:info

- Command: db:console
  • Loading branch information
ktomk committed Dec 12, 2016
1 parent 0e61309 commit e4a9332
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@ RECENT CHANGES

1.97.28
-------
* Fix: Empty database hostname for mysql cli (report by Seansan, fix by Tom Klingenberg, #880)

1.97.27
-------
Expand Down
5 changes: 4 additions & 1 deletion src/N98/Magento/Command/Database/InfoCommand.php
Expand Up @@ -3,6 +3,7 @@
namespace N98\Magento\Command\Database;

use InvalidArgumentException;
use N98\Util\Console\Helper\DatabaseHelper;
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -87,7 +88,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$settings['JDBC-Connection-String'] = $jdbcConnectionString;

$mysqlCliString = 'mysql ' . $this->getHelper('database')->getMysqlClientToolConnectionString();
/* @var $database DatabaseHelper */
$database = $this->getHelper('database');
$mysqlCliString = 'mysql ' . $database->getMysqlClientToolConnectionString();
$settings['MySQL-Cli-String'] = $mysqlCliString;

$rows = array();
Expand Down
4 changes: 2 additions & 2 deletions src/N98/Magento/DbSettings.php
Expand Up @@ -98,7 +98,7 @@ private function parseResources(SimpleXMLElement $resources)
'password' => null,
);

$config = ((array) $resources->default_setup->connection) + $config;
$config = array_merge($config, (array) $resources->default_setup->connection);
$config['prefix'] = (string) $resources->db->table_prefix;

// known parameters: host, port, unix_socket, dbname, username, password, options, charset, persistent,
Expand Down Expand Up @@ -203,7 +203,7 @@ public function getMysqlClientToolConnectionString()
if (null !== $this->config['unix_socket']) {
$segments[] = '--socket=' . escapeshellarg($this->config['unix_socket']);
} else {
$segments[] = '-h' . escapeshellarg($this->config['host']);
$segments[] = '-h ' . escapeshellarg($this->config['host']);
}

$segments[] = '-u' . escapeshellarg($this->config['username']);
Expand Down

0 comments on commit e4a9332

Please sign in to comment.