From 79451c09b14c49271ea040cd5e774055a9899cac Mon Sep 17 00:00:00 2001 From: Nicolas Moncada Date: Mon, 21 Dec 2015 18:21:35 -0300 Subject: [PATCH] #1542 implement DrupalStyle class in Update commands --- src/Command/Update/DebugCommand.php | 86 +++++++++++---------------- src/Command/Update/ExecuteCommand.php | 43 ++++---------- 2 files changed, 44 insertions(+), 85 deletions(-) diff --git a/src/Command/Update/DebugCommand.php b/src/Command/Update/DebugCommand.php index c0a54b9ba..e518d80e9 100644 --- a/src/Command/Update/DebugCommand.php +++ b/src/Command/Update/DebugCommand.php @@ -9,8 +9,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Helper\Table; use Drupal\Console\Command\ContainerAwareCommand; +use Drupal\Console\Style\DrupalStyle; class DebugCommand extends ContainerAwareCommand { @@ -23,8 +23,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $table = new Table($output); - $table->setStyle('compact'); + $io = new DrupalStyle($input, $output); $this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc'); $this->getDrupalHelper()->loadLegacyFile('/core/includes/install.inc'); @@ -37,75 +36,58 @@ protected function execute(InputInterface $input, OutputInterface $output) $severity = drupal_requirements_severity($requirements); if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING)) { - $output->writeln( - '[-] ' . - $this->trans('commands.update.debug.messages.requirements-error') - . '' - ); - - $table->setHeaders( - [ - $this->trans('commands.update.debug.messages.severity'), - $this->trans('commands.update.debug.messages.title'), - $this->trans('commands.update.debug.messages.value'), - $this->trans('commands.update.debug.messages.description') - ] - ); + $io->info($this->trans('commands.update.debug.messages.requirements-error')); + $tableHeader = [ + $this->trans('commands.update.debug.messages.severity'), + $this->trans('commands.update.debug.messages.title'), + $this->trans('commands.update.debug.messages.value'), + $this->trans('commands.update.debug.messages.description'), + ]; + + $tableRows = []; foreach ($requirements as $requirement) { if (isset($requirement['minimum schema']) & in_array($requirement['minimum schema'], array(REQUIREMENT_ERROR, REQUIREMENT_WARNING))) { - $table->addRow( - [ - $requirement['severity'], - $requirement['title'], - $requirement['value'], - $requirement['description'] - ] - ); + $tableRows[] = [ + $requirement['severity'], + $requirement['title'], + $requirement['value'], + $requirement['description'], + ]; } } - $table->render(); + $io->table($tableHeader, $tableRows, 'compact'); + return; } if (empty($updates)) { - $output->writeln( - '[-] ' . - $this->trans('commands.update.debug.messages.no-updates') - . '' - ); + $io->info($this->trans('commands.update.debug.messages.no-updates')); + return; } - $table->setHeaders( - [ - $this->trans('commands.update.debug.messages.module'), - $this->trans('commands.update.debug.messages.update-n'), - $this->trans('commands.update.debug.messages.description') - ] - ); - - $output->writeln( - ''. - $this->trans('commands.update.debug.messages.module-list') - .'' - ); + $tableHeader = [ + $this->trans('commands.update.debug.messages.module'), + $this->trans('commands.update.debug.messages.update-n'), + $this->trans('commands.update.debug.messages.description') + ]; + $io->info($this->trans('commands.update.debug.messages.module-list')); + $tableRows = []; foreach ($updates as $module => $module_updates) { foreach ($module_updates['pending'] as $update_n => $update) { list(, $description) = explode($update_n . " - ", $update); - $table->addRow( - [ - $module, - $update_n, - trim($description) - ] - ); + $tableRows[] = [ + $module, + $update_n, + trim($description), + ]; } } - $table->render(); + $io->table($tableHeader, $tableRows, 'compact'); } } diff --git a/src/Command/Update/ExecuteCommand.php b/src/Command/Update/ExecuteCommand.php index 0b668e381..b4301654e 100644 --- a/src/Command/Update/ExecuteCommand.php +++ b/src/Command/Update/ExecuteCommand.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Drupal\Console\Command\ContainerAwareCommand; +use Drupal\Console\Style\DrupalStyle; class ExecuteCommand extends ContainerAwareCommand { @@ -25,6 +26,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $io = new DrupalStyle($input, $output); + $this->getDrupalHelper()->loadLegacyFile('/core/includes/install.inc'); $this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc'); @@ -39,13 +42,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $updates = update_get_update_list(); if ($module != 'all') { if (!isset($updates[$module])) { - $output->writeln( - '[-] ' . - sprintf( + $io->error(sprintf( $this->trans('commands.update.execute.messages.no-module-updates'), $module ) - . '' ); return; } else { @@ -53,25 +53,17 @@ protected function execute(InputInterface $input, OutputInterface $output) $updates = [$module => $updates[$module]]; if ($update_n && !isset($updates[$module]['pending'][$update_n])) { - $output->writeln( - '[-] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.update.execute.messages.module-update-function-not-found'), $module, $update_n ) - . '' ); } } } - - $output->writeln( - '[-] ' . - $this->trans('commands.site.maintenance.description') - . '' - ); + $io->info($this->trans('commands.site.maintenance.description')); \Drupal::state()->set('system.maintenance_mode', true); foreach ($updates as $module_name => $module_updates) { @@ -82,32 +74,21 @@ protected function execute(InputInterface $input, OutputInterface $output) //Executing all pending updates if ($update_n > $module_updates['start']) { - $output->writeln( - '[-] ' . - $this->trans('commands.update.execute.messages.executing-required-previous-updates') - . '' - ); + $io->info($this->trans('commands.update.execute.messages.executing-required-previous-updates')); } for ($update_index=$module_updates['start']; $update_index<=$update_number; $update_index++) { - $output->writeln( - '[-] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name ) - . '' ); try { $module_handler->invoke($module_name, 'update_' . $update_index); } catch (\Exception $e) { watchdog_exception('update', $e); - $output->writeln( - '' . - $e->getMessage() . - '' - ); + $io->error($e->getMessage()); } //Update module schema version @@ -117,11 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } \Drupal::state()->set('system.maintenance_mode', false); - $output->writeln( - '[-] ' . - $this->trans('commands.site.maintenance.messages.maintenance-off') - . '' - ); + $io->info($this->trans('commands.site.maintenance.messages.maintenance-off')); $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); }