[BUGFIX] _languageUid property not set on insert 27/43427/2
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:35:25 +0000 (20:35 +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: I57c4834f7e77644620831abeeb2bc2e644f95395
Reviewed-on: http://review.typo3.org/43427
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 98a3783..a4e6b42 100644 (file)
@@ -633,8 +633,9 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                $dataMap = $this->dataMapper->getDataMap(get_class($object));
                $row = array();
                $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 ($parentObject !== NULL && $parentPropertyName) {
                        $parentColumnDataMap = $this->dataMapper->getDataMap(get_class($parentObject))->getColumnMap($parentPropertyName);
index 277ebc1..21e1ef9 100644 (file)
@@ -70,4 +70,38 @@ class AddTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
                $newBlogCount = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
                $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']);
+       }
+
 }