[TASK] Rework pseudo-site backend preview url generation 82/58182/5
authorBenjamin Franzke <bfr@qbus.de>
Tue, 4 Sep 2018 09:25:43 +0000 (11:25 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 7 Sep 2018 19:03:37 +0000 (21:03 +0200)
When there is no site configuration, no TCEMAN.preview
configuration and no sys_domain record available, the host
URL needs to be derived from TYPO3_SITE_URL.

This recently broke (and was fixed). Due to wrong logic
the protocol was added twice, resulting in URLs like:

http://http://hostname.tld/

It initially broke due to the site handling features, probably
with https://review.typo3.org/57949
A condition became dead, due to $domain being always set,
when it was null before that change (if a sys_domain record
could not be found).

The bug was fixed by adding an additional condition (without
removing the dead "else" condition) in https://review.typo3.org/c/58177/

This patch tries to clean this up by removing the new condition
(introduced in #58177) and rather restructure the code.

To circumvent those bugs and to avoid confusion what $domain
actually refers to (now always including the protocol) the
code is refactored to not re-assign $domain over and over again.

Change-Id: I155db1b91357bb6345da1ef469d32b0125344b16
Releases: master
Resolves: #86140
Reviewed-on: https://review.typo3.org/58182
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index 0733c71..c923644 100644 (file)
@@ -2827,6 +2827,7 @@ class BackendUtility
         if (!empty($rootLine)) {
             $protocol = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https' : 'http';
             $previewDomainConfig = self::getPagesTSconfig($pageId)['TCEMAIN.']['previewDomain'] ?? '';
+            $domainName = null;
             if (!empty($previewDomainConfig)) {
                 if (strpos($previewDomainConfig, '://') !== false) {
                     list($protocol, $domainName) = explode('://', $previewDomainConfig);
@@ -2843,9 +2844,7 @@ class BackendUtility
                     }
                 }
             }
-            if ($domainName) {
-                $domain = $domainName;
-            } else {
+            if ($domainName === null) {
                 // Fetch the "sys_domain" record: First, check for the given domain,
                 // and find the "root page" = PseudoSite to that domain, then fetch the first
                 // available sys_domain record.
@@ -2853,17 +2852,13 @@ class BackendUtility
                 $result = $siteMatcher->matchRequest(new ServerRequest($domain));
                 $site = $result->getSite();
                 if ($site instanceof PseudoSite) {
-                    $domain = (string)$site->getBase();
-                    $domain = ltrim($domain, '/');
+                    $domainName = (string)$site->getBase();
+                    $domainName = ltrim($domainName, '/');
                 }
             }
-            if ($domain) {
-                // prepend the current protocol, if none is given
-                if (!parse_url($domain, PHP_URL_SCHEME)) {
-                    $domain = $protocol . '://' . $domain;
-                }
-            } else {
-                $domain = rtrim(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'), '/');
+
+            if ($domainName) {
+                $domain = $protocol . '://' . $domainName;
             }
             // Append port number if lockSSLPort is not the standard port 443
             $portNumber = (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'];