Commit 1873b9ab authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Benni Mack
Browse files

[TASK] Make "lang:language:update" a symfony console command

This commit migrates the command "lang:language:update" from
an extbase command controller to a symfony console command.

Also, the alias language:update will be flagged deprecated.

Resolves: #82315
Releases: master
Change-Id: If9fd08981ee8286bd8187fe5eaa5b36f625bd576
Reviewed-on: https://review.typo3.org/53928

Reviewed-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Tested-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent cae1b06d
.. include:: ../../Includes.txt
=========================================================
Deprecation: #82315 - Deprecate bin/typo3 language:update
=========================================================
See :issue:`82315`
Description
===========
The command language:update is an alias of lang:language:update, therefore it's superfluous and will be removed in the future.
Impact
======
The command language:update will not work any more.
Affected Installations
======================
All installations that make use of the command language:update. Most likely there are cronjobs that need to be adjusted.
Migration
=========
Use bin/typo3 lang:language:update instead.
.. index:: CLI, NotScanned
......@@ -13,96 +13,147 @@ namespace TYPO3\CMS\Lang\Command;
*
* The TYPO3 project - inspiring people to share!
*/
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Package\PackageInterface;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher as SignalSlotDispatcher;
use TYPO3\CMS\Lang\Domain\Repository\LanguageRepository;
use TYPO3\CMS\Lang\Service\RegistryService;
use TYPO3\CMS\Lang\Service\TranslationService;
/**
* Language command controller updates translation packages
* Core function for updating the language files
*/
class LanguageCommandController extends CommandController
class LanguageUpdateCommand extends Command
{
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
*/
protected $signalSlotDispatcher;
/**
* @var \TYPO3\CMS\Lang\Service\RegistryService
* @var ObjectManagerInterface
*/
protected $registryService;
protected $objectManager;
/**
* @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
* @param string $name
* @throws \Symfony\Component\Console\Exception\LogicException
* @throws \InvalidArgumentException
*/
public function injectSignalSlotDispatcher(Dispatcher $signalSlotDispatcher)
public function __construct($name = null)
{
$this->signalSlotDispatcher = $signalSlotDispatcher;
parent::__construct($name);
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
}
/**
* @param \TYPO3\CMS\Lang\Service\RegistryService $registryService
* Configure the command by defining the name, options and arguments
*/
public function injectRegistryService(RegistryService $registryService)
protected function configure()
{
$this->registryService = $registryService;
$description = ($this->getName() === 'language:update')
? '[Deprecated] Use lang:language:update instead'
: 'Update the language files of all activated extensions';
$this
->setDescription($description)
->addArgument(
'locales',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL
);
}
/**
* Update language file for each extension
* @param InputInterface $input
* @param OutputInterface $output
*
* @param string $localesToUpdate Comma separated list of locales that needs to be updated
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*
* @return int
*/
public function updateCommand($localesToUpdate = '')
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->getName() === 'language:update') {
$message = 'bin/typo3 language:update is deprecated, use bin/typo3 lang:language:update instead';
GeneralUtility::deprecationLog($message);
$output->writeln('<error>' . $message . '</error>');
}
try {
$localesToUpdate = $input->getArgument('locales');
} catch (\Exception $e) {
$localesToUpdate = [];
}
/** @var $translationService \TYPO3\CMS\Lang\Service\TranslationService */
$translationService = $this->objectManager->get(TranslationService::class);
/** @var $languageRepository \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository */
$languageRepository = $this->objectManager->get(LanguageRepository::class);
$locales = [];
if (!empty($localesToUpdate)) {
$locales = GeneralUtility::trimExplode(',', $localesToUpdate, true);
} else {
$languages = $languageRepository->findSelected();
foreach ($languages as $language) {
/** @var $language \TYPO3\CMS\Lang\Domain\Model\Language */
$locales[] = $language->getLocale();
}
$allLocales = array_map(function ($language) {
/** @var $language \TYPO3\CMS\Lang\Domain\Model\Language */
return $language->getLocale();
}, $languageRepository->findSelected());
$nonUpdatableLocales = array_diff($localesToUpdate, $allLocales);
$updatableLocales = array_intersect($localesToUpdate, $allLocales);
$locales = empty($updatableLocales) ? $allLocales : $updatableLocales;
foreach ($nonUpdatableLocales as $nonUpdatableLocale) {
$output->writeln(sprintf(
'<error>Skipping locale "%s" as it is not activated in the backend</error>',
$nonUpdatableLocale
));
}
$output->writeln(sprintf(
'<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
implode('", "', $locales)
));
/** @var RegistryService $registryService */
$registryService = $this->objectManager->get(RegistryService::class);
/** @var PackageManager $packageManager */
$packageManager = $this->objectManager->get(PackageManager::class);
$this->emitPackagesMayHaveChangedSignal();
$packages = $packageManager->getAvailablePackages();
$this->outputLine((sprintf('Updating language packs of all activated extensions for locales "%s"', implode(', ', $locales))));
$this->output->progressStart(count($locales) * count($packages));
$progressBar = new ProgressBar($output, count($locales) * count($packages));
foreach ($locales as $locale) {
/** @var PackageInterface $package */
foreach ($packages as $package) {
$extensionKey = $package->getPackageKey();
$result = $translationService->updateTranslation($extensionKey, $locale);
if (empty($result[$extensionKey][$locale]['error'])) {
$this->registryService->set($locale, $GLOBALS['EXEC_TIME']);
$registryService->set($locale, $GLOBALS['EXEC_TIME']);
}
$this->output->progressAdvance();
$progressBar->advance();
}
}
$progressBar->finish();
// Flush language cache
GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
$this->output->progressFinish();
return 0;
}
/**
* Emits packages may have changed signal
*
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
*/
protected function emitPackagesMayHaveChangedSignal()
{
$this->signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
$this->objectManager->get(SignalSlotDispatcher::class)->dispatch('PackageManagement', 'packagesMayHaveChanged');
}
}
<?php
/**
* Commands to be executed by typo3, where the key of the array
* is the name of the command (to be called as the first argument after typo3).
* Required parameter is the "class" of the command which needs to be a subclass
* of Symfony/Console/Command.
*
* example: bin/typo3 lang:language:update
*/
return [
'lang:language:update' => [
'class' => \TYPO3\CMS\Lang\Command\LanguageUpdateCommand::class
],
'language:update' => [
'class' => \TYPO3\CMS\Lang\Command\LanguageUpdateCommand::class
]
];
<?php
defined('TYPO3_MODE') or die();
// Register language update command controller
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = \TYPO3\CMS\Lang\Command\LanguageCommandController::class;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment