Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[theme:debug] Implement DrupalStyle #1547

Merged
merged 2 commits into from
Dec 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 42 additions & 43 deletions src/Command/Theme/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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])) {
Expand All @@ -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(['<info>' . $theme->info['name'] . '</info>']);
$table->addRow(
'<info>' . $theme->info['name'] . '</info>',
],
[
' <comment>+ ' . $this->trans('commands.theme.debug.messages.status') . '</comment>',
$status,
]
);

$table->addRow(
],
[
' <comment>+ ' . $this->trans('commands.theme.debug.messages.version') . '</comment>',
$theme->info['version'],
],
[
' <comment>+ ' . $this->trans('commands.theme.debug.messages.regions') . '</comment>',
]
);

$table->addRow([' <comment>+ ' . $this->trans('commands.theme.debug.messages.regions') . '</comment>']);
$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
)
Expand All @@ -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([' <comment>- </comment>'.$key, $value]);
$tableRows[] = [
' <comment>- </comment>'.$key,
$value,
];
}
}

return $table;
return $tableRows;
}
}
41 changes: 16 additions & 25 deletions src/Command/Theme/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
Expand All @@ -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(
'[+] <info>'.sprintf(
$io->info(sprintf(
$this->trans('commands.theme.download.messages.getting-releases'),
implode(',', array($theme))
).'</info>'
)
);

try {
$link = $httpClient->getHeader('https://www.drupal.org/project/'.$theme, 'link');
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
$io->error($e->getMessage());
return;
}

Expand All @@ -60,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$html = $httpClient->getHtml($project_release_d8);
} catch (\Exception $e) {
$output->writeln('[+] <error>'.$e->getMessage().'</error>');
$io->error($e->getMessage());

return;
}
Expand All @@ -83,11 +84,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (empty($releases)) {
$output->writeln(
'[+] <error>'.sprintf(
$io->error(sprintf(
$this->trans('commands.theme.download.messages.no-releases'),
implode(',', array($theme))
).'</error>'
)
);

return;
Expand All @@ -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(
'[-] <info>'.
sprintf(
$io->info(sprintf(
$this->trans('commands.theme.download.messages.downloading'),
$theme,
$release_selected
).
'</info>'
)
);

$release_file_path = 'http://ftp.drupal.org/files/projects/'.$theme.'-'.$release_selected.'.tar.gz';
Expand All @@ -130,24 +127,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($drupalRoot) {
$theme_contrib_path = $drupalRoot . '/themes/contrib';
} else {
$output->writeln(
'[-] <info>'.
sprintf(
$io->info(sprintf(
$this->trans('commands.theme.download.messages.outside-drupal'),
$theme,
$release_selected
).
'</info>'
)
);
$theme_contrib_path = getcwd() . '/themes/contrib';
}

// Create directory if does not exist
if (!file_exists($theme_contrib_path)) {
if (!mkdir($theme_contrib_path, 0777, true)) {
$output->writeln(
' <error>'. $this->trans('commands.theme.download.messages.error-creating-folder') . ': ' . $theme_contrib_path .'</error>'
);
$io->error($this->trans('commands.theme.download.messages.error-creating-folder') . ': ' . $theme_contrib_path);
return;
}
}
Expand All @@ -159,16 +151,15 @@ protected function execute(InputInterface $input, OutputInterface $output)

unlink($destination);

$output->writeln(
'[-] <info>'.sprintf(
$io->info(sprintf(
$this->trans('commands.theme.download.messages.downloaded'),
$theme,
$release_selected,
$theme_contrib_path
).'</info>'
)
);
} catch (\Exception $e) {
$output->writeln('[+] <error>'.$e->getMessage().'</error>');
$io->error($e->getMessage());

return;
}
Expand Down