[BUGFIX] _languageUid property not set on insert 95/41595/8
authorMarco Huber <mail@marco-huber.de>
Fri, 17 Jul 2015 19:07:54 +0000 (21:07 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 18 Sep 2015 18:34:03 +0000 (20:34 +0200)
The patch ensures new objects are created with default language only.
Database field and object property are set properly to 0.

Furthermore the language uid is set only if not set before from outside.

Resolves: #65363
Resolves: #65364
Releases: master, 6.2
Change-Id: Ifc777e482ef12dba46938f826548a97758e531a1
Reviewed-on: http://review.typo3.org/41595
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php
typo3/sysext/extbase/Tests/Functional/Persistence/AddTest.php

index 06af379..8e62564 100644 (file)
@@ -662,8 +662,9 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        }
                }
                $this->addCommonFieldsToRow($object, $row);
-               if ($dataMap->getLanguageIdColumnName() !== NULL) {
-                       $row[$dataMap->getLanguageIdColumnName()] = -1;
+               if ($dataMap->getLanguageIdColumnName() !== NULL && $object->_getProperty('_languageUid') === NULL) {
+                       $row[$dataMap->getLanguageIdColumnName()] = 0;
+                       $object->_setProperty('_languageUid', 0);
                }
                if ($dataMap->getTranslationOriginColumnName() !== NULL) {
                        $row[$dataMap->getTranslationOriginColumnName()] = 0;
index 114e480..16fd5bc 100644 (file)
@@ -70,4 +70,37 @@ class AddTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
                $this->assertSame(1, $newBlogCount);
        }
 
+       /**
+        * @test
+        */
+       public function addObjectSetsDefaultLanguageTest() {
+               $newBlogTitle = 'aDi1oogh';
+               $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
+               $newBlog->setTitle($newBlogTitle);
+
+               /** @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository $blogRepository */
+               $this->blogRepository->add($newBlog);
+               $this->persistentManager->persistAll();
+
+               $newBlogRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
+               $this->assertEquals(0, $newBlogRecord['sys_language_uid']);
+       }
+
+       /**
+        * @test
+        */
+       public function addObjectSetsDefinedLanguageTest() {
+               $newBlogTitle = 'aDi1oogh';
+               $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
+               $newBlog->setTitle($newBlogTitle);
+               $newBlog->_setProperty('_languageUid', -1);
+
+               /** @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository $blogRepository */
+               $this->blogRepository->add($newBlog);
+               $this->persistentManager->persistAll();
+
+               $newBlogRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
+               $this->assertEquals(-1, $newBlogRecord['sys_language_uid']);
+       }
+
 }