[TASK] Decouple record fetching from ContentContentObject 81/41681/4
authorPatrick Broens <patrick@patrickbroens.nl>
Sat, 18 Jul 2015 14:48:16 +0000 (16:48 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 20 Jul 2015 16:09:32 +0000 (18:09 +0200)
The content object CONTENT has a construct to fetch records from the
database overlaying version and language. This functionality can be
used for multiple purposes and for that needs to be moved to the
ContentObjectRenderer.

This patch is taking out this functionality and puts it in
ContentObjectRenderer

Change-Id: If8dca3490497da1a9f400d6979985a52f0fdd202
Resolves: #68342
Releases: master
Reviewed-on: http://review.typo3.org/41681
Reviewed-by: Stefan Froemken <froemken@gmail.com>
Tested-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

index 2a75bc1..024e754 100644 (file)
@@ -66,56 +66,37 @@ class ContentContentObject extends AbstractContentObject {
                $again = FALSE;
                $tmpValue = '';
                $cobjValue = '';
-               $databaseConnection = $this->getDatabaseConnection();
+
                do {
-                       $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
-                       if ($error = $databaseConnection->sql_error()) {
-                               $this->getTimeTracker()->setTSlogMessage($error, 3);
-                       } else {
-                               $this->cObj->currentRecordTotal = $databaseConnection->sql_num_rows($res);
-                               $this->getTimeTracker()->setTSlogMessage('NUMROWS: ' . $databaseConnection->sql_num_rows($res));
+                       $records = $this->cObj->getRecords($conf);
+                       if (!empty($records)) {
+                               $this->cObj->currentRecordTotal = count($records);
+                               $this->getTimeTracker()->setTSlogMessage('NUMROWS: ' .  count($records));
+
                                /** @var $cObj ContentObjectRenderer */
                                $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
                                $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
                                $this->cObj->currentRecordNumber = 0;
                                $cobjValue = '';
-                               while (($row = $databaseConnection->sql_fetch_assoc($res)) !== FALSE) {
-                                       // Versioning preview:
-                                       $frontendController->sys_page->versionOL($conf['table'], $row, TRUE);
-                                       // Language overlay:
-                                       if (is_array($row) && $frontendController->sys_language_contentOL) {
-                                               if ($conf['table'] == 'pages') {
-                                                       $row = $frontendController->sys_page->getPageOverlay($row);
-                                               } else {
-                                                       $row = $frontendController->sys_page->getRecordOverlay(
-                                                               $conf['table'],
-                                                               $row,
-                                                               $frontendController->sys_language_content,
-                                                               $frontendController->sys_language_contentOL
-                                                       );
+
+                               foreach ($records as $row) {
+                                       // Call hook for possible manipulation of database row for cObj->data
+                                       if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
+                                               foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
+                                                       $_procObj = GeneralUtility::getUserObj($_classRef);
+                                                       $_procObj->modifyDBRow($row, $conf['table']);
                                                }
                                        }
-                                       // Might be unset in the sys_language_contentOL
-                                       if (is_array($row)) {
-                                               // Call hook for possible manipulation of database row for cObj->data
-                                               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
-                                                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
-                                                               $_procObj = GeneralUtility::getUserObj($_classRef);
-                                                               $_procObj->modifyDBRow($row, $conf['table']);
-                                                       }
-                                               }
-                                               if (!$frontendController->recordRegister[($conf['table'] . ':' . $row['uid'])]) {
-                                                       $this->cObj->currentRecordNumber++;
-                                                       $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
-                                                       $frontendController->currentRecord = $conf['table'] . ':' . $row['uid'];
-                                                       $this->cObj->lastChanged($row['tstamp']);
-                                                       $cObj->start($row, $conf['table']);
-                                                       $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
-                                                       $cobjValue .= $tmpValue;
-                                               }
+                                       if (!$frontendController->recordRegister[($conf['table'] . ':' . $row['uid'])]) {
+                                               $this->cObj->currentRecordNumber++;
+                                               $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
+                                               $frontendController->currentRecord = $conf['table'] . ':' . $row['uid'];
+                                               $this->cObj->lastChanged($row['tstamp']);
+                                               $cObj->start($row, $conf['table']);
+                                               $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
+                                               $cobjValue .= $tmpValue;
                                        }
                                }
-                               $databaseConnection->sql_free_result($res);
                        }
                        if ($slideCollectReverse) {
                                $theValue = $cobjValue . $theValue;
index df9fc0c..3eefefa 100755 (executable)
@@ -7835,6 +7835,52 @@ class ContentObjectRenderer {
        }
 
        /**
+        * Executes a SELECT query for records from $table and with conditions based on the configuration in the $conf array
+        * and overlays with translation and version if available
+        *
+        * @param array $configuration The TypoScript configuration properties
+        * @return array The records
+        */
+       public function getRecords(array $configuration) {
+               $records = [];
+
+               $res = $this->exec_getQuery($configuration['table'], $configuration['select.']);
+
+               if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
+                       $GLOBALS['TT']->setTSlogMessage($error, 3);
+
+               } else {
+                       while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
+
+                               // Versioning preview:
+                               $GLOBALS['TSFE']->sys_page->versionOL($configuration['table'], $row, TRUE);
+
+                               // Language overlay:
+                               if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
+                                       if ($configuration['table'] === 'pages') {
+                                               $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
+                                       } else {
+                                               $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay(
+                                                       $configuration['table'],
+                                                       $row,
+                                                       $GLOBALS['TSFE']->sys_language_content,
+                                                       $GLOBALS['TSFE']->sys_language_contentOL
+                                               );
+                                       }
+                               }
+
+                               // Might be unset in the sys_language_contentOL
+                               if (is_array($row)) {
+                                       $records[] = $row;
+                               }
+                       }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+               }
+
+               return $records;
+       }
+
+       /**
         * Creates and returns a SELECT query for records from $table and with conditions based on the configuration in the $conf array
         * Implements the "select" function in TypoScript
         *