[+TASK] Extbase (Persistence): findOneBy*() methods should return NULL if no item...
authorBastian Waidelich <bastian@typo3.org>
Wed, 24 Nov 2010 18:56:00 +0000 (18:56 +0000)
committerBastian Waidelich <bastian@typo3.org>
Wed, 24 Nov 2010 18:56:00 +0000 (18:56 +0000)
This resolves: #10958

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

index b2d9b1a..ff9264f 100644 (file)
@@ -157,7 +157,7 @@ class Tx_Extbase_MVC_Controller_Argument {
        }
 
        /**
-        * @param Tx_Extbase_Reflection_Service $reflectionService 
+        * @param Tx_Extbase_Reflection_Service $reflectionService
         * @return void
         */
        public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
@@ -393,7 +393,7 @@ class Tx_Extbase_MVC_Controller_Argument {
         * Finds an object from the repository by searching for its technical UID.
         *
         * @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
+        * @return object Either the object matching the uid or, if none or more than one object was found, NULL
         */
        protected function findObjectByUid($uid) {
                $query = $this->queryFactory->create($this->dataType);
index 3b70ca7..a481784 100644 (file)
@@ -463,9 +463,6 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                        } elseif (strpos($propertyMetaData['type'], '_') !== FALSE) {
                                if (is_object($result) && $result instanceof Tx_Extbase_Persistence_QueryResultInterface) {
                                        $propertyValue = $result->getFirst();
-                                       if ($propertyValue === FALSE) {
-                                               $propertyValue = NULL;
-                                       }
                                } else {
                                        $propertyValue = $result;
                                }
index 9e3f15b..20f7c7e 100644 (file)
@@ -127,13 +127,16 @@ class Tx_Extbase_Persistence_QueryResult implements Tx_Extbase_Persistence_Query
                if (is_array($this->queryResult)) {
                        $queryResult = $this->queryResult;
                        reset($queryResult);
-                       return current($queryResult);
                } else {
                        $query = clone $this->query;
                        $query->setLimit(1);
                        $queryResult = $this->dataMapper->map($this->query->getType(), $this->persistenceManager->getObjectDataByQuery($this->query));
-                       return current($queryResult);
                }
+               $firstResult = current($queryResult);
+               if ($firstResult === FALSE) {
+                       $firstResult = NULL;
+               }
+               return $firstResult;
        }
 
        /**
index e98a359..edb144c 100644 (file)
@@ -307,7 +307,7 @@ class Tx_Extbase_Persistence_Repository implements Tx_Extbase_Persistence_Reposi
                        $object = $query->matching($query->equals('uid', $uid))
                                        ->execute()
                                        ->getFirst();
-                       if ($object !== FALSE) {
+                       if ($object !== NULL) {
                                $this->identityMap->registerObject($object, $uid);
                        }
                }
index f55e8fb..211c50a 100644 (file)
@@ -79,7 +79,7 @@ class Tx_Extbase_Property_Mapper implements t3lib_Singleton {
        protected $queryFactory;
 
        /**
-        * @param Tx_Extbase_Validation_ValidatorResolver $validatorResolver 
+        * @param Tx_Extbase_Validation_ValidatorResolver $validatorResolver
         * @return void
         */
        public function injectValidatorResolver(Tx_Extbase_Validation_ValidatorResolver $validatorResolver) {
@@ -324,7 +324,7 @@ class Tx_Extbase_Property_Mapper implements t3lib_Singleton {
         *
         * @param string $dataType the data type to fetch
         * @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
+        * @return object Either the object matching the uid or, if none or more than one object was found, NULL
         */
        // TODO This is duplicated code; see Argument class
        protected function findObjectByUid($dataType, $uid) {