[BUGFIX] Check WorkspaceEnabled for MM field related table 83/28783/9
authorSebastian Lechenbauer <email@lechenbauer.de>
Tue, 25 Mar 2014 16:55:21 +0000 (17:55 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Wed, 26 Mar 2014 09:37:10 +0000 (10:37 +0100)
If you try to edit a MM field associated to a table which doesn't use
versioning (t3ver_* fields are missing) you get a database error.
This patch adds a check if versioning for the table is enabled.

Resolves: #57291
Releases: 6.2
Change-Id: I3fc5dfeb77ce9a67a6e4494a3b2247c3007d0d25
Reviewed-on: https://review.typo3.org/28783
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/core/Classes/Database/RelationHandler.php
typo3/sysext/core/Tests/Unit/Database/RelationHandlerTest.php [new file with mode: 0644]

index f2b0182..de85f5c 100644 (file)
@@ -1166,9 +1166,10 @@ class RelationHandler {
                }
 
                foreach ($this->tableArray as $itemTableName => $itemIds) {
-                       if (!count($itemIds)) {
+                       if (!count($itemIds) || !BackendUtility::isTableWorkspaceEnabled($itemTableName)) {
                                continue;
                        }
+
                        $purgedItemIds = call_user_func(array($this, $purgeCallback), $itemTableName, $itemIds);
                        $removedItemIds = array_diff($itemIds, $purgedItemIds);
                        foreach ($removedItemIds as $removedItemId) {
diff --git a/typo3/sysext/core/Tests/Unit/Database/RelationHandlerTest.php b/typo3/sysext/core/Tests/Unit/Database/RelationHandlerTest.php
new file mode 100644 (file)
index 0000000..2e94597
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Database;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Klaas Johan Kooistra <k.kooistra@drecomm.nl>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the text file GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Test case for \TYPO3\CMS\Core\Database\RelationHandler
+ */
+class RelationHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Database\RelationHandler
+        */
+       protected $fixture;
+
+       /**
+        * @return void
+        */
+       public function setUp() {
+               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Database\\RelationHandler', array('purgeVersionedIds', 'purgeLiveVersionedIds'));
+       }
+
+       /**
+        * @return void
+        */
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       /**
+        * @test
+        */
+       public function purgeItemArrayReturnsFalseIfVersioningForTableIsDisabled() {
+               $GLOBALS['TCA']['sys_category']['ctrl']['versioningWS'] = FALSE;
+
+               $this->fixture->tableArray = array(
+                       'sys_category' => array(1, 2, 3),
+               );
+
+               $this->assertFalse($this->fixture->purgeItemArray(0));
+       }
+
+       /**
+        * @test
+        */
+       public function purgeItemArrayReturnsTrueIfItemsHaveBeenPurged() {
+               $GLOBALS['TCA']['sys_category']['ctrl']['versioningWS'] = 2;
+
+               $this->fixture->tableArray = array(
+                       'sys_category' => array(1, 2, 3),
+               );
+
+               $this->fixture->expects($this->once())
+                       ->method('purgeVersionedIds')
+                       ->with('sys_category', array(1, 2, 3))
+                       ->will($this->returnValue(array(2)));
+
+               $this->assertTrue($this->fixture->purgeItemArray(0));
+       }
+}
\ No newline at end of file