From 43bc0900bb992acb73f36cc0dcdf3f8fc45fe868 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 6 May 2016 11:35:28 +0200 Subject: [PATCH 01/12] Update version of development branch --- CHANGELOG.md | 3 +++ src/N98/Magento/Application.php | 2 +- version.txt | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74191edd0..bb4294483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ RECENT CHANGES ============== +1.97.21 +------- + 1.97.20 ------- diff --git a/src/N98/Magento/Application.php b/src/N98/Magento/Application.php index ab896fbef..d841ca72f 100644 --- a/src/N98/Magento/Application.php +++ b/src/N98/Magento/Application.php @@ -38,7 +38,7 @@ class Application extends BaseApplication /** * @var string */ - const APP_VERSION = '1.97.20'; + const APP_VERSION = '1.97.21'; /** * @var int diff --git a/version.txt b/version.txt index cc92627e8..ab6b6c7b9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.97.20 +1.97.21 From b3a7ba741cdc5d3706d1c9dd234e611defe50e7a Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 6 May 2016 12:13:12 +0200 Subject: [PATCH 02/12] Polish --- src/N98/Magento/Command/System/Cron/RunCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/N98/Magento/Command/System/Cron/RunCommand.php b/src/N98/Magento/Command/System/Cron/RunCommand.php index 5e9f309dc..adc2adab8 100644 --- a/src/N98/Magento/Command/System/Cron/RunCommand.php +++ b/src/N98/Magento/Command/System/Cron/RunCommand.php @@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $runConfig = $jobConfig->run; if ($runConfig->model) { - if (!preg_match(self::REGEX_RUN_MODEL, (string) $runConfig->model, $run)) { + if (!preg_match(self::REGEX_RUN_MODEL, (string)$runConfig->model, $run)) { throw new RuntimeException('Invalid model/method definition, expecting "model/class::method".'); } $model = \Mage::getModel($run[1]); @@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * @param OutputInterface $output - * @param array $jobs array of array containing "job" keyed string entries of job-codes + * @param array $jobs array of array containing "job" keyed string entries of job-codes * * @return string job-code * @throws InvalidArgumentException when user selects invalid job interactively @@ -136,6 +136,7 @@ function ($typeInput) use ($keyMap, $jobs) { if (!isset($jobs[$key])) { throw new InvalidArgumentException('Invalid job'); } + return $jobs[$key]['Job']; } ); From aaced19bc365da110b24cba20ef621c58873ca41 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 6 May 2016 17:57:57 +0200 Subject: [PATCH 03/12] Extract StringTyped Generic string formatting and parsing functions. --- .../Command/AbstractMagentoCommand.php | 9 ++--- src/N98/Util/StringTyped.php | 38 +++++++++++++++++++ tests/N98/Util/StringTypedTest.php | 29 ++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 src/N98/Util/StringTyped.php create mode 100644 tests/N98/Util/StringTypedTest.php diff --git a/src/N98/Magento/Command/AbstractMagentoCommand.php b/src/N98/Magento/Command/AbstractMagentoCommand.php index afd3a5b3e..122f8015c 100644 --- a/src/N98/Magento/Command/AbstractMagentoCommand.php +++ b/src/N98/Magento/Command/AbstractMagentoCommand.php @@ -5,6 +5,7 @@ use Composer\Package\PackageInterface; use InvalidArgumentException; use N98\Util\OperatingSystem; +use N98\Util\StringTyped; use RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -414,7 +415,7 @@ protected function _getResourceSingleton($mage1code, $mage2class) */ protected function _parseBoolOption($value) { - return in_array(strtolower($value), array('y', 'yes', 1, 'true')); + return StringTyped::parseBoolOption($value); } /** @@ -423,11 +424,7 @@ protected function _parseBoolOption($value) */ protected function formatActive($value) { - if (in_array($value, array(1, 'true'))) { - return 'active'; - } - - return 'inactive'; + return StringTyped::formatActive($value); } /** diff --git a/src/N98/Util/StringTyped.php b/src/N98/Util/StringTyped.php new file mode 100644 index 000000000..87fabc960 --- /dev/null +++ b/src/N98/Util/StringTyped.php @@ -0,0 +1,38 @@ + + */ + +namespace N98\Util; + +/** + * StringTyped String formatter / parser + * + * @package N98\Util + */ +abstract class StringTyped +{ + /** + * @param string $value + * @return bool + */ + public static function parseBoolOption($value) + { + return in_array(strtolower($value), array('y', 'yes', 1, 'true')); + } + + /** + * @param string $value + * @return string + */ + public static function formatActive($value) + { + if (in_array($value, array(1, 'true'))) { + return 'active'; + } + + return 'inactive'; + } +} diff --git a/tests/N98/Util/StringTypedTest.php b/tests/N98/Util/StringTypedTest.php new file mode 100644 index 000000000..834861815 --- /dev/null +++ b/tests/N98/Util/StringTypedTest.php @@ -0,0 +1,29 @@ + + */ + +namespace N98\Util; + +use PHPUnit_Framework_TestCase as TestCase; + +/** + * Class StringTypedTest + * + * @package N98\Util + */ +class StringTypedTest extends TestCase +{ + /** + * @test + */ + public function scope() + { + $this->assertSame(true, StringTyped::parseBoolOption("true")); + + $this->assertSame('inactive', StringTyped::formatActive(null)); + $this->assertSame('active', StringTyped::formatActive('1')); + } +} From 37ddcf1727c796a3f9778e0b399f7859a3606151 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 6 May 2016 18:47:11 +0200 Subject: [PATCH 04/12] Extract magento modules magerun module Small module to wrap module accessing and filtering as used by the modules-list-command (and other commands). More tests will be added soon, this commit is for a third party developer to review the new module and to check if the interface suffices. --- .../Command/Developer/Module/ListCommand.php | 58 ++------- src/N98/Magento/Modules.php | 118 ++++++++++++++++++ tests/N98/Magento/ModulesTest.php | 38 ++++++ 3 files changed, 167 insertions(+), 47 deletions(-) create mode 100644 src/N98/Magento/Modules.php create mode 100644 tests/N98/Magento/ModulesTest.php diff --git a/src/N98/Magento/Command/Developer/Module/ListCommand.php b/src/N98/Magento/Command/Developer/Module/ListCommand.php index ca5e70bc8..4a680ce49 100644 --- a/src/N98/Magento/Command/Developer/Module/ListCommand.php +++ b/src/N98/Magento/Command/Developer/Module/ListCommand.php @@ -2,9 +2,8 @@ namespace N98\Magento\Command\Developer\Module; -use Mage; use N98\Magento\Command\AbstractMagentoCommand; -use N98\Util\ArrayFunctions; +use N98\Magento\Modules; use N98\Util\Console\Helper\Table\Renderer\RendererFactory; use N98\Util\Console\Helper\TableHelper; use Symfony\Component\Console\Input\InputInterface; @@ -44,12 +43,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->writeSection($output, 'Magento Modules'); } $this->initMagento(); - $modules = $this->findInstalledModules(); - $modules = $this->filterModules($modules, $input); - if (empty($modules)) { - $output->writeln("No modules match the specified criteria."); + $modules = $this->filterModules($input); + if (!count($modules)) { + $output->writeln("No modules match the specified criteria."); return; } @@ -57,53 +55,19 @@ protected function execute(InputInterface $input, OutputInterface $output) $table = $this->getHelper('table'); $table ->setHeaders(array('Code pool', 'Name', 'Version', 'Status')) - ->renderByFormat($output, $modules, $input->getOption('format')); + ->renderByFormat($output, iterator_to_array($modules), $input->getOption('format')); } /** - * @return array - */ - private function findInstalledModules() - { - $return = array(); - - $modules = Mage::app()->getConfig()->getNode('modules')->asArray(); - foreach ($modules as $moduleName => $moduleInfo) { - $codePool = isset($moduleInfo['codePool']) ? $moduleInfo['codePool'] : ''; - $version = isset($moduleInfo['version']) ? $moduleInfo['version'] : ''; - $active = isset($moduleInfo['active']) ? $moduleInfo['active'] : ''; - - $return[] = array( - 'Code pool' => trim($codePool), - 'Name' => trim($moduleName), - 'Version' => trim($version), - 'Status' => $this->formatActive($active), - ); - } - - return $return; - } - - /** - * Filter modules by codepool, status and vendor if such options were inputted by user - * - * @param array $modules * @param InputInterface $input - * @return array + * + * @return Modules */ - private function filterModules(array $modules, InputInterface $input) + private function filterModules(InputInterface $input) { - if ($input->getOption('codepool')) { - $modules = ArrayFunctions::matrixFilterByValue($modules, "codePool", $input->getOption('codepool')); - } - - if ($input->getOption('status')) { - $modules = ArrayFunctions::matrixFilterByValue($modules, 'Status', $input->getOption('status')); - } - - if ($input->getOption('vendor')) { - $modules = ArrayFunctions::matrixFilterStartswith($modules, 'Name', $input->getOption('vendor')); - } + $modules = new Modules(); + $modules = $modules->findInstalledModules() + ->filterModules($input); return $modules; } diff --git a/src/N98/Magento/Modules.php b/src/N98/Magento/Modules.php new file mode 100644 index 000000000..1f37cd1f6 --- /dev/null +++ b/src/N98/Magento/Modules.php @@ -0,0 +1,118 @@ + + */ + +namespace N98\Magento; + +use ArrayIterator; +use Countable; +use IteratorAggregate; +use Mage; +use N98\Util\ArrayFunctions; +use N98\Util\StringTyped; +use Symfony\Component\Console\Input\InputInterface; +use Traversable; + +/** + * Magento Modules + * + * @package N98\Magento + */ +class Modules implements IteratorAggregate, Countable +{ + /** + * @var array + */ + private $list; + + public function __construct(array $list = null) + { + if (null === $list) { + $list = array(); + } + + $this->list = $list; + } + + /** + * @return Modules + */ + public function findInstalledModules() + { + $list = array(); + + $modules = Mage::app()->getConfig()->getNode('modules')->asArray(); + foreach ($modules as $moduleName => $moduleInfo) { + $codePool = isset($moduleInfo['codePool']) ? $moduleInfo['codePool'] : ''; + $version = isset($moduleInfo['version']) ? $moduleInfo['version'] : ''; + $active = isset($moduleInfo['active']) ? $moduleInfo['active'] : ''; + + $list[] = array( + 'Code pool' => trim($codePool), + 'Name' => trim($moduleName), + 'Version' => trim($version), + 'Status' => StringTyped::formatActive($active), + ); + } + + $installed = new Modules(); + $installed->list = $list; + + return $installed; + } + + /** + * Filter modules by codepool, status and vendor if such options were inputted by user + * + * @param InputInterface $input + * @return Modules + */ + public function filterModules(InputInterface $input) + { + $list = $this->list; + + if ($input->getOption('codepool')) { + $list = ArrayFunctions::matrixFilterByValue($list, "Code pool", $input->getOption('codepool')); + } + + if ($input->getOption('status')) { + $list = ArrayFunctions::matrixFilterByValue($list, 'Status', $input->getOption('status')); + } + + if ($input->getOption('vendor')) { + $list = ArrayFunctions::matrixFilterStartswith($list, 'Name', $input->getOption('vendor')); + } + + $filtered = new self(); + $filtered->list = $list; + + return $filtered; + } + + ### Traversable Interface ### + + /** + * Retrieve an external iterator + * + * @return Traversable|array[] + */ + public function getIterator() + { + return new ArrayIterator($this->list); + } + + ### Countable Interface ### + + /** + * Count elements of an object + * + * @return int The custom count as an integer. + */ + public function count() + { + return count($this->list); + } +} diff --git a/tests/N98/Magento/ModulesTest.php b/tests/N98/Magento/ModulesTest.php new file mode 100644 index 000000000..25fd6e215 --- /dev/null +++ b/tests/N98/Magento/ModulesTest.php @@ -0,0 +1,38 @@ + + */ +namespace N98\Magento; + +use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit_Framework_TestCase as TestCase; +use Symfony\Component\Console\Input\ArrayInput; + +class ModulesTest extends TestCase +{ + /** + * @test + */ + public function creation() + { + $modules = new Modules(); + $this->assertInstanceOf(__NAMESPACE__ . '\Modules', $modules); + } + + /** + * @test + */ + public function filtering() + { + $modules = new Modules(); + + /** @var $input PHPUnit_Framework_MockObject_MockObject|ArrayInput */ + $input = $this->getMock('Symfony\Component\Console\Input\ArrayInput', array('getOption'), array(), '', false); + $input->method('getOption')->willReturn(false); + + $result = $modules->filterModules($input); + $this->assertInstanceOf(__NAMESPACE__ . '\Modules', $result); + } +} From 9ab8d57abbea55ed220f8958a706c059f0887214 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 6 May 2016 19:58:31 +0200 Subject: [PATCH 05/12] Improve modules and tests Get coverage to 100%, add @covers annotations for new tests, polish. --- src/N98/Magento/Modules.php | 18 +++---- tests/N98/Magento/ModulesTest.php | 76 ++++++++++++++++++++++++++++-- tests/N98/Util/StringTypedTest.php | 1 + 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/src/N98/Magento/Modules.php b/src/N98/Magento/Modules.php index 1f37cd1f6..d11026dec 100644 --- a/src/N98/Magento/Modules.php +++ b/src/N98/Magento/Modules.php @@ -58,10 +58,7 @@ public function findInstalledModules() ); } - $installed = new Modules(); - $installed->list = $list; - - return $installed; + return new Modules($list); } /** @@ -72,24 +69,21 @@ public function findInstalledModules() */ public function filterModules(InputInterface $input) { - $list = $this->list; + $filtered = $this->list; if ($input->getOption('codepool')) { - $list = ArrayFunctions::matrixFilterByValue($list, "Code pool", $input->getOption('codepool')); + $filtered = ArrayFunctions::matrixFilterByValue($filtered, "Code pool", $input->getOption('codepool')); } if ($input->getOption('status')) { - $list = ArrayFunctions::matrixFilterByValue($list, 'Status', $input->getOption('status')); + $filtered = ArrayFunctions::matrixFilterByValue($filtered, 'Status', $input->getOption('status')); } if ($input->getOption('vendor')) { - $list = ArrayFunctions::matrixFilterStartswith($list, 'Name', $input->getOption('vendor')); + $filtered = ArrayFunctions::matrixFilterStartswith($filtered, 'Name', $input->getOption('vendor')); } - $filtered = new self(); - $filtered->list = $list; - - return $filtered; + return new self($filtered); } ### Traversable Interface ### diff --git a/tests/N98/Magento/ModulesTest.php b/tests/N98/Magento/ModulesTest.php index 25fd6e215..26130f21b 100644 --- a/tests/N98/Magento/ModulesTest.php +++ b/tests/N98/Magento/ModulesTest.php @@ -6,10 +6,17 @@ */ namespace N98\Magento; +use InvalidArgumentException; +use N98\Magento\Command\PHPUnit\TestCase; use PHPUnit_Framework_MockObject_MockObject; -use PHPUnit_Framework_TestCase as TestCase; use Symfony\Component\Console\Input\ArrayInput; +/** + * Class ModulesTest + * + * @package N98\Magento + * @covers N98\Magento\Modules + */ class ModulesTest extends TestCase { /** @@ -24,15 +31,74 @@ public function creation() /** * @test */ - public function filtering() + public function filteringCountAndIterating() { $modules = new Modules(); + $result = $modules->filterModules($this->filter()); + $this->assertInstanceOf(__NAMESPACE__ . '\Modules', $result); + $this->assertCount(0, $result); + $this->assertCount(0, iterator_to_array($result)); + } + + /** + * @test + */ + public function findInstalledModulesAndFilterThem() + { + $this->getApplication()->initMagento(); + + $modules = new Modules(); + $this->assertCount(0, $modules); + $total = count($modules->findInstalledModules()); + $this->assertGreaterThan(10, $total); + + $filtered = $modules->filterModules($this->filter('codepool', 'core')); + $this->assertLessThan($total, count($filtered)); + + $filtered = $modules->filterModules($this->filter('status', 'active')); + $this->assertLessThan($total, count($filtered)); + + $filtered = $modules->filterModules($this->filter('vendor', 'Mage_')); + $this->assertLessThan($total, count($filtered)); + } + + /** + * Helper method to create a fake input + * + * @param string $option + * @param string $value + * @return PHPUnit_Framework_MockObject_MockObject|ArrayInput + */ + private function filter($option = null, $value = null) + { + $defaultOptions = array('codepool' => false, 'status' => false, 'vendor' => false); + + $options = $defaultOptions; + if (null !== $option) { + if (!array_key_exists($option, $defaultOptions)) { + throw new InvalidArgumentException(sprintf('Invalid option "%s"', $option)); + } + $options[$option] = $value; + } + /** @var $input PHPUnit_Framework_MockObject_MockObject|ArrayInput */ $input = $this->getMock('Symfony\Component\Console\Input\ArrayInput', array('getOption'), array(), '', false); - $input->method('getOption')->willReturn(false); + $i = 0; + foreach ($options as $option => $value) { + $input->expects($this->at($i++)) + ->method('getOption') + ->with($option) + ->willReturn($value); + if (!$value) { + continue; + } + $input->expects($this->at($i++)) + ->method('getOption') + ->with($option) + ->willReturn($value); + } - $result = $modules->filterModules($input); - $this->assertInstanceOf(__NAMESPACE__ . '\Modules', $result); + return $input; } } diff --git a/tests/N98/Util/StringTypedTest.php b/tests/N98/Util/StringTypedTest.php index 834861815..2f06b8e9b 100644 --- a/tests/N98/Util/StringTypedTest.php +++ b/tests/N98/Util/StringTypedTest.php @@ -13,6 +13,7 @@ * Class StringTypedTest * * @package N98\Util + * @covers N98\Util\StringTyped */ class StringTypedTest extends TestCase { From efc3224de369f61f92f9d8149f4e876ea712fcdb Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Fri, 6 May 2016 23:36:39 +0200 Subject: [PATCH 06/12] Polish Some minor fixes in function comment blocks and an empty line too much. --- build/local/test_setup.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build/local/test_setup.sh b/build/local/test_setup.sh index fa9bf60da..30305118b 100755 --- a/build/local/test_setup.sh +++ b/build/local/test_setup.sh @@ -52,14 +52,13 @@ ensure_environment() { buildecho "directory: '${directory}'" } -# create mysql database ($1) if it does not yet exists +# create mysql database if it does not yet exists ensure_mysql_db() { local db_host="${test_setup_db_host}" local db_user="${test_setup_db_user}" local db_pass="${test_setup_db_pass}" local db_name="${test_setup_db_name}" - if [ "" == "${db_pass}" ]; then mysql -u"${db_user}" -h"${db_host}" -e "CREATE DATABASE IF NOT EXISTS \`${db_name}\`;" else @@ -69,7 +68,7 @@ ensure_mysql_db() { buildecho "mysql database: '${db_name}' (${db_user}@${db_host})" } -# install into a directory ($1) a Magento version ($2) with or w/o sample-data ($3) +# install into a directory a Magento version with or w/o sample-data ensure_magento() { local directory="${test_setup_directory}" local db_host="${test_setup_db_host}" From ecc430bb3eff7659fdc01fc5e87e87dd10b7d421 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Sat, 7 May 2016 01:57:48 +0200 Subject: [PATCH 07/12] Improve test setup - Add database port - Handle mysql non-passwords (empty passwords) w/o if - Bright and bold buildecho style --- build/local/test_setup.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build/local/test_setup.sh b/build/local/test_setup.sh index 30305118b..623382eac 100755 --- a/build/local/test_setup.sh +++ b/build/local/test_setup.sh @@ -7,7 +7,7 @@ IFS=$'\n\t' buildecho() { - echo -en "\e[44m[TEST-SETUP]\e[49m " + echo -en "\e[1;44;97m[TEST-SETUP]\e[0m " echo "${1}" } @@ -55,15 +55,12 @@ ensure_environment() { # create mysql database if it does not yet exists ensure_mysql_db() { local db_host="${test_setup_db_host}" + local db_port="${test_setup_db_port}" local db_user="${test_setup_db_user}" local db_pass="${test_setup_db_pass}" local db_name="${test_setup_db_name}" - if [ "" == "${db_pass}" ]; then - mysql -u"${db_user}" -h"${db_host}" -e "CREATE DATABASE IF NOT EXISTS \`${db_name}\`;" - else - mysql -u"${db_user}" -p"${db_pass}" -h"${db_host}" -e "'CREATE DATABASE IF NOT EXISTS \`${db_name}\`;'" - fi; + mysql -u"${db_user}" --password="${db_pass}" -h"${db_host}" -P"${db_port}" -e "CREATE DATABASE IF NOT EXISTS \`${db_name}\`;" buildecho "mysql database: '${db_name}' (${db_user}@${db_host})" } @@ -72,6 +69,7 @@ ensure_mysql_db() { ensure_magento() { local directory="${test_setup_directory}" local db_host="${test_setup_db_host}" + local db_port="${test_setup_db_port}" local db_user="${test_setup_db_user}" local db_pass="${test_setup_db_pass}" local db_name="${test_setup_db_name}" @@ -87,7 +85,8 @@ ensure_magento() { else php -dmemory_limit=1g -f "${magerun_cmd}" -- install \ --magentoVersionByName="${magento_version}" --installationFolder="${directory}" \ - --dbHost="${db_host}" --dbUser="${db_user}" --dbPass="${db_pass}" --dbName="${db_name}" \ + --dbHost="${db_host}" --dbPort="${db_port}" --dbUser="${db_user}" --dbPass="${db_pass}" \ + --dbName="${db_name}" \ --installSampleData="${install_sample_data}" --useDefaultConfigParams=yes \ --baseUrl="http://dev.magento.local/" buildecho "magento version '${magento_version}' installed." @@ -98,6 +97,7 @@ test_setup_basename="n98-magerun" test_setup_magerun_cmd="bin/${test_setup_basename}" test_setup_directory="./magento/www" test_setup_db_host="127.0.0.1" +test_setup_db_port="${test_setup_db_port:-3306}" test_setup_db_user="root" test_setup_db_pass="" test_setup_db_name="magento_magerun_test" From 5fbd063d68e50f37851fd47602d08c578f0aa00e Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Sat, 7 May 2016 18:40:47 +0200 Subject: [PATCH 08/12] Revert to "codePool" instead of "Code pool" Switching back to original header "codePool" that was fixed in recent revision cd86ca0 - Ref: cd86ca0 - Introducing PR: #816 --- .../Magento/Command/Developer/Module/ListCommand.php | 2 +- src/N98/Magento/Modules.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/N98/Magento/Command/Developer/Module/ListCommand.php b/src/N98/Magento/Command/Developer/Module/ListCommand.php index 4a680ce49..41db5fced 100644 --- a/src/N98/Magento/Command/Developer/Module/ListCommand.php +++ b/src/N98/Magento/Command/Developer/Module/ListCommand.php @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output) /** @var TableHelper $table */ $table = $this->getHelper('table'); $table - ->setHeaders(array('Code pool', 'Name', 'Version', 'Status')) + ->setHeaders(array('codePool', 'Name', 'Version', 'Status')) ->renderByFormat($output, iterator_to_array($modules), $input->getOption('format')); } diff --git a/src/N98/Magento/Modules.php b/src/N98/Magento/Modules.php index d11026dec..724edd15f 100644 --- a/src/N98/Magento/Modules.php +++ b/src/N98/Magento/Modules.php @@ -51,10 +51,10 @@ public function findInstalledModules() $active = isset($moduleInfo['active']) ? $moduleInfo['active'] : ''; $list[] = array( - 'Code pool' => trim($codePool), - 'Name' => trim($moduleName), - 'Version' => trim($version), - 'Status' => StringTyped::formatActive($active), + 'codePool' => trim($codePool), + 'Name' => trim($moduleName), + 'Version' => trim($version), + 'Status' => StringTyped::formatActive($active), ); } @@ -72,7 +72,7 @@ public function filterModules(InputInterface $input) $filtered = $this->list; if ($input->getOption('codepool')) { - $filtered = ArrayFunctions::matrixFilterByValue($filtered, "Code pool", $input->getOption('codepool')); + $filtered = ArrayFunctions::matrixFilterByValue($filtered, "codePool", $input->getOption('codepool')); } if ($input->getOption('status')) { From fe726488c98b8c748e63462b4b388d128b1bb343 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Sat, 7 May 2016 19:06:33 +0200 Subject: [PATCH 09/12] Track changes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb4294483..00c02904f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ RECENT CHANGES 1.97.21 ------- +* Fix: codePool header regression in 1.97.20(reported by Jeroen Boersma) + 1.97.20 ------- From e0069d46cac17e50e49dafcc4fe8b4ccfdf25d4b Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Sat, 7 May 2016 22:12:03 +0200 Subject: [PATCH 10/12] Name invalid URL and limit attemps to three --- src/N98/Magento/Command/Installer/InstallCommand.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/N98/Magento/Command/Installer/InstallCommand.php b/src/N98/Magento/Command/Installer/InstallCommand.php index 6ed6737f6..d21c08993 100644 --- a/src/N98/Magento/Command/Installer/InstallCommand.php +++ b/src/N98/Magento/Command/Installer/InstallCommand.php @@ -660,6 +660,7 @@ protected function removeEmptyFolders() protected function installMagento(InputInterface $input, OutputInterface $output) { $this->getApplication()->setAutoExit(false); + /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ $dialog = $this->getHelperSet()->get('dialog'); $defaults = $this->commandConfig['installation']['defaults']; @@ -754,7 +755,9 @@ protected function installMagento(InputInterface $input, OutputInterface $output $validateBaseUrl = function ($input) { if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $input)) { - throw new InvalidArgumentException('Please enter a valid URL'); + throw new InvalidArgumentException( + sprintf('Invalid URL %s. Please enter a valid URL', var_export($input, true)) + ); } if (parse_url($input, \PHP_URL_HOST) == 'localhost') { throw new InvalidArgumentException( @@ -769,7 +772,7 @@ protected function installMagento(InputInterface $input, OutputInterface $output $output, 'Please enter the base url: ', $validateBaseUrl, - false + 3 ); $baseUrl = rtrim($baseUrl, '/') . '/'; // normalize baseUrl From c925a846d2f14942a47be35beb11d60bec89eb25 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Sun, 8 May 2016 00:40:56 +0200 Subject: [PATCH 11/12] Fix non-interactive parameter validation for install base-url There are many other places where non-interactive mode is not at all supported with magerun commands. This can lead to endless loops when invoked non interactively. --- .../Command/Installer/InstallCommand.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/N98/Magento/Command/Installer/InstallCommand.php b/src/N98/Magento/Command/Installer/InstallCommand.php index d21c08993..651ed21bc 100644 --- a/src/N98/Magento/Command/Installer/InstallCommand.php +++ b/src/N98/Magento/Command/Installer/InstallCommand.php @@ -768,12 +768,18 @@ protected function installMagento(InputInterface $input, OutputInterface $output return $input; }; - $baseUrl = ($input->getOption('baseUrl') !== null) ? $input->getOption('baseUrl') : $dialog->askAndValidate( - $output, - 'Please enter the base url: ', - $validateBaseUrl, - 3 - ); + $baseUrl = $input->getOption('baseUrl'); + if (null === $baseUrl) { + if (!$input->isInteractive()) { + throw new InvalidArgumentException('Installation base url is mandatory, use --baseUrl.'); + } + $baseUrl = $dialog->askAndValidate( + $output, + 'Please enter the base url: ', + $validateBaseUrl + ); + } + $validateBaseUrl($baseUrl); $baseUrl = rtrim($baseUrl, '/') . '/'; // normalize baseUrl /** From 3a64839a4479401c7c036c8a554bad72f8b6e099 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Sun, 8 May 2016 01:11:52 +0200 Subject: [PATCH 12/12] Improve database already exists install error message --- .../Command/Installer/InstallCommand.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/N98/Magento/Command/Installer/InstallCommand.php b/src/N98/Magento/Command/Installer/InstallCommand.php index 651ed21bc..587fc70a0 100644 --- a/src/N98/Magento/Command/Installer/InstallCommand.php +++ b/src/N98/Magento/Command/Installer/InstallCommand.php @@ -505,19 +505,23 @@ protected function validateDatabaseSettings(OutputInterface $output, InputInterf return $db; } - - if ($input->getOption('noDownload') && !$input->getOption('forceUseDb')) { - $output->writeln("Database {$this->config['db_name']} already exists."); - - return false; - } - - return $db; } catch (PDOException $e) { $output->writeln('' . $e->getMessage() . ''); + return false; + } + + if ($input->getOption('noDownload') && !$input->getOption('forceUseDb')) { + $output->writeln( + sprintf( + "Database '%s' already exists, use --forceUseDb in combination with --noDownload" . + " to use an existing database", + $this->config['db_name'] + ) + ); + return false; } - return false; + return $db; } /**