[BUGFIX] Added handling for array in findOneByXXX result
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Repository.php
index 1c8302d..89cc889 100644 (file)
@@ -403,8 +403,14 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
                } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) {
                        $propertyName = lcfirst(substr($methodName, 9));
                        $query = $this->createQuery();
                } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) {
                        $propertyName = lcfirst(substr($methodName, 9));
                        $query = $this->createQuery();
-                       $object = $query->matching($query->equals($propertyName, $arguments[0]))->setLimit(1)->execute()->getFirst();
-                       return $object;
+
+                       $result = $query->matching($query->equals($propertyName, $arguments[0]))->setLimit(1)->execute();
+                       if ($result instanceof \TYPO3\CMS\Extbase\Persistence\QueryResultInterface) {
+                               return $result->getFirst();
+                       } elseif (is_array($result)) {
+                               return isset($result[0]) ? $result[0] : NULL;
+                       }
+
                } elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) {
                        $propertyName = lcfirst(substr($methodName, 7));
                        $query = $this->createQuery();
                } elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) {
                        $propertyName = lcfirst(substr($methodName, 7));
                        $query = $this->createQuery();