[BUGFIX] Prevent sql errors with unsupported relation
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Sat, 17 Nov 2012 16:59:08 +0000 (17:59 +0100)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Mon, 19 Nov 2012 13:42:25 +0000 (14:42 +0100)
Using passthrough as relation causes sql errors
in the addUnionStatement of Typo3DbBackend. To
prevent this an Exception is introduced which will
be thrown instead.

Fixes: #27057
Releases: 6.0
Change-Id: I3e57d2b8c290e8f8b445278a3a25ffef15adbeb5
Reviewed-on: http://review.typo3.org/16537
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Tomasz Grzemski
Tested-by: Tomasz Grzemski
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
typo3/sysext/extbase/Classes/Persistence/Generic/Exception/InvalidRelationConfigurationException.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php

diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Exception/InvalidRelationConfigurationException.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Exception/InvalidRelationConfigurationException.php
new file mode 100644 (file)
index 0000000..72b4fbb
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+namespace TYPO3\CMS\Extbase\Persistence\Generic\Exception;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  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 textfile 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!
+ ***************************************************************/
+/**
+ * An "InvalidRelationConfigurationException" exception
+ */
+class InvalidRelationConfigurationException extends \TYPO3\CMS\Extbase\Persistence\Generic\Exception {
+
+}
+
+?>
\ No newline at end of file
index a2e6090..2518698 100644 (file)
@@ -679,6 +679,7 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
         * @param $propertyPath
         * @param array $sql
         * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidRelationConfigurationException
         */
        protected function addUnionStatement(&$className, &$tableName, &$propertyPath, array &$sql) {
                $explodedPropertyPath = explode('.', $propertyPath, 2);
@@ -688,6 +689,11 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
                $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
                $parentKeyFieldName = $columnMap->getParentKeyFieldName();
                $childTableName = $columnMap->getChildTableName();
+
+               if ($childTableName === NULL) {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidRelationConfigurationException('The relation information for property "' . $propertyName . '" of class "' . $className . '" is missing.', 1353170925);
+               }
+
                if ($columnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_ONE) {
                        if (isset($parentKeyFieldName)) {
                                $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;