8ccaef699bdac7d9b8b9717e85600b077badec9f
[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\OutputInterface;
23 use TYPO3\CMS\Core\Cache\CacheManager;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Install\Service\LanguagePackService;
26
27 /**
28 * Core function for updating language packs
29 */
30 class LanguagePackCommand extends Command
31 {
32 /**
33 * Configure the command by defining the name, options and arguments
34 */
35 protected function configure()
36 {
37 $this->setAliases(['lang:language:update']);
38 $this->setDescription('Update the language files of all activated extensions')
39 ->addArgument(
40 'locales',
41 InputArgument::IS_ARRAY | InputArgument::OPTIONAL
42 );
43 }
44
45 /**
46 * Update language packs of all active languages for all active extensions
47 *
48 * @param InputInterface $input
49 * @param OutputInterface $output
50 * @throws \InvalidArgumentException
51 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
52 * @return int
53 */
54 protected function execute(InputInterface $input, OutputInterface $output)
55 {
56 if (substr_count($input->getArgument('command'), ':') === 2) {
57 $message = 'bin/typo3 lang:language:update is deprecated, use bin/typo3 language:update instead';
58 $output->writeln('<error>' . $message . '</error>');
59 trigger_error($message, E_USER_DEPRECATED);
60 }
61
62 $languagePackService = GeneralUtility::makeInstance(LanguagePackService::class);
63
64 try {
65 $isos = $input->getArgument('locales');
66 } catch (\Exception $e) {
67 $isos = [];
68 }
69 if (empty($isos)) {
70 $isos = $languagePackService->getActiveLanguages();
71 }
72
73 $output->writeln(sprintf(
74 '<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
75 implode('", "', $isos)
76 ));
77
78 $extensions = $languagePackService->getExtensionLanguagePackDetails();
79 $progressBar = new ProgressBar($output, count($isos) * count($extensions));
80 $languagePackService->updateMirrorBaseUrl();
81 foreach ($isos as $iso) {
82 foreach ($extensions as $extension) {
83 $languagePackService->languagePackDownload($extension['key'], $iso);
84 $progressBar->advance();
85 }
86 }
87 $languagePackService->setLastUpdatedIsoCode($isos);
88 $progressBar->finish();
89
90 // Flush language cache
91 GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
92
93 return 0;
94 }
95 }