[BUGFIX] Use fallback for source link in wildcard redirects 55/55455/9
authorJigal van Hemert <jigal.van.hemert@typo3.org>
Thu, 25 Jan 2018 11:45:38 +0000 (12:45 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Sat, 27 Jan 2018 14:43:33 +0000 (15:43 +0100)
If a wildcard source host is used in a redirect record the link in
the list of redirects the view domain for the first page in the
page tree is used now.

Resolves: #83658
Releases: master
Change-Id: Id7d64711c359ad744639ebd7159581ad606bf097
Reviewed-on: https://review.typo3.org/55455
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Reiner Teubner <rteubner@me.com>
Tested-by: Reiner Teubner <rteubner@me.com>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/redirects/Classes/Controller/ManagementController.php
typo3/sysext/redirects/Classes/Service/UrlService.php [new file with mode: 0644]
typo3/sysext/redirects/Resources/Private/Templates/Management/Overview.html

index 0bff003..db8aebd 100644 (file)
@@ -28,6 +28,7 @@ use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Redirects\Service\RedirectCacheService;
+use TYPO3\CMS\Redirects\Service\UrlService;
 use TYPO3Fluid\Fluid\View\ViewInterface;
 
 /**
@@ -96,7 +97,12 @@ class ManagementController
         $this->getButtons();
 
         $redirects = GeneralUtility::makeInstance(RedirectCacheService::class)->getAllRedirects();
-        $this->view->assign('redirects', $redirects);
+        $defaultUrl = GeneralUtility::makeInstance(UrlService::class)->getDefaultUrl();
+
+        $this->view->assignMultiple([
+            'redirects' => $redirects,
+            'defaultUrl' => $defaultUrl,
+        ]);
     }
 
     /**
diff --git a/typo3/sysext/redirects/Classes/Service/UrlService.php b/typo3/sysext/redirects/Classes/Service/UrlService.php
new file mode 100644 (file)
index 0000000..eda9f96
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Redirects\Service;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Service for URL-related data
+ */
+class UrlService
+{
+    /**
+     * Retrieves the first valid URL
+     *
+     * @return string a URL like "http://example.org"
+     */
+    public function getDefaultUrl(): string
+    {
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
+        $firstPageInTree = $connection->select(['uid'], 'pages', ['pid' => 0], [], ['sorting' => 'ASC'], 1)->fetchColumn(0);
+        $url = BackendUtility::getViewDomain($firstPageInTree);
+
+        return $url;
+    }
+}
index 99b7d1c..333f5a4 100644 (file)
@@ -7,7 +7,7 @@
 
 <f:section name="content">
        <f:if condition="{redirects -> f:count()}">
-               <f:then><f:render section="table" arguments="{redirects: redirects}" /></f:then>
+               <f:then><f:render section="table" arguments="{_all}" /></f:then>
                <f:else>
                        <f:be.infobox state="-1" title="{f:translate(key: 'LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:redirect_not_found.title')}">
                                <p><f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:redirect_not_found.message"/></p>
@@ -52,7 +52,7 @@
                                                                                </f:if>
                                                                                <core:iconForRecord table="sys_redirect" row="{redirect}" /></span>
                                                                                </f:alias>
-                                                                               <strong><f:link.external uri="{redirect.source_host}{redirect.source_path}" target="_blank">{redirect.source_path}</f:link.external></strong>
+                                                                               <strong><f:link.external uri="{f:if(condition: '{redirect.source_host} == \'*\'', then: defaultUrl, else: redirect.source_host)}{redirect.source_path}" target="_blank">{redirect.source_path}</f:link.external></strong>
                                                                        </td>
                                                                        <td><f:link.typolink parameter="{redirect.target}" target="_blank"><f:uri.typolink parameter="{redirect.target}"></f:uri.typolink></f:link.typolink> (<f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:destination_status_code"/>: {redirect.target_statuscode})</td>
                                                                        <td>