Commit 62e46dd3 authored by Georg Ringer's avatar Georg Ringer Committed by Daniel Goerz
Browse files

[!!!][TASK] Simplify host information for language packs

The host which contains the language zip files is now hardcoded into the
`LanguagePackService` instead of fetching an outdated information from
typo3.org and overriding it on the fly again.

Persisting and checking the registry is not needed anymore.
If the host needs to be overridden, the provided event
`ModifyLanguagePackRemoteBaseUrlEvent` can be used.

Resolves: #93081
Releases: master
Change-Id: I7acced228745f8ae428ff6474800d4e15c2e4ca7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67141

Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent fcd6c8e5
.. include:: ../../Includes.txt
==========================================================================
Breaking: #93081 - Removed fetching translation file mirror from typo3.org
==========================================================================
See :issue:`93081`
Description
===========
The process of downloading translation of XLF files has been simplified.
The URL `https://localize.typo3.org/xliff/` is always used instead of download a static XML
file from typo3.org and persisting the URL in the registry.
Impact
======
The URL `https://localize.typo3.org/xliff/` is always used and typo3.org is not contacted anymore.
If any extension has overriden the information in the registry, this path won't be taken into account anymore.
Affected Installations
======================
Any TYPO3 installation which uses a different URL to fetch translations of TYPO3 core or any extension.
Migration
=========
Use the existing event :php:`ModifyLanguagePackRemoteBaseUrlEvent` to change the URL used to fetch translations.
.. index:: Backend, Frontend, NotScanned, ext:install
......@@ -92,7 +92,6 @@ class LanguagePackCommand extends Command
$progressBarOutput = $output;
}
$progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
$languagePackService->updateMirrorBaseUrl();
$hasErrors = false;
foreach ($isos as $iso) {
foreach ($extensions as $extension) {
......
......@@ -644,7 +644,6 @@ class MaintenanceController extends AbstractController
]);
// This action needs TYPO3_CONF_VARS for full GeneralUtility::getUrl() config
$this->lateBootService->loadExtLocalconfDatabaseAndExtTables();
$this->languagePackService->updateMirrorBaseUrl();
$extensions = $this->languagePackService->getExtensionLanguagePackDetails();
return new JsonResponse([
'success' => true,
......
......@@ -24,6 +24,7 @@ use Symfony\Component\Finder\Finder;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Registry;
......@@ -63,11 +64,6 @@ class LanguagePackService implements LoggerAwareInterface
*/
protected $requestFactory;
private const OLD_LANGUAGE_PACK_URLS = [
'https://typo3.org/fileadmin/ter/',
'https://beta-translation.typo3.org/fileadmin/ter/',
'https://localize.typo3.org/fileadmin/ter/'
];
private const LANGUAGE_PACK_URL = 'https://localize.typo3.org/xliff/';
public function __construct(EventDispatcherInterface $eventDispatcher, RequestFactory $requestFactory)
......@@ -200,43 +196,6 @@ class LanguagePackService implements LoggerAwareInterface
return $extensions;
}
/**
* Update main language pack download location if possible.
* Store to registry to be used during language pack update
*
* @return string
*/
public function updateMirrorBaseUrl(): string
{
$repositoryUrl = 'https://repositories.typo3.org/mirrors.xml.gz';
$downloadBaseUrl = false;
try {
$response = $this->requestFactory->request($repositoryUrl);
if ($response->getStatusCode() === 200) {
$xmlContent = @gzdecode($response->getBody()->getContents());
if (!empty($xmlContent['mirror']['host']) && !empty($xmlContent['mirror']['path'])) {
$downloadBaseUrl = 'https://' . $xmlContent['mirror']['host'] . $xmlContent['mirror']['path'];
}
} else {
$this->logger->warning(sprintf(
'Requesting %s was not successful, got status code %d (%s)',
$repositoryUrl,
$response->getStatusCode(),
$response->getReasonPhrase()
));
}
} catch (\Exception $e) {
// Catch generic exception, fallback handled below
$this->logger->error('Failed to download list of mirrors', ['exception' => $e]);
}
if (empty($downloadBaseUrl)) {
// Hard coded fallback if something went wrong fetching & parsing mirror list
$downloadBaseUrl = self::LANGUAGE_PACK_URL;
}
$this->registry->set('languagePacks', 'baseUrl', $downloadBaseUrl);
return $downloadBaseUrl;
}
/**
* Download and unpack a single language pack of one extension.
*
......@@ -266,20 +225,13 @@ class LanguagePackService implements LoggerAwareInterface
throw new \RuntimeException('Extension ' . (string)$key . ' not loaded', 1520117245);
}
$languagePackBaseUrl = $this->registry->get('languagePacks', 'baseUrl');
if (empty($languagePackBaseUrl)) {
throw new \RuntimeException('Language pack baseUrl not found', 1520169691);
}
if (in_array($languagePackBaseUrl, self::OLD_LANGUAGE_PACK_URLS, true)) {
$languagePackBaseUrl = self::LANGUAGE_PACK_URL;
}
$languagePackBaseUrl = self::LANGUAGE_PACK_URL;
// Allow to modify the base url on the fly
$event = $this->eventDispatcher->dispatch(new ModifyLanguagePackRemoteBaseUrlEvent(new Uri($languagePackBaseUrl), $key));
$languagePackBaseUrl = $event->getBaseUrl();
$path = ExtensionManagementUtility::extPath($key);
$majorVersion = explode('.', TYPO3_branch)[0];
$majorVersion = GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion();
if (strpos($path, '/sysext/') !== false) {
// This is a system extension and the package URL should be adapted to have different packs per core major version
// https://localize.typo3.org/xliff/b/a/backend-l10n/backend-l10n-fr.v9.zip
......@@ -344,12 +296,11 @@ class LanguagePackService implements LoggerAwareInterface
public function setLastUpdatedIsoCode(array $isos)
{
$activeLanguages = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lang']['availableLanguages'] ?? [];
$registry = GeneralUtility::makeInstance(Registry::class);
foreach ($isos as $iso) {
if (!in_array($iso, $activeLanguages, true)) {
throw new \RuntimeException('Language iso code ' . (string)$iso . ' not available or active', 1520176318);
}
$registry->set('languagePacks', $iso, time());
$this->registry->set('languagePacks', $iso, time());
}
}
......
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