[BUGFIX] findByUid should respect query settings of repository 71/21171/5
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Fri, 31 May 2013 08:51:11 +0000 (10:51 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 13 Jun 2013 09:52:34 +0000 (11:52 +0200)
Prior to 6.1 findByUid built its own query which respected
the settings of its repository. Now findByUid just fetches
the object from the persistence manager which builds its own
query without respecting the query setting of the repository.

This leads to the error that the user isn't able to fetch
hidden records by uid any more. Therefore the
old behaviour of the repository must be used.
An according deprecation hint is added.

Releases: 6.2, 6.1
Resolves: #48571
Change-Id: Ic9a48d5d06f20b2ab8032c39eecb89cd52f898af
Reviewed-on: https://review.typo3.org/21171
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Persistence/Repository.php

index aeddf95..b3bbfc5 100644 (file)
@@ -239,7 +239,7 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
         * @api
         */
        public function findByUid($uid) {
-               return $this->persistenceManager->getObjectByIdentifier($uid, $this->objectType);
+               return $this->findByIdentifier($uid);
        }
 
        /**
@@ -250,7 +250,30 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
         * @api
         */
        public function findByIdentifier($identifier) {
-               return $this->persistenceManager->getObjectByIdentifier($identifier, $this->objectType);
+               /**
+                * @todo: This method must be changed again in 6.2 + 1
+                * This is marked @deprecated to be found in cleanup sessions.
+                *
+                * The repository should directly talk to the backend which
+                * does not respect query settings of the repository as
+                * findByIdentifier is strictly defined by finding an
+                * undeleted object by its identifier regardless if it
+                * is hidden/visible or a versioning/translation overlay.
+                *
+                * As a consequence users will be forced to overwrite this method
+                * and mimic this behaviour to be able to find objects by identifier
+                * respecting their query settings from 6.1 + 1 on.
+                */
+               if ($this->session->hasIdentifier($identifier, $this->objectType)) {
+                       $object = $this->session->getObjectByIdentifier($identifier, $this->objectType);
+               } else {
+                       $query = $this->createQuery();
+                       $query->getQuerySettings()->setRespectStoragePage(FALSE);
+                       $query->getQuerySettings()->setRespectSysLanguage(FALSE);
+                       $object = $query->matching($query->equals('uid', $identifier))->execute()->getFirst();
+               }
+
+               return $object;
        }
 
        /**