[BUGFIX] No content in workspace preview when using select.selectFields
authorTolleiv Nietsch <info@tolleiv.de>
Mon, 10 Oct 2011 01:32:02 +0000 (03:32 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Mon, 12 Mar 2012 16:30:13 +0000 (17:30 +0100)
The TypoScript property select.selectFields does not consider workspaces
in the frontend rendering process.

Taking the results from #29783 into account.

Change-Id: I6b2b68ed03163e9e0d7dd281aafea8af67fec224
Resolves: #17284
Releases: 4.6, 4.5, 4.4
Reviewed-on: http://review.typo3.org/4950
Reviewed-by: Oliver Hader
Reviewed-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/cms/tslib/class.tslib_content.php

index 0e555ad..3c24f69 100644 (file)
@@ -7463,7 +7463,11 @@ class tslib_cObj {
                $queryParts = $this->getWhere($table, $conf, TRUE);
 
                        // Fields:
-               $queryParts['SELECT'] = $conf['selectFields'] ? $conf['selectFields'] : '*';
+               if ($conf['selectFields']) {
+                       $queryParts['SELECT'] = self::sanitizeSelectPart($conf['selectFields'], $table);
+               } else {
+                       $queryParts['SELECT'] = '*';
+               }
 
                        // Setting LIMIT:
                if ($conf['max'] || $conf['begin']) {
@@ -7640,6 +7644,47 @@ class tslib_cObj {
        }
 
        /**
+        * Helper function for getQuery, sanitizing the select part
+        *
+        * This functions checks if the necessary fields are part of the select
+        * and adds them if necessary.
+        *
+        * @param string        select part
+        * @param string        table to select from
+        * @return string       sanitized select part
+        * @access private
+        * @see getQuery
+        */
+       protected function sanitizeSelectPart($selectPart, $table) {
+               // pattern matching parts
+               $matchStart = '/(^\s*|,\s*|' . $table . '\.)';
+               $matchEnd = '(\s*,|\s*$)/';
+
+               $necessaryFields = array('uid', 'pid');
+               $wsFields = array('t3ver_state');
+
+               if (isset($GLOBALS['TCA'][$table]) && strpos($selectPart, '*')!== FALSE) {
+                       foreach ($necessaryFields as $field) {
+                               $match = $matchStart . $field . $matchEnd;
+                               if (!preg_match($match, $selectPart)) {
+                                       $selectPart .= ', ' . $table . '.' . $field . ' as ' . $field;
+                               }
+                       }
+
+                       if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
+                               foreach ($wsFields as $field) {
+                                       $match = $matchStart . $field . $matchEnd;
+                                       if (!preg_match($match, $selectPart)) {
+                                               $selectPart .= ', ' . $table . '.' . $field . ' as ' . $field;
+                                       }
+                               }
+                       }
+               }
+               return $selectPart;
+       }
+
+
+       /**
         * Removes Page UID numbers from the input array which are not available due to enableFields() or the list of bad doktype numbers ($this->checkPid_badDoktypeList)
         *
         * @param       array           array of Page UID numbers for select and for which pages with enablefields and bad doktypes should be removed.