[~FEATURE] Extbase (MVC): Implemented reverse type mapping for arguments. You can...
authorJochen Rau <j.rau@web.de>
Wed, 21 Apr 2010 13:52:44 +0000 (13:52 +0000)
committerJochen Rau <j.rau@web.de>
Wed, 21 Apr 2010 13:52:44 +0000 (13:52 +0000)
[~TASK] Extbase: Improved error message for missing objects (former "... but was of type NULL").

typo3/sysext/extbase/Classes/MVC/Controller/Argument.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php
typo3/sysext/extbase/Classes/Property/Mapper.php

index 6fb2709..4efa608 100644 (file)
@@ -378,10 +378,12 @@ class Tx_Extbase_MVC_Controller_Argument {
        protected function findObjectByUid($uid) {
                $query = $this->queryFactory->create($this->dataType);
                $query->getQuerySettings()->setRespectSysLanguage(FALSE);
-               $result = $query->matching($query->withUid($uid))->execute();
+               $result = $query->matching($query->equals('uid', $uid))->execute();
                $object = NULL;
                if (count($result) > 0) {
                        $object = current($result);
+               } else {
+                       throw new Tx_Extbase_Persistence_Exception_UnknownObject('The requested object with the identifier "' . $uid . '" was not found.', 1271856793);
                }
                return $object;
        }
index 1a9017b..2c1d902 100644 (file)
@@ -155,14 +155,17 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
         */
        public function getTargetType($className, array $row) {
                $dataMap = $this->getDataMap($className);
-               if ($dataMap->getRecordTypeColumnName() === NULL) return $className;
-               foreach ($dataMap->getSubclasses() as $subclassName) {
-                       $recordSubtype = $this->getDataMap($subclassName)->getRecordType();
-                       if ($row[$dataMap->getRecordTypeColumnName()] === $recordSubtype) {
-                               return $subclassName;
+               $targetType = $className;
+               if ($dataMap->getRecordTypeColumnName() !== NULL) {
+                       foreach ($dataMap->getSubclasses() as $subclassName) {
+                               $recordSubtype = $this->getDataMap($subclassName)->getRecordType();
+                               if ($row[$dataMap->getRecordTypeColumnName()] === $recordSubtype) {
+                                       $targetType =  $subclassName;
+                                       break;
+                               }
                        }
                }
-               return $className;
+               return $targetType;
        }
        
        /**
index dc0e8a2..a2c85bb 100644 (file)
@@ -82,6 +82,7 @@ class Tx_Extbase_Property_Mapper {
         * Constructs the Property Mapper.
         */
        public function __construct() {
+               // TODO Clean up this dependencies; inject the instance
                $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_Manager');
                $this->validatorResolver = t3lib_div::makeInstance('Tx_Extbase_Validation_ValidatorResolver');
                $this->validatorResolver->injectObjectManager($objectManager);
@@ -310,6 +311,7 @@ class Tx_Extbase_Property_Mapper {
         * @param int $uid The object's uid
         * @return mixed Either the object matching the uid or, if none or more than one object was found, FALSE
         */
+       // TODO This is duplicated code; see Argument class
        protected function findObjectByUid($dataType, $uid) {
                $query = $this->queryFactory->create($dataType);
                $query->getQuerySettings()->setRespectSysLanguage(FALSE);
@@ -317,6 +319,8 @@ class Tx_Extbase_Property_Mapper {
                $object = NULL;
                if (count($result) > 0) {
                        $object = current($result);
+               } else {
+                       throw new Tx_Extbase_Persistence_Exception_UnknownObject('The requested object with the identifier "' . $uid . '" was not found.', 1271856793);
                }
                return $object;
        }