[BUGFIX] Use less memory in CLI lowlevel_refindex
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Database / ReferenceIndex.php
index a9dba67..623c8d7 100644 (file)
@@ -1091,8 +1091,8 @@ class ReferenceIndex {
                        }
                        // Traverse all records in tables, including deleted records:
                        $fieldNames = (BackendUtility::isTableWorkspaceEnabled($tableName) ? 'uid,t3ver_wsid' : 'uid');
-                       $allRecs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fieldNames, $tableName, '1=1');
-                       if (!is_array($allRecs)) {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldNames, $tableName, '1=1');
+                       if ($GLOBALS['TYPO3_DB']->sql_error()) {
                                // Table exists in $TCA but does not exist in the database
                                GeneralUtility::sysLog(sprintf('Table "%s" exists in $TCA but does not exist in the database. You should run the Database Analyzer in the Install Tool to fix this.', $tableName), 'core', GeneralUtility::SYSLOG_SEVERITY_ERROR);
                                continue;
@@ -1100,7 +1100,7 @@ class ReferenceIndex {
                        $tableNames[] = $tableName;
                        $tableCount++;
                        $uidList = array(0);
-                       foreach ($allRecs as $recdat) {
+                       while ($recdat = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                /** @var $refIndexObj ReferenceIndex */
                                $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
                                if (isset($recdat['t3ver_wsid'])) {
@@ -1117,6 +1117,8 @@ class ReferenceIndex {
                                        }
                                }
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
                        // Searching lost indexes for this table:
                        $where = 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tableName, 'sys_refindex') . ' AND recuid NOT IN (' . implode(',', $uidList) . ')';
                        $lostIndexes = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('hash', 'sys_refindex', $where);