Project

General

Profile

Actions

Bug #65364

closed

_languageUid gets overwritten on updating a new domain object.

Added by Marco Huber over 9 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2015-02-26
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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.


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #65363: Set _languageUid to -1 only if the developer hasn't set it himselfClosed2015-02-26

Actions
Related to TYPO3 Core - Bug #60544: Pid property not set after insertClosed2014-07-24

Actions
Actions

Also available in: Atom PDF