[BUGFIX] Fix SQL error on recursive TypoScript template inclusion 47/40147/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 10 Jun 2015 11:09:16 +0000 (13:09 +0200)
committerBenjamin Mack <benni@typo3.org>
Wed, 17 Jun 2015 17:18:25 +0000 (19:18 +0200)
If TypoScript templates are included recusively (a > b > a), the
$basedOnIds array is empty and creates an invalid SQL query.

Resolves: #64654
Releases: master, 6.2
Change-Id: Ia3001e1e620d6bb4d2d1f3ad016816bc5636dff1
Reviewed-on: http://review.typo3.org/40147
Reviewed-by: Pierrick Caillon <pierrick.caillon@plan-net.fr>
Tested-by: Pierrick Caillon <pierrick.caillon@plan-net.fr>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/core/Classes/TypoScript/TemplateService.php

index c6adb1f..2f0d173 100644 (file)
@@ -659,19 +659,21 @@ class TemplateService {
                if (trim($row['basedOn'])) {
                        // Normal Operation, which is to include the "based-on" sys_templates,
                        // if they are not already included, and maintaining the sorting of the templates
                if (trim($row['basedOn'])) {
                        // Normal Operation, which is to include the "based-on" sys_templates,
                        // if they are not already included, and maintaining the sorting of the templates
-                       $basedOnIds = GeneralUtility::intExplode(',', $row['basedOn']);
+                       $basedOnIds = GeneralUtility::intExplode(',', $row['basedOn'], TRUE);
                        // skip template if it's already included
                        foreach ($basedOnIds as $key => $basedOnId) {
                                if (GeneralUtility::inList($idList, 'sys_' . $basedOnId)) {
                                        unset($basedOnIds[$key]);
                                }
                        }
                        // skip template if it's already included
                        foreach ($basedOnIds as $key => $basedOnId) {
                                if (GeneralUtility::inList($idList, 'sys_' . $basedOnId)) {
                                        unset($basedOnIds[$key]);
                                }
                        }
-                       $subTemplates = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_template', 'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause, '', '', '', 'uid');
-                       // Traversing list again to ensure the sorting of the templates
-                       foreach ($basedOnIds as $id) {
-                               if (is_array($subTemplates[$id])) {
-                                       $this->versionOL($subTemplates[$id]);
-                                       $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
+                       if (!empty($basedOnIds)) {
+                               $subTemplates = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_template', 'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause, '', '', '', 'uid');
+                               // Traversing list again to ensure the sorting of the templates
+                               foreach ($basedOnIds as $id) {
+                                       if (is_array($subTemplates[$id])) {
+                                               $this->versionOL($subTemplates[$id]);
+                                               $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
+                                       }
                                }
                        }
                }
                                }
                        }
                }