Skip to content

Commit

Permalink
[BUGFIX] Refactor to ProcessingInstruction lost DeepL mode information
Browse files Browse the repository at this point in the history
With changing translation configuration to runtime cache, the
information about translation custom mode got lost. As this is saved
inside the cache, ensure setting the DeepL translation mode, if a
subprocess DataHandler instance is created, e.g., by DataMapProcessor
  • Loading branch information
calien666 committed Dec 11, 2024
1 parent 5ecb0eb commit be34742
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 54 deletions.
85 changes: 65 additions & 20 deletions Build/phpstan/Core11/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Hooks/TranslateHookTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Hooks\\\\TranslateHookTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Hooks/TranslateHookTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Hooks\\\\TranslateHookTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -335,11 +330,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\GlossaryRegressionTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\GlossaryRegressionTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -375,6 +365,71 @@ parameters:
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor invoked with 3 parameters, 1\\-2 required\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildErrorHandlingConfiguration\\(\\) has parameter \\$codes with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildErrorHandlingConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildLanguageConfiguration\\(\\) has parameter \\$fallbackIdentifiers with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:mergeSiteConfiguration\\(\\) has parameter \\$overrides with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$errorHandling with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$languages with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$site with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Parameter \\#1 \\$current of method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:mergeInstruction\\(\\) expects TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction, TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction\\|null given\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Parameter \\#2 \\$coreCache of class TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\SiteConfiguration constructor expects TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\PhpFrontend\\|null, Psr\\\\EventDispatcher\\\\EventDispatcherInterface given\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Cannot access property \\$code on DeepL\\\\Language\\|null\\.$#"
count: 7
Expand Down Expand Up @@ -410,11 +465,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Services/LanguageServiceTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Services\\\\LanguageServiceTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Services/LanguageServiceTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Services\\\\LanguageServiceTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -480,11 +530,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
75 changes: 55 additions & 20 deletions Build/phpstan/Core12/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Hooks/TranslateHookTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Hooks\\\\TranslateHookTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Hooks/TranslateHookTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Hooks\\\\TranslateHookTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -310,11 +305,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\GlossaryRegressionTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\GlossaryRegressionTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -345,6 +335,61 @@ parameters:
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildErrorHandlingConfiguration\\(\\) has parameter \\$codes with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildErrorHandlingConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildLanguageConfiguration\\(\\) has parameter \\$fallbackIdentifiers with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:mergeSiteConfiguration\\(\\) has parameter \\$overrides with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$errorHandling with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$languages with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$site with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Parameter \\#1 \\$current of method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:mergeInstruction\\(\\) expects TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction, TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction\\|null given\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Cannot access property \\$code on DeepL\\\\Language\\|null\\.$#"
count: 7
Expand Down Expand Up @@ -375,11 +420,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Services/LanguageServiceTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Services\\\\LanguageServiceTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Services/LanguageServiceTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Services\\\\LanguageServiceTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -435,11 +475,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:buildSiteConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:failIfArrayIsNotEmpty\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/GlossaryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ protected function getTargetLanguageIsoCode(Site $site, int $languageId): string
{
if ((new Typo3Version())->getMajorVersion() >= 12) {
return $site->getLanguageById($languageId)->getLocale()->getLanguageCode();
} else {
return $site->getLanguageById($languageId)->getTwoLetterIsoCode();
}
return $site->getLanguageById($languageId)->getTwoLetterIsoCode();

}

/**
Expand Down
8 changes: 8 additions & 0 deletions Classes/Service/ProcessingInstruction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public function setProcessingInstruction(?string $table = null, $id = null, $dee
'id' => $id,
'deeplMode' => $deeplMode,
];
// if processing instructions are already set, detect the current DeepL mode.
// this is needed for sub instances of DataHandler, mostly
// when translating inline elements via command and the DataMapProcessor
// manually triggers an inline translation
// which leads to loss of deepl mode information from original request
if ($this->runtimeCache->has(self::PROCESSING_CACHE_IDENTIFIER)) {
$processingInformation['deeplMode'] = $this->isDeeplMode();
}
$this->runtimeCache->set(self::PROCESSING_CACHE_IDENTIFIER, $processingInformation);
}

Expand Down
29 changes: 17 additions & 12 deletions Tests/Functional/Fixtures/Traits/SiteBasedTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ protected function mergeSiteConfiguration(
}
}

/**
* @param array<non-empty-string, mixed> $additionalRootConfiguration
* @return array<string, mixed>
*/
protected function buildSiteConfiguration(
int $rootPageId,
string $base = '',
string $websiteTitle='',
array $additionalRootConfiguration = []
): array {
return array_merge([
'rootPageId' => $rootPageId,
'base' => $base,
'websiteTitle' => $websiteTitle,
], $additionalRootConfiguration);
}

protected function createSiteConfiguration(string $path): SiteConfiguration
{
if ((new Typo3Version())->getMajorVersion() < 12) {
Expand All @@ -93,18 +110,6 @@ protected function createSiteConfiguration(string $path): SiteConfiguration
);
}

protected function buildSiteConfiguration(
int $rootPageId,
string $base = '',
string $websiteTitle=''
): array {
return [
'rootPageId' => $rootPageId,
'base' => $base,
'websiteTitle' => $websiteTitle,
];
}

protected function buildDefaultLanguageConfiguration(
string $identifier,
string $base
Expand Down
4 changes: 4 additions & 0 deletions Tests/Functional/Fixtures/be_users.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"be_users"
,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id"
# The password is "password"
,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pages
,uid,pid,title,sys_language_uid,l10n_parent,doktype,media
,1,0,"proton beam",0,0,1,1
,2,0,"Protonenstrahl",1,1,1,1
sys_file_reference
,uid,pid,uid_local,uid_foreign,tablenames,fieldname,sys_language_uid,title,l10n_parent
,1,1,1,1,pages,media,0,"proton beam",0
,2,1,1,2,pages,media,1,"Protonenstrahl",1
12 changes: 12 additions & 0 deletions Tests/Functional/Regression/Fixtures/localizationInline.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pages
,"uid","pid","title","sys_language_uid","slug","media"
,1,0,"proton beam",0,"/",1
sys_file
,uid,pid,name,identifier,storage
,1,0,clear.gif,/clear.gif,1
sys_file_metadata
,uid,pid,file
,1,0,1
sys_file_reference
,uid,pid,uid_local,uid_foreign,tablenames,fieldname,sys_language_uid,title,l10n_parent
,1,1,1,1,pages,media,0,"proton beam",0
Loading

0 comments on commit be34742

Please sign in to comment.