Commit 9d5ff89a authored by Jochen Roth's avatar Jochen Roth Committed by Christian Kuhn
Browse files

[BUGFIX] Don't fail language:update command when translation missing

Currently language:update command fails when
a translation of a extension is missing.

This has been fixed by returning a successful
status code even though the file was not found
on the translation server. With the additional
option '--fail-on-warnings' the command fails
if the download of a language pack was not
successful.

Missing files are still reported in CLI stdout
and it still fails if the server is not reachable.
Also missing translations are now logged.

Resolves: #95700
Resolves: #96054
Resolves: #96055
Resolves: #96053
Releases: master, 11.5
Change-Id: I9a19de919e99b591dcf02a5cf70465ad9c5c76b7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72274

Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 5e3730b3
......@@ -64,6 +64,12 @@ class LanguagePackCommand extends Command
InputOption::VALUE_NONE,
'Disable progress bar.'
)
->addOption(
'fail-on-warnings',
null,
InputOption::VALUE_NONE,
'Fail command when translation was not found on the server.'
)
->addOption(
'skip-extension',
null,
......@@ -89,6 +95,8 @@ class LanguagePackCommand extends Command
$noProgress = $input->getOption('no-progress') || $output->isVerbose();
$isos = (array)$input->getArgument('locales');
$skipExtensions = (array)$input->getOption('skip-extension');
$failOnWarnings = (bool)$input->getOption('fail-on-warnings');
$status = 0;
// Condition for the scheduler command, e.g. "de fr pt"
if (count($isos) === 1 && str_contains($isos[0], ' ')) {
......@@ -111,7 +119,6 @@ class LanguagePackCommand extends Command
$progressBarOutput = $output;
}
$progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
$hasErrors = false;
foreach ($isos as $iso) {
foreach ($extensions as $extension) {
if (in_array($extension['key'], $skipExtensions, true)) {
......@@ -124,8 +131,7 @@ class LanguagePackCommand extends Command
if ($noProgress) {
switch ($result) {
case 'failed':
$output->writeln(sprintf('<error>Fetching pack for language "%s" for extension "%s" failed</error>', $iso, $extension['key']));
$hasErrors = true;
$output->writeln(sprintf('<comment>Fetching pack for language "%s" for extension "%s" failed</comment>', $iso, $extension['key']));
break;
case 'update':
$output->writeln(sprintf('<info>Updated pack for language "%s" for extension "%s"</info>', $iso, $extension['key']));
......@@ -135,6 +141,12 @@ class LanguagePackCommand extends Command
break;
}
}
// Fail only if --fail-on-warnings is set and a language pack was not found.
if ($failOnWarnings && $result === 'failed') {
$status = 1;
}
$progressBar->advance();
}
}
......@@ -144,6 +156,6 @@ class LanguagePackCommand extends Command
// Flush language cache
GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
return $hasErrors ? 1 : 0;
return $status;
}
}
......@@ -247,33 +247,32 @@ class LanguagePackService
$packResult = $packExists ? 'update' : 'new';
$operationResult = false;
try {
$response = $this->requestFactory->request($languagePackBaseUrl . $packageUrl);
if ($response->getStatusCode() === 200) {
$languagePackContent = $response->getBody()->getContents();
if (!empty($languagePackContent)) {
$operationResult = true;
if ($packExists) {
$operationResult = GeneralUtility::rmdir($absoluteExtractionPath, true);
}
if ($operationResult) {
GeneralUtility::mkdir_deep(Environment::getVarPath() . '/transient/');
$operationResult = GeneralUtility::writeFileToTypo3tempDir($absolutePathToZipFile, $languagePackContent) === null;
}
$this->unzipTranslationFile($absolutePathToZipFile, $absoluteLanguagePath);
if ($operationResult) {
$operationResult = unlink($absolutePathToZipFile);
}
$response = $this->requestFactory->request($languagePackBaseUrl . $packageUrl, 'GET', ['http_errors' => false]);
if ($response->getStatusCode() === 200) {
$languagePackContent = $response->getBody()->getContents();
if (!empty($languagePackContent)) {
$operationResult = true;
if ($packExists) {
$operationResult = GeneralUtility::rmdir($absoluteExtractionPath, true);
}
if ($operationResult) {
GeneralUtility::mkdir_deep(Environment::getVarPath() . '/transient/');
$operationResult = GeneralUtility::writeFileToTypo3tempDir($absolutePathToZipFile, $languagePackContent) === null;
}
$this->unzipTranslationFile($absolutePathToZipFile, $absoluteLanguagePath);
if ($operationResult) {
$operationResult = unlink($absolutePathToZipFile);
}
} else {
$this->logger->warning('Requesting {request} was not successful, got status code {status} ({reason})', [
'request' => $languagePackBaseUrl . $packageUrl,
'status' => $response->getStatusCode(),
'reason' => $response->getReasonPhrase(),
]);
}
} catch (\Exception $e) {
} else {
$operationResult = false;
$this->logger->warning('Requesting {request} was not successful, got status code {status} ({reason})', [
'request' => $languagePackBaseUrl . $packageUrl,
'status' => $response->getStatusCode(),
'reason' => $response->getReasonPhrase(),
]);
}
if (!$operationResult) {
$packResult = 'failed';
......
Markdown is supported
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