diff --git a/.github/workflows/mage-os_nightly_test.yml b/.github/workflows/mage-os_nightly_test.yml index 51c4af0cf..f855e898c 100644 --- a/.github/workflows/mage-os_nightly_test.yml +++ b/.github/workflows/mage-os_nightly_test.yml @@ -28,32 +28,26 @@ jobs: --health-timeout=5s --health-retries=10 + mariadb: + image: "mariadb:10.6" + env: + MARIADB_ROOT_PASSWORD: root + MARIADB_DATABASE: magento + ports: + - 3306 # Standard MariaDB/MySQL port + # Options remain largely the same, health check uses mysqladmin (compatible) + options: >- + --health-cmd="mariadb-admin ping -uroot -proot || exit 1" + --health-interval=10s + --health-timeout=5s + --health-retries=10 + steps: - name: Checkout develop branch uses: actions/checkout@v4.2.2 with: ref: develop - - uses: shogo82148/actions-setup-mysql@v1 - with: - distribution: "mariadb" - mysql-version: "11.4" - auto-start: "true" - root-password: "root" - - - name: Check MariaDB version - run: "mariadb -uroot -proot -e 'SELECT version();'" - - - name: List installed MySQL/MariaDB tools - run: | - mariadb --version || true - mariadb-dump --version || true - mysql --version || true - mysqldump --version || true - - - name: Create Magento database - run: "mariadb -uroot -proot -e 'CREATE DATABASE magento;'" - - name: Linux Setup run: ./.github/workflows/linux-setup.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 865b6228e..a63d7ef5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ RECENT CHANGES - Imp: feat(dev:hyva:build): Add check for Hyvä theme in dev:hyva:build command (by Christian Münch) - Fix: better TTY handling in proxy command (PR #1667, issue #1422, by Christian Münch) - Fix: PHP 8.4 compatibility updates (PR #1655, issue #1654, by Christian Münch) +- Fix: Port handling in database helper (by Christian Münch) - Build: CI release workflow enhancements (PR #1657, issue #1657, by Christian Münch) 8.1.1 diff --git a/src/N98/Util/Console/Helper/DatabaseHelper.php b/src/N98/Util/Console/Helper/DatabaseHelper.php index 3954a3564..6c4a4d0c5 100644 --- a/src/N98/Util/Console/Helper/DatabaseHelper.php +++ b/src/N98/Util/Console/Helper/DatabaseHelper.php @@ -153,8 +153,14 @@ public function detectDbSettings(?OutputInterface $output) if (strpos($this->dbSettings['host'], '/') !== false) { $this->dbSettings['unix_socket'] = $this->dbSettings['host']; unset($this->dbSettings['host']); - } elseif (strpos($this->dbSettings['host'], ':') !== false) { - list($this->dbSettings['host'], $this->dbSettings['port']) = explode(':', $this->dbSettings['host']); + } elseif (strpos($this->dbSettings['host'], ':') !== false + && substr_count($this->dbSettings['host'], ':') === 1) { + // Only split if not IPv6 (which has multiple colons) + list($host, $port) = explode(':', $this->dbSettings['host'], 2); + $this->dbSettings['host'] = $host; + if (is_numeric($port)) { + $this->dbSettings['port'] = (int)$port; + } } } @@ -195,8 +201,13 @@ public function getConnection(?OutputInterface $output = null, bool $reconnect = if (strpos($this->dbSettings['host'], '/') !== false) { $this->dbSettings['unix_socket'] = $this->dbSettings['host']; unset($this->dbSettings['host']); - } elseif (strpos($this->dbSettings['host'], ':') !== false) { - list($this->dbSettings['host'], $this->dbSettings['port']) = explode(':', $this->dbSettings['host']); + } elseif (strpos($this->dbSettings['host'], ':') !== false && substr_count($this->dbSettings['host'], ':') === 1) { + // Only split if not IPv6 (which has multiple colons) + list($host, $port) = explode(':', $this->dbSettings['host'], 2); + $this->dbSettings['host'] = $host; + if (is_numeric($port)) { + $this->dbSettings['port'] = (int)$port; + } } } @@ -440,7 +451,7 @@ public function getMysqlClientToolConnectionString() . ' ' . '-u' . escapeshellarg($this->dbSettings['username']) . ' ' - . (isset($this->dbSettings['port']) + . (isset($this->dbSettings['port']) && is_numeric($this->dbSettings['port']) && (int)$this->dbSettings['port'] > 0 ? '-P' . escapeshellarg($this->dbSettings['port']) . ' ' : '') . (strlen($this->dbSettings['password']) ? '--password=' . escapeshellarg($this->dbSettings['password']) . ' ' : '') diff --git a/tests/bats/functional_magerun_commands.bats b/tests/bats/functional_magerun_commands.bats index fb29af5c1..fa6a8d1a9 100755 --- a/tests/bats/functional_magerun_commands.bats +++ b/tests/bats/functional_magerun_commands.bats @@ -530,6 +530,18 @@ function cleanup_files_in_magento() { assert_output --partial "innodb_buffer_pool_size" } + +# ============================================ +# Command: db:query +# ============================================ + +@test "Command: db:query --format=csv" { + run $BIN "db:query" --format=csv "SELECT 1 AS foo, 2 AS bar" + assert_output --partial '"foo","bar"' + assert_output --partial '"1","2"' + assert [ "$status" -eq 0 ] +} + # ============================================ # Command: design:demo-notice # ============================================ @@ -549,17 +561,6 @@ function cleanup_files_in_magento() { # assert_output --partial "di" #} -# ============================================ -# Command: db:query -# ============================================ - -@test "Command: db:query --format=csv" { - run $BIN "db:query" --format=csv "SELECT 1 AS foo, 2 AS bar" - assert_output --partial '"foo","bar"' - assert_output --partial '"1","2"' - assert [ "$status" -eq 0 ] -} - # ============================================ # Command: dev:module:create # ============================================