[BUGFIX] LanguagePackCommand: Hide progress output by default
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Command / LanguagePackCommand.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Install\Command;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Helper\ProgressBar;
20 use Symfony\Component\Console\Input\InputArgument;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Output\NullOutput;
23 use Symfony\Component\Console\Output\OutputInterface;
24 use TYPO3\CMS\Core\Cache\CacheManager;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Install\Service\LanguagePackService;
27
28 /**
29 * Core function for updating language packs
30 */
31 class LanguagePackCommand extends Command
32 {
33 /**
34 * Configure the command by defining the name, options and arguments
35 */
36 protected function configure()
37 {
38 $this->setAliases(['lang:language:update']);
39 $this->setDescription('Update the language files of all activated extensions')
40 ->addArgument(
41 'locales',
42 InputArgument::IS_ARRAY | InputArgument::OPTIONAL
43 );
44 }
45
46 /**
47 * Update language packs of all active languages for all active extensions
48 *
49 * @param InputInterface $input
50 * @param OutputInterface $output
51 * @throws \InvalidArgumentException
52 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
53 * @return int
54 */
55 protected function execute(InputInterface $input, OutputInterface $output)
56 {
57 if (substr_count($input->getArgument('command'), ':') === 2) {
58 $message = 'bin/typo3 lang:language:update is deprecated, use bin/typo3 language:update instead';
59 $output->writeln('<error>' . $message . '</error>');
60 trigger_error($message, E_USER_DEPRECATED);
61 }
62
63 $languagePackService = GeneralUtility::makeInstance(LanguagePackService::class);
64
65 try {
66 $isos = $input->getArgument('locales');
67 } catch (\Exception $e) {
68 $isos = [];
69 }
70 if (empty($isos)) {
71 $isos = $languagePackService->getActiveLanguages();
72 }
73
74 if ($output->isVerbose()) {
75 $output->writeln(sprintf(
76 '<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
77 implode('", "', $isos)
78 ));
79 }
80
81 $extensions = $languagePackService->getExtensionLanguagePackDetails();
82
83 if (!$output->isVerbose()) {
84 $progressBarOutput = new NullOutput();
85 } else {
86 $progressBarOutput = $output;
87 }
88 $progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
89 $languagePackService->updateMirrorBaseUrl();
90 foreach ($isos as $iso) {
91 foreach ($extensions as $extension) {
92 $languagePackService->languagePackDownload($extension['key'], $iso);
93 $progressBar->advance();
94 }
95 }
96 $languagePackService->setLastUpdatedIsoCode($isos);
97 $progressBar->finish();
98
99 // Flush language cache
100 GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
101
102 return 0;
103 }
104 }