[TASK] Document variables assigned to mail templates
[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->setDescription('Update the language files of all activated extensions')
39 ->addArgument(
40 'locales',
41 InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
42 'Provide iso codes separated by space to update only selected language packs. Example `bin/typo3 language:update de ja`.'
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 $languagePackService = GeneralUtility::makeInstance(LanguagePackService::class);
58
59 try {
60 $isos = $input->getArgument('locales');
61 } catch (\Exception $e) {
62 $isos = [];
63 }
64 if (empty($isos)) {
65 $isos = $languagePackService->getActiveLanguages();
66 }
67
68 if ($output->isVerbose()) {
69 $output->writeln(sprintf(
70 '<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
71 implode('", "', $isos)
72 ));
73 }
74
75 $extensions = $languagePackService->getExtensionLanguagePackDetails();
76
77 if (!$output->isVerbose()) {
78 $progressBarOutput = new NullOutput();
79 } else {
80 $progressBarOutput = $output;
81 }
82 $progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
83 $languagePackService->updateMirrorBaseUrl();
84 foreach ($isos as $iso) {
85 foreach ($extensions as $extension) {
86 $languagePackService->languagePackDownload($extension['key'], $iso);
87 $progressBar->advance();
88 }
89 }
90 $languagePackService->setLastUpdatedIsoCode($isos);
91 $progressBar->finish();
92
93 // Flush language cache
94 GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
95
96 return 0;
97 }
98 }