From 62e46dd30be1f214ff0d32bdde3a5c5c5bfa70a6 Mon Sep 17 00:00:00 2001 From: Georg Ringer <georg.ringer@gmail.com> Date: Tue, 15 Dec 2020 14:44:48 +0100 Subject: [PATCH] [!!!][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 <aleichsenring@ab-softlab.de> Tested-by: Markus Klein <markus.klein@typo3.org> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Daniel Goerz <daniel.goerz@posteo.de> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Markus Klein <markus.klein@typo3.org> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de> --- ...chingTranslationFileMirrorFromTypo3org.rst | 36 ++++++++++++ .../Classes/Command/LanguagePackCommand.php | 1 - .../Controller/MaintenanceController.php | 1 - .../Classes/Service/LanguagePackService.php | 57 ++----------------- 4 files changed, 40 insertions(+), 55 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-93081-RemovedFetchingTranslationFileMirrorFromTypo3org.rst diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-93081-RemovedFetchingTranslationFileMirrorFromTypo3org.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-93081-RemovedFetchingTranslationFileMirrorFromTypo3org.rst new file mode 100644 index 000000000000..b861d3fb838d --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-93081-RemovedFetchingTranslationFileMirrorFromTypo3org.rst @@ -0,0 +1,36 @@ +.. 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 diff --git a/typo3/sysext/install/Classes/Command/LanguagePackCommand.php b/typo3/sysext/install/Classes/Command/LanguagePackCommand.php index a48a591cf881..bbec4eab1cca 100644 --- a/typo3/sysext/install/Classes/Command/LanguagePackCommand.php +++ b/typo3/sysext/install/Classes/Command/LanguagePackCommand.php @@ -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) { diff --git a/typo3/sysext/install/Classes/Controller/MaintenanceController.php b/typo3/sysext/install/Classes/Controller/MaintenanceController.php index 182874450369..97bebbd22347 100644 --- a/typo3/sysext/install/Classes/Controller/MaintenanceController.php +++ b/typo3/sysext/install/Classes/Controller/MaintenanceController.php @@ -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, diff --git a/typo3/sysext/install/Classes/Service/LanguagePackService.php b/typo3/sysext/install/Classes/Service/LanguagePackService.php index 310c321f8a98..4dde9c2276d8 100644 --- a/typo3/sysext/install/Classes/Service/LanguagePackService.php +++ b/typo3/sysext/install/Classes/Service/LanguagePackService.php @@ -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()); } } -- GitLab