From m+typo3-dev at qxio.tk Wed Jun 13 22:40:13 2018 From: m+typo3-dev at qxio.tk (Mika) Date: Wed, 13 Jun 2018 22:40:13 +0200 Subject: [TYPO3-dev] Correct usage of translated records in CLI Message-ID: Dear all, I've searched and debugged the last couple of days how to obtain the translated version of a DomainModel in a CommandController in Typo3 v8.7. In Typo3 4.5/4.7 I've done the following: - input: DomainModel in default language - build a query that finds the record with the l10n_parent matching the given domain model - obtain a new domain model with the desired sys_language_uid Unfortunately this does not work in Typo3 v8.7 any more. I always get the domain model for the default language. I've traced this down to the method 'Typo3DbBackend::doLanguageAndWorkspaceOverlay' called via 'Typo3DbBackend::getObjectDataByQuery'. The query returns the correct (translated) row, but then the variable $row gets overwritten in doLanguageAndWorkspaceOverlay no matter how I set the querySettings 'setLanguageOverlayMode' and 'setLanguageMode'. So what is the correct way to get a translated domain model in a CommandController? thanks for your help, mika From m+typo3-dev at qxio.tk Sat Jun 16 11:05:51 2018 From: m+typo3-dev at qxio.tk (m+typo3-dev at qxio.tk) Date: Sat, 16 Jun 2018 11:05:51 +0200 Subject: [TYPO3-dev] Correct usage of translated records in CLI In-Reply-To: References: Message-ID: Hello again, here's an update for my issue: I think I'm a step further. If I add ->setQueryLanguage(1) to the query settings, doLanguageAndWorkspaceOverlay() tries to fetch the translated record for language = 1. But in order to succeed I need to trick the FrontendGroupRestriction class by setting $GLOBALS['TSFE']->gr_list = "0,-2";. The array returned by doLanguageAndWorkspaceOverlay() now contains all translated entries, except the uid, which is still the uid from the record in the main language. The uid of the translated record is stored in _LOCALIZED_UID. Now my problem now is that I still get the record in the main laguage because DataMapper->mapSingleRow() (called via DataMapper->map()) has some kind of object cache and thus returns the object in the default language (because the uid is still the one of the record in the main language). All this seems a little hackish. So again my question: what is the correct way to get a translated domain model in a CommandController? thanks, mika From m+typo3-dev at qxio.tk Wed Jun 20 21:45:53 2018 From: m+typo3-dev at qxio.tk (Mika) Date: Wed, 20 Jun 2018 21:45:53 +0200 Subject: [TYPO3-dev] Correct usage of translated records in CLI In-Reply-To: References: Message-ID: Hello, its Mika again, On 16.06.18 11:05, m+typo3-dev at qxio.tk wrote: [...] > Now my problem now is that I still get the record in the main laguage > because DataMapper->mapSingleRow() (called via DataMapper->map()) has > some kind of object cache and thus returns the object in the default > language (because the uid is still the one of the record in the main > language). I feel quite lonely here. is this mailinglist still active? I have two updates on my problem that I want to post here for documentation purpose. 1) solution to the issue described above: To avoid invoking the DataMapper as part of the query from Typo3DbBackend, I used a raw query (argument for ->execute()) and get back an array, that already went through language overlay etc. BUT: in the array the '_LOCALIZED_UID' is still available. So I overwrite the uid with the value from '_LOCALIZED_UID' and invoke the DataMapper manually. Quite cumbersome and very hackish to overcome the Typo3 backend shortcomings... 2) alternative solution: based on the solution above, I decided that I can do almost everything on my own. So what I do now is i) create an independend querybuilder for the according table: > $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName); ii) select the record with the desired l10n_parent and sys_language_uid > $query = $queryBuilder->select('*') > ->from($tableName) > ->where($queryBuilder->expr()->eq('sys_language_uid', $langId)) > ->andWhere($queryBuilder->expr()->eq('l10n_parent', $parentUid)) > ->execute(); iii) fetch all records into an array > $rows = $query->fetchAll(); iv) invoke the DataMapper manually to get the object > $dataMapper = $this->objectManager->get(DataMapper::class); > $translated = $dataMapper->map($className, $rows); I know it has nothing to do with the ModelRepository any more, but it works quite fine for now... that's all folks best regards, Mika