From 36cd2bb5ae3f56078de3a5efe03324d7f98b1d0b Mon Sep 17 00:00:00 2001 From: mnico Date: Sun, 20 Dec 2015 20:41:55 -0500 Subject: [PATCH 1/2] #1542 implement DrupalStyle class in [theme:download] command --- src/Command/Theme/DownloadCommand.php | 41 +++++++++++---------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/Command/Theme/DownloadCommand.php b/src/Command/Theme/DownloadCommand.php index 0d122e1f1..170789974 100644 --- a/src/Command/Theme/DownloadCommand.php +++ b/src/Command/Theme/DownloadCommand.php @@ -14,6 +14,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Drupal\Console\Command\Command; use Alchemy\Zippy\Zippy; +use Drupal\Console\Style\DrupalStyle; class DownloadCommand extends Command { @@ -28,6 +29,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $io = new DrupalStyle($input, $output); $httpClient = $this->getHttpClientHelper(); $theme = $input->getArgument('theme'); @@ -38,17 +40,16 @@ protected function execute(InputInterface $input, OutputInterface $output) $release_selected = $version; } else { // Getting Theme page header and parse to get theme Node - $output->writeln( - '[+] '.sprintf( + $io->info(sprintf( $this->trans('commands.theme.download.messages.getting-releases'), implode(',', array($theme)) - ).'' + ) ); try { $link = $httpClient->getHeader('https://www.drupal.org/project/'.$theme, 'link'); } catch (\Exception $e) { - $output->writeln('[+] ' . $e->getMessage() . ''); + $io->error($e->getMessage()); return; } @@ -60,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $html = $httpClient->getHtml($project_release_d8); } catch (\Exception $e) { - $output->writeln('[+] '.$e->getMessage().''); + $io->error($e->getMessage()); return; } @@ -83,11 +84,10 @@ protected function execute(InputInterface $input, OutputInterface $output) } if (empty($releases)) { - $output->writeln( - '[+] '.sprintf( + $io->error(sprintf( $this->trans('commands.theme.download.messages.no-releases'), implode(',', array($theme)) - ).'' + ) ); return; @@ -106,14 +106,11 @@ protected function execute(InputInterface $input, OutputInterface $output) } // Start the process to download the zip file of release and copy in contrib folter - $output->writeln( - '[-] '. - sprintf( + $io->info(sprintf( $this->trans('commands.theme.download.messages.downloading'), $theme, $release_selected - ). - '' + ) ); $release_file_path = 'http://ftp.drupal.org/files/projects/'.$theme.'-'.$release_selected.'.tar.gz'; @@ -130,14 +127,11 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($drupalRoot) { $theme_contrib_path = $drupalRoot . '/themes/contrib'; } else { - $output->writeln( - '[-] '. - sprintf( + $io->info(sprintf( $this->trans('commands.theme.download.messages.outside-drupal'), $theme, $release_selected - ). - '' + ) ); $theme_contrib_path = getcwd() . '/themes/contrib'; } @@ -145,9 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Create directory if does not exist if (!file_exists($theme_contrib_path)) { if (!mkdir($theme_contrib_path, 0777, true)) { - $output->writeln( - ' '. $this->trans('commands.theme.download.messages.error-creating-folder') . ': ' . $theme_contrib_path .'' - ); + $io->error($this->trans('commands.theme.download.messages.error-creating-folder') . ': ' . $theme_contrib_path); return; } } @@ -159,16 +151,15 @@ protected function execute(InputInterface $input, OutputInterface $output) unlink($destination); - $output->writeln( - '[-] '.sprintf( + $io->info(sprintf( $this->trans('commands.theme.download.messages.downloaded'), $theme, $release_selected, $theme_contrib_path - ).'' + ) ); } catch (\Exception $e) { - $output->writeln('[+] '.$e->getMessage().''); + $io->error($e->getMessage()); return; } From 72d477181e708e8833d1dbf8de8ed5a1abd67be3 Mon Sep 17 00:00:00 2001 From: Nicolas Moncada Date: Mon, 21 Dec 2015 14:40:45 -0300 Subject: [PATCH 2/2] #1542 implement DrupalStyle class in [theme:debug], [theme:install] and [theme:uninstall] commands --- src/Command/Theme/DebugCommand.php | 85 +++++++++++++------------- src/Command/Theme/InstallCommand.php | 54 +++++----------- src/Command/Theme/UninstallCommand.php | 53 +++++----------- 3 files changed, 70 insertions(+), 122 deletions(-) diff --git a/src/Command/Theme/DebugCommand.php b/src/Command/Theme/DebugCommand.php index 968a409f2..a001958c1 100644 --- a/src/Command/Theme/DebugCommand.php +++ b/src/Command/Theme/DebugCommand.php @@ -10,8 +10,8 @@ use Symfony\Component\Console\Input\InputArgument; 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 { @@ -25,41 +25,41 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $theme = $input->getArgument('theme'); + $io = new DrupalStyle($input, $output); - $table = new Table($output); - $table->setStyle('compact'); + $theme = $input->getArgument('theme'); if ($theme) { - $this->getTheme($theme, $output, $table); + $this->getTheme($theme, $io); } else { - $this->getAllThemes($output, $table); + $this->getAllThemes($io); } } - protected function getAllThemes($output, $table) + protected function getAllThemes(DrupalStyle $io) { - $table->setHeaders( - [ - $this->trans('commands.theme.debug.messages.theme-id'), - $this->trans('commands.theme.debug.messages.theme-name'), - $this->trans('commands.theme.debug.messages.status'), - $this->trans('commands.theme.debug.messages.version'), - ] - ); + $tableHeader = [ + $this->trans('commands.theme.debug.messages.theme-id'), + $this->trans('commands.theme.debug.messages.theme-name'), + $this->trans('commands.theme.debug.messages.status'), + $this->trans('commands.theme.debug.messages.version'), + ]; $themes = $this->getThemeHandler()->rebuildThemeData(); - + $tableRows = []; foreach ($themes as $themeId => $theme) { $status = $this->getThemeStatus($themeId); - $table->addRow([$themeId, $theme->info['name'], $status, $theme->info['version']]); + $tableRows[] = [ + $themeId, $theme->info['name'], + $status, $theme->info['version'], + ]; } - $table->render(); + + $io->table($tableHeader, $tableRows, 'compact'); } - protected function getTheme($themeId, $output, $table) + protected function getTheme($themeId, $io) { $theme = null; - $message = $this->getMessageHelper(); $themes = $this->getThemeHandler()->rebuildThemeData(); if (isset($themes[$themeId])) { @@ -78,35 +78,31 @@ protected function getTheme($themeId, $output, $table) $theme = $themes[$themeId]; $status = $this->getThemeStatus($themeId); - $table->setHeaders( + $tableHeader = [ + $this->trans('commands.theme.debug.messages.theme-id'), + $this->trans('commands.theme.debug.messages.theme-properties'), + ]; + $tableRows = [ [ - $this->trans('commands.theme.debug.messages.theme-id'), - $this->trans('commands.theme.debug.messages.theme-properties'), - ] - ); - - $table->addRow(['' . $theme->info['name'] . '']); - $table->addRow( + '' . $theme->info['name'] . '', + ], [ ' + ' . $this->trans('commands.theme.debug.messages.status') . '', $status, - ] - ); - - $table->addRow( + ], [ ' + ' . $this->trans('commands.theme.debug.messages.version') . '', $theme->info['version'], + ], + [ + ' + ' . $this->trans('commands.theme.debug.messages.regions') . '', ] - ); - - $table->addRow([' + ' . $this->trans('commands.theme.debug.messages.regions') . '']); - $table = $this->addThemeAttributes($theme->info['regions'], $table); + ]; + $tableRows = $this->addThemeAttributes($theme->info['regions'], $tableRows); - $table->render(); + $io->table($tableHeader, $tableRows, 'compact'); } else { - $message->addErrorMessage( - sprintf( + $io->error(sprintf( $this->trans('commands.theme.debug.messages.invalid-theme'), $themeId ) @@ -127,16 +123,19 @@ protected function getThemeStatus($theme) return $status; } - protected function addThemeAttributes($attr, $table) + protected function addThemeAttributes($attr, $tableRows) { foreach ($attr as $key => $value) { if (is_array($value)) { - $table = $this->addThemeAttributes($value, $table); + $tableRows = $this->addThemeAttributes($value, $tableRows); } else { - $table->addRow([' - '.$key, $value]); + $tableRows[] = [ + ' - '.$key, + $value, + ]; } } - return $table; + return $tableRows; } } diff --git a/src/Command/Theme/InstallCommand.php b/src/Command/Theme/InstallCommand.php index a73714475..9b9b49261 100644 --- a/src/Command/Theme/InstallCommand.php +++ b/src/Command/Theme/InstallCommand.php @@ -38,7 +38,7 @@ protected function configure() */ protected function interact(InputInterface $input, OutputInterface $output) { - $output = new DrupalStyle($input, $output); + $io = new DrupalStyle($input, $output); $theme = $input->getArgument('theme'); @@ -59,10 +59,10 @@ protected function interact(InputInterface $input, OutputInterface $output) $theme_list[$theme_id] = $theme->getName(); } - $output->writeln('[+] '.$this->trans('commands.theme.install.messages.disabled-themes').''); + $io->info($this->trans('commands.theme.install.messages.disabled-themes')); while (true) { - $theme_name = $output->choiceNoList( + $theme_name = $io->choiceNoList( $this->trans('commands.theme.install.questions.theme'), array_keys($theme_list) ); @@ -84,6 +84,8 @@ protected function interact(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output) { + $io = new DrupalStyle($input, $output); + $configFactory = $this->getConfigFactory(); $config = $configFactory->getEditable('system.theme'); @@ -94,10 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $default = $input->getOption('set-default'); if ($default && count($theme) > 1) { - $output->writeln( - '[-] ' . $this->trans('commands.theme.install.messages.invalid-theme-default') - .'' - ); + $io->error($this->trans('commands.theme.install.messages.invalid-theme-default')); return; } @@ -122,88 +121,63 @@ protected function execute(InputInterface $input, OutputInterface $output) try { if ($themeHandler->install($theme)) { if (count($themesAvailable) > 1) { - $output->writeln( - '[+] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.install.messages.themes-success'), implode(',', $themesAvailable) ) - . '' ); } else { if ($default) { // Set the default theme. $config->set('default', $theme[0])->save(); - $output->writeln( - '[+] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.install.messages.theme-default-success'), $themesAvailable[0] ) - . '' ); } else { - $output->writeln( - '[+] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.install.messages.theme-success'), $themesAvailable[0] ) - . '' ); } } } } catch (UnmetDependenciesException $e) { - print 'error3'; - $output->writeln( - '[+] '. - sprintf( + $io->error(sprintf( $this->trans('commands.theme.install.messages.success'), $theme ) - .'' ); drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $theme), 'error'); } } elseif (empty($themesAvailable) && count($themesInstalled) > 0) { if (count($themesInstalled) > 1) { - $output->writeln( - '[-] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.install.messages.themes-nothing'), implode(',', $themesInstalled) ) - . '' ); } else { - $output->writeln( - '[-] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.install.messages.theme-nothing'), implode(',', $themesInstalled) ) - . '' ); } } else { if (count($themesUnavailable) > 1) { - $output->writeln( - '[-] ' . - sprintf( + $io->error(sprintf( $this->trans('commands.theme.install.messages.themes-missing'), implode(',', $themesUnavailable) ) - . '' ); } else { - $output->writeln( - '[-] ' . - sprintf( + $io->error(sprintf( $this->trans('commands.theme.install.messages.theme-missing'), implode(',', $themesUnavailable) ) - . '' ); } } diff --git a/src/Command/Theme/UninstallCommand.php b/src/Command/Theme/UninstallCommand.php index 32f3ebd61..244b04705 100644 --- a/src/Command/Theme/UninstallCommand.php +++ b/src/Command/Theme/UninstallCommand.php @@ -31,7 +31,7 @@ protected function configure() */ protected function interact(InputInterface $input, OutputInterface $output) { - $output = new DrupalStyle($input, $output); + $io = new DrupalStyle($input, $output); $theme = $input->getArgument('theme'); @@ -51,10 +51,10 @@ protected function interact(InputInterface $input, OutputInterface $output) $theme_list[$theme_id] = $theme->getName(); } - $output->writeln('[+] '.$this->trans('commands.theme.uninstall.messages.installed-themes').''); + $io->info($this->trans('commands.theme.uninstall.messages.installed-themes')); while (true) { - $theme_name = $output->choiceNoList( + $theme_name = $io->choiceNoList( $this->trans('commands.theme.uninstall.questions.theme'), array_keys($theme_list) ); @@ -76,6 +76,8 @@ protected function interact(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output) { + $io = new DrupalStyle($input, $output); + $configFactory = $this->getConfigFactory(); $config = $configFactory->getEditable('system.theme'); @@ -102,26 +104,20 @@ protected function execute(InputInterface $input, OutputInterface $output) try { foreach ($themesAvailable as $themeKey => $themeName) { if ($themeKey === $config->get('default')) { - $output->writeln( - '[+] ' . - sprintf( + $io->error(sprintf( $this->trans('commands.theme.uninstall.messages.error-default-theme'), implode(',', $themesAvailable) ) - . '' ); return; } if ($themeKey === $config->get('admin')) { - $output->writeln( - '[+] ' . - sprintf( + $io->error(sprintf( $this->trans('commands.theme.uninstall.messages.error-admin-theme'), implode(',', $themesAvailable) ) - . '' ); return; } @@ -130,73 +126,52 @@ protected function execute(InputInterface $input, OutputInterface $output) $themeHandler->uninstall($theme); if (count($themesAvailable) > 1) { - $output->writeln( - '[+] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.uninstall.messages.themes-success'), implode(',', $themesAvailable) ) - . '' ); } else { - $output->writeln( - '[+] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.uninstall.messages.theme-success'), array_shift($themesAvailable) ) - . '' ); } } catch (UnmetDependenciesException $e) { - $output->writeln( - '[+] '. - sprintf( + $io->error(sprintf( $this->trans('commands.theme.uninstall.messages.dependencies'), $e->getMessage() ) - .'' ); drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $theme), 'error'); } } elseif (empty($themesAvailable) && count($themesUninstalled) > 0) { if (count($themesUninstalled) > 1) { - $output->writeln( - '[-] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.uninstall.messages.themes-nothing'), implode(',', $themesUninstalled) ) - . '' ); } else { - $output->writeln( - '[-] ' . - sprintf( + $io->info(sprintf( $this->trans('commands.theme.uninstall.messages.theme-nothing'), implode(',', $themesUninstalled) ) - . '' ); } } else { if (count($themesUnavailable) > 1) { - $output->writeln( - '[-] ' . - sprintf( + $io->error(sprintf( $this->trans('commands.theme.uninstall.messages.themes-missing'), implode(',', $themesUnavailable) ) - . '' ); } else { - $output->writeln( - '[-] ' . - sprintf( + $io->error(sprintf( $this->trans('commands.theme.uninstall.messages.theme-missing'), implode(',', $themesUnavailable) ) - . '' ); } }