Skip to content

Commit

Permalink
[BUGFIX] Output messages and progress for language:update
Browse files Browse the repository at this point in the history
Always output a progress bar and information that it is
actually doing something even when not called with --verbose

When no output is required or wanted, the global option --quiet
can be used instead.

To further improve the command, --no-progress is added
which removes the progress bar output, and shows messages instead.

Last but not least, output success or error messages for each
of the language pack fetches and exit with error code when
failures occurred.

To not make the command always fail when private extensions are used,
individual extensions can be skipped.

Releases: master, 10.4
Resolves: #91988
Change-Id: Ie7b7717f7f6fc2f884e974dbca564ca5a2c013af
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65484
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
helhum authored and bmack committed Sep 1, 2020
1 parent 55034b1 commit 2d0a5b9
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions typo3/sysext/install/Classes/Command/LanguagePackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
Expand All @@ -41,7 +42,21 @@ protected function configure()
->addArgument(
'locales',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
'Provide iso codes separated by space to update only selected language packs. Example `bin/typo3 language:update de ja`.'
'Provide iso codes separated by space to update only selected language packs. Example `bin/typo3 language:update de ja`.',
[]
)
->addOption(
'no-progress',
null,
InputOption::VALUE_NONE,
'Disable progress bar.'
)
->addOption(
'skip-extension',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Skip extension. Useful for e.g. for not public extensions, which don\'t have language packs.',
[]
);
}

Expand All @@ -57,35 +72,51 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$languagePackService = GeneralUtility::makeInstance(LanguagePackService::class);

try {
$isos = $input->getArgument('locales');
} catch (\Exception $e) {
$isos = [];
}
$noProgress = $input->getOption('no-progress') || $output->isVerbose();
$isos = $input->getArgument('locales');
$skipExtensions = $input->getOption('skip-extension');
if (empty($isos)) {
$isos = $languagePackService->getActiveLanguages();
}

if ($output->isVerbose()) {
$output->writeln(sprintf(
'<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
implode('", "', $isos)
));
}
$output->writeln(sprintf(
'<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
implode('", "', $isos)
));

$extensions = $languagePackService->getExtensionLanguagePackDetails();

if (!$output->isVerbose()) {
if ($noProgress) {
$progressBarOutput = new NullOutput();
} else {
$progressBarOutput = $output;
}
$progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
$languagePackService->updateMirrorBaseUrl();
$hasErrors = false;
foreach ($isos as $iso) {
foreach ($extensions as $extension) {
$languagePackService->languagePackDownload($extension['key'], $iso);
if (in_array($extension['key'], $skipExtensions, true)) {
continue;
}
if ($noProgress) {
$output->writeln(sprintf('<info>Fetching pack for language "%s" for extension "%s"</info>', $iso, $extension['key']), $output::VERBOSITY_VERY_VERBOSE);
}
$result = $languagePackService->languagePackDownload($extension['key'], $iso);
if ($noProgress) {
switch ($result) {
case 'failed':
$output->writeln(sprintf('<error>Fetching pack for language "%s" for extension "%s" failed</error>', $iso, $extension['key']));
$hasErrors = true;
break;
case 'update':
$output->writeln(sprintf('<info>Updated pack for language "%s" for extension "%s"</info>', $iso, $extension['key']));
break;
case 'new':
$output->writeln(sprintf('<info>Fetching new pack for language "%s" for extension "%s"</info>', $iso, $extension['key']));
break;
}
}
$progressBar->advance();
}
}
Expand All @@ -95,6 +126,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Flush language cache
GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();

return 0;
return $hasErrors ? 1 : 0;
}
}

0 comments on commit 2d0a5b9

Please sign in to comment.