From d8ce76f2bcafd76dae6490e964ab9bd917e4fe33 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 31 Jul 2024 07:13:38 +0200 Subject: [PATCH] getDatabaseHelper() --- src/N98/Magento/Command/AbstractMagentoCommand.php | 9 +++++++++ .../Command/Database/AbstractDatabaseCommand.php | 11 +---------- .../Magento/Command/Database/AbstractShowCommand.php | 4 +--- src/N98/Magento/Command/Database/ConsoleCommand.php | 5 +---- src/N98/Magento/Command/Database/CreateCommand.php | 2 +- src/N98/Magento/Command/Database/DropCommand.php | 4 +--- src/N98/Magento/Command/Database/DumpCommand.php | 6 +----- src/N98/Magento/Command/Database/ImportCommand.php | 2 +- src/N98/Magento/Command/Database/InfoCommand.php | 4 +--- .../Command/Database/Maintain/CheckTablesCommand.php | 2 +- src/N98/Magento/Command/Database/QueryCommand.php | 3 +-- .../Command/Developer/Code/Model/MethodCommand.php | 4 +--- .../Command/Developer/Translate/ExportCommand.php | 4 +--- .../Installer/SubCommand/InstallSampleData.php | 5 +---- 14 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/N98/Magento/Command/AbstractMagentoCommand.php b/src/N98/Magento/Command/AbstractMagentoCommand.php index 889e73e8a..60ff7c702 100644 --- a/src/N98/Magento/Command/AbstractMagentoCommand.php +++ b/src/N98/Magento/Command/AbstractMagentoCommand.php @@ -14,6 +14,7 @@ use N98\Magento\Application; use N98\Magento\Command\SubCommand\ConfigBag; use N98\Magento\Command\SubCommand\SubCommandFactory; +use N98\Util\Console\Helper\DatabaseHelper; use N98\Util\Console\Helper\IoHelper; use N98\Util\Console\Helper\MagentoHelper; use N98\Util\Console\Helper\ParameterHelper; @@ -692,6 +693,14 @@ public function addFormatOption(): self return $this; } + /** + * @return DatabaseHelper + */ + public function getDatabaseHelper(): DatabaseHelper + { + return $this->getHelper('database'); + } + /** * @return IoHelper */ diff --git a/src/N98/Magento/Command/Database/AbstractDatabaseCommand.php b/src/N98/Magento/Command/Database/AbstractDatabaseCommand.php index 0fb8cb190..411bf49d7 100644 --- a/src/N98/Magento/Command/Database/AbstractDatabaseCommand.php +++ b/src/N98/Magento/Command/Database/AbstractDatabaseCommand.php @@ -6,7 +6,6 @@ use N98\Magento\Command\Database\Compressor\AbstractCompressor; use N98\Magento\Command\Database\Compressor\Compressor; use N98\Magento\DbSettings; -use N98\Util\Console\Helper\DatabaseHelper; use Symfony\Component\Console\Output\OutputInterface; /** @@ -99,14 +98,6 @@ protected function _dsn() return $this->getDatabaseHelper()->dsn(); } - /** - * @return DatabaseHelper - */ - protected function getDatabaseHelper() - { - return $this->getHelper('database'); - } - /** * @param array $excludes * @param array $definitions @@ -118,6 +109,6 @@ protected function getDatabaseHelper() */ protected function resolveTables(array $excludes, array $definitions, array $resolved = []) { - return $this->getHelper('database')->resolveTables($excludes, $definitions, $resolved); + return $this->getDatabaseHelper()->resolveTables($excludes, $definitions, $resolved); } } diff --git a/src/N98/Magento/Command/Database/AbstractShowCommand.php b/src/N98/Magento/Command/Database/AbstractShowCommand.php index 23a54cc24..46a59a3bb 100644 --- a/src/N98/Magento/Command/Database/AbstractShowCommand.php +++ b/src/N98/Magento/Command/Database/AbstractShowCommand.php @@ -3,7 +3,6 @@ namespace N98\Magento\Command\Database; use Description; -use N98\Util\Console\Helper\DatabaseHelper; use N98\Util\Filesystem; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -173,8 +172,7 @@ protected function renderTable(array $header, array $rows) */ protected function initVariables($variable = null) { - /** @var DatabaseHelper $database */ - $database = $this->getHelper('database'); + $database = $this->getDatabaseHelper(); $this->_allVariables = $database->{$this->showMethod}($variable); } diff --git a/src/N98/Magento/Command/Database/ConsoleCommand.php b/src/N98/Magento/Command/Database/ConsoleCommand.php index 9da04fcbc..eaf940bf9 100644 --- a/src/N98/Magento/Command/Database/ConsoleCommand.php +++ b/src/N98/Magento/Command/Database/ConsoleCommand.php @@ -2,7 +2,6 @@ namespace N98\Magento\Command\Database; -use N98\Util\Console\Helper\DatabaseHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -79,9 +78,7 @@ private function processCommand($command) */ private function getMysqlClientToolConnection() { - /* @var DatabaseHelper $database */ - $database = $this->getHelper('database'); - + $database = $this->getDatabaseHelper(); return $database->getMysqlClientToolConnectionString(); } } diff --git a/src/N98/Magento/Command/Database/CreateCommand.php b/src/N98/Magento/Command/Database/CreateCommand.php index 75b089b32..d5fe0af1f 100644 --- a/src/N98/Magento/Command/Database/CreateCommand.php +++ b/src/N98/Magento/Command/Database/CreateCommand.php @@ -39,7 +39,7 @@ public function getHelp(): string */ protected function execute(InputInterface $input, OutputInterface $output): int { - $this->getHelper('database')->createDatabase($output); + $this->getDatabaseHelper()->createDatabase($output); return 0; } } diff --git a/src/N98/Magento/Command/Database/DropCommand.php b/src/N98/Magento/Command/Database/DropCommand.php index 32b106ecd..d0f35dd9a 100644 --- a/src/N98/Magento/Command/Database/DropCommand.php +++ b/src/N98/Magento/Command/Database/DropCommand.php @@ -2,7 +2,6 @@ namespace N98\Magento\Command\Database; -use N98\Util\Console\Helper\DatabaseHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -48,8 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->detectDbSettings($output); $dialog = $this->getQuestionHelper(); - /** @var DatabaseHelper $dbHelper */ - $dbHelper = $this->getHelper('database'); + $dbHelper = $this->getDatabaseHelper(); if ($input->getOption('force')) { $shouldDrop = true; diff --git a/src/N98/Magento/Command/Database/DumpCommand.php b/src/N98/Magento/Command/Database/DumpCommand.php index 6f6bcb903..ea7c32ab6 100644 --- a/src/N98/Magento/Command/Database/DumpCommand.php +++ b/src/N98/Magento/Command/Database/DumpCommand.php @@ -5,10 +5,8 @@ use InvalidArgumentException; use N98\Magento\Command\Database\Compressor\Compressor; use N98\Util\Console\Enabler; -use N98\Util\Console\Helper\DatabaseHelper; use N98\Util\Exec; use N98\Util\VerifyOrDie; -use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -183,9 +181,7 @@ private function getTableDefinitions() $this->commandConfig = $this->getCommandConfig(); if (is_null($this->tableDefinitions)) { - /* @var DatabaseHelper $dbHelper */ - $dbHelper = $this->getHelper('database'); - + $dbHelper = $this->getDatabaseHelper(); $this->tableDefinitions = $dbHelper->getTableDefinitions($this->commandConfig); } diff --git a/src/N98/Magento/Command/Database/ImportCommand.php b/src/N98/Magento/Command/Database/ImportCommand.php index 8cbc1258f..d45ecfd7a 100644 --- a/src/N98/Magento/Command/Database/ImportCommand.php +++ b/src/N98/Magento/Command/Database/ImportCommand.php @@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->detectDbSettings($output); $this->writeSection($output, 'Import MySQL Database'); - $dbHelper = $this->getHelper('database'); + $dbHelper = $this->getDatabaseHelper(); $fileName = $this->checkFilename($input); diff --git a/src/N98/Magento/Command/Database/InfoCommand.php b/src/N98/Magento/Command/Database/InfoCommand.php index c0eb5ad10..c225e10f8 100644 --- a/src/N98/Magento/Command/Database/InfoCommand.php +++ b/src/N98/Magento/Command/Database/InfoCommand.php @@ -3,7 +3,6 @@ namespace N98\Magento\Command\Database; use InvalidArgumentException; -use N98\Util\Console\Helper\DatabaseHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -91,8 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $settings['JDBC-Connection-String'] = $jdbcConnectionString; - /* @var DatabaseHelper $database */ - $database = $this->getHelper('database'); + $database = $this->getDatabaseHelper(); $mysqlCliString = 'mysql ' . $database->getMysqlClientToolConnectionString(); $settings['MySQL-Cli-String'] = $mysqlCliString; diff --git a/src/N98/Magento/Command/Database/Maintain/CheckTablesCommand.php b/src/N98/Magento/Command/Database/Maintain/CheckTablesCommand.php index 9cbf4b498..9f9b90aa2 100644 --- a/src/N98/Magento/Command/Database/Maintain/CheckTablesCommand.php +++ b/src/N98/Magento/Command/Database/Maintain/CheckTablesCommand.php @@ -137,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->output = $output; $this->isTypeAllowed(); $this->detectMagento($output); - $this->dbHelper = $this->getHelper('database'); + $this->dbHelper = $this->getDatabaseHelper(); $this->showProgress = $input->getOption('format') == null; if ($input->getOption('table')) { diff --git a/src/N98/Magento/Command/Database/QueryCommand.php b/src/N98/Magento/Command/Database/QueryCommand.php index a336bc42b..5af63a4ad 100644 --- a/src/N98/Magento/Command/Database/QueryCommand.php +++ b/src/N98/Magento/Command/Database/QueryCommand.php @@ -77,8 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $query = $this->getOrAskForArgument('query', $input, $output, 'SQL Query'); - /** @var \N98\Util\Console\Helper\DatabaseHelper $helper */ - $helper = $this->getHelper('database'); + $helper = $this->getDatabaseHelper(); $exec = sprintf('mysql %s -e %s', $helper->getMysqlClientToolConnectionString(), escapeshellarg($query)); if ($input->getOption('only-command')) { diff --git a/src/N98/Magento/Command/Developer/Code/Model/MethodCommand.php b/src/N98/Magento/Command/Developer/Code/Model/MethodCommand.php index 0e264b3d4..dc8d37a8b 100644 --- a/src/N98/Magento/Command/Developer/Code/Model/MethodCommand.php +++ b/src/N98/Magento/Command/Developer/Code/Model/MethodCommand.php @@ -164,9 +164,7 @@ protected function getColumnType($columnType) */ protected function initTableColumns() { - $dbHelper = $this->getHelper('database'); - /* @var \N98\Util\Console\Helper\DatabaseHelper $dbHelper */ - /** @var PDO $connection */ + $dbHelper = $this->getDatabaseHelper(); $connection = $dbHelper->getConnection($this->_output); $stmt = $connection->query('SHOW COLUMNS FROM ' . $this->_mageModelTable, PDO::FETCH_ASSOC); foreach ($stmt as $row) { diff --git a/src/N98/Magento/Command/Developer/Translate/ExportCommand.php b/src/N98/Magento/Command/Developer/Translate/ExportCommand.php index b7e7f1b2e..ae2a7bfe2 100644 --- a/src/N98/Magento/Command/Developer/Translate/ExportCommand.php +++ b/src/N98/Magento/Command/Developer/Translate/ExportCommand.php @@ -5,7 +5,6 @@ use Locale; use Mage; use N98\Magento\Command\AbstractMagentoCommand; -use N98\Util\Console\Helper\DatabaseHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -41,8 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - /** @var DatabaseHelper $helper */ - $helper = $this->getHelper('database'); + $helper = $this->getDatabaseHelper(); $db = $helper->getConnection(); $filename = $input->getArgument('filename'); diff --git a/src/N98/Magento/Command/Installer/SubCommand/InstallSampleData.php b/src/N98/Magento/Command/Installer/SubCommand/InstallSampleData.php index d13958677..c231998fb 100644 --- a/src/N98/Magento/Command/Installer/SubCommand/InstallSampleData.php +++ b/src/N98/Magento/Command/Installer/SubCommand/InstallSampleData.php @@ -3,11 +3,9 @@ namespace N98\Magento\Command\Installer\SubCommand; use N98\Magento\Command\SubCommand\AbstractSubCommand; -use N98\Util\Console\Helper\DatabaseHelper; use N98\Util\Database; use N98\Util\Exec; use N98\Util\Filesystem; -use N98\Util\OperatingSystem; use N98\Util\StringTyped; use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Process\Process; @@ -119,8 +117,7 @@ private function installSampleData(array $demoPackageData): void $this->config['installationFolder'] . '/magento_*sample_data*sql' ); - /** @var DatabaseHelper $dbHelper */ - $dbHelper = $this->command->getHelper('database'); + $dbHelper = $this->command->getDatabaseHelper(); if (isset($sampleDataSqlFile[0])) { $this->output->writeln('Import sample data db data');