[BUGFIX] Prevent PHP errors with missing ColumnMap object
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Wed, 20 Feb 2013 09:47:31 +0000 (10:47 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 4 Mar 2013 11:26:31 +0000 (12:26 +0100)
If the TCA configuration for an object is missing
no ColumnMap object is created by data mapper which leads
to PHP fatal errors in Typo3DbBackend.
Instead an Exception should be thrown.

This is a fixed version of the reverted commit reviewed in
https://review.typo3.org/16536

Releases: 6.0, 6.1
Fixes: #7267
Change-Id: Ie945d2e198c7ef8847a14a9c154c8bf7b8c372cf
Reviewed-on: https://review.typo3.org/18392
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Persistence/Generic/Exception/MissingColumnMapException.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/MissingColumnMapException.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Exception/MissingColumnMapException.php
new file mode 100644 (file)
index 0000000..dfa4396
--- /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!
+ ***************************************************************/
+/**
+ * A "Missing ColumnMap" exception
+ */
+class MissingColumnMapException extends \TYPO3\CMS\Extbase\Persistence\Generic\Exception {
+
+}
+
+?>
\ No newline at end of file
index 6f11536..d305c08 100644 (file)
@@ -689,6 +689,7 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
         * @param array $sql
         * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
         * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidRelationConfigurationException
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException
         */
        protected function addUnionStatement(&$className, &$tableName, &$propertyPath, array &$sql) {
                $explodedPropertyPath = explode('.', $propertyPath, 2);
@@ -696,6 +697,11 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
                $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
                $tableName = $this->dataMapper->convertClassNameToTableName($className);
                $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
+
+               if ($columnMap === NULL) {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException('The ColumnMap for property "' . $propertyName . '" of class "' . $className . '" is missing.', 1355142232);
+               }
+
                $parentKeyFieldName = $columnMap->getParentKeyFieldName();
                $childTableName = $columnMap->getChildTableName();
 
@@ -1233,4 +1239,4 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
        }
 }
 
-?>
+?>
\ No newline at end of file