[BUGFIX] Use class name to mark upgrade wizards done
[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 'Provide iso codes separated by space to update only selected language packs. Example `bin/typo3 language:update de ja`.'
44 );
45 }
46
47 /**
48 * Update language packs of all active languages for all active extensions
49 *
50 * @param InputInterface $input
51 * @param OutputInterface $output
52 * @throws \InvalidArgumentException
53 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
54 * @return int
55 */
56 protected function execute(InputInterface $input, OutputInterface $output)
57 {
58 if (substr_count($input->getArgument('command'), ':') === 2) {
59 $message = 'bin/typo3 lang:language:update is deprecated, use bin/typo3 language:update instead';
60 $output->writeln('<error>' . $message . '</error>');
61 trigger_error($message, E_USER_DEPRECATED);
62 }
63
64 $languagePackService = GeneralUtility::makeInstance(LanguagePackService::class);
65
66 try {
67 $isos = $input->getArgument('locales');
68 } catch (\Exception $e) {
69 $isos = [];
70 }
71 if (empty($isos)) {
72 $isos = $languagePackService->getActiveLanguages();
73 }
74
75 if ($output->isVerbose()) {
76 $output->writeln(sprintf(
77 '<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
78 implode('", "', $isos)
79 ));
80 }
81
82 $extensions = $languagePackService->getExtensionLanguagePackDetails();
83
84 if (!$output->isVerbose()) {
85 $progressBarOutput = new NullOutput();
86 } else {
87 $progressBarOutput = $output;
88 }
89 $progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
90 $languagePackService->updateMirrorBaseUrl();
91 foreach ($isos as $iso) {
92 foreach ($extensions as $extension) {
93 $languagePackService->languagePackDownload($extension['key'], $iso);
94 $progressBar->advance();
95 }
96 }
97 $languagePackService->setLastUpdatedIsoCode($isos);
98 $progressBar->finish();
99
100 // Flush language cache
101 GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
102
103 return 0;
104 }
105 }