Bug #65364
closed_languageUid gets overwritten on updating a new domain object.
100%
Description
When creating a new domain object the property _languageUid is NULL. When this object gets persisted \TYPO3\CMS\Extbase\Persistence\Generic\Backend::insertObject() sets the language field to "-1" like it is described in the documentation http://docs.typo3.org/typo3cms/ExtbaseFluidBook/9-CrosscuttingConcerns/1-localizing-and-internationalizing-an-extension.html#multi-language-domain-objects. But after the insert the objects are updated (f.e. to insert missing relation ids and stuff) immediately and persisted again. \TYPO3\CMS\Extbase\Persistence\Generic\Backend::updateObject() sets "$row[$dataMap->getLanguageIdColumnName()] = $object->_getProperty('_languageUid');" and because the object's property _languageUid is NULL a 0 is inserted in the database.
So if the object was created in a multi language environment (sys_language_uid > 0) extbase doesn't find it anymore.
Solution 1:
Update the object's property _languageUid in \TYPO3\CMS\Extbase\Persistence\Generic\Backend::insertObject(). But this should be done only, if the developer hasn't set _languageUid himself (see FORGE). Then the update finds the -1 in the property _languageUid and everything works like it is documentated.
diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php index 8c6e3f0..b7f1efd 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php @@ -635,6 +635,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface $this->addCommonFieldsToRow($object, $row); if ($dataMap->getLanguageIdColumnName() !== NULL && ($object->_getProperty('_languageUid') === NULL || !$object->_getProperty('_languageUid'))) { $row[$dataMap->getLanguageIdColumnName()] = -1; + $object->_setProperty('_languageUid', -1); } if ($parentObject !== NULL && $parentPropertyName) { $parentColumnDataMap = $this->dataMapper->getDataMap(get_class($parentObject))->getColumnMap($parentPropertyName);
Solution 2:
Do "$row[$dataMap->getLanguageIdColumnName()] = $object->_getProperty('_languageUid');" only if _languageUid is not NULL in \TYPO3\CMS\Extbase\Persistence\Generic\Backend::updateObject().
diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php index f3d89c9..c6aeb59 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php @@ -850,7 +850,9 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface $this->addCommonFieldsToRow($object, $row); $row['uid'] = $object->getUid(); if ($dataMap->getLanguageIdColumnName() !== NULL) { - $row[$dataMap->getLanguageIdColumnName()] = $object->_getProperty('_languageUid'); + if($object->_getProperty('_languageUid') !== NULL){ + $row[$dataMap->getLanguageIdColumnName()] = $object->_getProperty('_languageUid'); + } if ($object->_getProperty('_localizedUid') !== NULL) { $row['uid'] = $object->_getProperty('_localizedUid'); }
I would prefer the first solution, because it seems cleaner to me. Or should both solutions be implemented?
If someone has a good idea for a commit message I will submit a patch to gerrit.
Updated by Marco Huber over 9 years ago
Workaround: Set _languageUid manually.
$myObject = $objectManager->get('MyObject') $myObject->_setProperty('_languageUid', -1); //or whatever you want, f.e. $GLOBALS['TSFE']->sys_language_uid $myObjectRepository->add($myObject); $persistanceManager->persistAll();
Updated by Gerrit Code Review over 9 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/41595
Updated by Gerrit Code Review over 9 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/41595
Updated by Daniel Goerz over 9 years ago
Hey Marco,
could you provide the steps to reproduce this error (and maybe add a testextension to the ticket) so we can test your patch? That would be great.
Updated by Gerrit Code Review about 9 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/41595
Updated by Gerrit Code Review about 9 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/41595
Updated by Gerrit Code Review about 9 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/41595
Updated by Gerrit Code Review about 9 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/41595
Updated by Gerrit Code Review about 9 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/41595
Updated by Gerrit Code Review about 9 years ago
Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/43427
Updated by Marco Huber about 9 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 86ac2558aa880d5e4995b3cd980d272e53d38034.