[BUGFIX] FAL storage repo uses hard-coded enableFields
authorBenjamin Mack <benni@typo3.org>
Tue, 9 Oct 2012 14:27:34 +0000 (16:27 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Wed, 10 Oct 2012 07:37:19 +0000 (09:37 +0200)
The storage repository has hardcoded SQL where clauses
for deleted and hidden.
Solution: Create a new function that returns the additional
where clause, based on the frontend / backend context.

Change-Id: I6258ee639d4cc8d97a9712596baeb86ea1e576b6
Resolves: #41715
Releases: 6.0
Reviewed-on: http://review.typo3.org/15445
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Resource/StorageRepository.php

index 4eeb23e..6eeec4c 100644 (file)
@@ -59,9 +59,12 @@ class StorageRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
         */
        public function findByStorageType($storageType) {
                $storageObjects = array();
-               $whereClause = 'deleted=0 AND hidden=0';
-               $whereClause .= ' AND ' . $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($storageType, $this->table);
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->table, $whereClause);
+               $whereClause = $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($storageType, $this->table);
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       '*',
+                       $this->table,
+                       $whereClause . $this->getWhereClauseForEnabledFields()
+               );
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $storageObjects[] = $this->createDomainObject($row);
                }
@@ -77,11 +80,15 @@ class StorageRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
         */
        public function findAll() {
                $storageObjects = array();
-               $whereClause = 'deleted=0 AND hidden=0';
+               $whereClause = NULL;
                if ($this->type != '') {
-                       $whereClause .= ' AND ' . $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table);
+                       $whereClause = $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table);
                }
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->table, $whereClause);
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       '*',
+                       $this->table,
+                       ($whereClause ? $whereClause : '1=1') . $this->getWhereClauseForEnabledFields()
+               );
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $storageObjects[] = $this->createDomainObject($row);
                }
@@ -144,6 +151,22 @@ class StorageRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
                return $this->factory->getStorageObject($databaseRow['uid'], $databaseRow);
        }
 
+       /**
+        * get the WHERE clause for the enabled fields of this TCA table
+        * depending on the context
+        *
+        * @return string the additional where clause, something like " AND deleted=0 AND hidden=0"
+        */
+       protected function getWhereClauseForEnabledFields() {
+               if (is_object($GLOBALS['TSFE'])) {
+                       // frontend context
+                       $whereClause = $GLOBALS['TSFE']->sys_page->enableFields($this->table);
+               } else {
+                       // backend context
+                       $whereClause = \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($this->table);
+               }
+               return $whereClause;
+       }
 }